WeBWorK Problems

Editing problems in a local library

Editing problems in a local library

by Larry Riddle -
Number of replies: 5

I have created a local library for our WeBWorK server for collections of problems that we have written here as well as problems from other sources that are not available in the OPL. I would like to be able to edit these pg problems from the Library Browser like I can do with problems saved in an individual course's template directory. But when I view a problem from our local library in the Library Browser and click the edit button, I am told the file is protected and that "To edit this text you must first make a copy of this file using the 'NewVersion' action below." This is even when logged in as the admin user.

The permissions of the directories and files in the local library are listed as
drwxrwxr-x wwadmin wwadmin

I saw that in the template directory of the actual courses, the user is www-data and the group is wwdata.

As an experiment, I ran chown on one of the directories in the local library to change wwadmin to www-data and wwdata for the files in that directory. I was then able to go to the Library Browser and edit a problem in that local library directory without having to make a NewVersion copy.

I did log in as a "professor" and noticed that professors could also edit these particular problems in the local library. I'm ok with that because we only have 4 people in the department and they are not likely to try any editing. (And I have backup copies if anything really did get messed up.)

But is this the best way to handle a local library and allow at least the admin to edit pg files in the local library directly from the Library Browser?

In reply to Larry Riddle

Re: Editing problems in a local library

by Alex Jordan -
One option I would consider is to have a course that is dedicated to your local library. In its templates/ folder, you'd have some folder mylibrary/ and in there is where you keep these files and edit them.

Then in each regular course's templates/ folder, make a symlink to the library course's templates/mylibrary/ folder. (If you do this in a model course, then the symlink will carry over when new courses are initialized from that model course.)

And then add the special course's mylibrary/ folder to the global collection of libraries so that it has a button in regular courses' Library Browsers.

You would use the special course to manage these files, and regular courses would still be locked out of making edits to the core copies. But maybe this is not helpful if you really do want to edit the core problem files from a course where you are using them. It's just that this could lead to your regular instructors unintentionally doing things that affect other courses.



In reply to Alex Jordan

Re: Editing problems in a local library

by Larry Riddle -
This is a great idea and seems to be a perfect solution. I have implemented the steps described and everything seems to work as hoped for. Thank you, Alex!!
In reply to Larry Riddle

Re: Editing problems in a local library

by Larry Riddle -
Oops...It appears with what I have done that regular courses are not actually locked out of making edits to the files in the library course's templates/mylibrary folder. The permissions for the mylibrary folder are

drwxr-s--- 5 www-data wwdata

and the permissions for a directory of problems in that folder are

drwxr-sr-x 12 www-data wwdata

All directories were created from the WW web interface. Only creating the symbolic links and editing localOverrides to add the button were done on the comand line. Is there something missing I needed to do to lock out the regular courses that have the symbolic links to mylibrary?
In reply to Larry Riddle

Re: Editing problems in a local library

by Glenn Rice -
You can not follow symbolic links in the file manager (unless they are listed in $webworkDirs{valid_symlinks}), but it seems that you can edit files that are linked to in the templates directory. That is assuming that the server user (www-data on Ubuntu) has permission to do so.

So unfortunately Alex's suggestion won't work. This is probably an issue that should be made at https://github.com/openwebwork/webwork2.
In reply to Larry Riddle

Re: Editing problems in a local library

by Alex Jordan -

Oh, I didn't realize that symlinks used in this way would still allow users to edit. The difference with these files and OPL files is permissions, but you would not want to change permissions to prevent editing from the regular course, or else the the files would be unwriteable in the library course too.

The code controlling this is:
https://github.com/openwebwork/webwork2/blob/488d48e77d5672a4dab61ab7e359dc09fd247d38/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm#L373

and it's just based on whether the www-data user can write to that file.

Hmm, then it seems that precisely what you asked for can't be done right now. For what it's worth, I do our library management the following more complicated way:

  1. Our local library is a git repo inside the libraries/ folder (so parallel to webwork-open-linbrary)
  2. For each instructor who might do edits to the core library they have a dedicated course. (For you, maybe you are the only such instructor.)
  3. In each of those special courses, there is a folder that is a copy of that repository.
  4. If instructor X wants to edit a core library problem, they edit it within their development course. Then they notify me.
  5. I sign into the server, navigate to their library folder, and run `git diff` to examine their edits or additions. If it's all good, I commit their edits. (And it's all set up to credit the commit to that instructor.)
  6. Then I run a script that pushes each of their course git repos the the core repo, and then pushes back from the core repo out to each of thosthee instructor repos.
It ha s lag from when they make an edit to when they see that edit live in their own courses. But also there is a bit of quality control since my eyes go over the diff.