From 75f9377f6c84d2fc74853bb4af5f8d5f0b358a7d Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Wed, 13 Nov 2024 12:18:05 -0700 Subject: [PATCH] Only assign initial users to sets/achievements once. 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. --- lib/WeBWorK/Utils/CourseManagement.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/WeBWorK/Utils/CourseManagement.pm b/lib/WeBWorK/Utils/CourseManagement.pm index 6ea4eac5db..a20f797e5f 100644 --- a/lib/WeBWorK/Utils/CourseManagement.pm +++ b/lib/WeBWorK/Utils/CourseManagement.pm @@ -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}; @@ -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}; @@ -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]); } @@ -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();