Commit Graph
6 Commits
Author SHA1 Message Date
Sébastien Theys 005b76462a [IMP] mail, im_livechat, *: simplify channel ACL
* = bus, crm_livechat, hr, mail_bot, test_discuss_full, test_mail,
    website_livechat

Now that livechat uses guest, we can write proper ACL for channel and
channel member to check if the current user/guest is a member.

This allows removing most sudo in code and to simplify search domains.
Remaining sudo in discuss folder have been reviewed and commented.

task-3394829

closes odoo/odoo#138330

Related: odoo/upgrade#5295
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2023-10-24 12:38:21 +00:00
Alexandre Kühn 631ae1c4d8 [REF] mail: simplify JS discuss models further
- Remove "channel" field in thread formatter.
- Pass `type` for all persona formatters.
- Remove some snake_case to camelCase conversions.
- Add support for inverse fields in discuss JS models.

Details:

1. [REF] mail: remove field 'channel' in thread formatter

This field was used for channel-specific fields, which made
sense when there was a dedicated Channel model that was modeled
with composition with Thread.

To simplify formatter of threads, it's best to flatten props
so that channel-specific fields are immediately available on
thread model. This will improve insertion of data with Threads.

This commit also makes the following other changes:

- remove `discuss.channel/legacy_insert` to use
   `mail.record/insert` instead.

- Introduce `toData()` on record, which is helpful to have record
  in data format e.g. to pass as a JSON.stringifiable object.

2. [REF] mail: slightly simplify Message.insert from notif

The handling of `mail.record/insert` for Message was handling
transition from starred non-empty message to starred empty message.

To simplify all record insert from server formatted data, the notif
data is just inserted in Message. The adjustment of starred counter
is managed at model level.

This is a prerequisite to significantly simplify all
`mail.record/insert` handling.

3. [REF] mail: rename 'res.users.settings' notifications

Before this commit, notifications related to changes of user
settings were using named notification `mail.record/insert`.

This named notification should be only used for Discuss data that
should be inserted in models. `res.users.settings` is not integrated
in Discuss model, thus it has no reason to use this named
notification.

This commit rename the notification name to `res.users.settings` for
these specific notifications. This prepares simplification on
handling any `mail.record/insert` notifications that should simply
call `Record.insert()`

4. [REF] mail: make dedicate notif for Thread/fold_state

This was using named notif "mail.record/insert", which should
be used to immediately insert data in models. This is however
a dedicated notification to imperatively manager chat window
state based on timing of receiving thread data.

This may eventually become a `mail.record/insert` in the future,
but right now it's much simpler to define it as its own named
notification, in preparation to simplify `mail.record/insert`
notifications handling.

5. [REF] mail: remove Channel in mail.record/insert

This is replaced by `Thread`, so that these data can be
immediately inserted in Thread model.

6. [REF] mail: simplify slightly Attachment.update()

Now that data containing commands is supported, we could
just assign with the command rather than destructure and pick
the dict data part.

7. [REF] mail: introduce assignIn() utils

This function helps reduce LOCs from using the "in" conditional
in sequence:
```js
if (a in data) {
	this[a] = data[a];
}
if (b in data) {
	this[b] = data[b];
}
if (c in data) {
	this[c] = data[c];
}
```

To simply:
```js
assignIn(this, data, [a, b, c]);
```

8. [REF] mail: remove snake_case to camelCase conversion in models

They exist for the sake of keeping Python code snake_case and
JS camelCase. While it's good that each language have a community
that prefer syntax convention, when a codebase uses both languages
and they should work with the same data, it's not great to convert
snake_case to camelCase and vice-versa all the time.

Since server has authority over the data, the server chooses the
format for the keys. Most of them are snake_cased, therefore this
is usually the one we pick.

9. [REF] mail: rename Message.messageReactionGroups to Message.reactions

Easier to read, and matches relation name in JS model

10. [REF] mail: remove explicit assign of some many relations in Message

This reduce amount of custom code in insert(), in preparation to make
all models behave the same in response to inserting data.

11. [REF] mail: rename Thread.customName to Thread.channel_custom_name

To match server data field name, and avoid useless conversion in JS.

12. [REF] mail: simplify Message.insert for recipients

Have formatted data contain `type: "partner"` so it can be assigned
in relational field without adding `type: "partner"` manually in JS.

