mdjnelson / moodle-mod_customcert

Enables the creation of dynamically generated certificates with complete customisation via the web browser.
https://moodle.org/plugins/mod_customcert
GNU General Public License v3.0
90 stars 158 forks source link

Feature proposal: Restrict loading of certificate templates #493

Open dermuck opened 2 years ago

dermuck commented 2 years ago

Hello everyone, we are using mod_customcert for creating certificates based on many different templates. To keep things as simple as possible, we would like to restrict the list of "loadable" templates for every course, so course creators will not have to choose "their" template from a large list. Desired result is to enable admins to make certificate templates available for all courses or restrict them to courses offered by one specific faculty/department/subdepartment.

First idea we had was to create a new kind of moodle context for certificates, assign one instance of this non-standard context to every certificate template and grant our users a "use customcert template"-right in this context. This seems possible but requires quite a lot custom changes in the system. Discussing this idea in the forums and with other moodle-users made us rethink our plans, as most developers are not at all happy with the idea of creating custom context levels in moodle. Seems to be something you'd better keep your hands off... As an easier solution to our problem, we could assign every existing certificate template to exactly one coursecategory. When a course creator users edits the certificate in one of his courses, we could restrict him to load only templates that are assigned to one of the courses parent categories. This solution is quite simple but likely to satisfy our demands.

Before starting development I'd like to ask for your opinion regarding the two possibilities. Maybe there are more users of this great plugin interested in having a solution for this. Cant promise anything, but if this is the case I can try to provide a new feature suitable for more users than just us,

Best regards, Markus

lcaylat commented 2 years ago

Hello Markus, Thank you for this highly anticipated development proposal. A simple limitation at the category level is a good robust and efficient solution, IMHO. Best regards, Lionel

antoniobeermann commented 2 years ago

Hello, That would be awesome! IMHO the usage of categories seems ideal. (Maybe courses too - but that would make GUI and programming more sophisticated? versus creating a simply category in moodle and put that one course into it)

Several other things come into my mind:

I am stopping here to stay in the scope :) Looking forward to see any kind of your suggested features!

best regards! Antonio

antifaschiert commented 2 years ago

Hi @ all, this topic is not dead yet. Discussed it with @dermuck , we managed to create an "easy" solution for this. As templates already were assigned to contexts, almost everything needed was already there. We "just" had to add a possibility to assign a template to a context on its creation (other than CONTEXT_SYSTEM) and prevent the user from loading templates from contexts he is not allowed to do. And add some context selectors. And so on. Guess he' s going to upload it the next few days. Would be nice if someone could help us with testing our solution before creating a pull-request. To keep things simple we currently only allow systemwide templates (assigned to the systemcontext) or assign a template to the context of exactly one top-level-coursecategory. This limitation prevents us from displaying a VERY LARGE lists of contexts to choose from in systems with many subcategories. When editing the certificate in one specific moduleinstance, we only offer templates for loading which are assigned to one of the modules parent contexts (this is all systemwide templates and all templates assigned to the current courses top-level-category).

@antoniobeermann :

please keep the configuration as simple as possible

We did: no specific settings for our solution at all. Newly created templates will be assigned the context CONTEXT_SYSTEM by default, so there is no need to perform any additional actions.

it would be nice to restrict the usage of a template (e.g. without asigning it to a dummy category)

Nice idea, but out of our scope. This is easy to add, but it would require a change in database structure (as we would need to add a new property to the termplate). We are very happy that our solution comes without any change in the plugins database structure, which should reduce the risk of breaking anything. Maybe we or someone else can add this feature later.

a very handy feature could be to show the usage of the template

Sadly this is not possible. Every instance of mod_customcert has its own "template" assigned to the instances context. What happens when you load a "global" template into one module instance is, that all the templates content (all pages, containing the field-definitions with their positioning, et cetera) is copied over into the instances own template, there simply is NO LINK between these two templates. So no counting of references, sorry.

Best regards Matt

dermuck commented 2 years ago

Hello everyone, here we are. As Matt already described we found an easy (more or less) way to assign templates to top-level coursecategories. This is what we need in our moodle ecosystem, and this feature may be of interest for some other users too. Our code is availabe for testing here: https://github.com/dermuck/moodle-mod_customcert/tree/Issue_493 I dont know how to continue from now on. I will be testing this on my own, but every feedback of others is very welcome. If the feature seems okay i would create a pull request, maybe we can get this included in the "standard version" of this great plugin. Thanks for testing, Markus

