From f0c7d8cdd487d0649070bbea16937f5567d97ca4 Mon Sep 17 00:00:00 2001 From: Jeffrey Lembeck Date: Mon, 27 Feb 2023 13:53:46 -0800 Subject: [PATCH 1/2] fix(testinfo): add creator field to file This has the user who created the test. This isn't always the owner! Sometimes this is different in our system and this can cause an issue with private tests given how we check for an owner --- www/runtest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/www/runtest.php b/www/runtest.php index be9d972a01..b820c56f2f 100644 --- a/www/runtest.php +++ b/www/runtest.php @@ -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; } @@ -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']); } From fa7f3eae241f971843db255db5e8894a738ad5b0 Mon Sep 17 00:00:00 2001 From: Jeffrey Lembeck Date: Mon, 27 Feb 2023 15:46:07 -0800 Subject: [PATCH 2/2] fix(ownership): creators are owners, too Previously, only owners were owners, but also sometimes the creator of the test does not line up as the owner. This is a fix for that --- www/common.inc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/www/common.inc b/www/common.inc index 763162c751..ef926fac1c 100644 --- a/www/common.inc +++ b/www/common.inc @@ -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) {