Commit Graph
103 Commits
Author SHA1 Message Date
Christophe Simonis 7717f082c0 [MERGE] forward port branch saas-11.3 up to af35aea6b0 2018-08-09 19:33:32 +02:00
Christophe Simonis a98131d5bc [FIX] test_mail: bump query count
An extra query is made because of new group added to fields in 57ea939eda.
2018-08-09 18:52:46 +02:00
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
Christophe Simonis 73652a0b19 [MERGE] forward port branch saas-11.3 up to 50860317cc
Note: 1aacc96262 has been ignored and will
be forward-ported later
2018-06-15 13:27:27 +02:00
Thibault Delavallée 9e811c608c [IMP] test_mail: add a tag on performance tests
It allow to easily recompute performance-related tests when working on
mail thread features. Tags are awesome.
2018-06-08 15:20:03 +02:00
Thibault Delavallée 60614d9961 [FIX] test_mail: fix timezone issue in activity test
Due to timezone difference between two test users the state of activities
depend on the time when the test is running. Indeed if user 1 plans an
activity for tomorrow this could already be today for user 2. Test
that ensure tomorrow is correctly computed should therefore be done with
users being in the same timezone. Current behavior is correct as activities
manipulate date that cannot always be timezoned back to another timezone.

How to reproduce the issue before this fix: run the activity mixin tests
between 0:00 and 1:00 in +1 TZ (Brussels).
2018-06-07 13:59:02 +02:00
XavierDo 133eeb1bbf [ADD] mail, mass_mailing: allow a user to resend a mail with failures
When a mail is in failure state, a red envelope appears next to the message
in a thread but it was difficult to send the mail again.
This tasks will allow users to send mail again easily, or mark notification
as cancelled if the user want to ignore this failure.
A notification will appear in sender systray while mail are in failure.

Task: #46158
PR: #24628
2018-06-07 11:46:28 +02:00
Mathieu Duckaerts-Antoine 299ebb2cdf [IMP] mail: add moderation on channels
Purpose of this commit is to allow moderation on incoming messages in
discussion channels. On some channels on which moderation is required
messages should be in a pending moderation stage. Moderators can accept
or refuse messages as well as always allow or ban messages coming from
a given set of emails.

Channels now have an option to be moderated. Moderators can be added on
channels. They have access to a specific UI in Discuss to see and take
action on messages waiting for moderation.

Concerning mail.thread message that are pending moderation are not notified.
It means nobody receives a notification about them. Moderation process calls
the notification once the message is validated.

Various features included in this commit :

 * a model is added to store the decision about emails, allow or ban;
 * access rights are updated so that only moderators can modify moderation
   fields on message;
 * specific bus notifications are send to moderated people as well as to
   moderators on incoming emails as well as when a decision is taken;
 * options are added on channels to send explanations to moderated emails;
 * options are added on channels to write and send guidelines explaining
   why and how moderation is performed;
 * a reminder is send daily to moderators with remaining messages to moderate;
 * discuss UI is adapted and a new channel is added below Inbox and Starred
   giving access to moderation tools;
 * chanenl UI is adapted allowing to moderate directly inside channels;

This commit is linked to task ID 29521. Closes #21921.
2018-06-06 16:01:33 +02:00
Thibault Delavallée eeab18d753 [IMP] test_mail: assert_email now allow email_from, not only a partner-based author
Some tests could require it.
2018-06-06 15:58:23 +02:00
Thibault Delavallée de0b9e519d [IMP] test_mail: add an assert method for bus notifications content
Purpose is to ease the check of bus notifications content by having a tool
method doing it.
2018-06-06 15:58:23 +02:00
Christophe Simonis f36e6917bd [MERGE] forward port branch saas-11.3 up to 37eed7c509 2018-05-29 17:34:43 +02:00
Christophe Simonis 644f0959d0 [MERGE] forward port branch saas-11.2 up to 1655202924 2018-05-17 14:23:37 +02:00
Christophe Simonis 1655202924 [MERGE] forward port branch 11.0 up to 59a8a1cd8e 2018-05-17 13:19:49 +02:00
Xavier Dollé f555bfeca3 [FIX] mail: correctly filter needaction on unread notifications in message_format
Previously to this commit needaction used by JS was not taking into account
read notifications. It means notably Inbox counter could be higher than
expected as taking into account read messages while Inbox displays only
unread messages. This commit fixes that by checking notification state when
giving needaction_partner_ids to message_format result.

