diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-10-14 11:05:55 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-12-02 15:18:44 +0000 |
| commit | 5649fc88e8f3022f4143400a124f2e3c1e5c0df8 (patch) | |
| tree | cb172be462e568baca8235f7af13855733cfaf8b /addons/website_mail | |
| parent | 46b9a97b56d74503d6e86b16466982c750a66422 (diff) | |
[REF] {website_}mail: move and replace published field of mail.message to is_internal
PURPOSE
Clean posting process and improve mail.message definition and comprehension.
SPECIFICATIONS
Website mail defines a website_published field allowing to publish / unpublish
comments on the frontend of some modules. This field has several drawbacks :
* it is used only for front-end people (portal, public) and has no real
effect in chatter / classic discussions;
* it is used only in some advanced front-end module and is not available
in portal by default;
* its naming is not really correct as it is not linked to fields coming
from the website_published mixin and its behavior is not really
the same;
* its use is a bit duplicated with internal flag coming from subtype
allowing to hide messages related to an internal subtype;
* there are overrides of standard mail.message methods just to handle
this flag;
In this commit we change that field by an is_internal flag directly on
mail.message model itself. It tells if share people (customers, share users)
are allowed to read the message. This field can be given through posting
API or set manually using widgets. It is also used in access rights custom
methods and managed like the internal flag of subtypes.
Mailgateway was already using an internal flag for internal note replies. It
is renamed to is_internal and propagated as it is now a standard field. It
also eases code understanding.
Portal is updated to allow managing the flag directly. It means customer portal
now natively allows to moderate customer comments without any need of website
modules.
Rating is updated accordingly. An is_internal field is added, replacing the
related on website published.
LINKS
Task ID 2071556
PR #38692
Diffstat (limited to 'addons/website_mail')
| -rw-r--r-- | addons/website_mail/__manifest__.py | 4 | ||||
| -rw-r--r-- | addons/website_mail/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/website_mail/models/mail_message.py | 58 | ||||
| -rw-r--r-- | addons/website_mail/security/website_mail_security.xml | 13 | ||||
| -rw-r--r-- | addons/website_mail/static/src/js/portal_chatter.js | 13 | ||||
| -rw-r--r-- | addons/website_mail/static/src/xml/portal_chatter.xml | 23 | ||||
| -rw-r--r-- | addons/website_mail/views/assets.xml | 1 |
7 files changed, 1 insertions, 112 deletions
diff --git a/addons/website_mail/__manifest__.py b/addons/website_mail/__manifest__.py index fb4dc268da2..b91958c65f2 100644 --- a/addons/website_mail/__manifest__.py +++ b/addons/website_mail/__manifest__.py @@ -7,14 +7,12 @@ 'summary': 'Website Module for Mail', 'version': '0.1', 'description': """ -Module holding mail improvements for website. -It is responsible of comments moderation for published documents (forum, slides, blog, ...) +Module holding mail improvements for website. It holds the follow widget. """, 'depends': ['website', 'mail'], 'data': [ 'views/assets.xml', 'views/website_mail_templates.xml', - 'security/website_mail_security.xml', ], 'installable': True, 'auto_install': True, diff --git a/addons/website_mail/models/__init__.py b/addons/website_mail/models/__init__.py index 75ea63bd6d8..d138acf14cc 100644 --- a/addons/website_mail/models/__init__.py +++ b/addons/website_mail/models/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import mail_message from . import update diff --git a/addons/website_mail/models/mail_message.py b/addons/website_mail/models/mail_message.py deleted file mode 100644 index 2de32b9f4f0..00000000000 --- a/addons/website_mail/models/mail_message.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import api, fields, models, _ -from odoo.osv import expression -from odoo.exceptions import AccessError - - -class MailMessage(models.Model): - _inherit = 'mail.message' - - @api.model - def default_get(self, fields_list): - defaults = super(MailMessage, self).default_get(fields_list) - - # Note: explicitly implemented in default_get() instead of field default, - # to avoid setting to True for all existing messages during upgrades. - # TODO: this default should probably be dynamic according to the model - # on which the messages are attached, thus moved to create(). - if 'website_published' in fields_list: - defaults.setdefault('website_published', True) - - return defaults - - website_published = fields.Boolean(string='Published', help="Visible on the website as a comment", copy=False) - - @api.model - def _non_employee_message_domain(self): - domain = super(MailMessage, self)._non_employee_message_domain() - return expression.AND([domain, [('website_published', '=', True)]]) - - @api.model - def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None): - """ Override that adds specific access rights of mail.message, to restrict - messages to published messages for public users. """ - if self.user_has_groups('base.group_public'): - args = expression.AND([[('website_published', '=', True)], list(args)]) - - return super(MailMessage, self)._search(args, offset=offset, limit=limit, order=order, - count=count, access_rights_uid=access_rights_uid) - - def check_access_rule(self, operation): - """ Add Access rules of mail.message for non-employee user: - - read: - - raise if the type is comment and subtype NULL (internal note) - """ - if self.user_has_groups('base.group_public'): - self.env.cr.execute('SELECT id FROM "%s" WHERE website_published IS FALSE AND id = ANY (%%s)' % (self._table), (self.ids,)) - if self.env.cr.fetchall(): - raise AccessError( - _('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation) - + ' - ({} {}, {} {})'.format(_('Records:'), self.ids[:6], _('User:'), self._uid) - ) - return super(MailMessage, self).check_access_rule(operation=operation) - - def _portal_message_format(self, fields_list): - fields_list += ['website_published'] - return super(MailMessage, self)._portal_message_format(fields_list) diff --git a/addons/website_mail/security/website_mail_security.xml b/addons/website_mail/security/website_mail_security.xml deleted file mode 100644 index d814fff16ef..00000000000 --- a/addons/website_mail/security/website_mail_security.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<odoo> - <data noupdate="1"> - - <record id="mail_message_rule_public" model="ir.rule"> - <field name="name">mail.message: portal/public: read published messages</field> - <field name="model_id" ref="mail.model_mail_message"/> - <field name="domain_force">[('website_published', '=', True)]</field> - <field name="groups" eval="[(4, ref('base.group_portal')), (4, ref('base.group_public'))]"/> - </record> - - </data> -</odoo> diff --git a/addons/website_mail/static/src/js/portal_chatter.js b/addons/website_mail/static/src/js/portal_chatter.js deleted file mode 100644 index 923c17032fe..00000000000 --- a/addons/website_mail/static/src/js/portal_chatter.js +++ /dev/null @@ -1,13 +0,0 @@ -odoo.define('website_mail.thread', function (require) { -'use strict'; - -var portalChatter = require('portal.chatter'); - -/** - * Extends Frontend Chatter to handle rating - */ -portalChatter.PortalChatter.include({ - xmlDependencies: (portalChatter.PortalChatter.prototype.xmlDependencies || []) - .concat(['/website_mail/static/src/xml/portal_chatter.xml']), -}); -}); diff --git a/addons/website_mail/static/src/xml/portal_chatter.xml b/addons/website_mail/static/src/xml/portal_chatter.xml deleted file mode 100644 index 70f51435c3b..00000000000 --- a/addons/website_mail/static/src/xml/portal_chatter.xml +++ /dev/null @@ -1,23 +0,0 @@ -<templates id="template" xml:space="preserve"> - - <t t-name="website_mail.publish_short"> - <t t-if="is_publisher" t-ignore="true"> - <div t-attf-class="float-right js_publish_management #{object.website_published and 'css_published' or 'css_unpublished'}" t-att-data-id="res_id" t-att-data-object="res_model" t-att-data-controller="publish_controller"> - <button class="btn btn-danger js_publish_btn">Unpublished</button> - <button class="btn btn-success js_publish_btn">Published</button> - </div> - </t> - </t> - - <t t-extend="portal.chatter_messages"> - <t t-jquery=".o_portal_chatter_message_title" t-operation="before"> - <t t-call="website_mail.publish_short"> - <t t-set="res_model" t-value="'mail.message'"/> - <t t-set="res_id" t-value="message.id"/> - <t t-set="object" t-value="message"/> - <t t-set="is_publisher" t-value="widget.options['is_user_publisher']"/> - </t> - </t> - </t> - -</templates> diff --git a/addons/website_mail/views/assets.xml b/addons/website_mail/views/assets.xml index 30d581cf4a4..c0c293a1b39 100644 --- a/addons/website_mail/views/assets.xml +++ b/addons/website_mail/views/assets.xml @@ -3,7 +3,6 @@ <template id="head" inherit_id="website.assets_frontend" name="Mail customization"> <xpath expr="." position="inside"> <script type="text/javascript" src="/website_mail/static/src/js/follow.js"></script> - <script type="text/javascript" src="/website_mail/static/src/js/portal_chatter.js"></script> <link rel="stylesheet" type="text/scss" href="/website_mail/static/src/css/website_mail.scss"/> </xpath> </template> |
