Skip to content

Commit

Permalink
Merge pull request openwebwork#2672 from drgrice1/copy-set-level-proc…
Browse files Browse the repository at this point in the history
…tors-with-sets

Copy set level proctors when adding a course and copying sets.
  • Loading branch information
somiaj authored Feb 18, 2025
2 parents d3997e0 + fc7f210 commit ab56984
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
35 changes: 25 additions & 10 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,36 @@ sub addCourse {

# add sets
if ($db0 && $options{copySets}) {
my @set_ids = $db0->listGlobalSets;
for my $set_id (@set_ids) {
eval { $db->addGlobalSet($db0->getGlobalSet($set_id)) };
my @sets = $db0->getGlobalSetsWhere;
for my $set (@sets) {
eval { $db->addGlobalSet($set) };
warn $@ if $@;

my @Problem = $db0->getGlobalProblemsWhere({ set_id => $set_id });
my @Problem = $db0->getGlobalProblemsWhere({ set_id => $set->set_id });
for my $problem (@Problem) {
eval { $db->addGlobalProblem($problem) };
warn $@ if $@;
}

my @Location = $db0->getGlobalSetLocationsWhere({ set_id => $set_id });
my @Location = $db0->getGlobalSetLocationsWhere({ set_id => $set->set_id });
for my $location (@Location) {
eval { $db->addGlobalSetLocation($location) };
warn $@ if $@;
}

# Copy the set level proctor user for this set if there is one (despite the for loop there can only be one).
for my $setProctor ($db0->getUsersWhere({ user_id => 'set_id:' . $set->set_id })) {
eval { $db->addUser($setProctor) };
warn $@ if $@;

my $password = $db0->getPassword($setProctor->user_id);
eval { $db->addPassword($password) } if $password;
warn $@ if $@;

my $permission = $db0->getPermissionLevel($setProctor->user_id);
eval { $db->addPermissionLevel($permission) } if $permission;
warn $@ if $@;
}
}
if ($options{copyNonStudents}) {
foreach my $userTriple (@users) {
Expand All @@ -408,19 +422,20 @@ sub addCourse {
assignSetsToUsers($db, $ce, \@user_sets, [$user_id]);
}
}
assignSetsToUsers($db, $ce, \@set_ids, [ map { $_->[0]{user_id} } @initialUsers ]) if @initialUsers;
assignSetsToUsers($db, $ce, [ map { $_->set_id } @sets ], [ map { $_->[0]{user_id} } @initialUsers ])
if @initialUsers;
}

# add achievements
if ($db0 && $options{copyAchievements}) {
my @achievement_ids = $db0->listAchievements;
for my $achievement_id (@achievement_ids) {
eval { $db->addAchievement($db0->getAchievement($achievement_id)) };
my @achievement = $db0->getAchievementsWhere;
for my $achievement (@achievement) {
eval { $db->addAchievement($achievement) };
warn $@ if $@;
for (@initialUsers) {
my $userAchievement = $db->newUserAchievement();
$userAchievement->user_id($_->[0]{user_id});
$userAchievement->achievement_id($achievement_id);
$userAchievement->achievement_id($achievement->achievement_id);
$db->addUserAchievement($userAchievement);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
</div>
</div>
<fieldset class="mb-3">
<legend class="fw-bold fs-6">Copy These Components:</legend>
<legend class="fw-bold fs-6"><%= maketext('Copy These Components:') %></legend>
<div class="form-check">
<label class="form-check-label">
<%= check_box select_all => 1, class => 'select-all form-check-input',
Expand Down

0 comments on commit ab56984

Please sign in to comment.