This fix has a small impact on performances as message_format is used in
notification process for chat or push. A better implementation of message
format and its postprocess could probably lessen this fix impact. As we
target stable version we avoid rewriting other part of the code. Optimization
will be done in development version.

Related to task ID 1841243. This is a manual forward port of commit 69714fbeee
done in saas-11.2.
2018-05-16 16:17:59 +02:00
Xavier Dollé 92abf95a87 [FIX] mail: correctly filter needaction on unread notifications in message_format
Previously to this commit needaction used by JS was not taking into account
read notifications. It means notably Inbox counter could be higher than
expected as taking into account read messages while Inbox displays only
unread messages. This commit fixes that by checking notification state when
giving needaction_partner_ids to message_format result.

This fix has a small impact on performances as message_format is used in
notification process for chat or push. A better implementation of message
format and its postprocess could probably lessen this fix impact. As we
target stable version we avoid rewriting other part of the code. Optimization
will be done in development version.

Related to task ID 1841243. This is a manual forward-port of commit 69714fbeee
done in saas-11.2.
2018-05-16 16:06:10 +02:00
Xavier Dollé 69714fbeee [FIX] mail: correctly filter needaction on unread notifications in message_format
Previously to this commit needaction used by JS was not taking into account
read notifications. It means notably Inbox counter could be higher than
expected as taking into account read messages while Inbox displays only
unread messages. This commit fixes that by checking notification state when
giving needaction_partner_ids to message_format result.

This fix has a small impact on performances as message_format is used in
notification process for chat or push. A better implementation of message
format and its postprocess could probably lessen this fix impact. As we
target stable version we avoid rewriting other part of the code. Optimization
will be done in development version.

Related to task ID 1841243.
2018-05-16 16:00:06 +02:00
Thibault Delavallée 96a223a5f0 [IMP] mail: prevent creation of activities to users that have no access to document
This commit is related to task ID 58968 . Closes #24176.
2018-05-15 15:42:54 +02:00
Raphael ColletandThibault Delavallee 4412cb0bf4 [IMP] tests: do not warn about margins and improve logging
* margin have been recently added on some query count tests as currently query
   count is not completely deterministic. Setting a warning is not really
   interesting as it is the current behavior. Being in margin is now green
   and solely provide a different logging message;
 * logged messages are improved to ease grep;

This also reverts aae54ecc15 .

Co-authored-by: Thibault Delavallee <tde@odoo.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
2018-05-15 13:29:30 +02:00
Christophe Simonis bca769a1e8 [MERGE] forward port branch saas-11.2 up to e70e5b6cf3 2018-05-14 17:31:53 +02:00
Christophe Simonis e70e5b6cf3 [MERGE] forward port branch 11.0 up to 2787de8c68 2018-05-14 16:46:11 +02:00
Christophe Simonis aae54ecc15 [FIX] test_mail: bump expected query count 2018-05-09 14:51:11 +02:00
Thibault Delavallée 324ae5ed8f [REF] mail: get rid of thread_model context key
message_post and various mail.thread related code still support a thread_model
context key allowing to redirect message post on another model. Purpose of
this commit is to get rid of that context key and support model / res_id
fields coming from either the record on which we run, either parameters of
message_post. Indeed those parameter match the one used as fields on mail
message. It makes sense to support them for customization if necessary
instead of using a context key.

