From 81d7b17c5cda4557be0d84493482d500489cda61 Mon Sep 17 00:00:00 2001 From: std-odoo Date: Thu, 28 Apr 2022 11:55:50 +0000 Subject: [PATCH] [IMP] mail_plugin: hide the create button if we do not have access right Purpose ======= Hide the "Create Partner" button if we do not have the "create" access right. Do not offer to create a project if the current user can't. Do not try to enrich if we can't create a partner. The write access on the partner is checked on the record itself because of access rules. Task-2826471 X-original-commit: b678a9bc1298e9a1973074740a8c8a1d471b6848 Part-of: odoo/odoo#93058 --- .../crm_mail_plugin/i18n/crm_mail_plugin.pot | 14 +++++++++++ .../src/to_translate/translations_gmail.xml | 1 + .../src/to_translate/translations_outlook.xml | 1 + addons/mail_plugin/controllers/mail_plugin.py | 18 +++++++++++--- .../controllers/mail_plugin.py | 2 ++ .../i18n/project_mail_plugin.pot | 24 +++++++++++++++++++ .../src/to_translate/translations_gmail.xml | 3 +++ .../src/to_translate/translations_outlook.xml | 3 +++ 8 files changed, 63 insertions(+), 3 deletions(-) diff --git a/addons/crm_mail_plugin/i18n/crm_mail_plugin.pot b/addons/crm_mail_plugin/i18n/crm_mail_plugin.pot index 150bdb9f016..d414e0084b5 100644 --- a/addons/crm_mail_plugin/i18n/crm_mail_plugin.pot +++ b/addons/crm_mail_plugin/i18n/crm_mail_plugin.pot @@ -111,3 +111,17 @@ msgstr "" #, python-format msgid "Save Contact to create new Opportunities." msgstr "" + +#. module: crm_mail_plugin +#. openerp-web +#: code:addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml:0 +#, python-format +msgid "The Contact needs to exist to create Opportunity." +msgstr "" + +#. module: crm_mail_plugin +#. openerp-web +#: code:addons/crm_mail_plugin/static/src/to_translate/translations_gmail.xml:0 +#, python-format +msgid "You can only create opportunities for existing customers." +msgstr "" diff --git a/addons/crm_mail_plugin/static/src/to_translate/translations_gmail.xml b/addons/crm_mail_plugin/static/src/to_translate/translations_gmail.xml index 945677f4090..4193d4f28cd 100644 --- a/addons/crm_mail_plugin/static/src/to_translate/translations_gmail.xml +++ b/addons/crm_mail_plugin/static/src/to_translate/translations_gmail.xml @@ -10,4 +10,5 @@ %(expected_revenue)s at %(probability)s% %(expected_revenue)s + %(recurring_revenue)s %(recurring_plan)s at %(probability)s% Save Contact to create new Opportunities. + You can only create opportunities for existing customers. diff --git a/addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml b/addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml index 22ce4b7c5fd..e3c045f7d11 100644 --- a/addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml +++ b/addons/crm_mail_plugin/static/src/to_translate/translations_outlook.xml @@ -8,4 +8,5 @@ %(expected_revenue)s + %(recurring_revenue)s %(recurring_plan)s at %(probability)s% Save Contact to create new Opportunities. No opportunities found for this contact. + The Contact needs to exist to create Opportunity. diff --git a/addons/mail_plugin/controllers/mail_plugin.py b/addons/mail_plugin/controllers/mail_plugin.py index 19f50679392..5c10516c525 100644 --- a/addons/mail_plugin/controllers/mail_plugin.py +++ b/addons/mail_plugin/controllers/mail_plugin.py @@ -9,6 +9,7 @@ from werkzeug.exceptions import Forbidden from odoo import http, tools, _ from odoo.addons.iap.tools import iap_tools +from odoo.exceptions import AccessError from odoo.http import request _logger = logging.getLogger(__name__) @@ -168,7 +169,10 @@ class MailPluginController(http.Controller): 'enrichment_info': None, } company = self._find_existing_company(normalized_email) - if not company: # create and enrich company + + can_create_partner = request.env['res.partner'].check_access_rights('create', raise_exception=False) + + if not company and can_create_partner: # create and enrich company company, enrichment_info = self._create_company_from_iap(normalized_email) response['partner']['enrichment_info'] = enrichment_info response['partner']['company'] = self._get_company_data(company) @@ -366,8 +370,14 @@ class MailPluginController(http.Controller): partner_values['title'] = partner.function partner_values['enrichment_info'] = None - return partner_values + try: + partner.check_access_rights('write') + partner.check_access_rule('write') + partner_values['can_write_on_partner'] = True + except AccessError: + partner_values['can_write_on_partner'] = False + return partner_values def _get_contact_data(self, partner): """ @@ -387,7 +397,9 @@ class MailPluginController(http.Controller): return { 'partner': partner_response, - 'user_companies': request.env['res.users'].browse(request.uid).company_ids.ids + 'user_companies': request.env.user.company_ids.ids, + 'can_create_partner': request.env['res.partner'].check_access_rights( + 'create', raise_exception=False), } def _mail_content_logging_models_whitelist(self): diff --git a/addons/project_mail_plugin/controllers/mail_plugin.py b/addons/project_mail_plugin/controllers/mail_plugin.py index f7be93255b8..f8c05054eaa 100644 --- a/addons/project_mail_plugin/controllers/mail_plugin.py +++ b/addons/project_mail_plugin/controllers/mail_plugin.py @@ -44,6 +44,8 @@ class MailPluginController(mail_plugin.MailPluginController): } for task in partner_tasks if task.project_id.id in accessible_projects] contact_values['tasks'] = tasks_values + contact_values['can_create_project'] = request.env['project.project'].check_access_rights( + 'create', raise_exception=False) return contact_values diff --git a/addons/project_mail_plugin/i18n/project_mail_plugin.pot b/addons/project_mail_plugin/i18n/project_mail_plugin.pot index 1f697bb17b5..466c8de8c49 100644 --- a/addons/project_mail_plugin/i18n/project_mail_plugin.pot +++ b/addons/project_mail_plugin/i18n/project_mail_plugin.pot @@ -85,6 +85,13 @@ msgstr "" msgid "Log the email on the task" msgstr "" +#. module: project_mail_plugin +#. openerp-web +#: code:addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml:0 +#, python-format +msgid "No project" +msgstr "" + #. module: project_mail_plugin #. openerp-web #: code:addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml:0 @@ -188,9 +195,26 @@ msgstr "" msgid "Tasks (%s)" msgstr "" +#. module: project_mail_plugin +#. openerp-web +#: code:addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml:0 +#: code:addons/project_mail_plugin/static/src/to_translate/translations_outlook.xml:0 +#, python-format +msgid "The Contact needs to exist to create Task." +msgstr "" + #. module: project_mail_plugin #. openerp-web #: code:addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml:0 #, python-format msgid "The project name is required" msgstr "" + +#. module: project_mail_plugin +#. openerp-web +#: code:addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml:0 +#, python-format +msgid "" +"There are no project in your database. Please ask your project manager to " +"create one." +msgstr "" diff --git a/addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml b/addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml index a16863056f0..fc79a184b82 100644 --- a/addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml +++ b/addons/project_mail_plugin/static/src/to_translate/translations_gmail.xml @@ -20,4 +20,7 @@ Save the contact to create new tasks. The project name is required No project found. + The Contact needs to exist to create Task. + No project + There are no project in your database. Please ask your project manager to create one. diff --git a/addons/project_mail_plugin/static/src/to_translate/translations_outlook.xml b/addons/project_mail_plugin/static/src/to_translate/translations_outlook.xml index 850c5670752..a826e7ee8d1 100644 --- a/addons/project_mail_plugin/static/src/to_translate/translations_outlook.xml +++ b/addons/project_mail_plugin/static/src/to_translate/translations_outlook.xml @@ -9,4 +9,7 @@ Create %(name)s Search Projects... Log Email Into Task + The Contact needs to exist to create Task. + No Project Found + No project