Commit Graph
556 Commits
Author SHA1 Message Date
Zelong Lin d57c64f95b [IMP] mail, *: remove 'public' field in channel
*: im_livechat, website_livechat

Access right should be based on channel type and membership instead.
Chat always private, group always private, channel private should
disapear and be a group instead (migration needed), and other channel
always public (but they can still be further restricted with
the "allowed groups" feature)

task-2632861

closes odoo/odoo#90415

Related: odoo/enterprise#30980
Related: odoo/upgrade#3850
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-09-06 10:57:59 +02:00
Didier (did) 7ceb079455 [IMP] mail: implement link preview with OpenGraph Protocol
OpenGraph Protocol https://ogp.me/ allow us to get some data from the link that
are shared in message.

task-2365881

closes odoo/odoo#82641

Related: odoo/enterprise#30867
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-09-05 14:49:30 +02:00
Sébastien Theys 545d23888b [IMP] mail, im_livechat, *: add typing for guest and clean code
* = bus, hr_holidays, test_discuss_full

- use channel member instead of partner for typing
- use channel member instead of partner for all other return values from server
- remove temporary partner hack in livechat and keep public partner
- remove some obsolete convert data
- adapt format methods accordingly

task-2664853

closes odoo/odoo#98923

Related: odoo/enterprise#30760
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-09-01 20:21:58 +02:00
Pierre-Yves Dufays ac67e6a8df [IMP] base,{fetch}mail,l10n_it_edi,{test}mass_mailing:prevent using arch server
Prevent archiving in-use mail servers by displaying an error message that
lists where it is still used, allowing to easily identify what need to be
updated before being able to archive the mail server.

Additionally,
- prevent the use of archived server as a fall-safe
- when duplicating a mailing with an archived mail server, replace mail
server by the default one

Detailed explanation:
1. A check has been added that raise an exception when trying to connect to the
smtp server or send an email when the server is archived.
With that solution,
- testing the connection of an archived server displays an error telling that
an archived server cannot be used.
- if a mail is still sent with an archived server, mail are in error :
"Connection failed (outgoing mail server problem)"
This fail-safe ensures that no mail will be sent through an archived mail server
and that the user will get some feedback about it.

The same fail-safe for the incoming mail server has been added.

Notes:
- the connection will outlive the archiving of a mail server still allowing
to send email through the archived server until the connection is closed. But
connection are not kept for long so this shouldn't be a problem.
- it cannot be tested because the connect method return immediately in test
mode.

2. When a mail server is archived, an user error is raised if it is in-use.
The implementation relies on each module to override the method
"_active_usages_compute" in "ir_mail_server" to complete the list with
user-friendly message describing the active elements that could send mail
through the mail server. This has been implemented for:
- l10n_it_edi: server used to send e-invoice
- mail: optional server configured for template
- mass_mailing:
-- default mail server
-- active server configured for mailing

Mail server are referenced in other elements but are not active anymore, it is
just for temporary or history purpose. Those references doesn’t prevent the
archiving of the mail server:
- mail_message
- wizard survey_invite and compose_message
- res_config_settings

Task-2821516

closes odoo/odoo#91240

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-09-01 15:32:44 +02:00
Zelong Lin 14316ddd74 [IMP] mail: group_id explicit in channel_create
follow up https://github.com/odoo/odoo/pull/94510/commits/64d01d43a0f69c29cb9ad900c7aaa6ae00d8b4e4

task-2893661

closes odoo/odoo#98875

Related: odoo/enterprise#30722
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-09-01 13:08:47 +02:00
Louis Wicket (wil) 6a6e737f61 [IMP] mail, *: move channel concerns in Thread from Thread to Channel
This commit is the continuation of task-2948676 which consists of
lightening the Thread model by moving the channel-specific behaviours to
the Channel model.

The changes revolve around the DiscussSidebarCategoryItem model. The
goal is to use channel instead of thread as identifying field for
DiscussSidebarCategoryItem, and to move channel-specific fields involved
in the computes of this model from Thread to Channel.

Changes in this commit include:
+ move `avatarCacheKey` from Thread to Channel
+ move `correspondent`
+ move `correspondentOfDmChat`
+ move `custom_channel_name`
+ move `localMessageUnreadCounter`
+ move `serverMessageUnreadCounter`
+ introduce `Channel/displayName`
+ use channel instead of thread as identifying field for
DiscussSidebarCategoryItem

Part of task-2948676.

closes odoo/odoo#98149

Related: odoo/enterprise#30457
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-08-30 20:22:14 +02:00
std-odooandThibault Delavallée 9b11a9d82b [IMP] mail: schedule emails and notifications
Purpose
=======

Currently, only email sending can be scheduled with the `scheduled_date` field
defined on on <mail.mail>. It's not possible to delay the sending of
notifications.

We want to be able to delay the sending of the emails, but also the inbox
and bus bus notifications.

Technical
=========

For that purpose, we created a new model which stores the message we need to
notify with the scheduled date. When a scheduled_datetime is given we skip the
notification process. Instead an entry in that new model is created. A cron
regularly polls the scheduled message and launch the notification process on
messages that are ready to be sent.

Task-2207626 (Rating: Delay rating notification to ease feedback)

Part-of: odoo/odoo#95623
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2022-08-25 19:57:16 +02:00
Sébastien Theys 34d775e873 [IMP] mail, *: remove explicit usage of insert-and-replace
* = calendar, im_livechat, rating, snailmail, test_discuss_full, test_mail,
    website_livechat

Distinction between "replace" and "insert-and-replace" can be guessed based on
the type of the provided data.

task-2957295

closes odoo/odoo#98404

Related: odoo/enterprise#30580
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-08-19 11:53:05 +02:00
Nikunj Ladava c8cdd6f5a3 [IMP] mail,sms: reset template button
Before Commit :
- Sometimes user breaks their Mail/SMS templates and have no way to go back to the
original one easily. They don't have any option to reset the template.

After Commit :
- Added new "Reset Template" button
- now user can reset the Mail/SMS template to its first version.
- also it will update the translation of the template
- added New "Reset Mail Templates/Reset SMS Templates" action to edit multiple templates

task- 2231977

closes odoo/odoo#83759

Related: odoo/upgrade#3674
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-08-17 11:20:56 +02:00
Thibault Delavallée b3fc41cc44 [IMP] mail: add a post server action
Currently only an email action based on template exists in server actions when
having mail app installed. It basically sends an email based on a mail template.

However being able to post a message on record is also useful. Instead of
sending emails it post on a document as a comment or as a note, like what
users can do using the chatter. Notification flow for those cases is the
classic from post: followers, specified partners, Inbox/Email, ...

Task-2613245 (Server actions mail update / cleaning)
Closes #45640

Part-of: odoo/odoo#75906
2022-08-12 23:37:03 +02:00
thcl-odoo 1a3517a572 [FIX] mail: correct starred count computation in private channels
Current behavior

Starred messages counter takes into account the starred messages of a private
channels even if we no longer have access to this channel. Happens with deleted
messages too.

Steps channels
- Install Discuss
- Create a Private Channel and invite Marc Demo to join it
then send him a message
- *As Marc Demo*, star the message then leave the channel
-> Starred counter still shows 1

Steps for deleted messages
- Join the private channel again
- Delete the starred message (with Mitchell Admin)
-> Starred counter still shows 1 for Marc Demo

Reasons
Starred message count is computed by a raw sql [1] which only counts partner's
occurrences without taking into account the message's state and/or the
associated channel.
Side records (stars, notifications) are not removed when emptying a message
content [2].

With changes

- It doesn't take into account messages from a private channel which we no
longer have access to by doing a search on mail.message instead of doing it
in SQL (which filters out invisible messages);
- It correctly voids side records when emptying messages;

Side effects

This somehow raises number of queries because we now check access on messages
and records. However this is necessary as bypassing ACLs means unreachable
notifications or stars.

OPW-2742092
Task-2813738

[1] : https://github.com/odoo/odoo/blob/2c1c6b1373c238216fda1e2d9d2f00b5d16c8ca3/addons/mail/models/res_partner.py#L49-L51
[2] : 776d1ee08b

closes odoo/odoo#97974

X-original-commit: b1e8f7d97e3a1fa624436d2dd6801bf5fe7d19aa
Related: odoo/enterprise#30415
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-08-12 17:06:02 +02:00
Didier (did) 633f58f8a4 [IMP] mail: im_status for guests
task-2883466

