Commit Graph
6 Commits
Author SHA1 Message Date
XavierDo c8d283a592 [FIX]: mail: storing add_sign on mail message
Only the add_sign from notif_values is usefull for a resend. We can consider
that a mail on resend can be delete in every case, and we can find the
model_description from model since a resend can only be performed on
message linked to a model.

The other notif_values are now parameter in order to ease the understanding
of what can transit through this flow.

Task: #1860054
PR: #25622
2018-07-11 12:25:33 +02:00
Thibault Delavallée b6d2351df4 [REF] mail: improve implementation of message subscribe
This commit refactors mail.thread message_subscribe method. It is done for two
purposes. First one is to optimize performance by using the new followers
computation methods introduced recently. Second purpose is to clean the API
of message_subscribe to make it simpler to use.

This commit splits message_subscribe in two main parts :

 * _message_subscribe is a private method calling the follower new
   subscription methods and updating the record set;
 * message_subscribe is a public wrapper on _message_subscribe that adds
   access rights checks;

Simplification comes by removing message_subscribe_users that was a
shortcut to message_subscribe. Having a method to subscribe partners and
channels is sufficient as we would like to avoid bloating the public API
of mail.thread. A force parameter is also removed from message_subscribe
as this implementation detail can be induced in the computation.

Various addons using the removed methods are updated in order to use the new
subscription API. They have the same functional behavior.

This commit has a great impact when subscribing several followers. In a more
general way all code using message_post is also optimized as posting a message
generally implies subscribing followers. It also improves activity use as
posting a message and subscribing new followers are common process in
activities.
2018-04-03 17:11:43 +02:00
Thibault Delavallée b6e621717e [IMP] mail: add method to notify recipients of content not related to a document
Mail API contains a message_post method allowing to post a message on a
document. In some cases we would like to push notifications to recipients
that are not necessarily linked to a document. For that purpose we
introduce message_notify. It is a shortcut that prepares the message and
speeds up the computation by pre-computing message values. This method
calls message_post and therefore the whole notification process. It
means no custom code for pushing inbox or email notifications is necessary.
2018-02-20 14:34:54 +01:00
Thibault Delavallée 8a026e26c6 [IMP] mail: update _notify API
Purpose of this commit is to allow to give additional values when rendering
notification emails and to make some parameters explicit.

This commit updates the _notify API. It allow to propagate a dictionary
containing values given to the rendering of the notification template.
This allow to have more complex templates and/or to control the rendering
depending on some parameters. Indeed currently only some fixed values and
values coming form the message to notify are given to the rendering
context.

First use will be soon when pushing notification emails not necessarily
linked to documents. In this process some values will be given by the caller
and not only by the message context anymore.

This commit also moves some context key used to control the notification
process directly in values given to the _notify method. It allows to make
those parameters explicit and rely less on context.

The _notify method now takes a values dictionary that may contain

 * add_sign: add user signature to notification email, default is True.
   It replaces the ``mail_notify_user_signature`` context key;
 * mail_auto_delete: auto delete send emails, default is True. It
   replaces the ``mail_auto_delete`` context key;
 * other values are given to the context used to render the notification
   template, allowing customization.

It allows to remove some context switch notably in the composer. A values
dictionary is computed and given to message_post and then propagated to
the notification mechanism.
2018-02-20 14:32:09 +01:00
Thibault Delavallée 8ddca6f95a [IMP] mail: introduce _message_log as shortcut when logging notifications
This commit introduces _message_log to use when logging notification-based
notes on a document. Its main purpose is to provide a shortcut to the
complex mechanism of message_post. As it is a lighter code and as it
performs less checks and value computation it allows to clearly gain
queries when logging notes.

It does

 * skip the notification process completely. Side effect is that followers
   following note subtype are not notified of document created and pure
   note tracking. This is considered more as a fix than a feature change.
   Indeed following notes means that followers want to receive notes
   logged by other users. The fact that system notifications without a
   specific subtypes are also notes is a side-effect of the current
   implementation;
 * support only notification-based notes and should not be used currently
   when logging real notes as those could trigger the notification
   process;
 * skip access rights checks as it creates the message as superuser. It
   is therefore defined as a private method and should be called within
   a method where access rights are already granted;

On community runbot installing all 203 modules takes 580K queries instead
of 690 at the time of testing. It is a 15% performance increase based on
the 'all modules installation' metric.

In a distant future message_post and message_log could be merged after
some cleaning but it is easier currently to have this shortcut available.
Moreover as there are clouds on the mail module some developers prefer
to already have some optimization and code cleaning done to avoid
loosing all their hair.

This commit includes a small test. In a same distant future more tests
will probably be added depending on how mail API evolves.
2018-01-30 17:20:45 +01:00
Thibault Delavallée d040bfde89 [MOV] (test_)mail: move tests into their dedicated module
Purpose: avoid having useless tables for test models in a
production environment.
2017-11-29 10:11:15 +01:00