Skip to content

Commit 78ffb2f

Browse files
committed
Rework when the "save" tab is shown, and when the file being edited is considered a template.
Basically, any file that is not in the course's templates directory is now considered a template, and for these files the "save" tab is not shown. Note that this uses the `WeBWorK::Utils::Files::path_is_subdir` method, and so files that are linked to from the course's templates directory are not considered templates. Although, if those files are not writable by the server, then the message `The file "[_1]" is protected. You may use "Save As" to create a new file.` will be shown. So OPL or Contrib problems will not be considered templates, but if file permissions are correct on your server, then the message above will be shown. However, if a file is in a location in `$webworkDirs{valid_symlinks}` array, and file permissions are correct on your server, then no message will be shown, and the file can be saved.
1 parent 34d8c10 commit 78ffb2f

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ use constant ACTION_FORM_TITLES => {
129129
revert => x('Revert'),
130130
};
131131

132-
my $BLANKPROBLEM = 'newProblem.pg';
133-
134132
sub pre_header_initialize ($c) {
135133
my $ce = $c->ce;
136134
my $authz = $c->authz;
@@ -247,14 +245,11 @@ sub initialize ($c) {
247245
));
248246
}
249247

250-
if ($c->{file_type} eq 'blank_problem' || $c->{file_type} eq 'sample_problem') {
251-
$c->addbadmessage($c->maketext('This file is a template. You may use "Save As" to create a new file.'));
252-
} elsif ($c->{inputFilePath} =~ /$BLANKPROBLEM$/) {
253-
$c->addbadmessage($c->maketext(
254-
'The file "[_1]" is a template. You may use "Save As" to create a new file.',
255-
$c->shortPath($c->{inputFilePath})
256-
));
257-
}
248+
$c->addbadmessage($c->maketext(
249+
'The file "[_1]" is a template. You may use "Save As" to create a new file.',
250+
$c->shortPath($c->{inputFilePath})
251+
))
252+
if !path_is_subdir($c->{editFilePath}, $ce->{courseDirs}{templates});
258253

259254
# Find the text for the editor, either in the temporary file if it exists, in the original file in the template
260255
# directory, or in the problem contents gathered in the initialization phase.

templates/ContentGenerator/Instructor/PGProblemEditor/save_form.html.ep

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
% # Can't save blank problems without changing names, and can't save if lacking write permissions.
2-
% last if $c->{file_type} eq 'blank_problem'
3-
% || $c->{file_type} eq 'sample_problem'
4-
% || $c->{editFilePath} =~ /newProblem\.pg$/
5-
% || !-w $c->{editFilePath};
1+
% use WeBWorK::Utils::Files qw(path_is_subdir);
2+
% # Can't save files outside of the course templates directory, and can't save if lacking write permissions.
3+
% last if !path_is_subdir($c->{editFilePath}, $ce->{courseDirs}{templates}, 1) || !-w $c->{editFilePath};
64
%
75
<div>
86
<div class="mb-2">

0 commit comments

Comments
 (0)