Skip to content

Commit

Permalink
Ease access rights on communication revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Aug 15, 2024
1 parent 1756a35 commit e7c901a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
10 changes: 3 additions & 7 deletions partner_communication_revision/models/communication_revision.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ class CommunicationRevision(models.Model):
"Responsible",
domain=[("share", "=", False)],
tracking=True,
readonly=False,
)
correction_user_id = fields.Many2one(
"res.users",
"Corrector",
domain=[("share", "=", False)],
tracking=True,
readonly=False,
)
update_user_id = fields.Many2one(
"res.users", "Modified by", default=lambda self: self.env.uid, readonly=True
Expand Down Expand Up @@ -134,8 +132,7 @@ class CommunicationRevision(models.Model):
string="Loops",
readonly=False,
)
is_proposer = fields.Boolean(compute="_compute_allowed")
is_corrector = fields.Boolean(compute="_compute_allowed")
is_editor = fields.Boolean(compute="_compute_is_editor")
display_name = fields.Char(compute="_compute_display_name")
active_revision_id = fields.Many2one(
comodel_name="partner.communication.revision.history",
Expand Down Expand Up @@ -205,12 +202,11 @@ def _check_corrector(self):
)
return True

def _compute_allowed(self):
def _compute_is_editor(self):
user = self.env.user
admin = self.env.ref("base.group_erp_manager") in user.groups_id
for rev in self:
rev.is_proposer = user == rev.user_id or admin
rev.is_corrector = user == rev.correction_user_id or admin
rev.is_editor = user in (rev.user_id, rev.correction_user_id) or admin

def _compute_display_name(self):
for rev in self:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
<field name="arch" type="xml">
<form>
<header>
<field name="is_proposer" invisible="1" />
<field name="is_corrector" invisible="1" />
<field name="is_editor" invisible="1" />
<field name="is_old_version" invisible="1" />
<field name="state" widget="statusbar" />
<!-- Proposition to submit -->
Expand All @@ -96,7 +95,7 @@
name="submit_proposition"
string="Submit proposition"
class="oe_highlight"
attrs="{'invisible': ['|', ('state', '!=', 'pending'),('is_proposer', '=', False)]}"
attrs="{'invisible': ['|', ('state', '!=', 'pending'),('is_editor', '=', False)]}"
/>

<!-- Proposition to Approve / Corrections to submit-->
Expand All @@ -105,15 +104,15 @@
name="validate_proposition"
string="Validate proposition"
class="oe_highlight"
attrs="{'invisible': ['|', ('state', '!=', 'submit'),('is_corrector', '=', False)]}"
attrs="{'invisible': ['|', ('state', '!=', 'submit'),('is_editor', '=', False)]}"
confirm="This will approve the proposition text."
/>
<button
type="object"
name="submit_correction"
string="Submit corrections"
class="oe_highlight"
attrs="{'invisible': ['|', ('state', '!=', 'submit'),('is_corrector', '=', False)]}"
attrs="{'invisible': ['|', ('state', '!=', 'submit'),('is_editor', '=', False)]}"
/>

<!-- Corrections to Approve / New Proposition -->
Expand All @@ -122,22 +121,22 @@
name="validate_correction"
string="Approve corrections"
class="oe_highlight"
attrs="{'invisible': ['|', ('state', '!=', 'corrected'),('is_proposer', '=', False)]}"
attrs="{'invisible': ['|', ('state', '!=', 'corrected'),('is_editor', '=', False)]}"
confirm="This will approve the corrections."
/>
<button
type="object"
name="edit_correction"
string="Edit corrections"
class="oe_highlight"
attrs="{'invisible': ['|', ('state', '!=', 'corrected'),('is_proposer', '=', False)]}"
attrs="{'invisible': ['|', ('state', '!=', 'corrected'),('is_editor', '=', False)]}"
confirm="This will discard your original proposition and allow you to edit further the corrected text."
/>
<button
type="object"
name="discard_correction"
string="Discard corrections"
attrs="{'invisible': ['|', ('state', '!=', 'corrected'),('is_proposer', '=', False)]}"
attrs="{'invisible': ['|', ('state', '!=', 'corrected'),('is_editor', '=', False)]}"
confirm="This will discard corrections and let you start over your proposition."
/>

Expand All @@ -146,7 +145,7 @@
type="object"
name="cancel_approve"
string="Cancel approval"
attrs="{'invisible': ['|', ('state', '!=', 'approved'), '&amp;', ('is_proposer', '=', False),('is_corrector', '=', False)]}"
attrs="{'invisible': ['|', ('state', '!=', 'approved'), '&amp;', ('is_editor', '=', False),('is_editor', '=', False)]}"
/>

<button
Expand Down Expand Up @@ -187,38 +186,38 @@
<group>
<field
name="user_id"
attrs="{'required': [('state', '=', 'pending')], 'readonly': ['|', ('is_proposer', '=', False), ('state', '!=', 'pending')]}"
attrs="{'required': [('state', '=', 'pending')], 'readonly': [('state', '!=', 'pending')]}"
/>
</group>
<group>
<field
name="correction_user_id"
attrs="{'required': [('state', '=', 'pending')], 'readonly': [('is_proposer', '=', False)]}"
attrs="{'required': [('state', '=', 'pending')]}"
/>
</group>
</group>
<group>
<group>
<field
name="subject"
attrs="{'required': [('state', '=', 'pending')], 'readonly': ['|', ('is_proposer', '=', False), ('state', '!=', 'pending')]}"
attrs="{'required': [('state', '=', 'pending')], 'readonly': ['|', ('is_editor', '=', False), ('state', '!=', 'pending')]}"
/>
<field
name="proposition_text"
attrs="{'required': [('state', '=', 'pending')], 'readonly': ['|', ('is_proposer', '=', False), ('state', '!=', 'pending')]}"
attrs="{'required': [('state', '=', 'pending')], 'readonly': ['|', ('is_editor', '=', False), ('state', '!=', 'pending')]}"
/>
</group>
<group
attrs="{'invisible': [('proposition_correction', '=', False)]}"
>
<field
name="subject_correction"
attrs="{'readonly': ['|', ('is_corrector', '=', False),('state','!=','submit')]}"
attrs="{'readonly': ['|', ('is_editor', '=', False),('state','!=','submit')]}"
states="pending,submit,corrected"
/>
<field
name="proposition_correction"
attrs="{'readonly': ['|', ('is_corrector', '=', False),('state','!=','submit')]}"
attrs="{'readonly': ['|', ('is_editor', '=', False),('state','!=','submit')]}"
states="pending,submit,corrected"
/>
</group>
Expand Down

0 comments on commit e7c901a

Please sign in to comment.