Skip to content
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
16 changes: 9 additions & 7 deletions test/functional/WorkerUnityCourseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

class WorkerUnityCourseTest extends UnityWebPortalTestCase
{
private static string $course_id = "cs124";
private static string $course_org = "org1_test";
private static string $course_owner_uid = "cs124_org1_test";
private static string $course_gid = "pi_cs124_org1_test";
private static array $course_owner_name = ["cs124", "Fall 2025"];
private static string $course_semester = "Fall 2025";
private static string $test1_manager_uid = "user2_org1_test";
private static array $test2_manager_uids = ["user2_org1_test", "user1_org1_test"];
private static string $test2_manager_uids_str = " user2_org1_test , user1_org1_test , ,,, user2_org1_test ";
Expand All @@ -23,9 +25,9 @@ public function testCreateCourse()
$this->assertFalse($pi_group_entry->exists());
$this->assertFalse($owner_user_entry->exists());
$stdin_file = writeLinesToTmpFile([
self::$course_owner_name[0],
self::$course_owner_name[1],
self::$course_owner_uid,
self::$course_id,
self::$course_semester,
self::$course_org,
self::$test1_manager_uid,
]);
$stdin_file_path = getPathFromFileHandle($stdin_file);
Expand Down Expand Up @@ -62,9 +64,9 @@ public function testCreateCourseMultipleManagers()
$this->assertFalse($pi_group_entry->exists());
$this->assertFalse($owner_user_entry->exists());
$stdin_file = writeLinesToTmpFile([
self::$course_owner_name[0],
self::$course_owner_name[1],
self::$course_owner_uid,
self::$course_id,
self::$course_semester,
self::$course_org,
self::$test2_manager_uids_str,
]);
$stdin_file_path = getPathFromFileHandle($stdin_file);
Expand Down
20 changes: 8 additions & 12 deletions workers/unity-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
use UnityWebPortal\lib\UnityOrg;
use UnityWebPortal\lib\UserFlag;

function cn2org($cn)
{
$matches = [];
_preg_match("/.*_([^_]+_[^_]+)$/", $cn, $matches);
assert(count($matches) == 2, "failed to extract org from cn: '$cn'");
return $matches[1];
}

// if array is length 1 then replace it with its one element
function flatten_attributes(array $attributes): array
{
Expand All @@ -32,17 +24,21 @@ function parse_comma_delimited_list(string $input): array
}

$givenName = trim(readline("Enter the course ID (example: CS123): "));
if (!_preg_match("/^[a-zA-Z0-9_-]+$/", $givenName)) {
_die("error: course ID '$givenName' contains invalid characters", 1);
}
Comment on lines 26 to +29
$sn = trim(readline("Enter the year and semester of the course (example: Fall 2025): "));
$cn = strtolower(
trim(readline("Please enter the cn to be used for the course (example: cs123_umass_edu): ")),
);
$org_gid = strtolower(trim(readline("Please enter the organization (example: umass_edu): ")));
if (!_preg_match("/^[a-z0-9_]+$/", $org_gid)) {
_die("error: organization '$org_gid' contains invalid characters", 1);
}
$cn = implode("_", [strtolower($givenName), $org_gid]);
Comment on lines +27 to +35
$manager_uids = parse_comma_delimited_list(
readline("Enter the UID(s) of the group manager(s) (example: simonleary_umass_edu,bryank_uri_edu): ")
);
if (count($manager_uids) === 0) {
_die("at least one group manager UID is required", 1);
}
$org_gid = cn2org($cn);

$managers = [];
foreach ($manager_uids as $manager_uid) {
Expand Down
Loading