Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] attachment_delete_restrict: Migration to 16.0 #2673

Open
wants to merge 16 commits into
base: 16.0
Choose a base branch
from

Conversation

AungKoKoLin1997
Copy link
Contributor

@AungKoKoLin1997 AungKoKoLin1997 commented Jul 7, 2023

@qrtl

This PR encompasses the following steps:

  1. Standard Migration
  2. Fixes
    - Removal of the display of duplicate allowed user names.
    - Correct the many2many field relation
    - Correction of domain values and addition of the many2many_tags widget in views.
  3. Improvements
    - Addition of _onchange_restrict_delete_attachment() to clear groups and users when restrict_delete_attachment is not set to custom or owner_custom.

Copy link
Sponsor Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AungKoKoLin1997 I think some of the changes should be in separate commits to be backported to 14.0.

@@ -33,7 +33,7 @@ def _raise_delete_attachment_error(self, allowed_users):
"You are not allowed to delete this attachment.\n\nUsers with "
"the delete permission:\n%s"
)
% ("\n".join(allowed_users.mapped("name")) or "None")
% ("\n".join(list(set(allowed_users.mapped("name")))) or "None")
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set() should be done when allowed_users is updated in _check_custom_delete_attachment() instead. It should perhaps be in a separate commit to be backported.

)

@api.onchange("restrict_delete_attachment")
def _clear_groups_users(self):
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _clear_groups_users(self):
def _onchange_restrict_delete_attachment(self):

I suppose this should also be in a separate commit to be backported.

Comment on lines 14 to 15
"the models "
"assigned here.",
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"the models "
"assigned here.",
"the models assigned here. Restrict Attachment Deletion must be 'Custom' or 'Owner + Custom' for the model to be selected here.",

Comment on lines 18 to 29
def write(self, vals):
res = super(ResGroups, self).write(vals)
if "delete_attachment_model_ids" in vals:
for group in self:
for model in group.delete_attachment_model_ids:
if group not in model.delete_attachment_group_ids:
model.write(
{
"delete_attachment_group_ids": [(4, group.id)],
}
)
return res
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why this should be needed?

Comment on lines 17 to 29
def write(self, vals):
res = super(ResUsers, self).write(vals)
if "delete_attachment_model_ids" in vals:
for user in self:
for model in user.delete_attachment_model_ids:
if user not in model.delete_attachment_user_ids:
model.write(
{
"delete_attachment_user_ids": [(4, user.id)],
}
)
return res
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-attachment_delete_restrict branch from 3840945 to 2fdfe5f Compare July 11, 2023 02:55
if self.env.user not in allowed_users:
return self._raise_delete_attachment_error(allowed_users)

def unlink(self):
res_models = list(set(self.filtered("res_model").mapped("res_model")))
if res_models:
models = self.env["ir.model"].search([("model", "in", res_models)])
models = self.env["ir.model"].sudo().search([("model", "in", res_models)])
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be part of the migration, due to the ACL change in 16.0 (or 15.0, I haven't checked).

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-attachment_delete_restrict branch from 2fdfe5f to ca37da1 Compare July 11, 2023 04:32
@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-attachment_delete_restrict branch from ca37da1 to f0c88d3 Compare November 1, 2023 07:52
@legalsylvain
Copy link
Contributor

hi @yostashiro. Thanks for your review. could you update it ?
thanks !

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-mig-attachment_delete_restrict branch from f0c88d3 to 434dc12 Compare January 30, 2024 03:50
@AungKoKoLin1997
Copy link
Contributor Author

@OCA-server-tools-maintainers
Is it possible to review this PR?

Copy link
Sponsor Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review and functional test. LGTM.

Copy link

@kanda999 kanda999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and Function : LGTM

@kanda999
Copy link

@AungKoKoLin1997
Could you rebase this PR to restart runboat?

- Add _onchange_restrict_delete_attachment() to clear groups and users when restrict_delete_attachment is not set to custom or owner_custom.
@OCA-git-bot
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants