Skip to content

Commit 1938199

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 1938199

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-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: 5 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

@@ -127,7 +128,7 @@ async sub rpc_execute {
127128
unless $command_package;
128129

129130
my $result = eval {
130-
my $out = $command_package->$command($self, $self->{inputs_ref});
131+
my $out = $command_package->$command($self, $inputs_ref);
131132
return await $out if ref $out eq 'Future' || ref $out eq 'Mojo::Promise';
132133
return $out;
133134
};
@@ -257,7 +258,7 @@ sub command_permission {
257258
convertCodeToPGML => 'access_instructor_tools',
258259

259260
# WebworkWebservice::RenderProblem
260-
renderProblem => 'proctor_quiz_login',
261+
renderProblem => 'webservice_render_problem',
261262

262263
# WebworkWebservice::SetActions
263264
listGlobalSets => 'access_instructor_tools',

lib/WebworkWebservice/RenderProblem.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ async sub renderProblem {
2626
# is enabled. That is an expensive method to always call here.
2727
debug(pretty_print_rh($rh)) if $WeBWorK::Debug::Enabled;
2828

29+
# If the problem source is provided, check user is allow to render problem source.
30+
if (!$ws->authz->hasPermissions($rh->{user}, 'webservice_render_source')
31+
&& ($rh->{problemSource} || $rh->{rawProblemSource} || $rh->{uriEncodedProblemSource}))
32+
{
33+
$ws->error_string(__PACKAGE__ . ": User $rh->{user} does not have permission to render problem source.");
34+
return {};
35+
}
36+
2937
my $problemSeed = $rh->{problemSeed} // '1234';
3038

3139
my $beginTime = Benchmark->new;

0 commit comments

Comments
 (0)