13. [REF] mail: introduce inverse field in discuss models

With this commit, fields in different models can be linked
together, so that one is mirror of the other field.

This simplifies some `onAdd`/`onDelete` that were added to
sync such fields, and this also simplifies insertion in
relational fields for discuss models that are identified
by records, such as the `MessageReactions` that is identified
by the message and the emoji.

14. [REF] mail: rename CannedResponse.name to 'source'

To make JS model and server data more alike.

15. [REF] mail: remove assignDefined in Persona model

So that eventually all model inserts use `Object.assign()`.

16. [REF] mail: remove 'last_message_id' from channel_info

At some point it was used to display last message in messaging menu.
This is already covered by `channel_fetch_preview` when opening the
messaging menu for the 1st time, so passing `last_message_id` in
channel_info is obsolete.

closes odoo/odoo#137750

Related: odoo/enterprise#48484
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
2023-10-13 11:46:13 +00:00
Didier (did) 365f5a9863 [IMP] mail: introduce notification handler mail.record/insert
Some of our current bus notification only insert data in the models system. We
can now simplify the way we handle them by using a generic `mail.record/insert`
handler.

closes odoo/odoo#102863

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-10-21 15:19:18 +02:00
Louis Wicket (wil) d91f7852db [IMP] mail, *: user settings improvements
* = im_livechat, test_discuss_full

Various improvements to user settings, including:

+ Introduce new js models `res.users.settings` and `res.users.settings.volumes`
to mirror the python models.
+ Avoid reformatting server data and simplify the way notifications are handled.
+ Clean dead code (unused convertData).
+ Reword and add documentation.

closes odoo/odoo#93390

Related: odoo/enterprise#28291
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-06-17 14:14:14 +02:00
Didier (did) 1afcc9c368 [IMP] bus, mail, *: improve longpolling bus notification format
* = auth_signup, calendar, im_livechat, snailmail_account, survey, test_mail,
    web_editor, website_crm_iap_reveal, website_livechat

The aim of this PR is to improve/fix various flaws and limitation of the current
API, to make it easier to use and more efficient.

Notification are now defined with 3 distinct parts:

- the channel determines which client(s) should receive it
- the type determines how it should be handled
- the payload determines any extra information helpful for handling it

Channel
=======

Business code
-------------

- Record channel is introduced for ease of subscribing to and sending
  notifications to specific partners, channels, documents, ...
- String channel is still supported (but it is converted internally to the tuple
  channel).
- Tuple channel is still supported without any change (but should be avoided
  whenever possible due to its complex syntax).

The channel is no longer sent to the client. When the channel was used for
business purpose, the information it contained has been moved into either the
new type, or the payload itself.

Technical note
--------------

All channels are now internally converted to the tuple (db, ...) channel, which
is necessary for the platform code (saas/sh).

Internally, the bus.bus table is not changed, type and payload are grouped
together into what was (and still is) called message.

Type
====

Type is introduced to uniformize the way notifications are sent and handled.
All existing notifications already had some kind of manually-built type in them.
This is now officially supported at the bus API.

In client code this will allow (to be done in future commits) to register one
handler per specific type, instead of having to iterate and to filter all
received notifications on every handler.

Payload
=======

Payload (ex message) did not change, it can still be anything depending on
business needs.

Few adaptations:
- When the type was included on the payload, the type has been moved to the new
  type parameter.
- When the channel was used in business code, its data has been copied into the
  payload.

task-1891151

closes odoo/odoo#79201

X-original-commit: 543af27c7d6836ffac9e80ff8490b6ddbd849221
Related: odoo/enterprise#21998
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-10-29 16:05:23 +00:00
Qiuyu (QHO) 463af6f61b [IMP] mail, im_livechat: improve Discuss sidebar
The commit is to refactor the discuss sidebar

 - threads are now organized in categories based on the thread type e.g. chat, channel
 - categories can be folded or unfolded by clicking the category title
 - for active thread, even if the category is folded, it remains under the category title
 - for channel category, a new cog button is added to view all channels
 - the active indicator bar is removed. The active item now is highlighted with a different background color
 - thread avatar is used for livechat, chat and channel
 - for livechat and chat, threads are now sorted by last activity time (pin or message exchange)

closes odoo/odoo#70986

Task-id: 2440073
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-08-25 17:00:06 +00:00