Skip to content

Commit 5edf777

Browse files
committed
Add permissions to render problems with WebworkWebservice.
First, this adds the permission `webservice_render_problem` used to determine if a user can render a problem with the WebworkWebservice, instead of using the `proctor_quiz_login` permission for this. Second, this adds an additional permission `webservice_render_source` used to determine if a user can render problems using the problem provided with the request. The use case for this is to allow users which can render problems only using a problem filename, but not by providing the problem's source. These permissions are both set to `login_proctor` to match current behavior and are provided to allow server admins to change which users can render problems. These permissions are not added to the course configuration page as they are permissions that should not be modified by most users, only server admins via `localOverrides.conf` or `course.conf`.
1 parent d3708c5 commit 5edf777

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

conf/defaults.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,13 @@ $authen{admin_module} = ['WeBWorK::Authen::Basic_TheLastOption'];
780780
modify_tags => "admin",
781781
edit_restricted_files => "admin",
782782

783+
# Permission to render problems using the WebworkWebservice.
784+
# Users with only webservice_render_problem can render problems with a provided filename.
785+
# Users with both permissions can also render problems with providing the problem source.
786+
# Note the Problem Editor requires having both permissions.
787+
webservice_render_problem => "login_proctor",
788+
webservice_render_source => "login_proctor",
789+
783790
##### Behavior of the interactive problem processor #####
784791
show_correct_answers_before_answer_date => "ta",
785792
show_solutions_before_answer_date => "ta",

lib/WebworkWebservice.pm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ the result_object of the instance. An error_string will be set on failure.
9595

9696
async sub rpc_execute {
9797
my ($self, $command) = @_;
98-
my $c = $self->c;
99-
my $user_id = $c->param('user');
98+
my $c = $self->c;
99+
my $user_id = $c->param('user');
100+
my $inputs_ref = $self->{inputs_ref};
100101

101102
$command //= 'renderProblem';
102103

@@ -108,6 +109,12 @@ async sub rpc_execute {
108109
return $self->error_string(__PACKAGE__ . ": User $user_id does not have permission for the command $command")
109110
unless $c->authz->hasPermissions($user_id, $permission);
110111

112+
# If rendering a problem and problem source is provided, check user is allow to render the provided source.
113+
return $self->error_string(__PACKAGE__ . ": User $user_id does not have permission to render problem source.")
114+
unless $command ne 'renderProblem'
115+
|| $c->authz->hasPermissions($user_id, 'webservice_render_source')
116+
|| !($inputs_ref->{problemSource} || $inputs_ref->{rawProblemSource} || $inputs_ref->{uriEncodedProblemSource});
117+
111118
# Determine the package that contains the method for this command.
112119
my $command_package = '';
113120
for my $package (
@@ -127,7 +134,7 @@ async sub rpc_execute {
127134
unless $command_package;
128135

129136
my $result = eval {
130-
my $out = $command_package->$command($self, $self->{inputs_ref});
137+
my $out = $command_package->$command($self, $inputs_ref);
131138
return await $out if ref $out eq 'Future' || ref $out eq 'Mojo::Promise';
132139
return $out;
133140
};
@@ -257,7 +264,7 @@ sub command_permission {
257264
convertCodeToPGML => 'access_instructor_tools',
258265

259266
# WebworkWebservice::RenderProblem
260-
renderProblem => 'proctor_quiz_login',
267+
renderProblem => 'webservice_render_problem',
261268

262269
# WebworkWebservice::SetActions
263270
listGlobalSets => 'access_instructor_tools',

0 commit comments

Comments
 (0)