closes odoo/odoo#97076

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-08-08 21:02:21 +02:00
Zelong Lin 3ee2363a56 [REF] discuss: rewrite tests on test_mail_channel
rewrite some asserts on test_mail_channel.

task-2893661

closes odoo/odoo#94510

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-08-02 23:56:54 +02:00
Zelong Lin d072e6a860 [REF] discuss: rewrite setup classes on mail tests
rewrite setup classes on test files. Making it clear
for adding asserts in the future.

task-2893661

Part-of: odoo/odoo#94510
2022-08-02 23:56:53 +02:00
Zelong Lin e3dcad0fb7 [REF] discuss: rename variables on mail tests
rename some variables on test files to make a better sense.

task-2893661

Part-of: odoo/odoo#94510
2022-08-02 23:56:53 +02:00
Thanh Dodeur 174ff9ff83 [REF] mail: use the channelMember relation for RtcSession
part of task-2692836

closes odoo/odoo#96394

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-07-25 20:12:42 +02:00
Thibault Delavallée ba6b8baa23 [IMP] test_mail: improve tests about mail sending issue status update
Purpose of this commit is to add tests on ``failure_reason`` usage of
notification model. Tests already exists for MailMail and other fields
but not that specific one. Followup of odoo/odoo@d895f3514e

New tests are added to check the usage of email_to and email_cc when
sending emails. Notably wrong usage of email_cc (lost formatting, copy
of all sent emails) is asserted to be fixed afterwards.

A performance test about batch sending is also added.

Prepares Task-2684479 (Mail: Better send error storage and display)

Part-of: odoo/odoo#96223
2022-07-19 11:51:12 +02:00
Thibault Delavallée 7cfb49e67e [IMP] test_mail: allow to assert value of email_cc/bcc when sending emails
Purpose is to ease addition of new tests related to email sending, notably
to check failure reasons.

Prepares Task-2684479 (Mail: Better send error storage and display)

Part-of: odoo/odoo#96223
2022-07-19 11:51:12 +02:00
Thibault Delavallée 039c63cf6e [REF][MOV] test(_mass)_mail(_sms): move sms tests in their own addon
In this commit we introduce a new module ``test_mail_sms`` that holds the
tests for sms application, like ``test_mail`` does for mail. Currently all
sms tests are inside ``test_mail_full``. After this commit code is moved
from ``test_mail_full`` into that module. Full testing module should be used
mainly to test integrations with a lot of submodules and for performance
tests, not testing details of SMS implementation.

