[FIX] website, *: not fail on visitors views without event rights

*: website_crm, website_event, website_event_track

Before this commit, when accessing the visitor views without having any
event rights, an error was triggered.

This commit restricts the display of the `event_registration_count`
field on the `website_visitor_view_form` restricted to the
`event.group_event_user` group so that its invisible condition does not
fail. Similarly it restricts a visibility condition on
`event_track_wishlisted_count` to the `event.group_event_manager` group.
To avoid encountering the same issue with further extensions of
`_compute_email_phone` on the `website.visitor` model, we make its
fields `compute_sudo=True`, and revert the specific `sudo` that had
been added in [1].

Steps to reproduce:
- install `website_event`
- set Demo user to have no Events right, but be an "Editor and Designer"
for Website
- register to an event as an anonymous user
- access the Visitors page as Demo user

=> An error was produced.

Steps to reproduce (2):
- install `website_event_track`
- set Demo user to have no Events right, but be an "Editor and Designer"
- access the Visitors page as Demo user

=> An error was produced.

[1]: https://github.com/odoo/odoo/commit/5ba09c2cb2bb180cfb1363c352f35bd8cf3b132b

opw-3537849

closes odoo/odoo#139271

X-original-commit: 4cb18fab5e8d14dd9a2dfb5cb3e65b43fab02846
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
This commit is contained in:
Benoit Socias
2023-10-20 22:10:39 +00:00
parent 880e68b39a
commit 55e64beb47
4 changed files with 5 additions and 3 deletions
+2 -2
View File
@@ -62,8 +62,8 @@ class WebsiteVisitor(models.Model):
country_flag = fields.Char(related="country_id.image_url", string="Country Flag")
lang_id = fields.Many2one('res.lang', string='Language', help="Language from the website when visitor has been created")
timezone = fields.Selection(_tz_get, string='Timezone')
email = fields.Char(string='Email', compute='_compute_email_phone')
mobile = fields.Char(string='Mobile', compute='_compute_email_phone')
email = fields.Char(string='Email', compute='_compute_email_phone', compute_sudo=True)
mobile = fields.Char(string='Mobile', compute='_compute_email_phone', compute_sudo=True)
# Visit fields
visit_count = fields.Integer('# Visits', default=1, readonly=True, help="A new visit is considered if last connection was more than 8 hours ago.")
+1 -1
View File
@@ -21,7 +21,7 @@ class WebsiteVisitor(models.Model):
super(WebsiteVisitor, self)._compute_email_phone()
left_visitors = self.filtered(lambda visitor: not visitor.email or not visitor.mobile)
leads = left_visitors.sudo().mapped('lead_ids').sorted('create_date', reverse=True)
leads = left_visitors.mapped('lead_ids').sorted('create_date', reverse=True)
visitor_to_lead_ids = dict((visitor.id, visitor.lead_ids.ids) for visitor in left_visitors)
for visitor in left_visitors:
@@ -21,6 +21,7 @@
<button name="%(website_event.event_registration_action_from_visitor)d"
type="action"
class="oe_stat_button" icon="fa-ticket"
groups="event.group_event_user"
invisible="event_registration_count == 0">
<field name="event_registration_count" widget="statinfo" string="Registrations"/>
</button>
@@ -21,6 +21,7 @@
<button name="%(website_event_track.event_track_action_from_visitor)d"
type="action"
class="oe_stat_button" icon="fa-ticket"
groups="event.group_event_manager"
invisible="event_track_wishlisted_count == 0">
<field name="event_track_wishlisted_count" widget="statinfo" string="Tracks"/>
</button>