Skip to content

Commit 43bcc37

Browse files
author
Eric Neuhaus
committed
Added handling for user role assignment
1 parent 44617e4 commit 43bcc37

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

QuickProjects.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ public function generateProject() {
5757

5858
session_start();
5959

60-
error_log('test');
61-
6260
global $conn;
6361
if (!isset($conn))
6462
{
6563
db_connect(false);
6664
}
6765

68-
error_log($_REQUEST['token']);
69-
7066
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
7167
self::returnResultMessage(["ERROR: The requested method is not implemented."], null);
7268
}
@@ -292,6 +288,32 @@ public function generateProject() {
292288
$reservedPID = db_fetch_assoc($result)['project_id'];
293289
}
294290

291+
// assign to roles if necessary
292+
foreach ($users as $index=>$user) {
293+
$rightsLookup = $rights[$index];
294+
295+
$role_name = $permissionsPresets[$rightsLookup]['data']['assign_manual_role'];
296+
297+
if ($role_name != '') {
298+
$project_id = $reservedPID;
299+
300+
$sql = "select role_id from redcap_user_roles where role_name = '$role_name' and project_id = $project_id";
301+
302+
$role_id = db_fetch_assoc(db_query($sql))['role_id'];
303+
304+
$sql = "insert into redcap_user_rights (project_id, username, role_id) values ($project_id, '" . db_escape($user) . "', " . checkNull($role_id) . ")
305+
on duplicate key update role_id = $role_id";
306+
if (db_query($sql)) {
307+
// Logging (if user was created)
308+
if (db_affected_rows() === 1) {
309+
\REDCap::logEvent("Created User\n<font color=\"#000066\">(Quick Projects)</font>", 'user = \'' . $user . '\'', NULL, NULL, NULL, $project_id);
310+
}
311+
// Logging for user assignment
312+
\REDCap::logEvent("Assign user to role\n<font color=\"#000066\">(Quick Projects)</font>", "user = '$user',\nrole = '$role_name'", NULL, NULL, NULL, $project_id);
313+
}
314+
}
315+
}
316+
295317
if ($_REQUEST['method'] == 'create' && $_REQUEST['return'] == 'publicSurveyLink') {
296318
$result = db_query('select event_id from redcap_events_metadata
297319
left join redcap_events_arms on redcap_events_metadata.arm_id = redcap_events_arms.arm_id

0 commit comments

Comments
 (0)