Skip to content

Commit

Permalink
Only assign initial users to sets/achievements once.
Browse files Browse the repository at this point in the history
When copying over old sets and achievements only assign the initial
users to sets or achievements once. This makes it so any initial user
is always assigned to everything, and will ignore (skip over) whatever
they were assigned to in the old course.

Also assign all initial users (including admins) to sets/achievements.
  • Loading branch information
somiaj committed Nov 13, 2024
1 parent 568c8e6 commit 75f9377
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ sub addCourse {

debug \@users;

my @initialUsers = grep { $_->[2]->permission < $ce->{userRoles}{admin} } @users;
my @initialUsers = @users;
my %user_args = map { $_->[0]{user_id} => 1 } @users;

# get the database layout out of the options hash
my $dbLayoutName = $courseOptions{dbLayoutName};
Expand Down Expand Up @@ -359,7 +360,6 @@ sub addCourse {
{ '!=' => $options{copyConfig} ? $ce0->{userRoles}{student} : $ce->{userRoles}{student} },
user_id => { not_like => 'set_id:%' }
}));
my %user_args = map { $_->[0]{user_id} => 1 } @users;

for my $user_id (@non_student_ids) {
next if $user_args{$user_id};
Expand Down Expand Up @@ -402,7 +402,8 @@ sub addCourse {
}
if ($options{copyNonStudents}) {
foreach my $userTriple (@users) {
my $user_id = $userTriple->[0]{user_id};
my $user_id = $userTriple->[0]{user_id};
next if $user_args{$user_id}; # Initial users will be assigned to everything below.
my @user_sets = $db0->listUserSets($user_id);
assignSetsToUsers($db, $ce, \@user_sets, [$user_id]);
}
Expand All @@ -425,7 +426,8 @@ sub addCourse {
}
if ($options{copyNonStudents}) {
foreach my $userTriple (@users) {
my $user_id = $userTriple->[0]{user_id};
my $user_id = $userTriple->[0]{user_id};
next if $user_args{$user_id}; # Initial users were assigned to all achievements above.
my @user_achievements = $db0->listUserAchievements($user_id);
for my $achievement_id (@user_achievements) {
my $userAchievement = $db->newUserAchievement();
Expand Down

0 comments on commit 75f9377

Please sign in to comment.