donhinkelman / moodle-block_sharing_cart

Content sharing plug-in for Moodle LMS. Now at version 4.4, release 3 (actually this is for Moodle LMS version 4.3. Requires PHP 7.4.
7 stars 38 forks source link

When a user does not have the required capabilities, an exception is shown #27

Closed acquaalta closed 4 years ago

acquaalta commented 4 years ago

Versions Moodle: 3.7 Sharing Cart: 3.6, release 1 (2019012000)

Hi, A user in "my" system tried to copy an item using the sharing cart. She could use the "Edit" menu of the item to copy the item into the sharing cart, but when she clicked the "Copy to course" button in the "Sharing Cart" block, she got an exception message. When I turned on debugging and repeated what she did before, I got the following error:

Sharing Cart - Restore courses error

Here is the same message in a text format: %%%%%%%%%%%%%%%%%%%% _required_capability_exception: Sorry, but you do not currently have permissions to do that (Restore courses). in [dirroot]/lib/accesslib.php:860 Stack trace: #0 [dirroot]/blocks/sharing_cart/classes/controller.php(435): require_capability('moodle/restore:...', Object(context_course)) #1 [dirroot]/blocks/sharing_cart/restore.php(111): sharing_cart\controller->restore(2, 284, 1) #2 {main}

More information about this error

×Debug info: Error code: notlocalisederrormessage ×Stack trace: line 494 of /lib/setuplib.php: moodle_exception thrown line 120 of /blocks/sharing_cart/restore.php: call to printerror() %%%%%%%%%%%%%%%%%%%%

I've got the following questions:

  1. Could you please update the code of the plugin, so when a user doesn't have the required capabilities, he would see a "more welcoming" message that would tell him that he needs to have the X, Y and Z permissions in order to use the "Sharing Cart" block/mechanism? It would be best if it would see this message at the start, when he try to copy the item into the sharing cart, and not only when he tries to finish the process. I thought about even not displaying the "Copy to Sharing Cart" option in the edit menu from the beginning, but it seems too much, because at least when it is shown, the user knows that there is a general option in the system to use the sharing cart.

  2. It seems that two capabilities are required by a user in order to use the plugin in the most basic scenario (copying an item): Restore activities (moodle/restore:restoreactivity) Restore courses (moodle/restore:restorecourse)

If that's true, could you please update the documentation of the plugin and include that info in it? One may assume that the plugin requires only one capability (activity/course), but it seems that in reality both are needed.

  1. There is a third "restore" capability which is the following: Restore sections (moodle/restore:restoresection) I thought that it would be needed for a user who wants to use the new "Section Copy" feature, but to my surprise the feature worked even without this capability being allowed. Is it intentional that it isn't needed for copying sections with the "Sharing Cart" plugin?
donhinkelman commented 4 years ago

Hi Acquaalta, I agree with everything you suggest, and I will try to find a programmer to work on it.

acquaalta commented 4 years ago

Thanks a lot :-) BTW, There is a recent comment on the plugin page ("Katja Neubehler Tue, Dec 17, 2019, 6:27 PM"), which deals with more capabilities that are required for the correct functionality of the plugin.

johnnypraxis commented 4 years ago

This bug is fixed.

A more welcoming error message will be displayed if the user does not have the following capabilities: Restore activities (moodle/restore:restoreactivity) Restore courses (moodle/restore:restorecourse)

And the "Copy to course" icon will be removed as well if the user does not have the capabilities.