Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/WeBWorK/Authz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ sub checkSet ($self) {

# First check to see if we have to worried about set-level access restrictions.
return 0
unless grep {/^$node_name$/}
unless grep { $node_name eq $_ }
(qw(
problem_list
problem_detail
show_me_another
gateway_quiz
gateway_quiz_version
proctored_gateway_quiz
Expand All @@ -208,15 +209,21 @@ sub checkSet ($self) {
# If there is no input userName, then the content generator will be forcing a login, so just bail.
return 0 if !$userName || !$effectiveUserName;

# The Undefined_Set is only valid for instructors viewing problems in a problem set or a test.
my $allowUndefinedSet =
$setName eq 'Undefined_Set'
&& (grep { $node_name eq $_ } qw(problem_detail gateway_quiz gateway_quiz_version))
&& $self->hasPermissions($userName, 'access_instructor_tools');

# Do we have a cached set that we can use?
my $set = $self->{merged_set};

if ($setVersion) {
if ($set && $set->set_id eq $setName && $set->user_id eq $effectiveUserName && $set->version_id == $setVersion)
{
# If we have all of this, then we can just use this set and skip the rest.
} elsif ($setName eq 'Undefined_Set' && $self->hasPermissions($userName, 'access_instructor_tools')) {
# This is the case of previewing a problem from a 'try it' link.
} elsif ($allowUndefinedSet) {
# This is the case of previewing a problem from the problem editor or library browser.
return 0;
} else {
if ($db->existsSetVersion($effectiveUserName, $setName, $setVersion)) {
Expand All @@ -241,9 +248,8 @@ sub checkSet ($self) {
} else {
if ($db->existsUserSet($effectiveUserName, $setName)) {
$set = $db->getMergedSet($effectiveUserName, $setName);
} elsif ($setName eq 'Undefined_Set' && $self->hasPermissions($userName, 'access_instructor_tools')) {
# This is the case of the library browser, when we don't actually have a set to look at. This only
# happens for instructor tool users.
} elsif ($allowUndefinedSet) {
# This is the case of viewing a problem from the problem editor or library browser.
return 0;
} else {
return $c->maketext('Requested set "[_1]" is not assigned to user [_2].', $setName, $effectiveUserName);
Expand Down Expand Up @@ -301,7 +307,10 @@ sub checkSet ($self) {
}

# Check to be sure that gateways are being sent to the correct content generator.
if (defined $set->assignment_type && $set->assignment_type =~ /gateway/ && $node_name eq 'problem_detail') {
if (defined $set->assignment_type
&& $set->assignment_type =~ /gateway/
&& ($node_name eq 'problem_detail' || $node_name eq 'show_me_another'))
{
return $c->maketext(
'Requested set "[_1]" is a test but the regular homework assignment content '
. 'generator [_2] was called. Try re-entering the set from the problem sets listing page.',
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/ContentGenerator/API/SetActions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ sub createNewSet ($c) {

$newSetName =~ s/\s/_/g;

return $c->renderError('The set name "Undefined_Set" is reserved.') if $newSetName eq 'Undefined_Set';

my $db = $c->db;

return $c->renderError("The set name '$newSetName' already exists. "
Expand Down
9 changes: 6 additions & 3 deletions lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,16 @@ sub initialize ($c) {
sub path ($c, $args) {
# We need to build a path to the problem being edited by hand, since it is not the same as the url path for this
# page. The bread crumb path leads back to the problem being edited, not to the Instructor tool.
# Don't link to the set or problem for the Undefined_Set, since neither exist.
my $isUndefinedSet = ($c->stash('setID') // '') eq 'Undefined_Set';
return $c->pathMacro(
$args,
'WeBWorK' => $c->url_for('root'),
$c->stash('courseID') => $c->url_for('set_list'),
($c->stash('setID') // '') => $c->url_for('problem_list'),
($c->{prettyProblemNumber} // '') =>
$c->url_for('problem_detail', problemID => $c->stash('problemID') || ''),
($c->stash('setID') // '') => $isUndefinedSet ? '' : $c->url_for('problem_list'),
($c->{prettyProblemNumber} // '') => $isUndefinedSet
? ''
: $c->url_for('problem_detail', problemID => $c->stash('problemID') || ''),
$c->maketext('Editor') => ''
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/ContentGenerator/Instructor/ProblemSetList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ sub create_handler ($c) {
$newSetID =~ s/_/ /gr
)
) unless $newSetID =~ m/^[-a-zA-Z0-9_.]*$/;
return (0, $c->maketext('Failed to create new set: The set name "[_1]" is reserved.', 'Undefined_Set'))
if $newSetID eq 'Undefined_Set';
return (
0,
$c->maketext(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ sub initialize ($c) {

if (!$newSetName) {
$c->addbadmessage($c->maketext('Please specify a new set name.'));
} elsif ($newSetName eq 'Undefined_Set') {
$c->addbadmessage($c->maketext('The set name "[_1]" is reserved.', 'Undefined_Set'));
} elsif (defined $db->getGlobalSet($newSetName)) {
$c->addbadmessage($c->maketext('The set "[_1]" already exists.', $newSetName));
} else {
Expand Down
Loading