antoniobeermann commented 2 years ago

Great!

I will try to get the code and put it on a testing envirement! Will give feedback within the next days (I will try as soon as possible)

best regards

Am 26.04.22 um 00:01 schrieb Markus Jungbauer:

Hello everyone, here we are. As Matt already described we found an easy (more or less) way to assign templates to top-level coursecategories. This is what we need in our moodle ecosystem, and this feature may be of interest for some other users too. Our code is availabe for testing here: https://github.com/dermuck/moodle-mod_customcert/tree/Issue_493 I dont know how to continue from now on. I will be testing this on my own, but every feedback of others is /very/ welcome. If the feature seems okay i would create a pull request, maybe we can get this included in the "standard version" of this great plugin. Thanks for testing, Markus

— Reply to this email directly, view it on GitHub https://github.com/mdjnelson/moodle-mod_customcert/issues/493#issuecomment-1109083522, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSL33EDEYH5ZRYBH6EYMCLVG4I4BANCNFSM5TAXMECQ. You are receiving this because you were mentioned.Message ID: @.***>

lcaylat commented 2 years ago

Hi, Not possible to install this version with Moodle 3.9.13. With Moodle 4.0 : smoke testing OK. I'll go deeper when I have some time. Thanks for the new version. Regards.

lcaylat commented 2 years ago

Hi, When a teacher tries to upload a template certificate from his course category, he get an error "Sorry, but you do not currently have permissions to do that (Manage a custom certificate)." On the other hand, when he loads a template certificate from the system, it works fine.

Any idea ? Regards.

lcaylat commented 2 years ago

Hi, I want to clarify: additionally, a category manager can also use category certificates successfully. Regards.

dermuck commented 2 years ago

Hi, thanks @lcaylat for testing. I was able to reproduce the problem you reported, there indeed is a problem with trainers loading templates. To keep users from loading templates of "foreign" coursecategories, we added an auth check on "mod/customcert:manage" in the context of the coursecategory the desired template to load is assigned to. This is is fine with managers of a coursecategory, but trainers usually do not have this right on category level. In my system, trainers are never allowed to manage certificates, so I did not find this issue. Sorry for this! The solution is to remove the auth check and to ensure the given load-template belongs to a context above the coursemodule edited, so no one can trick the plugin into loading a template he should not load. I just fixed this in my local branch over here: https://github.com/dermuck/moodle-mod_customcert/tree/Issue_493

Regards, markus

lcaylat commented 2 years ago

Hi Markus, Sorry but I have a 500 internal server error now when I load a template with all users. /mod/customcert/load_template.php ? Thanks in advance for debugging that. Regards.

dermuck commented 2 years ago

Shame on me: added a last minute typo when cleaning up the file... Fixed this a few seconds ago.

Regards Markus

lcaylat commented 2 years ago

Hi Markus, The last fix works well: the teacher role can now load models that match its context.

But... the manager role does not see the "Manage templates" link (/mod/customcert/manage_templates.php) while he has permissions to access this page and create new templates. It's a lack for us. We use this plugin on a fairly large platform and it is important to make our users autonomous in their category;) Is it possible to change this behavior? Thanks in advance. Regards.

dermuck commented 2 years ago

Hi @lcaylat this can be changed. Currently the link to manage templates is displayed whenever the current user has the capability 'mod/customcert:manage' in system-context and the currently edited template is NOT in system context (i.e. the users edits an certificate-instance within an actvity). I did change this behaviour, so the link will always be displayed whenever the user has the capability named above in system or any coursecategory-context. Guess this is what you need.

Updated code here: https://github.com/dermuck/moodle-mod_customcert/tree/Issue_493

Best regards, markus

lcaylat commented 2 years ago

Hi Marjus, Perfect ! I tested this new development successfully.

Il have two new questions :

Thank you very much for all this work. Best regards.

lcaylat commented 1 year ago

Hi @dermuck

Allow me to revive the topic:

Thanks in advance for the reply. Best regards.

lcaylat commented 1 year ago

Hi Markus,

My project is now at Moodle 4.1.3. Should this issue going to be published in next release ? Users are waiting for this :-)

Best regards?

mdjnelson commented 5 months ago

Just got my eye on this. I did not receive any emails about this because I wasn't pinged. I have updated my preferences to get emails from any topic regardless if I am mentioned or not. I will create a PR and look at this.