[IMP] project: detect if the user changes the access rights

Before this commit, the user cannot remove all access rights for project
sharing feature of a project with allow_project_sharing enabled.

This commit checks if the user has made a change in the access rights if
yes then the 'Confirm Access' button appears otherwise only 'Send'
button appears.

task-2379518

closes #73341
This commit is contained in:
Xavier BOL (xbo)
2021-08-26 14:59:33 +02:00
parent 57b8eb7e3b
commit 7ed6e9e16b
2 changed files with 21 additions and 3 deletions
@@ -28,12 +28,29 @@ class ProjectShareWizard(models.TransientModel):
partner_ids = fields.Many2many(compute="_compute_partner_ids", readonly=False, store=True, required=False)
line_ids = fields.One2many('project.share.wizard.line', 'project_share_id')
has_access_changed = fields.Boolean(compute='_compute_has_access_changed')
@api.depends('line_ids.user_id')
def _compute_partner_ids(self):
for project_share_wizard in self:
project_share_wizard.partner_ids |= project_share_wizard.line_ids.user_id.partner_id
@api.depends('line_ids.user_id', 'line_ids.access_mode')
def _compute_has_access_changed(self):
project_sharing_access_read = self.env['project.sharing.access'].search_read([('project_id', '=', self.res_id)], ['user_id', 'access_mode'])
project_sharing_access_dict = {res['user_id'][0]: res['access_mode'] for res in project_sharing_access_read}
for project_share in self:
if len(project_share.line_ids) != len(project_sharing_access_dict):
project_share.has_access_changed = True
continue
has_access_changed = False
for line in project_share.line_ids:
access_mode = project_sharing_access_dict.get(line.user_id.id)
if not access_mode or access_mode != line.access_mode:
has_access_changed = True
break
project_share.has_access_changed = has_access_changed
def action_send_mail_and_confirm_access(self):
if not self.partner_ids:
raise UserError(_('Impossible to send email, no recipients are mentionned.'))
@@ -27,9 +27,10 @@
</field>
</group>
<footer>
<button string="Confirm Access" name="action_confirm_access" attrs="{'invisible': ['|', ('access_warning', '!=', ''), ('line_ids', '=', [])]}" type="object" class="btn-primary" data-hotkey="v"/>
<button string="Send" name="action_send_mail" attrs="{'invisible': ['|', ('access_warning', '!=', ''), ('line_ids', '!=', [])]}" type="object" class="btn-primary" data-hotkey="q"/>
<button string="Send &amp; Confirm" name="action_send_mail_and_confirm_access" attrs="{'invisible': ['|', ('access_warning', '!=', ''), ('line_ids', '=', [])]}" type="object" class="btn-primary" data-hotkey="q"/>
<field name="has_access_changed" invisible="1" />
<button string="Confirm Access" name="action_confirm_access" attrs="{'invisible': ['|', ('access_warning', '!=', ''), ('has_access_changed', '=', False)]}" type="object" class="btn-primary" data-hotkey="v"/>
<button string="Send" name="action_send_mail" attrs="{'invisible': ['|', ('access_warning', '!=', ''), ('has_access_changed', '=', True)]}" type="object" class="btn-primary" data-hotkey="q"/>
<button string="Send &amp; Confirm" name="action_send_mail_and_confirm_access" attrs="{'invisible': ['|', ('access_warning', '!=', ''), ('has_access_changed', '=', False)]}" type="object" class="btn-primary" data-hotkey="q"/>
<button string="Cancel" class="btn-default" special="cancel" data-hotkey="z" />
</footer>
</form>