This context key exists since a lot of time. It is difficult to find the
source as history is quite complex when the mail was refactored in 2012.
See notably 6aa4f80b2d and 2c4ed841b9 for example.
2018-05-07 11:00:03 +02:00
Thibault Delavallée 282733cf8d [REF] mail: make notification methods semi-generic
mail.thread mixing class defines several methods used in notification process
that are not specific to mail.thread enabled models. It means some models
could override it while some other models do not even have a direct access
to that method.

When calling those methods we have to manually check for method being
available on a record or call a default implementation from mail.thread
even if the model does not inherit from the mixin.

In this commit we propose to hide this check in generic wrappers located
in mail.thread class. It checks for method existence on record and call
the model-specific implementation or falls back on standard behavior. It
allows to be sure the right method is called.

Functionally behavior should stay globally the same. However when updating
some addons code has been updated. Previous code could lead to records not
having correct alias which should not be the case anymore. This commit is
linked to task ID 47934.
2018-05-07 10:58:54 +02:00
Thibault Delavallée c5c369355d [IMP] mail, mass_mailing: clean mail body processing and mail sent post processing
Purpose is to lessen query count by avoiding to browse and/or fetch data when
not necessary. This commit does two main things

 * first one is to avoid checking for existing statistics in mass_mailing
   where only checking existing of a mass_mailing on a mail to send is
   sufficient. It allows to avoid fetching data from statistics table;
 * second one is to rewrite part of the post_process code called after sending
   emails. Using list comprehension and mailing_id existence on mail_mail
   allows to save several queries on standard post flows;

Most tests benefit from this code update. On overall community runbot about
3K queries are saved with those small optimizations.
2018-05-02 11:42:24 +02:00
Thibault Delavallée 0603dab655 [IMP] test_mail: update top counters due to enterprise update.
mail_push module in enterprise was adding too much extra queries. mail_push
being auto-install in enterprise mail performance tests were done with its
overhead taken into account. Commit done in enterprise cleaned a bit the code
to lessen mail_push impact allowing to lessen some top counters. Community
runbot counters are now nearer enterprise-based counters.

This commit is related to enterprise commit https://github.com/odoo/enterprise/commit/0a3ba658f18e03fd76caba86cba7be32d047f0a9 .
2018-05-02 11:41:27 +02:00
Thibault Delavallée 058d2fd4f6 [REF] mail: shortcut chat notification if no one to notify
Well, it seems we gain a lot of query when avoiding to format a message we
actually don't have to send on any bus. Cheers.

Formatting message for bus notification is quite costly as it has to fetch
data from message, partner, attachments, subtypes, ... meaning a lot of
queries. With this commit we avoid calling that method when not necessary.

It allows a gain of queries in simple cases when no-one has to be notified
as shown in the performance counters. On overall community runbot about 9K
queries are saved which is not bad for a 2-lines commit.
2018-05-02 11:39:57 +02:00
Thibault Delavallée c832452590 [IMP] mail: update subscription instead of unlink / create new followers
In some cases when subscribing followers code may ask to force subtypes
of the subscription. It means existing followers should have only asked
subtypes independently from existing subtypes. Previously it was done
by unlinking and creating new followers for same partner or channel.
This commit proposes to instead update missing subtypes and remove extra
subtypes.

It has a small impact in real life as forcing subtype is not done often.
Some tests are improved thanks to this commit. This commit is linked to
task ID 1839043. Closes #24417.
2018-05-02 11:18:22 +02:00
Thibault Delavallée 79daa2e262 [IMP] test_mail: follow activities in performance tests
Commit 07ae0ccc4e set activities as not followed by default on records.
However this has an impact on performance test that should not happen.
Indeed performance tests should be based on technical decisions, not business
decisions. We therefore set activities as followed by default in some advanced
performance tests to always have results that can be compared.
2018-04-11 13:33:38 +02:00
Thibault Delavallée 4859b642d8 [FIX] test_mail: add forgotten margin on activity test
Those are notoriously prone to have a one query more-or-less behavior.
2018-04-10 12:37:29 +02:00
Thibault Delavallée 9f3889eba3 [IMP] mail: limit cache invalidation when managing messages
This commit proposes to limit cache invalidation at some cases that will
trigger some behavior change when dealing with mail messages :

 * creating messages linked to a document;
 * update model or res_id of a message;
 * updating notifications, as notified people could change some computed
   fields on the record;

