dms icon indicating copy to clipboard operation
dms copied to clipboard

[15.0][IMP] dms_field: Add model_ref to access groups to avoid possible errors when creating directories from a template.

Open victoralmau opened this issue 1 year ago • 8 comments

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

victoralmau avatar Mar 27 '24 12:03 victoralmau

I don't get the use case for this. For what do you need this?

pedrobaeza avatar Mar 27 '24 16:03 pedrobaeza

The example use case and the steps to reproduce it are in the initial description.

Before ejemplo-antes

After ejemplo-despues

victoralmau avatar Apr 01 '24 06:04 victoralmau

But shouldn't it be then 2 fields: the model and the res_id?

pedrobaeza avatar Apr 01 '24 07:04 pedrobaeza

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)

victoralmau avatar Apr 01 '24 07:04 victoralmau

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"?

pedrobaeza avatar Apr 01 '24 07:04 pedrobaeza

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_ref field 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?

victoralmau avatar Apr 02 '24 08:04 victoralmau

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?

pedrobaeza avatar Apr 19 '24 17:04 pedrobaeza

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.

victoralmau avatar Apr 22 '24 07:04 victoralmau

New changes added, please @pedrobaeza and @CarlosRoca13 , can you review it?

victoralmau avatar Jun 12 '24 10:06 victoralmau

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.

victoralmau avatar Jun 13 '24 06:06 victoralmau

/ocabot merge minor

pedrobaeza avatar Jun 18 '24 06:06 pedrobaeza

On my way to merge this fine PR! Prepared branch 15.0-ocabot-merge-pr-320-by-pedrobaeza-bump-minor, awaiting test results.

OCA-git-bot avatar Jun 18 '24 07:06 OCA-git-bot

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). 🤖

OCA-git-bot avatar Jun 18 '24 07:06 OCA-git-bot

Congratulations, your PR was merged at 1c36089f5b3e4a85e51a78e70e58f464232a84e7. Thanks a lot for contributing to OCA. ❤️

OCA-git-bot avatar Jun 18 '24 07:06 OCA-git-bot