Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ownership): creators are owners, too #2721

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion www/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,17 @@ if (strlen($id)) {
$testDate = strftime('%x %X', (int)$test['testinfo']['completed'] + ($tz_offset * 60));
}

$creator_id = 0;
if (!is_null($request_context->getUser())) {
$creator_id = $request_context->getUser()->getUserId() ?? 0;
}

// $owner is set by CP details in AttachUser middleware if loaded
$owner_id_matches_test = array_key_exists('owner', $test['testinfo']) && strlen($owner) && $owner == $test['testinfo']['owner'];
$uid_matches_test = array_key_exists('uid', $test['testinfo']) && isset($uid) && strlen($uid) && $uid == $test['testinfo']['uid'];
$creator_id_matches_test = array_key_exists('creator', $test['testinfo']) && ($creator_id == $test['testinfo']['creator']);

$isOwner = $owner_id_matches_test || $uid_matches_test;
$isOwner = $owner_id_matches_test || $uid_matches_test || $creator_id_matches_test;
$test_is_private = array_key_exists('private', $test['testinfo']) && !!$test['testinfo']['private'];

if ($test_is_private && !$isOwner) {
Expand Down
11 changes: 11 additions & 0 deletions www/runtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,14 @@
$test['owner'] = $request_context->getUser()->getOwnerId();
}

$creator_id = 0;
if (!is_null($request_context->getUser())) {
$creator_id = $request_context->getUser()->getUserId() ?? 0;
}
if ($creator_id != 0) {
$test["creator"] = $creator_id;
}

if (isset($user) && !array_key_exists('user', $test)) {
$test['user'] = $user;
}
Expand Down Expand Up @@ -2742,6 +2750,9 @@ function CreateTest(&$test, $url, $batch = 0, $batch_locations = 0)
if (isset($test['owner']) && strlen($test['owner'])) {
AddIniLine($testInfo, "owner", $test['owner']);
}
if (!empty($test["creator"])) {
AddIniLine($testInfo, "creator", $test["creator"]);
}
if (isset($test['type']) && strlen($test['type'])) {
AddIniLine($testInfo, "type", $test['type']);
}
Expand Down