We also add ``mass_mailing_sms`` as dependency of ``test_mass_mailing`` so
that both mailing types are tested in the same module. It eases maintenance
and writing of tests. Mass mailing SMS tests  from `test_mail_full`` are
therefore moved in ``test_mass_mailing``.

This commit also allows some cleaning in classes used in tests, to have
classes in ``test_mail_sms`` and ``test_mail_full`` that contain everything
necessary to test mail features.

Task-2890111 (Test Mail/Mass Mailing: SMS tests reorganization and move)

Part-of: odoo/odoo#96223
2022-07-19 11:51:12 +02:00
Louis Wicket (wil) fdcaa53ca0 [IMP] mail, *: rename mail.channel.partner to mail.channel.member
* = calendar, crm_livechat, hr_holidays, im_livechat, privacy_lookup,
privacy_lookup, test_discuss_full, test_mail_full, website_livechat

closes odoo/odoo#95912

Related: odoo/upgrade#3681
Related: odoo/enterprise#29433
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-07-19 11:50:37 +02:00
Thanh Dodeur fcc6a008da [REF] mail, *: make rtc invitations use the new ChannelMember model
* test_discuss_full

channel invitation to rtc calls are now using the `ChannelMember` and
`mail.channel.partner` models instead of the `partner` and `guest`
models.

part of task-2692836

closes odoo/odoo#95898

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-07-15 14:21:50 +02:00
Thibault Delavallée 3ca98b1271 [IMP] (test_)mail: move some tools directly to mail test class
TestMail holds a tool to create test records in batch, notably with inline
partner creation. Allow its usage in some sub modules and tests depending
directly from the base mail test class. This allows notably usage of this
tool in performance tests (see enterprise PR).

Also explicitly set some test data to ease sub tests writing.

Prepares Task-2150462 (Mass Mailing: Unsubscribe flow improvement)

Part-of: odoo/odoo#94660
2022-06-27 16:25:54 +02:00
Jeremy Kersten 1186424387 [FIX] mail: check access on translation too
This commit checks that users without the access right 'Template Editor'
are not allowed to add dynamic qweb in the translations of a mail
template.

Old tests have been updated to keep the assertRaises and all the code
that handle the invalidation cache, ... But now we ensure that the
Access Error raised is the expected one.

Original tests was testing that a user without the group 'Mail Editor'
got an  access error due to the missing group, but since the commit
1a3e713 the Access Error is because you cannot edit a template that is
not created by yourself.

closes odoo/odoo#94597

X-original-commit: 127a598e96e0e4a9952c009d98b705ceccf40def
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-06-25 17:06:48 +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
Rahul Prajapati ac00d19c8d [IMP] mail: remove alias mixin from channel
Before this commit:

mail.alias.mixin is being used in mail.channel

After this commit:

removed mail.alias.mixin with all of its uses in mail.channel

Task-2823691

closes odoo/odoo#89652

Related: odoo/upgrade#3469
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-05-31 19:17:06 +02:00
std-odoo 036a739b62 [IMP] mail, mass_mailing: remove the <mail.mail> in batch
Purpose
=======
Improve the performance of mass mailing by removing the <mail.mail>, in
batch, all at once. The unlink operation is very expensive for the ORM,
in terms of SQL queries.

A new field `to_delete` is required to know which <mail.mail> we need
to delete. The reason is that the `failure_type` is stored on the
<mail.notification>, and it's possible to have <mail.mail> without
<mail.notification>.

Task-2587345

Part-of: odoo/odoo#73271
2022-05-31 14:58:53 +02:00
Xavier Morel 319f9bf5ea [IMP] mail: allow admins to remove channels they're not members of
The only mail.channel rule was that a user only had access to channels
they're members of, or can subscribe to (public, or group based).

This rule applied to admins as well, forcing them to switch to
super-admin mode in order to manage mail channels.

This is undesirable on lots of axis:

- superadmin mode is a bit of a last-ditch feature, as a result it's
  somewhat hidden
- there is a much higher risk of screwing up as superadmin mode
  basically lifts all the access rules, which can have correctness
  implications
- auditing completely breaks down when using superadmin mode, as the
  real identity of the user is lost

OPW-2857136

closes odoo/odoo#92299

X-original-commit: 1a77ab5726bbcc477d12f40f67433d474ea85316
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2022-05-30 09:28:49 +02:00
Raphael Collet 6cf8db906f [REF] *: adapt code to new flush API
closes odoo/odoo#87527

Related: odoo/upgrade#3497
Related: odoo/enterprise#26939
Signed-off-by: Raphael Collet <rco@odoo.com>
2022-05-25 18:00:47 +02:00
std-odoo 9c1cdd330e [IMP] mail: avoid email loops when Odoo reply automatically
Purpose
=======
In this commit, we will fix the loops that occur when you send an email
to an alias (to create a ticket e.g.). In that case Odoo can reply
"Your ticket has been created" and then the auto-replier of the user
can reply to this email and the loop occurs.

Specifications
==============
To solve this issues, we add 2 system parameters
- <mail.gateway.loop.minutes>, 120 minutes by default
- <mail.gateway.loop.threshold>, 20 by default

When an email is sent to an alias, we look on the last records created
<mail.gateway.loop.minutes> minutes ago. If we overcome the limit
<mail.gateway.loop.threshold> the email is ignored.

Alias creation detection
========================
To detect the number of records created by a specific email address we
use the `_primary_email` attribute set on the model.

Task-2294034

closes odoo/odoo#78597

Related: odoo/enterprise#21772
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-05-20 13:14:56 +02:00
Fabio Barbero fc79bd1e0e [IMP] sm modules: "neutralise" genders
Purpose
=======
Change all masculine nouns in Odoo's code to neutral nouns (when
possible), making sure that demo data is correctly handled. This is
particularly important since our code is open source, and nowadays lots
of machine learning models are trained on open source repositories.

With this small change we contribute to training more "fair" models, and
teaching models that "employee" or "user" != "he".

This also affects some text visible by the user, hence making it more
inclusive for Odoo users.

Task-2853046

closes odoo/odoo#91292

Related: odoo/enterprise#27302
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-05-16 10:09:32 +02:00
Denis Ledoux dd2958a760 [FIX] mail: allow regular users to create mail non-dynamic templates
closes odoo/odoo#90896

X-original-commit: 96770827e42615c43b70bdae6529fb76ac66c518
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
2022-05-09 17:05:43 +02:00
Thibault Delavallée 5c354ece04 [IMP] mail: strengthen assert email values check
Purpose is to ensure tools are called like intended, notably by filtering
input and raising if an unexpected value check is asked. Some code is also
made a bit more generic to have the same kind of parameters when searching
for mail.mail.

In this commit we therefore fix some bad calls to assertSentEmails which
were not checking the right stuff.

closes odoo/odoo#90082

X-original-commit: d9759b2ee86b79b4fb2739a4aebd24a8044cf947
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-04-29 12:06:03 +02:00
std-odoo 044e253ac2 [FIX] mail: fix assertMailNotifications when called in batch
Bug
===
When we called assertMailNotifications in batch, with different
notification status, it might raise an error when it shouldn't.

The reason for that is we check that no mail at all are created, for
the entire batch instead of filtering on the related partner.

`assertNoMail` should only check if no mail are created for the partner
it receive in arguments.

Task-2782150

closes odoo/odoo#89965

X-original-commit: 91be8b1eb2c3592029987524942ae2864988a7d3
Related: odoo/enterprise#26718
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-04-28 12:40:40 +02:00
Thibault Delavallée bc8421f022 [FW][IMP] mail: add message_id in references to help thread formation
Issue: when using Amazon's SES SMTP service they rewrite the Message-Id of all
outgoing messages. When someone replies, In-Reply-To contains the SES Message-Id
which we don't know. Threading is therefore broken. Amazon requires to remember
new Message-Id and handle it ourself, which is complicated [1].

Possible solution: copy the Message-Id to References in outgoing message as if
we were pretending that the message is part of a pre-existing thread with
itself. Since Amazon does not alter References it is kept during transport.
Replies will therefore contain both Amazon Message-Id and Odoo Message-Id as
well as original parent Message-Id in case of nested replies.

  * ``In-Reply-To``: Amazon Msg-Id
  * ``References``: Odoo Parent Msg-Id Odoo Msg-Id

Task-2643114 (Mail: Message-Id in references to ease thread formation)

[1] https://docs.aws.amazon.com/ses/latest/DeveloperGuide/header-fields.html

closes odoo/odoo#89328

X-original-commit: bc568747bdf92c6bbca400ce3ba11f6487679f3a
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-04-22 12:04:34 +02:00
Rahul Prajapati 8fc3df9617 [IMP] mail: remove obsolete method
Before this commit:

There is a obsolete method _action_remove_members in tests which is not
needed now

After this commit:

Removed this obsolete method

Task-2824921

closes odoo/odoo#88988

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-04-20 12:37:41 +02:00
Nasreddin Boulif (bon) 67b0dee2df [FIX] mail: add test to ensure a user can unfollow a private channel
opw-2820449

closes odoo/odoo#88960

X-original-commit: 6442a3a97eb4196c7c05046cd95755185140243f
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-04-19 12:15:06 +02:00
Sébastien Theys a29a7183a4 [IMP] mail, im_livechat: fix performance of channel access rule
Current access rule requires fetching all members of each channel, which does not scale.

Use is_member field instead, and make sure itself does not fetch all members.

task-2818759

closes odoo/odoo#88221

Related: odoo/upgrade#3422
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-04-08 15:52:31 +02:00
Thanh Dodeur abd50a5ccb [FIX] mail: prevents access error when portal users opens a channel link
Before this commit, since https://github.com/odoo/odoo/pull/83574,
attempting to join a call through the channel guest page while being
logged as a portal user would give an acess error.

This commit fixes this issue

closes odoo/odoo#87995

X-original-commit: e6a637dc1d4e024c67b946fbe26a1b1e0dd144f3
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-04-05 16:15:24 +02:00
Leonardo Pavan Rocha ed116c735b [IMP] mail: add invitation_url on channel
In mail we currently create the invitation URL by concatenating the values when
needed. However this could be improved so that when this url is used in other
places we don't need to create it again. Therefore it makes sense to have a
computed field that does that for us.

task-2685472

closes odoo/odoo#87701

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-03-31 19:11:44 +02:00
Zelong Lin 72cf79a1ff [IMP] mail: channel_type cannot be changed
get prevention when transforming the channel type.

task-2774330

closes odoo/odoo#85128

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-03-28 23:10:49 +02:00
Raphael ColletandDidier Debondt 036ef5b96d [FIX] core: use EXISTS in domain conditions on many2many fields
This fixes two problems that occur with conditions on many2many fields:
the subtle bug caused by NULL values that are returned by subqueries,
and the performance of those subqueries.

The problem with NULL values returned by subqueries is the fact that
they make the SQL condition undetermined instead of false, and this
discards some of the results returned by a query.  Simply consider:

    id NOT IN (1, 2, 3)

The value id=3 makes the condition false, while i=4 makes it true.  Now
consider that the set also includes a NULL value, like:

    id NOT IN (1, 2, 3, NULL)

The value id=3 makes the condition false, but the value id=4 makes it
undetermined.  Therefore this condition is actually undetermined for all
possible values of id, and a query containing that condition simply
returns nothing!

Regarding performance, consider a domain like [('tag_ids', '=', False)].
It is currently translated in SQL as

    "model".id NOT IN (
        SELECT "model_id"
        FROM "model_tag_rel"
        WHERE "model_id" IS NOT NULL
    )

PostgreSQL does not handle well this "NOT IN" expression when the
relation table is large, and uses some very inefficient query plan in
that case.  The inefficient query plan is possibly related to the
special handling of NULL values, by the way.  This commit changes the
above expression to a "NOT EXISTS" expression (as below), which is
executed with a much more efficient query plan, even with large tables.

    NOT EXISTS (
        SELECT 1
        FROM "model_tag_rel"
        WHERE "model_tag_rel"."model_id" = "model".id
    )

This change was motivated by a use-case with 2.7M account moves, 11M
account move lines and a many2many relation table with 2.3M lines
(`account_move_line_account_tax_rel`).  The query was timing out (15
minutes), and it now takes 15 seconds.

We have replaced all the conditions on many2many fields to use the
relational operators EXISTS and NOT EXISTS.

A test has been added to reflect a case where the many2many table
contains NULL values, like the one for channel_partner in regards to
partner_id and guest_id.

task-2753782

X-original-commit: 334b2aa2aa437d2ed86130f2ed426025f8fe4b86
Part-of: odoo/odoo#87285
Co-authored-by: Didier Debondt <did@odoo.com>
2022-03-25 17:47:43 +01:00
Thibault Delavallée 94ab6963cf [IMP] test_mail: add and improve tests for composer
PURPOSE

Cleanup and improve composer-related tests. As composer will soon be improved
better ensure we don't break flows.

SPECIFCIATIONS

Cleanup existing tests: rename, make it use tools, reoder them.

Add some tests about composer in order to better spot changes and differences
as well as to help debugging mail composer code update. Notably add tests
with Form tool, add tests for reply-to computation, auto-delete, mail server.

Performance tests about composer are added, notably using the Form tool. This
helps determining differences between creating / manipulating a composer in
code and in UI. Indeed notably onchange and some side effects may lead to
different query counters, which is the case as highlighted here. Tests
involving attachments are also added to see their impact on posting process.

Task-2673913 (TestMail: Cleanup and improve test coverage)

Part-of: odoo/odoo#86393
2022-03-24 13:57:36 +01:00
Thibault Delavallée 6d166d6088 [IMP] base, mail_*: use MockSmtplibCase and improve tests tooling
mail_* = mail, test_mail, test_mail_full, test_mass_mailing

PURPOSE

Improve tooling of mail tests. Use SMTP mockup class available in base tests
in mail tests to have a better and simplified mock tool when dealing with
mail tests. Remove old fashioned code.

SPECIFICATIONS

Include ``MockSmtplibCase`` directly into ``MockEmail`` so that we re-use
existing components for mocking outgoing emails. Also make parameters for
gateway coherent between those two classes (use same test values).

Remove 'sim_error' weird parameter of Mail ``mock_mail_gateway`` and use
standard mock 'side_effect' instead in some specific tests, notably on
SMTP.connect() mock.

Add some assert / tools method and improve existing tools, used for creating
or improving test data. This will be used in future commits when adding new
tests.

Add outgoing mail servers data in mail tests, allowing to make tests closer
to real life use cases.

Remove unnecessary calls to ``_init_mail_gateway`` as it is automatically
done in ``MailCommon.setUpClass()``.

Try to consolidate starting test data, notably with countries, phone numbers
or email in mind to be sure test mail are deterministic.

Task-2673913 (TestMail: Cleanup and improve test coverage)

Part-of: odoo/odoo#86393
2022-03-24 13:57:35 +01:00
Ipsita Borisagar 1043c6c65c [FIX] mail: do not allow guests for group restricted channels
Before this commit:

When user shares the invitation link of the channel(groups restricted), guests
are allowed to access it.

After this commit:

Guests will not be allowed to access channels that are restricted to groups.

Task-2679184

closes odoo/odoo#87004

X-original-commit: ea3232c111546ec636f543db912bf0e2a7ed345b
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-03-23 00:29:22 +01:00
Fabio Barbero 8ed0c6f54f [FIX] mail: add check valid email address
Purpose
=======
The method find_or_create of res.partner overwritten in mail does not
take into account the parameter assert_valid_email. This commit adds a
simple check and test.

Task-2799577

closes odoo/odoo#86943

X-original-commit: 7a07b365370d03e963aa7f7d9d19df7ee33e8a1c
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-03-22 22:13:04 +01:00
Didier (did) fc9e67bc6b [IMP] mail: move message unread counter to channel
The field could have been removed from thread since https://github.com/odoo/odoo/commit/88b8cd058713bfad2942f7e7434c34b6c1a6e7da

task-2746109

closes odoo/odoo#83765

Related: odoo/upgrade#3222
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-03-21 14:59:42 +01:00
tsm-odoo 1e828a14ec [IMP] mail: get closer from python model definition in test setup
*: hr, hr_holidays, im_livechat, mail, snailmail, test_mail, website_livechat,
website_slides.

This commit will remove the need to duplicate models definition for
test purposes. Indeed, for now, we need to mock the model definitions
on the client side. Those models definitions are often very different
from the ones found on the server.

This approach will allow us :
	- to ease model definitions during tests
	- to get closer from the real models

task-2767820

closes odoo/odoo#84828

Related: odoo/enterprise#24486
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-03-10 18:19:59 +00:00
Sébastien Theys 5dfcdb74e5 [FIX] mail: prevent inconsistencies when using message reply
closes odoo/odoo#86060

X-original-commit: 81ddfad51e9b35db8d14e1fb14aa24596b6af767
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-03-09 00:50:49 +00:00
Antoine Guenet 5c6b6cb4ae [FIX] mail: test adaptation forward port
We adapted a test in mail in commit be21041f9aa385f2b9ce1b242379bf147c54b158.

Basically, the test only contained mso comments and no regular comment.
While the python code teats them the same, they are not semantically
equivalent as mso comments actually do have side effects in outlook.
The adaptation is to add a regular comment to the test data so that both
comment types are properly covered by the test, even though the result
is technically the same regardless.

This is the only change from this commit that was not yet present in 15.2.

closes odoo/odoo#84786

X-original-commit: 9275b0119ee6bb2e9a4ee5bef66b00e8c2456d3d
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
2022-02-17 15:31:12 +00:00
Sébastien Theys 47bda95b98 [FIX] mail, sms, snailmail: fix perf of fetching failures of user
We are currently lacking an index with (author, failure) due to the information
being spread out in two different tables which are both rather big (there are a
lot of non-failure messages for the current user, as well as a lot of failure
messages for other users), so the fetch of failures for the current user can
become extremely slow (> 20s).

With this new index, the query takes less than 1ms.

task-2742946

closes odoo/odoo#83451

Related: odoo/upgrade#3204
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2022-02-01 18:07:02 +00:00