DMPRoadmap / roadmap

DCC/UC3 collaboration for a data management planning tool
MIT License
102 stars 109 forks source link

[FEATURE]: Allow admins to delete a template #3305

Closed Danny-dK closed 1 year ago

Danny-dK commented 1 year ago

Currently, templates created by admins cannot be deleted. Only current options are: image

It would be beneficial to have the option to delete unpublished templates.

briri commented 1 year ago

Templates can only be deleted if no plans were created from them because it would leave orphaned records in the database

Danny-dK commented 1 year ago

@briri Ah, I see... I tried quickly to copy a template and indeed there is a remove option. What if the DMPs on which the unpublished template (it is not a published template) were based on are all deleted from the webportal. There still is no option to delete the unpublished template. I was the only one that created that template and was the only one to create 2 dmps based on that template.

briri commented 1 year ago

Here is the logic that determines whether or not a template is 'removable'. https://github.com/DMPRoadmap/roadmap/blob/9ead17b2979d5624e57f6ce15174f7535094a080/app/models/template.rb#L366

If any version of a the template has plans, then it cannot be removed/deleted because removing it would require that all prior versions also be removed. If what you want to do is remove the currently published version of a template, you can just unpublished it which ensures that it will then not be available when a researcher creates a new plan. (Note that un-publishing does not re-publish a prior version)

Danny-dK commented 1 year ago

@briri Thank you, but I still don't understand. If I have an unpublished template on which I created 2 test DMP's under our own admin account, I deleted those 2 test DMP's and there are no other DMP's created under that template (other users cannot create a DMP on that template as it is an unpublished template), why can I still not delete my template (as there are no DMPs available for that specific unpublished template)? I searched through our 'plan' section in DMPonline just to be sure, but there are no DMPs using that unpublished template.

briri commented 1 year ago

Hi @Danny-dK you'd have to look in the DB not the UI to get a clear picture of what records would be orphaned by the deletion of the template. The templates table is complex. Each template has a family_id which ties different versions of a template together as well as a customization_of field for any templates that are customizations of the template (customizations are applicable only to funder templates). If there are any other templates or plans associated with any version or customization of the template then it cannot be deleted.

If you truly feel that it is an error, you can bypass the UI and application logic and simply delete the record manually in the DB (which I DO NOT recommend as you would need to ensure that you've deleted the appropriate records from about 1/2 of the database's tables). You will need to delete any associates, phases, sections, questions, question_options, conditional questions, notes, plans, answers, themes_in_questions, etc. for each version of your template.

Please feel free to review the code in the app/models directory to get a clearer picture of all the relationships

Danny-dK commented 1 year ago

Ah okay. We'll have to make sure not to make any templates arbitrarily for testing then. Thanks!