This commit also invalidates only mail-related fields as updating messages
should not invalidate other things than some computed fields linked to
mail.
2018-04-10 11:01:16 +02:00
Thibault Delavallée bcc6884737 [IMP] mail: limit cache invalidation when subscribing followers
Cache invalidation when subscribing people has been added at e6f038a821.
Indeed subscribing partners to a record may lead to an access right update
as some of them are based on followers. This is why a cache invalidation
is necessary to avoid access rights issues.

However subscribing people to a record should change their rights only on
the records involved in the subscription mechanism. We can therefore give
ids to the cache invalidation to limit to updated records.

Cache invalidation is also limited when writing on followers if writing
on model, res_id or partner_id fields. Indeed changing subtypes or
channel of a subscription should have no impact on cache and access rights.

Cache invalidation done manually in _message_subscribe is not necessary
as subscription create or update mail.followers records since f9c210923d.
Create and write of mail.followers records already ask for cache invalidation.
It is therefore not necessary to invalidate cache twice.

This commit allows to save a few queries on some tests, notably about
activities that deal with subscription and messages. As cache is now kept
it is not necessary to refetch some data, leading to a few query gain. We
gain about 1K queries on com runbot.

A side effect of limiting cache invalidation is that some unit tests require
a manual cache invalidation to have up to date results. Indeed record not
being up to date in cache was hidden by the invalidation we just removed.
2018-04-10 11:00:41 +02:00
Thibault Delavallée 26d110c472 [IMP] mail: remove cache invalidation when notifying a message with a parent
When notifying partners or channels of a message, a cache invalidation is
currently done if the message has a parent. This invalidation has been done
when migrating the mail module at the new API at 4b122ad41d.

In that time notifying people of a message lead to the creation of
notifications of the parent message, if any. It was due to the chatter
being threaded and therefore displaying message with their header message.
Adding notifications for the parent was necessary to avoid access rights
issues  when fetching parent message data. Indeed as being notified is one
of the rule to see a message record adding notifications was done. A cache
invalidation has therefore been added to clean the message cache and ensure
everything was fine.

Commit 88b8cd0587 changed the way notifications are modeled in Odoo.
Notification on parent message was removed and access rights changed. Threaded
mode for Chatter has also been removed. However cache invalidation has been
kept probably by fear of removing it.

It does not seem to have any viable reason to invalidate cache when a message
has a parent. Posting a message does not push other messages in users's Inbox
meaning there should not be any issue with the cache preventing to see
messages.

Removing this cache invalidation allow to gain queries in performance tests.
It has an impact on each process involving message creation which is quite
common in Odoo.
2018-04-10 10:58:40 +02:00
Thibault Delavallée 4403e6999f [IMP] test_mail: set a margin on some mail-related performance tests
Query count for some mail tests is not always the same for a given test.
This leads notably to runbot being randomly red although there is no real
error. This commit lessen the issue of having red runbot or wrongly
incremented tests by using the recently-introduced margin parameter on
performance tests.

Some work is still ongoing to find why some tests are not completely
reproducible. In the meantime let us have some warnings instead of errors.

Manual forward-port and improvement of 81a0852077.
2018-04-09 17:28:03 +02:00
Thibault Delavallée 81a0852077 [IMP] test_mail: set a margin on some mail-related performance tests
Query count for some mail tests is not always the same for a given test.
This leads notably to runbot being randomly red although there is no real
error. This commit lessen the issue of having red runbot or wrongly
incremented tests by using the recently-introduced margin parameter on
performance tests.

