Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPD] boolean for editing message #4

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions mail_edit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Message Edit
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9c6d48b6f06ab1a256ade283bc1c2618eab8721fc831fcb9c0347b1a9cae59de
!! source digest: sha256:73442b517f255855399f9bb28dde917dcbe559a578bf68b5e1fb018aa725be53
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
:target: https://github.com/OCA/social/tree/14.0/mail_edit
:alt: OCA/social
Expand Down Expand Up @@ -58,10 +58,7 @@ To use this module, you need to:
Known issues / Roadmap
======================

* Better live-updating of an edited message in the thread, right now only
'body' parameter is updated.
* For the body parameter, call processBody to correctly handle emoji.
* Live-update edited message through all threads, using the message bus.
* if you move a message to an object from a channel, it should also be removed from the channel.

Bug Tracker
===========
Expand Down
5 changes: 1 addition & 4 deletions mail_edit/demo/mail_edit_demo.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="base.user_demo" model="res.users">
<field
name="groups_id"
eval="[(4,ref('mail_edit.group_mail_edit_superuser'))]"
/>
<field name="groups_id" eval="[(4,ref('mail_edit.group_mail_edit_editor'))]" />
</record>
</odoo>
21 changes: 21 additions & 0 deletions mail_edit/models/compose_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
class MailMessage(models.Model):
_inherit = "mail.message"

can_edit_message = fields.Boolean(compute="_compute_can_edit_message")

def _compute_can_edit_message(self):
"""Disallow editing message in ui"""
groups = [
"mail_edit.group_mail_edit_editor",
"mail_edit.group_mail_edit_superuser",
]
self_user = self.env.user
for message in self:
message.can_edit_message = False
if not any(self_user.has_group(x) for x in groups):
continue
# superuser
if self_user.has_group(groups[1]):
message.can_edit_message = True
continue
# own message
if self_user.has_group(groups[0]):
message.can_edit_message = message.create_uid == self_user

@api.model
def _get_model_selection(self):
# Get models that supports messages, exclude transient models
Expand Down
57 changes: 27 additions & 30 deletions mail_edit/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Message Edit</title>
<style type="text/css">

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.

See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

Expand Down Expand Up @@ -367,40 +367,40 @@ <h1 class="title">Message Edit</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9c6d48b6f06ab1a256ade283bc1c2618eab8721fc831fcb9c0347b1a9cae59de
!! source digest: sha256:73442b517f255855399f9bb28dde917dcbe559a578bf68b5e1fb018aa725be53
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/14.0/mail_edit"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_edit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/14.0/mail_edit"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-14-0/social-14-0-mail_edit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of mail. You can edit message/mail
and move them to any model.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="id3">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id7">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="id8">Other credits</a><ul>
<li><a class="reference internal" href="#images" id="id9">Images</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-3">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-7">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-8">Other credits</a><ul>
<li><a class="reference internal" href="#images" id="toc-entry-9">Images</a></li>
</ul>
</li>
<li><a class="reference internal" href="#maintainers" id="id10">Maintainers</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-10">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To configure this module:</p>
<ul class="simple">
<li>Activate the ‘Move mail message’ or ‘Edit mail message’ permissions for a
user (the admin user has these rights by default)</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module, you need to:</p>
<ul class="simple">
<li>Go to <em>Message</em> <em>Chatter</em> in any model, click the Edit (pen) Icon to open up
Expand All @@ -411,32 +411,29 @@ <h1><a class="toc-backref" href="#id2">Usage</a></h1>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Better live-updating of an edited message in the thread, right now only
‘body’ parameter is updated.</li>
<li>For the body parameter, call processBody to correctly handle emoji.</li>
<li>Live-update edited message through all threads, using the message bus.</li>
<li>if you move a message to an object from a channel, it should also be removed from the channel.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_edit%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id5">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id6">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<ul class="simple">
<li>Therp BV</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id7">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul>
<li><p class="first"><a class="reference external" href="https://www.therp.nl">Therp BV</a>:</p>
<blockquote>
Expand All @@ -449,16 +446,16 @@ <h2><a class="toc-backref" href="#id7">Contributors</a></h2>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#id8">Other credits</a></h2>
<h2><a class="toc-backref" href="#toc-entry-8">Other credits</a></h2>
<div class="section" id="images">
<h3><a class="toc-backref" href="#id9">Images</a></h3>
<h3><a class="toc-backref" href="#toc-entry-9">Images</a></h3>
<ul class="simple">
<li>PICOL Icon Generator <a class="reference external" href="http://picol.org/picol_icon_generator">here</a>.</li>
</ul>
</div>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id10">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down
15 changes: 11 additions & 4 deletions mail_edit/static/src/components/message/mail_edit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<template>
<t t-inherit="mail.Message" t-inherit-mode="extension" owl="1">
<xpath expr="//div[hasclass('o_Message_headerCommands')]" t-operation="inside">
<span role="button"
class="o_Message_command o_Message_headerCommand o_Message_threadEditIcon" groups="mail_edit.group_mail_edit_editor">
<span
role="button"
class="o_Message_command o_Message_headerCommand o_Message_threadEditIcon"
groups="mail_edit.group_mail_edit_editor"
>
<i
class="fa o_Message_Edit fa-pencil"
t-att-data-message-id="message.localId"
t-on-click="_onClickMessageEdit"
title="Edit"
/>
</span>
<span role="button" class="o_Message_command o_Message_headerCommand o_Message_threadDeleteIcon" groups="mail_edit.group_mail_edit_editor">
<span
role="button"
class="o_Message_command o_Message_headerCommand o_Message_threadDeleteIcon"
groups="mail_edit.group_mail_edit_editor"
>
<i
class="fa o_Message_Delete fa-trash"
t-att-data-message-id="message.localId"
Expand Down
14 changes: 10 additions & 4 deletions mail_edit/views/compose_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<sheet>
<group>
<group>
<field name="can_edit_message" invisible="1" />
<field
name="subject"
groups="mail_edit.group_mail_edit_editor,mail_edit.group_mail_edit_superuser"
attrs="{'readonly':[('can_edit_message','=', False)]}"
/>
<field name="date" readonly="1" />
<field name="message_type" readonly="1" />
Expand All @@ -21,7 +22,7 @@
<group>
<field
name="destination_object_id"
groups="mail_edit.group_mail_edit_mover,mail_edit.group_mail_edit_superuser"
attrs="{'readonly':[('can_edit_message','=', False)]}"
/>
<field name="model" invisible="1" />
<field name="res_id" invisible="1" />
Expand All @@ -30,10 +31,15 @@
</group>
<field
name="body"
groups="mail_edit.group_mail_edit_editor,mail_edit.group_mail_edit_superuser"
attrs="{'readonly':[('can_edit_message','=', False)]}"
/>
<footer>
<button string="Save" special="save" class="btn-primary" />
<button
string="Save"
special="save"
class="btn-primary"
attrs="{'invisible':[('can_edit_message','=', False)]}"
/>
<button string="Discard" class="btn-secondary" special="cancel" />
</footer>
</sheet>
Expand Down
Loading