From 891162574eead15cf64a4f934e5f12346cbcfbbf Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Wed, 3 Jan 2024 17:32:36 +0100 Subject: [PATCH] [FIX] website: allow restricted editor to optimize SEO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Originally, restricted editors don't have the rights to edit the SEO of a record. It was probably a bad idea as they can already edit the record itself and can change the name / description of the record in the page. Changing the SEO seems to be very similar. Also, for our internal needs, we need our HR people (which are restricted editor with rights on jobs position) to be able to edit the SEO of their jobs. And we don't want to grant them the full editor right. Note: - We already have a `data-can-optimize-seo` attribute set on the HTML tag if one is logged in, but this is just about knowing if the record has SEO-mixin capability, it does not check the rights for a given record. - In master, one day, we would like to have the "Edit" button shown only when something can be edited for restricted editor (to not be able to enter edit mode to then not be able to edit anything). The same would be nice here: optimize seo menu could only be shown if you have the right, but we don't want to do an extra RPC each time for now. - We keep the info shown in readonly mode so the restricted user can see it and ask for a change to someone else if needed Related commits: - https://github.com/odoo/odoo/commit/94e2eefca28196efc0ac38f155a3b85acbbdeaae - https://github.com/odoo/odoo/commit/21464edf7ce858c065e113e32d857dfa4ace1788 closes odoo/odoo#147981 Signed-off-by: Jérémy Kersten --- addons/website/controllers/main.py | 9 +++++++++ addons/website/i18n/website.pot | 7 +++++++ addons/website/static/src/components/dialog/seo.js | 7 ++++--- addons/website/static/src/components/dialog/seo.xml | 8 ++++++-- .../website/static/src/services/website_custom_menus.js | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 2078f692e0d..17672de72af 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -752,6 +752,15 @@ class Website(Home): if res_model not in ('website.page', 'ir.ui.view') and 'seo_name' in record: # allow custom slugify res['seo_name_default'] = slugify(record.display_name) # default slug, if seo_name become empty res['seo_name'] = record.seo_name and slugify(record.seo_name) or '' + + try: + record.check_access_rights('write') + record.check_access_rule('write') + except AccessError: + res['can_edit_seo'] = False + else: + res['can_edit_seo'] = True + return res @http.route(['/google.html'], type='http', auth="public", website=True, sitemap=False) diff --git a/addons/website/i18n/website.pot b/addons/website/i18n/website.pot index 262446bd769..0304c3a6d07 100644 --- a/addons/website/i18n/website.pot +++ b/addons/website/i18n/website.pot @@ -12551,6 +12551,13 @@ msgstr "" msgid "You do not have the rights to publish/unpublish" msgstr "" +#. module: website +#. odoo-javascript +#: code:addons/website/static/src/components/dialog/seo.xml:0 +#, python-format +msgid "You don't have permissions to edit this record." +msgstr "" + #. module: website #. odoo-javascript #: code:addons/website/static/src/components/dialog/seo.xml:0 diff --git a/addons/website/static/src/components/dialog/seo.js b/addons/website/static/src/components/dialog/seo.js index 0b19250c567..7540d3a8245 100644 --- a/addons/website/static/src/components/dialog/seo.js +++ b/addons/website/static/src/components/dialog/seo.js @@ -383,9 +383,10 @@ export class OptimizeSEODialog extends Component { 'res_model': this.object.model, }); - this.canEditDescription = 'website_meta_description' in this.data; - this.canEditTitle = 'website_meta_title' in this.data; - this.canEditUrl = 'seo_name' in this.data; + this.canEditSeo = this.data.can_edit_seo; + this.canEditDescription = this.canEditSeo && 'website_meta_description' in this.data; + this.canEditTitle = this.canEditSeo && 'website_meta_title' in this.data; + this.canEditUrl = this.canEditSeo && 'seo_name' in this.data; seoContext.title = this.canEditTitle && this.data.website_meta_title; // If website.page, hide the google preview & tell user his page is currently unindexed diff --git a/addons/website/static/src/components/dialog/seo.xml b/addons/website/static/src/components/dialog/seo.xml index d857a98de5f..d086792c432 100644 --- a/addons/website/static/src/components/dialog/seo.xml +++ b/addons/website/static/src/components/dialog/seo.xml @@ -169,7 +169,11 @@ size="size" primaryClick="() => this.save()" primaryTitle="saveButton" + showFooter="canEditSeo" contentClass="contentClass"> + - - + env.services.website.currentWebsite - && env.services.website.isDesigner + && env.services.website.isRestrictedEditor && !!env.services.website.currentWebsite.metadata.canOptimizeSeo, }); registry.category('website_custom_menus').add('website.menu_ace_editor', {