Some work is still ongoing to find why some tests are not completely
reproducible. In the meantime let us have some warnings instead of errors.
2018-04-09 16:52:12 +02:00
Dharmang Soni 807c4c3f5e [REF] mail, note: move reminder feature from mail to note
This commit refactors f488dc58c3 that added reminder feature in activities.
After merging it was suggested specifications were not correct and it has
been decided to move the whole reminder feature in note.

Reminders are now notes instead of activities. Now when having note appµ
systray proposes to create a note / reminder. A note.note record is created
with info given by the user. If a date is given in the systray quick create
then an activity is scheduled on this note.

This means user can create records in activity systray that are not
activities but notes used as reminders. Those will use the first availableµ
note column for the user.

As reminders are now notes the support of activities not linked to any
document is removed, as well as archiving activities and tests linked to
that behavior.

This commit has been not carefully tested nor in-depth reviewied. It is
considered as too important for the upcoming freeze. This closes task ID
1833628. Closes #24129 . Many thanks to @dpr-odoo for its quick development
and good work on this task.
2018-04-09 14:35:06 +02:00
Thibault Delavallée 1eba78381d [REF] mail: improve implementation of auto subscription
This commit refactors mail.thread message_auto_subscribe method. Purpose
of this method is to automatically subscribe people to documents in several
scenarios

 * followers from an umbrella record to sub-records, like followers of project
   added to tasks;
 * responsible of documents, in addition to sending notifications to newly
   added responsibles;
 * some specific use case depending on some applications like managers
   for expense reports;

New auto subscription now uses the recently introduced method optimized to
compute new or to-update followers. It is also rewritten so that overriding
it is easier. Indeed simply overriding _message_auto_subscribe_followers is
now sufficient to add new followers to a record, depending on some updated
values. It is also now possible to specify a template to use for some
specific notification, if requested.

Fetching auto-subscription data in subtype is also optimized. It is now done
in a single SQL query. All data related to parent (like project) and child
(like task) as well as default and internal-only data is prepared in a single
query and given back to auto subscription process. This allows to gain
queries in auto subscription based on subtype like project / task use case.

This commit has a great impact on performance counters. Complex use cases
involving tracking and responsible notifications gain about 30 queries which
is about 15% of their total query count.
2018-04-03 17:47:26 +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 301f140cb6 [REF] mail: use new followers command when subscribing record creator
Override of create in mail.thread now uses the recently introduced
_add_default_followers to add the record's creator in the followers.

It allows to save one query when creating new records. It means for simple
models we approach the bottom limit in term of generated queries which is
quite a good news.
2018-04-03 17:10:54 +02:00
Thibault Delavallée 4451e505cd [IMP] mail: use xmlid_to_res_id instead of ref in remaining places of mail
As explained in previous commit we can use xmlid_to_res_id instead of ref()
which leads to some query gain. This commit update some other less important
places: when setting activities as done and in the composer. This lead to
a gain in tests involving activities and composer, including tracking
triggering a template. On community runbot this leads to a gain of about 1K
queries.
2018-03-28 16:57:05 +02:00
Thibault Delavallée a2511f3a5a [IMP] mail: use xmlid_to_res_id instead of ref to find subtype in various post methods
As explained in previous commit we can use xmlid_to_res_id instead of ref()
which leads to some query gain. We gain 1 query on most post due notably to
notify and logging is still improved. This leads to a gain of about 4K queries
on community runbot.
2018-03-28 16:56:16 +02:00
Thibault Delavallée 1e4ee402a3 [IMP] mail: use xmlid_to_res_id instead of ref to find subtype in message_format
Deleting comment / note / activity subtypes make the whole system quite
impossible to use. Indeed the whole communication mechanism is based on
those subtypes that are hardcoded.

There are some use of env.ref() about subtypes to try to avoid having those
removed. As there is some work to make some xml ids impossible to delete we
can already update some code to use xmlid_to_res_id instead of env.ref(). This
leads to some gain in query count as there is no exists() that is performed.

