@@ -61,6 +61,11 @@ Import sets:
61
61
- any users
62
62
- no users
63
63
64
+ Score sets:
65
+ - all
66
+ - visible
67
+ - selected
68
+
64
69
Create a set with a given name
65
70
66
71
Delete sets:
@@ -77,7 +82,7 @@ use WeBWorK::Utils qw(formatDateTime parseDateTime readFile readDirectory cryptP
77
82
use constant HIDE_SETS_THRESHOLD => 20;
78
83
79
84
use constant EDIT_FORMS => [qw( cancelEdit saveEdit) ];
80
- use constant VIEW_FORMS => [qw( filter sort edit publish import create delete) ];
85
+ use constant VIEW_FORMS => [qw( filter sort edit publish import score create delete) ];
81
86
82
87
use constant VIEW_FIELD_ORDER => [ qw( select set_id problems users published open_date due_date answer_date set_header problem_header) ];
83
88
use constant EDIT_FIELD_ORDER => [ qw( set_id published open_date due_date answer_date set_header problem_header) ];
@@ -133,18 +138,52 @@ use constant FIELD_PROPERTIES => {
133
138
},
134
139
};
135
140
136
- sub initialize {
141
+ sub pre_header_initialize {
137
142
my ($self ) = @_ ;
138
143
my $r = $self -> r;
139
144
my $db = $r -> db;
140
145
my $ce = $r -> ce;
141
146
my $authz = $r -> authz;
147
+ my $urlpath = $r -> urlpath;
142
148
my $user = $r -> param(' user' );
149
+ my $courseName = $urlpath -> arg(" courseID" );
150
+
151
+
152
+ if (defined $r -> param(" action" ) and $r -> param(" action" ) eq " score" ) {
153
+ my $scope = $r -> param(" action.score.scope" );
154
+ my @setsToScore = ();
155
+
156
+ if ($scope eq " none" ) {
157
+ return " No sets selected for scoring." ;
158
+ } elsif ($scope eq " all" ) {
159
+ @setsToScore = @{ $r -> param(" allSetIDs" ) };
160
+ } elsif ($scope eq " visible" ) {
161
+ @setsToScore = @{ $r -> param(" visibleSetIDs" ) };
162
+ } elsif ($scope eq " selected" ) {
163
+ @setsToScore = $r -> param(" selected_sets" );
164
+ }
165
+
166
+ my $uri = $self -> systemLink( $urlpath -> newFromModule(' WeBWorK::ContentGenerator::Instructor::Scoring' , courseID => $courseName ),
167
+ params => {
168
+ scoreSelected => " ScoreSelected" ,
169
+ selectedSet => \@setsToScore ,
170
+ # recordSingleSetScores=>''
171
+ }
172
+ );
143
173
144
- unless ($authz -> hasPermissions($user , " modify_student_data" )) {
145
- $self -> addmessage(CGI::div({class => " ResultsWithError" }, CGI::p(" You are not authorized to modify student data" )));
146
- return ;
174
+ $self -> reply_with_redirect($uri );
147
175
}
176
+
177
+ }
178
+
179
+
180
+ sub initialize {
181
+ my ($self ) = @_ ;
182
+ my $r = $self -> r;
183
+ my $db = $r -> db;
184
+ my $ce = $r -> ce;
185
+ my $authz = $r -> authz;
186
+ my $user = $r -> param(' user' );
148
187
149
188
}
150
189
@@ -570,6 +609,14 @@ sub sort_handler {
570
609
571
610
sub edit_form {
572
611
my ($self , $onChange , %actionParams ) = @_ ;
612
+ my $r = $self -> r;
613
+ my $authz = $r -> authz;
614
+ my $user = $r -> param(' user' );
615
+
616
+ unless ($authz -> hasPermissions($user , " modify_problem_sets" )) {
617
+ return CGI::em(" You are not authorized to modify problem sets" );
618
+ }
619
+
573
620
return join (" " ,
574
621
" Edit " ,
575
622
CGI::popup_menu(
@@ -588,6 +635,14 @@ sub edit_form {
588
635
589
636
sub edit_handler {
590
637
my ($self , $genericParams , $actionParams , $tableParams ) = @_ ;
638
+
639
+ my $r = $self -> r;
640
+ my $authz = $r -> authz;
641
+ my $user = $r -> param(' user' );
642
+
643
+ unless ($authz -> hasPermissions($user , " modify_problem_sets" )) {
644
+ return CGI::em(" You are not authorized to modify problem sets" );
645
+ }
591
646
592
647
my $result ;
593
648
@@ -610,6 +665,14 @@ sub edit_handler {
610
665
sub publish_form {
611
666
my ($self , $onChange , %actionParams ) = @_ ;
612
667
668
+ my $r = $self -> r;
669
+ my $authz = $r -> authz;
670
+ my $user = $r -> param(' user' );
671
+
672
+ unless ($authz -> hasPermissions($user , " modify_problem_sets" )) {
673
+ return CGI::em(" You are not authorized to modify problem sets" );
674
+ }
675
+
613
676
return join (" " ,
614
677
" Make " ,
615
678
CGI::popup_menu(
@@ -640,9 +703,16 @@ sub publish_form {
640
703
641
704
sub publish_handler {
642
705
my ($self , $genericParams , $actionParams , $tableParams ) = @_ ;
643
-
644
- my $r = $self -> r;
645
- my $db = $r -> db;
706
+
707
+ my $r = $self -> r;
708
+ my $db = $r -> db;
709
+ my $authz = $r -> authz;
710
+ my $user = $r -> param(' user' );
711
+
712
+
713
+ unless ($authz -> hasPermissions($user , " modify_problem_sets" )) {
714
+ return CGI::em(" You are not authorized to modify problem sets" );
715
+ }
646
716
647
717
my $result = " " ;
648
718
@@ -675,33 +745,122 @@ sub publish_handler {
675
745
676
746
}
677
747
678
-
679
- sub delete_form {
748
+ sub score_form {
680
749
my ($self , $onChange , %actionParams ) = @_ ;
681
- return join (" " ,
682
- qq! \n <div class="ResultsWithError">! ,
683
- " Delete " ,
750
+
751
+ my $r = $self -> r;
752
+ my $authz = $r -> authz;
753
+ my $user = $r -> param(' user' );
754
+
755
+ unless ($authz -> hasPermissions($user , " score_sets" )) {
756
+ return CGI::em(" You are not authorized to score sets" );
757
+ }
758
+
759
+
760
+ return join (" " ,
761
+ " Score " ,
684
762
CGI::popup_menu(
685
- -name => " action.delete .scope" ,
686
- -values => [qw( none visible selected) ],
687
- -default => $actionParams {" action.delete .scope" }-> [0] || " none" ,
763
+ -name => " action.score .scope" ,
764
+ -values => [qw( none all selected) ],
765
+ -default => $actionParams {" action.score .scope" }-> [0] || " none" ,
688
766
-labels => {
689
767
none => " no sets." ,
690
- # visble => "visible sets.",
768
+ all => " all sets." ,
691
769
selected => " selected sets." ,
692
770
},
693
771
-onchange => $onChange ,
694
772
),
695
- CGI::em(" Deletion destroys all set-related data and is not undoable!" ),
696
- " </div>\n " ,
773
+ );
774
+
775
+
776
+
777
+ }
778
+
779
+ sub score_handler {
780
+ my ($self , $genericParams , $actionParams , $tableParams ) = @_ ;
781
+
782
+ my $r = $self -> r;
783
+ my $urlpath = $r -> urlpath;
784
+ my $authz = $r -> authz;
785
+ my $user = $r -> param(' user' );
786
+ my $courseName = $urlpath -> arg(" courseID" );
787
+
788
+ unless ($authz -> hasPermissions($user , " score_sets" )) {
789
+ return CGI::em({class => " ResultsWithError" }, " You are not authorized to score sets" );
790
+ }
791
+
792
+
793
+ my $scope = $actionParams -> {" action.score.scope" }-> [0];
794
+ my @setsToScore ;
795
+
796
+ if ($scope eq " none" ) {
797
+ @setsToScore = ();
798
+ return " No sets selected for scoring." ;
799
+ } elsif ($scope eq " all" ) {
800
+ @setsToScore = @{ $self -> {allSetIDs } };
801
+ } elsif ($scope eq " visible" ) {
802
+ @setsToScore = @{ $self -> {visibleSetIDs } };
803
+ } elsif ($scope eq " selected" ) {
804
+ @setsToScore = @{ $genericParams -> {selected_sets } };
805
+ }
806
+
807
+ my $uri = $self -> systemLink( $urlpath -> newFromModule(' WeBWorK::ContentGenerator::Instructor::Scoring' , courseID => $courseName ),
808
+ params => {
809
+ scoreSelected => " Score Selected" ,
810
+ selectedSet => \@setsToScore ,
811
+ # recordSingleSetScores=>''
812
+ }
813
+ );
814
+
815
+
816
+ return $uri ;
817
+ }
818
+
819
+
820
+ sub delete_form {
821
+ my ($self , $onChange , %actionParams ) = @_ ;
822
+
823
+ my $r = $self -> r;
824
+ my $authz = $r -> authz;
825
+ my $user = $r -> param(' user' );
826
+
827
+ unless ($authz -> hasPermissions($user , " create_and_delete_problem_sets" )) {
828
+ return CGI::em(" You are not authorized to delete problem sets" );
829
+ }
830
+
831
+ return join (" " ,
832
+ CGI::div({class => " ResultsWithError" },
833
+ " Delete " ,
834
+ CGI::popup_menu(
835
+ -name => " action.delete.scope" ,
836
+ -values => [qw( none selected) ],
837
+ -default => $actionParams {" action.delete.scope" }-> [0] || " none" ,
838
+ -labels => {
839
+ none => " no sets." ,
840
+ # visble => "visible sets.",
841
+ selected => " selected sets." ,
842
+ },
843
+ -onchange => $onChange ,
844
+ ),
845
+ CGI::em(" Deletion destroys all set-related data and is not undoable!" ),
846
+ )
697
847
);
698
848
}
699
849
700
850
sub delete_handler {
701
851
my ($self , $genericParams , $actionParams , $tableParams ) = @_ ;
702
- my $r = $self -> r;
703
- my $db = $r -> db;
852
+
853
+ my $r = $self -> r;
854
+ my $db = $r -> db;
855
+ my $authz = $r -> authz;
856
+ my $user = $r -> param(' user' );
857
+
858
+ unless ($authz -> hasPermissions($user , " create_and_delete_problem_sets" )) {
859
+ return CGI::em(" You are not authorized to delete problem sets" );
860
+ }
861
+
704
862
my $scope = $actionParams -> {" action.delete.scope" }-> [0];
863
+
705
864
706
865
my @setIDsToDelete = ();
707
866
@@ -730,6 +889,14 @@ sub delete_handler {
730
889
731
890
sub create_form {
732
891
my ($self , $onChange , %actionParams ) = @_ ;
892
+
893
+ my $r = $self -> r;
894
+ my $authz = $r -> authz;
895
+ my $user = $r -> param(' user' );
896
+
897
+ unless ($authz -> hasPermissions($user , " create_and_delete_problem_sets" )) {
898
+ return CGI::em(" You are not authorized to create problem sets" );
899
+ }
733
900
734
901
return " Create a new set named: " ,
735
902
CGI::textfield(
@@ -742,8 +909,15 @@ sub create_form {
742
909
743
910
sub create_handler {
744
911
my ($self , $genericParams , $actionParams , $tableParams ) = @_ ;
745
-
746
- my $db = $self -> {r }-> {db };
912
+
913
+ my $r = $self -> r;
914
+ my $db = $r -> db;
915
+ my $authz = $r -> authz;
916
+ my $user = $r -> param(' user' );
917
+
918
+ unless ($authz -> hasPermissions($user , " create_and_delete_problem_sets" )) {
919
+ return CGI::em(" You are not authorized to create problem sets" );
920
+ }
747
921
748
922
my $newSetRecord = $db -> newGlobalSet;
749
923
my $newSetName = $actionParams -> {" action.create.name" }-> [0];
@@ -765,6 +939,14 @@ sub create_handler {
765
939
766
940
sub import_form {
767
941
my ($self , $onChange , %actionParams ) = @_ ;
942
+
943
+ my $r = $self -> r;
944
+ my $authz = $r -> authz;
945
+ my $user = $r -> param(' user' );
946
+
947
+ unless ($authz -> hasPermissions($user , " create_and_delete_problem_sets" )) {
948
+ return CGI::em(" You are not authorized to create problem sets" );
949
+ }
768
950
769
951
# this will make the popup menu alternate between a single selection and a multiple selection menu
770
952
# Note: search by name is required since document.problemsetlist.action.import.number is not seen as
@@ -804,23 +986,35 @@ sub import_form {
804
986
-width => " 50" ,
805
987
-onchange => $onChange ,
806
988
),
807
- " assigning this set to " ,
808
- CGI::popup_menu(
809
- -name => " action.import.assign" ,
810
- -value => [qw( all none) ],
811
- -default => $actionParams {" action.import.assign" }-> [0] || " none" ,
812
- -labels => {
813
- all => " all current users." ,
814
- none => " no users." ,
815
- },
816
- -onchange => $onChange ,
817
- ),
989
+ ($authz -> hasPermissions($user , " assign_problem_sets" ))
990
+ ?
991
+ " assigning this set to " .
992
+ CGI::popup_menu(
993
+ -name => " action.import.assign" ,
994
+ -value => [qw( all none) ],
995
+ -default => $actionParams {" action.import.assign" }-> [0] || " none" ,
996
+ -labels => {
997
+ all => " all current users." ,
998
+ none => " no users." ,
999
+ },
1000
+ -onchange => $onChange ,
1001
+ )
1002
+ :
1003
+ " " # user does not have permissions to assign problem sets
818
1004
);
819
1005
}
820
1006
821
1007
sub import_handler {
822
1008
my ($self , $genericParams , $actionParams , $tableParams ) = @_ ;
823
-
1009
+
1010
+ my $r = $self -> r;
1011
+ my $authz = $r -> authz;
1012
+ my $user = $r -> param(' user' );
1013
+
1014
+ unless ($authz -> hasPermissions($user , " create_and_delete_problem_sets" )) {
1015
+ return CGI::em(" You are not authorized to create problem sets" );
1016
+ }
1017
+
824
1018
my @fileNames = @{ $actionParams -> {" action.import.source" } };
825
1019
my $newSetName = $actionParams -> {" action.import.name" }-> [0];
826
1020
$newSetName = " " if $newSetName =~ / \( / ;
0 commit comments