Skip to content

Commit 1253512

Browse files
author
toenail
committed
added scoring ability
fixed permission tests git-svn-id: http://svn.webwork.maa.org/system/trunk/webwork2@2272 c0722133-6baf-4dd8-8699-98d999cd4f06
1 parent 462244a commit 1253512

File tree

1 file changed

+229
-35
lines changed

1 file changed

+229
-35
lines changed

lib/WeBWorK/ContentGenerator/Instructor/ProblemSetList.pm

+229-35
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ Import sets:
6161
- any users
6262
- no users
6363
64+
Score sets:
65+
- all
66+
- visible
67+
- selected
68+
6469
Create a set with a given name
6570
6671
Delete sets:
@@ -77,7 +82,7 @@ use WeBWorK::Utils qw(formatDateTime parseDateTime readFile readDirectory cryptP
7782
use constant HIDE_SETS_THRESHOLD => 20;
7883

7984
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)];
8186

8287
use constant VIEW_FIELD_ORDER => [ qw( select set_id problems users published open_date due_date answer_date set_header problem_header) ];
8388
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 => {
133138
},
134139
};
135140

136-
sub initialize {
141+
sub pre_header_initialize {
137142
my ($self) = @_;
138143
my $r = $self->r;
139144
my $db = $r->db;
140145
my $ce = $r->ce;
141146
my $authz = $r->authz;
147+
my $urlpath = $r->urlpath;
142148
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+
);
143173

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);
147175
}
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');
148187

149188
}
150189

@@ -570,6 +609,14 @@ sub sort_handler {
570609

571610
sub edit_form {
572611
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+
573620
return join("",
574621
"Edit ",
575622
CGI::popup_menu(
@@ -588,6 +635,14 @@ sub edit_form {
588635

589636
sub edit_handler {
590637
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+
}
591646

592647
my $result;
593648

@@ -610,6 +665,14 @@ sub edit_handler {
610665
sub publish_form {
611666
my ($self, $onChange, %actionParams) = @_;
612667

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+
613676
return join ("",
614677
"Make ",
615678
CGI::popup_menu(
@@ -640,9 +703,16 @@ sub publish_form {
640703

641704
sub publish_handler {
642705
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+
}
646716

647717
my $result = "";
648718

@@ -675,33 +745,122 @@ sub publish_handler {
675745

676746
}
677747

678-
679-
sub delete_form {
748+
sub score_form {
680749
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 ",
684762
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",
688766
-labels => {
689767
none => "no sets.",
690-
#visble => "visible sets.",
768+
all => "all sets.",
691769
selected => "selected sets.",
692770
},
693771
-onchange => $onChange,
694772
),
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+
)
697847
);
698848
}
699849

700850
sub delete_handler {
701851
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+
704862
my $scope = $actionParams->{"action.delete.scope"}->[0];
863+
705864

706865
my @setIDsToDelete = ();
707866

@@ -730,6 +889,14 @@ sub delete_handler {
730889

731890
sub create_form {
732891
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+
}
733900

734901
return "Create a new set named: ",
735902
CGI::textfield(
@@ -742,8 +909,15 @@ sub create_form {
742909

743910
sub create_handler {
744911
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+
}
747921

748922
my $newSetRecord = $db->newGlobalSet;
749923
my $newSetName = $actionParams->{"action.create.name"}->[0];
@@ -765,6 +939,14 @@ sub create_handler {
765939

766940
sub import_form {
767941
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+
}
768950

769951
# this will make the popup menu alternate between a single selection and a multiple selection menu
770952
# Note: search by name is required since document.problemsetlist.action.import.number is not seen as
@@ -804,23 +986,35 @@ sub import_form {
804986
-width => "50",
805987
-onchange => $onChange,
806988
),
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
8181004
);
8191005
}
8201006

8211007
sub import_handler {
8221008
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+
8241018
my @fileNames = @{ $actionParams->{"action.import.source"} };
8251019
my $newSetName = $actionParams->{"action.import.name"}->[0];
8261020
$newSetName = "" if $newSetName =~ /\(/;

0 commit comments

Comments
 (0)