Skip to content

Commit e97a71d

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 ea0bc2a commit e97a71d

2 files changed

Lines changed: 14 additions & 16 deletions

File tree

lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm

Lines changed: 11 additions & 11 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;
@@ -192,6 +190,11 @@ sub pre_header_initialize ($c) {
192190
# $c->{backupBasePath}: base path to the backup files
193191
$c->getFilePaths;
194192

193+
say "editFilePath: $c->{editFilePath}";
194+
say "tempFilePath: $c->{tempFilePath}";
195+
say "inputFilePath: $c->{inputFilePath}";
196+
say 'backupFilePath: ' . ($c->{backupFilePath} // 'undefined');
197+
195198
# Default problem contents
196199
$c->{r_problemContents} = \'';
197200

@@ -247,14 +250,11 @@ sub initialize ($c) {
247250
));
248251
}
249252

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-
}
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+
if !path_is_subdir($c->{editFilePath}, $ce->{courseDirs}{templates});
258258

259259
# Find the text for the editor, either in the temporary file if it exists, in the original file in the template
260260
# directory, or in the problem contents gathered in the initialization phase.
@@ -1280,7 +1280,7 @@ sub save_as_handler ($c) {
12801280
setID => $c->{setID},
12811281
problemID => $do_not_save ? $c->{problemID} : max($db->listGlobalProblems($c->{setID}))
12821282
);
1283-
$new_file_type = $file_type;
1283+
$new_file_type = 'problem';
12841284
} else {
12851285
$c->addbadmessage($c->maketext(
12861286
'Please use radio buttons to choose the method for saving this file. Unknown saveMode: [_1].', $saveMode

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)