From 472fac659ed33302158be8dd0ab5c588ddbea3d2 Mon Sep 17 00:00:00 2001 From: dja-odoo Date: Tue, 4 May 2021 07:38:11 +0000 Subject: [PATCH] [IMP] mail: limit followers edition/removal for users with read access Before this commit, if the user has read only access to a record: - User could see 'Add Followers' button, which raised AccessError - User could see edit and remove icons but performing these actions for followers other than one related to logged in user, it also raised AccessError. With this commit, we are restricting it based on the user rights, if the user has read only access to a record: - 'Add Followers', subtype edition(pencil icon) and follwer removal buttons will be visible only for the follower related to logged in user, not for others. This way we can avoid the unexpected AccessErrors. Note that if user is having write access for the record, nothing changes. task-id-2447776 closes odoo/odoo#70575 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/controllers/discuss.py | 13 +- .../follower_list_menu/follower_list_menu.xml | 24 ++- addons/mail/static/src/models/follower.js | 16 +- addons/mail/static/src/models/thread.js | 10 +- .../tests/helpers/model_definitions_setup.js | 3 - .../components/follow_button_tests.js | 3 - .../components/follower_list_menu_tests.js | 159 +++++++++++++++++- .../components/follower_subtype_tests.js | 3 - .../components/follower_tests.js | 7 +- 9 files changed, 203 insertions(+), 35 deletions(-) diff --git a/addons/mail/controllers/discuss.py b/addons/mail/controllers/discuss.py index 3d07c56fdb7..0f3c88eec38 100644 --- a/addons/mail/controllers/discuss.py +++ b/addons/mail/controllers/discuss.py @@ -8,7 +8,7 @@ from psycopg2 import IntegrityError from psycopg2.errorcodes import UNIQUE_VIOLATION from odoo import http -from odoo.exceptions import UserError +from odoo.exceptions import AccessError, UserError from odoo.http import request from odoo.tools import consteq, file_open from odoo.tools.misc import get_lang @@ -413,8 +413,14 @@ class DiscussController(http.Controller): @http.route('/mail/thread/data', methods=['POST'], type='json', auth='user') def mail_thread_data(self, thread_model, thread_id, request_list, **kwargs): - res = {} + res = {'hasWriteAccess': False} thread = request.env[thread_model].with_context(active_test=False).search([('id', '=', thread_id)]) + try: + thread.check_access_rights("write") + thread.check_access_rule("write") + res['hasWriteAccess'] = True + except AccessError: + pass if 'activities' in request_list: res['activities'] = thread.activity_ids.activity_format() if 'attachments' in request_list: @@ -427,9 +433,6 @@ class DiscussController(http.Controller): 'display_name': follower.display_name, 'email': follower.email, 'is_active': follower.is_active, - # When editing the followers, the "pencil" icon that leads to the edition of subtypes - # should be always be displayed and not only when "debug" mode is activated. - 'is_editable': True, 'partner': follower.partner_id.mail_partner_format()[follower.partner_id], } for follower in thread.message_follower_ids] if 'suggestedRecipients' in request_list: diff --git a/addons/mail/static/src/components/follower_list_menu/follower_list_menu.xml b/addons/mail/static/src/components/follower_list_menu/follower_list_menu.xml index 6d5d420c06c..04c3edafc7d 100644 --- a/addons/mail/static/src/components/follower_list_menu/follower_list_menu.xml +++ b/addons/mail/static/src/components/follower_list_menu/follower_list_menu.xml @@ -12,20 +12,26 @@