[FIX] website: allow restricted editor to optimize SEO

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 <jke@odoo.com>
This commit is contained in:
Romain Derie
2024-01-04 17:02:26 +00:00
parent c755f1763e
commit 891162574e
5 changed files with 27 additions and 6 deletions
+9
View File
@@ -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<string(length=16):key>.html'], type='http', auth="public", website=True, sitemap=False)
+7
View File
@@ -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
@@ -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
@@ -169,7 +169,11 @@
size="size"
primaryClick="() => this.save()"
primaryTitle="saveButton"
showFooter="canEditSeo"
contentClass="contentClass">
<div t-if="!canEditSeo" class="alert alert-warning" role="alert">
You don't have permissions to edit this record.
</div>
<TitleDescription canEditDescription="canEditDescription"
canEditUrl="canEditUrl"
canEditTitle="canEditTitle"
@@ -179,8 +183,8 @@
defaultTitle="defaultTitle"
previewDescription="previewDescription"
url="url"/>
<MetaKeywords/>
<ImageSelector previewDescription="socialPreviewDescription"
<MetaKeywords t-if="canEditSeo"/>
<ImageSelector t-if="canEditSeo" previewDescription="socialPreviewDescription"
defaultTitle="defaultTitle"
hasSocialDefaultImage="hasSocialDefaultImage"
pageImages="pageImages"
@@ -86,7 +86,7 @@ registry.category('website_custom_menus').add('website.menu_edit_menu', {
registry.category('website_custom_menus').add('website.menu_optimize_seo', {
Component: OptimizeSEODialog,
isDisplayed: (env) => 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', {