[15.0][IMP] dms_field: Add model_ref to access groups to avoid possible errors when creating directories from a template.
Add model_ref to access groups to avoid possible errors when creating directories from a template.
Example of use case:
- Create a partner.
- Create a template linked to partners.
- Create a directory through the template.
- An access group linked to the partner is created.
- Delete the partner directory.
- Creates a new directory through the template.
- No error will occur and the previous access group will be re-used.
Please @pedrobaeza and @CarlosRoca13 can you review it?
@Tecnativa TT48180
I don't get the use case for this. For what do you need this?
The example use case and the steps to reproduce it are in the initial description.
Before
After
But shouldn't it be then 2 fields: the model and the res_id?
But shouldn't it be then 2 fields: the model and the res_id?
I had thought about that possibility, but it would involve adding something like this https://github.com/OCA/dms/blob/15.0/dms/models/base.py#L11 (i don't like it)
But then you are returning a group that is not correct when there are more than 1 folder. Why don't you just put a link to the directory on the group with ondelete="cascade"?
Removing the access group when deleting a directory would be incorrect because the access group can be used in many other directories.
IMO there are different possibilities:
- Option A: Leave everything as it was before, an error message will be displayed and the access group will not be linked to any particular record.
- Option B: Create only the
model_reffield in the access groups and show data in the views. Do not re-use the group. Show an error if there is any access group linked to the record (e.g. employee) so that it is removed first.
Any other option?
I'm still not convinced of your statement that one group is for multiple folders. If I understand correctly, you link a parent folder "Employees" to the model hr.employee. Then, each record creates a subfolder "Employee 1", with a group allowing to access to that employee, "Employee 2" with another group, and so on...
Thus, each of these groups should be link to the directory, not to the model, as if not, we will have as many groups as employees you have. Am I wrong in something?
Currently dms_field will create as many groups (dms.access.group) automatically as appropriate when creating an employee's directory and link it to that directory. This functionality is required to add the employee's user as an extra user.
The "auto generated access group" will be linked to the employee's directory but if you delete the employee's directory and try to recreate it, it will try to recreate the auto access group and the error will occur because the name already exists, so you want to add these fields.
New changes added, please @pedrobaeza and @CarlosRoca13 , can you review it?
Further changes have been added to hr_dms_field to cover the case of modifying an employee (the auto-generated access group must be updated) and deleting it.
In v16 these changes can be added directly in dms_field in the dms.field.mixin model.
/ocabot merge minor
On my way to merge this fine PR! Prepared branch 15.0-ocabot-merge-pr-320-by-pedrobaeza-bump-minor, awaiting test results.
This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖
Congratulations, your PR was merged at 1c36089f5b3e4a85e51a78e70e58f464232a84e7. Thanks a lot for contributing to OCA. ❤️