Gain: 1 query on most tests implying post, because message_format is called
by bus notification. About 1.5K queries on community runbot
2018-03-28 16:55:08 +02:00
Thibault Delavallée d4dcfb6c6a [FIX] test_mail: increase activity-related counters to avoid sometimes-red runbot
Still this "sometimes one query more" in activity-related tests. Let us avoid
false red occurrences of runbot by adding one query on sometimes-failing tests.
Purpose of performance test is to have an idea of query count. Adding one query
is not harmful.
2018-03-28 16:17:36 +02:00
Thibault Delavallée 60b81e00b2 [IMP] mail: add tool methods to manage activities directly from the mixin
This commit adds tools methods related to activities in the mail.activity
mixin. It gives to models inheriting from the activity mixin an easy-to-use
API to schedule, unlink or mark activities as done. Purpose of those methods
is to avoid having people manually managing activities in the code to hide
the technical details of the activities model, notably access rights
or activity types.

A field is added on activity model to indicate they have been generated
automatically. This way when rescheduling or unlinking based on some
specific activity types we do not change user-created activities.

Those methods include scheduling activities, changing their dates, marking
them as done or unlinking them. Future commits will use those methods
in various addons to automatically generate activities based on workflow
we want to implement.

This commit also adds tests for the newly added code. Future commits should
probably have a look at activity security and add some tests cases to check
it is correctly taken into account. It is considered a bit out of scope for
this task.

Thanks to @jem-odoo for its in-depth review of this commit. Well thanks for
other commits also.
2018-03-27 15:00:46 +02:00
Thibault Delavallée 093dd9b512 [IMP] test_mail: clean reminder-related activity tests
It has not been done completely at f488dc58c3.
2018-03-27 15:00:36 +02:00
f488dc58c3 [IMP] mail: allow to use stand alone activities as reminders
This commit allows to create personal reminders and to manage them using
activities. It is done using activities not necessarily linked to a record
but only to a user. Reminders can be used for example as a personal todo
list.

Technically we choose to model a reminder as an activity related to no
record. This means having a void res_id and model. An activity type is
added to classify reminders in it.

Settings reminder as done is not done like classic activities. Indeed classic
activities are unlinked and a message is logged on the related document.
As there is no document for reminders those are archived instead. It means
an active field is added as well as an override of toggle_archive to update
systray counter.

Activities systray widget is improved to display reminders in activities
list. This entry leads to a kanban view of activities allowing their
management. It is also possible to create them directly from the systray
allowing a quick creation of reminders.

This commit is related to task ID 41745. Closes #22143 .

Co-authored-by: Dharmang Soni <dpr@odoo.com>
Co-authored-by: Xavier Dollé <xdo@odoo.com>
2018-03-27 13:26:41 +02:00
Thibault Delavallée f2e4ef741b [FIX] test_mail: update counter due to random additional query sometimes appearing 2018-03-23 17:33:48 +01:00
Toufik Benjaa 2a53338649 [FIX] test_mail: Update query count 2018-03-22 18:46:34 +01:00
Toufik Benjaa aeeb21128a [FIX] test_mail: Update query count 2018-03-22 17:52:39 +01:00
Thibault Delavallée 2826edcfbe [IMP] mail: use minimal context when rendering mail-related QWeb templates
Use option recently introduced to use a minimal context when rendering
some mail templates such as

 * notification template used to decorate messages sent to recipient
   when using email-based notifications;
 * user assignation template used when people are assigned on a record
   and a notification is sent to inbox or email;
 * message_post_with_template now uses minimal context meaning calls to
   that method should be sure evaluation context is correctly set in
   the given values;

This optimization allows to save some queries every time one of those
template is used, meaning all tests gain between 1 to 4 queries depending
on their complexity.

This commit is related to task ID 1817951. Closes #23291 .
2018-03-20 13:25:30 +01:00
Thibault Delavallée 1e040c8713 [FIX] test_mail: update one counter because of runbot crashing sometimes
Due to unknown reasons sometimes a performance test takes one query more to
run than expected. Let us therefore avoid red runbots by increasing the
query count by 1.
2018-03-15 14:18:18 +01:00