Commit Graph
539 Commits
Author SHA1 Message Date
Nicolas Seinlet 9a01a2953f [IMP] mail, im_livechat: inline sql instead of long id list
using inselect operator to inline sql in the search method and avoid ORM
to fetch multiple useless messages to check if there's one

closes odoo/odoo#70410

X-original-commit: 505c7b0946689d3ac1ac4dd2f59cf4d535c36cbb
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-05-05 12:40:29 +00:00
Thibault Delavallée 8f56f1ead0 [FW][FIX] sale: correctly redirect customers in "Pay Now" template
Mail holds a "Pay Now" notification template holding notably customized
links to portal for records like sale orders or invoices. It allow to
give a more personalized button than a plain simple "View document" link.

Currently frontend / backend links are not always correctly computed in this
template. This commit fixes that behavior.

Task ID-2513724
COM PR #69607
ENT PR odoo/enterprise#17849

closes odoo/odoo#69714

closes odoo/odoo#69744

closes odoo/odoo#69774

X-original-commit: c417ea6243cb968d17f5db0919ec8cd034f4cb5f
Related: odoo/enterprise#17889
Related: odoo/enterprise#17902
Related: odoo/enterprise#17916
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-04-23 15:24:58 +00:00
Anh Thao Pham (pta) 0d528d7007 [FIX] mail: prevent use of private addresses for followers, recipients,...
- Connect with Admin
- Go to Contacts, edit himself by adding a Private Address
- Create an Internal User without "Access to Private Addresses" right (i.e. User X)
- Go to any app implementing chatter (i.e. Sales)
- Create a SO
- Add the created Private Address as follower
- Make sure User X can access the record (i.e. Sales: Administrator)
- Connect with User X and open the SO
An Access Error is raised while trying to fetch data about the followers.

This commit prevents to:
- add a private address as follower of a record
- add a private address as Recipient in full composer
- propose private addresses when adding a mention to a partner

opw-2428936

closes odoo/odoo#68493

Task-id: 2463622
X-original-commit: 20536e1bbeb641539c0de44364f8376e7cef651b
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
2021-03-30 07:45:02 +00:00
Priyanka Kakadiya 18ba2befab [FIX] mail: notification not sent when using the full composer
Current behavior before PR:
mail notification not sent when using the full composer.

Desired behavior after PR is merged:
mail notification will send when using the full composer.

LINKS:
PR https://github.com/odoo/odoo/pull/66421
Task-2446855

closes odoo/odoo#67933

X-original-commit: 349f07670ea4938e7fc3d9fa3a6fc5fae40dac65
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-03-19 07:40:42 +00:00
Veronika Kotovich 43d70a670a [FIX] mail: prepare mail header References to avoid line breaks
When Odoo routes incoming emails it is looking for existing messages in
database using Message Ids which are coming from e-mail header
References.

In Odoo the message id looks pretty long like

    743570479975566.1584086032.522504091262817-openerp-message-notify@ip-172-31-45-160

As it declared in [RFC2822] long header bodies can be "folded" using
CRLF+WSP. And some mail clients do that very thing. They split
References header body which contains Message Ids by "\n ".  The example
of mail client where it can be reproduced is apps.rackspace.com We
created Sales Order in Odoo, sent this quotation to the client email. He
replied with e-mail, and this email can't be matched with any existing
message id and as result it's not attached to the Sales Order.

RFC2882: https://tools.ietf.org/html/rfc2822#section-2.2.3

closes odoo/odoo#68077

X-original-commit: 559f6cf62711ad45557eddec3af7c66616724eb5
Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2021-03-18 12:10:03 +00:00
Thibault Delavallée c4dacc24fa [REF] mail, sms: simplify notification recipients structure
Now that recipients in notification process are always partners due to
simplification of MailFollower model we can safely simplify the structure
used to collect and propagate recipients information.

Before this task it was a dictionary with a list of partner related data and
a list of channel related data. It is now simply a list of partner related
data, leading to various code cleaning.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
2021-03-17 18:22:20 +00:00
Thibault Delavallée d08e3676ea [IMP] mail: improve subscription low-level API readability
Purpose of this commit is to make low-level API of subscribe process a bit
easier to understand and use. Notably some parameters are now defined as
named parameters in order to better understand calls.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
2021-03-17 18:22:15 +00:00
Thibault Delavallée e5338146e7 [REF] mail: make message belongs to a single thread without listener channels
RATIONALE

Channel model is a mail.thread enabled model behaving strangely with followers,
notifications and discuss. Its code should however be simplified to be more
self contained and avoid unwanted side effects on other models.

PURPOSE

Remove channel ability to follow records as it mainly adds noise without a lot
of added value. Simplify channel notification flow by using directly members
and not a delegation through a channel self-following trick. Remove followers
being channels and posting with added listeners being channels.

SPECIFICATIONS

In this commit we force messages to belong to a single document using
``model`` / ``res_id`` pair. It is not possible anymore to link a message
to channels using ``channel_ids``. A message belongs to a document and
is displayed in that document's chatter.

This change implies modifying a lot of domains, notably in chatter. Indeed
discuss for channels does not use ``('channel_ids', 'in', [3])`` domains.
They now use ``('model', '=', 'mail.channel'), ('res_id', 'in', [3])`` like
other documents fetching their messages.

This commit also removes ``channel_message_ids`` field on ``mail.channel``
model. As channels are now considered as standard documents they will use
``message_ids`` field like all other documents. Linking a channel on a message
is possible only as a link in message from now on. It is not possible to push
it into a channel anymore (no more listener channels, no more channel link).

Finally a global cleaning also linked to all previous commits is done.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
2021-03-17 18:16:35 +00:00
Thibault Delavallée df013e76bc [REF] mail: do not support listener channels when posting a message
RATIONALE

Channel model is a mail.thread enabled model behaving strangely with followers,
notifications and discuss. Its code should however be simplified to be more
self contained and avoid unwanted side effects on other models.

PURPOSE

Remove channel ability to follow records as it mainly adds noise without a lot
of added value. Simplify channel notification flow by using directly members
and not a delegation through a channel self-following trick. Remove followers
being channels and posting with added listeners being channels.

SPECIFICATIONS

In this commit we remove support of ``channel_ids`` parameter when posting
a message. This means we do not support notifying channels as side-part
of notification mechanism on a document. Either we post on a channel and
its members are notified, either we post on a business documents and its
followers are notified. There is no possibility to add channels as being
notified when posting a message.

This is done as a followup of removing followers being channel-based and
prepares ground to make channel use model / res_id as all other documents
inheriting form mail.thread.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
2021-03-17 18:16:20 +00:00
Thibault Delavallée 4cb1f56aba [REF] mail, sms, test_mail: remove now unused channel_id field on Py and JS follower models
RATIONALE

Channel model is a mail.thread enabled model behaving strangely with followers,
notifications and discuss. Its code should however be simplified to be more
self contained and avoid unwanted side effects on other models.

PURPOSE

Remove channel ability to follow records as it mainly adds noise without a lot
of added value. Simplify channel notification flow by using directly members
and not a delegation through a channel self-following trick. Remove followers
being channels and posting with added listeners being channels.

SPECIFICATIONS

As there is no way to add channel-based follower anymore we can remove all
fields and code supporting this feature. Notably we can remove ``channel_id``
field on ``mail.follower`` model as well all code using it, notably compute
methods.

In this commit we also make ``partner_id`` field required as now followers
are always partners. Email, name and active fields are now simple related
fields on the partner.

Code computing data about subscription is also updated and simplified. As
we do not have channels anymore but only partners all custom SQL queries
are now simplified.

JS models for Discuss are also cleaned. Following python change, JS models
are simplified to match the backend models. Channel_id is removed, partner_id
is now required, and various code is updated according to the simplified
model.

Side note: we could probably get rid of specific index on ``partner_id``
field. However we have to ensure we never search for followers without being
in a model / res_id context. This will be done in another cleaning step to
be sure performance are not broken.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
2021-03-17 18:16:18 +00:00
Thibault Delavallée 305af13279 [REF] mail, note, test_mail: remove now unused message_channel_ids field on MailThread
RATIONALE

Channel model is a mail.thread enabled model behaving strangely with followers,
notifications and discuss. Its code should however be simplified to be more
self contained and avoid unwanted side effects on other models.

SPECIFICATIONS

Remove ``message_channel_ids`` field from ``mail.thread``. As we removed
support of (un)subscribing channel-based followers there is no need anymore
to have a field to access them. We can now safely remove this field as it
has no use anymore.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
2021-03-17 18:16:13 +00:00
Thibault Delavallée 7991118bfe [REF] mail, various: remove support of channels from message_subscribe API
RATIONALE

Channel model is a mail.thread enabled model behaving strangely with followers,
notifications and discuss. Its code should however be simplified to be more
self contained and avoid unwanted side effects on other models.

SPECIFICATIONS

Remove ``channel_ids`` argument and support from ``message_subscribe`` and
``message_unsubscribe`` API. Indeed we do not support adding channel-based
followers anymore. Only partners should be added or removed from followers.
It also allows to simplify API and understanding of both methods.

Various addons are updated to match the simplified (un)subscribe API. Some
enterprise addons may also be impacted.

LINKS

Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
2021-03-17 18:16:11 +00:00
ryv-odooandThibault Delavallée ba9e79f29c [REF] mail: rename mail.notification table
RATIONALE

A bit of history. Link between a message and its recipients has been added
at first mail refactoring towards a Chatter / Discuss feature. It was done
in v7 at d64f3c9783 with the base addition of mail notification model (lots
of commits follow that one but that's the first one about notification).

Due to some people thinking that it was unnecessary to keep a model for
notification it has been removed in v9 at 88b8cd0587. Notification table was
renamed from mail_notification to mail_message_res_partner_needaction_rel.

It was proven to be a mistake even if those "some people" were warned and
model made its way back to Odoo in v10 at 72dfcae2a4 . Table name mail_message
_res_partner_needaction_rel was kept to ease migration and backward
compatibility.

It is now time to complete the circle and rename it to mail_notification.

SPECIFICATIONS

Rename ``mail_message_res_partner_needaction_rel`` to ``mail_notification`` .

RIP JEM.

Never forget.

LINKS

Task ID-2477444
Prepares Task ID-2377974 (trace management cleaning task)
Prepares Task ID-2070632 (channel members main task)
Prepares Task ID-2419762 (channel members followup task)
COM PR odoo/odoo#67382
UPG PR odoo/upgrade#2245

Co-Authored-By: Rémy Voet <ryv@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
2021-03-05 15:20:53 +00:00
Thibault Delavallée d2079b1fca [DOC] mail: clean some docstrings and helpers
As I was passing by I found some docstrings or helpers could be updated or
rephrased a bit more clearly. This is free as in free beers, without beers.

Some code about mail features (posting) may also be re-indented to ease
understanding of future modifications. Or just because we had to read
it and go through many files. Still free beers.

LINKS

Task ID-2477444
Prepares Task ID-2377974 (trace management cleaning task)
Prepares Task ID-2070632 (channel members main task)
Prepares Task ID-2419762 (channel members followup task)
COM PR odoo/odoo#67382
UPG PR odoo/upgrade#2245
2021-03-05 15:20:53 +00:00
Martin Trigaux 6e6f5bd599 [FIX] mail: fallback on English message
In case of bad translation that doesn't contain the placeholder

Context:
A bad Japanese translation was inserted

  #. module: mail
  #: code:addons/mail/models/mail_thread.py:0
  #, python-format
  msgid "Create new %(document)s"
  msgstr "新しい%(ドキュメント)を作成する"

The translation has been corrected but use the 14.0 syntax of _ method
to include placeholders and fallback on the English source term in
case of bad translation
cf odoo/odoo#52155

closes odoo/odoo#65586

X-original-commit: 48cc6b1f2b3208e8affd5f6a261751fe973c2091
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2021-02-05 09:25:40 +00:00
b0e7cf9ebe [FW][FIX] mail: fix auto subscribe subtypes computation
This commit contains a followup / rewrite / backport of #34150 :

  * odoo/odoo@16dd3da
  * odoo/odoo@0b11ed8

Fix: propagate generic internal subtypes from parent to childs with auto
subscribe.

  With this commit, when the user subscribes to internal subtypes like
  activities on a parent record (e.g. a project) then the user follows them
  by default on every sub record creation (e.g. all new tasks of this project).

Fix: do not reset existing subtypes when changing parent of a record using
auto subscribe mechanism.

  With this commit, when changing subtype subscription from a parent record
  (e.g. project) avoid resetting all subtypes subscription on existing sub
  records (e.g. all new tasks of this project). Only new records will use the
  parent chosen subtypes. This is done through propagation of followers
  existing policy (see Follower._insert_followers() for more details);

Note that fix done here is slightly different from the one done in odoo/odoo@16dd3da
as there was some mismatch with internal model-related subtypes. Thix fix
will be forward ported and improve the previous one.

Task ID-2205643
COM PR #47336

X-original-commit: 01254f06e8ea37887e190758cc479a098591ab8e
X-original-pr: odoo/odoo#47336
Co-authored-by: Thibault Delavallee <tde@odoo.com>
Co-authored-by: Alexandre Khun <aku@odoo.com>
Co-authored-by: Priyanka kakadiya <pka@odoo.com>
2021-01-19 18:11:52 +00:00
Jairo Llopis 04362043f6 [FIX] mail: Do not consider reply if no "To:" is found
If an email was sent with empty "To:" and a proper alias in "CC:" (or any of the similar valid headers that conform the `rpc_tos_localparts` array), before 40ae36b7f8c412cd96dc9592d8d1fb90de1e52d2 the email wouldn't get rejected. After that commit it would get bounced.

This comes from the not-so-obvious new python idiom used, `all()`. Check this out:

```python
>>> all([False])
False
>>> all([])
True
```

So, apart from the fix introduced in that commit, which seems valid, we have to make sure `email_to_localparts` actually has contents. Otherwise we are producing false bounces here.

@Tecnativa TT23437

closes odoo/odoo#64528

X-original-commit: 8f094d3c01a6ad150b7945115cda515dbde1f4bc
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-01-14 10:18:31 +00:00
Thibault Delavallée b30648198a [IMP] mail: improve channel tests about moderation
Purpose of this commit is to rewrite channel tests, notably moderation
tests. In this commit we

  * use standard users instead of admin/root: this allows to test ACLs and
    more real life oriented use cases;
  * remove unnecessary tests or merge tests belonging to the same category;
  * add some coverage for corner cases;
  * make tests more readable;

We also improve some notification code and error messages that are not
really helpful for users.

Followup of odoo/odoo@e9571a403e
Task ID-2421795

closes odoo/odoo#64459

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-01-13 10:10:10 +00:00
Achraf (abz)andThibault Delavallée f5adb5b25d [FIX] mail: send notification mail with right access link when using mail.thread
PURPOSE

Notification may be sent using a generic mail.thread record, notably when
sending user notifications. In that case links to view document are
incorrect.

HOW TO REPRODUCE

Issue

    - Install "Approvals"
    - Submit new approval with you as "Request Owner"
    - Click on "View Approval Request" in your mailbox

    The link redirects to a 505 error

Cause

    The model is not the correct one and the res_id is undefined

Solution

    Specify the model and the res_id to _notify_get_action_link
    when creating the link with kwargs

SPECIFICATIONS

Propagate message value through various notification sub methods. That way
we can rely on them if model seems void.

Also limit values given as URL parameters to some white listed values.

LINKS

opw-2358846
Task ID-2379766
Followup of odoo/odoo#60998
Followup of odoo/odoo#61545
Closes odoo/odoo#63292
Closes odoo/enterprise#15585

closes odoo/odoo#64229

X-original-commit: 58bac5d242d6548d54f0163328fa64b319852e40
Related: odoo/enterprise#15634
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: Achraf Ben Azzouz <abz@odoo.com>
Co-authored-by: Thibault Delavallée <tde@odoo.com>
2021-01-07 17:44:37 +00:00
Julien Castiaux 1a20f11005 [FIX] mail: Receive EML file in attachment
Configure the incomming mail server, use another mail client to send a
message to Odoo with an EML file as attachment. The fetchmail server
fails.

Since the introduction of the new EmailMessage python API to
encode/decode email messages, every EML attachment is automatically
parsed into a EmailMessage.

closes odoo/odoo#63255

Task: 2329606
X-original-commit: e628defec14f3b36612951bc698fa51b7c9f56bb
Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
2020-12-11 14:59:27 +00:00
Didier (did) 581d226e03 [FIX] mail: clean sub-queries when searching error message
Thread search with `message_has_error` should only return threads containing
messages with failure of which the current user is author.

Follow up on https://github.com/odoo/odoo/pull/52403 that changed how
sub-queries were built. The current fix using `_search` is a non-ideal solution
until task-2366651 brings a new domain operator for this use case.

task-2409543

closes odoo/odoo#63231

X-original-commit: 337397eec5570fc9b3938d655a1ec0e4efcd73d9
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2020-12-11 11:50:58 +00:00
Jairo Llopis b8571322f9 [FIX] mail: add support for Text/RFC822-Headers content-type
WHY:

Some mail servers may provide `Message-Id` header in a section typed
`text/rfc822-headers` instead of a `message/rfc822`

According to https://tools.ietf.org/html/rfc6522#section-4 that section's body
actually contains the headers from the bounced email.

STEPS: a way to reproduce it should be using postfix v2.5+ with setting
bounce_size_limit=1. See
https://github.com/odoo/odoo/pull/42340#issuecomment-617605521

BEFORE: `bounced_message_id` is empty and thus the little email envelope icon
doesn't turn red, nor do the email resend features trigger in the UI. You could
be sending an invoice and never knowing it was bounced.

AFTER: bounces from mail servers that return the `text/rfc822-headers` part will
be handled properly.

---

@Tecnativa TT21170
opw-2162067
opw-2344252
closes #42340
closes #62551

closes odoo/odoo#62732

X-original-commit: 375ba5b37053a599922dd61c9e787553d6171291
Signed-off-by: Ivan Yelizariev // IEL <yelizariev@users.noreply.github.com>
2020-12-02 11:50:31 +00:00
Aurélien Warnon b46153f6cf [FIX] mail: fix mail.mail default values collision
This commit cleans the default_* keys of the context before creating mail.mails
and mail.notifications when notifying the record by email.

Without this change, there can be a collision when the ORM tries to compute
default values for the state field (for example):
- Model "A" has a 'state' field ;
- Create an action that redirects to model "A" form view, setting some default
  values in the context such as {'default_state': 'done'} ;
- Model "A" has an inherit on 'mail.thread' and a 'user_id' field to set a
  responsible user ;
- Model "A" record is created with a responsible user, who is automatically
  notified by email that the record "has been assigned to him" ;
  (see mail_thread#_message_auto_subscribe_notify)
- A 'mail.mail' is in turn created ;
- The 'mail.mail' model ALSO has a 'state' field, and the context is propagated
  so the ORM will try to assign 'done' to that field, which is an incorrect
  value ;
- -> Crash.

If we ensure that the default_* keys are cleaned from the context, the default
values computation of the mail.mail record will not be affected and everything
works fine.

A test was added to ensure this behavior.

Task 2393259

closes odoo/odoo#62589

X-original-commit: 6b6e546ac95d9acb2964121dd52aa2896d31bc33
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: awa-odoo <awa-odoo@users.noreply.github.com>
2020-11-30 10:25:36 +00:00
Julien Castiaux db9bf62431 [REF] mail: Use Command helper for x2many
closes odoo/odoo#60965

Task: 2366606
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-11-30 10:16:09 +00:00
Thibault Delavallée c819223e88 [REV][FIX] mail: Send mail with correct access link
This reverts commit fbd30f4266d86b53aa4b13b72a93bccee0d7eb69. Indeed kwargs
are used to build a link, meaning message value are given to some links when
using message_notify.

A better fix will be provided soon. Reverting to avoid issues in stable.

closes odoo/odoo#61632

X-original-commit: e861f7294a7bd6bde056b987f15e48df4b0ab877
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-11-12 09:18:44 +00:00
Achraf (abz) 5ea2922800 [FIX] mail: Send mail with correct access link
Issue

    - Install "Approvals"
    - Submit new approval with you as "Request Owner"
    - Click on "View Approval Request" in your mailbox

    The link redirects to a 505 error

Cause

    The model is not the correct one and the res_id is undefined

Solution

    Specify the model and the res_id to _notify_get_action_link
    when creating the link with kwargs

opw-2358846

closes odoo/odoo#61478

X-original-commit: 075325226d6f7c2af638013f25613ddd391e506b
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Achraf <abz-odoo@users.noreply.github.com>
2020-11-06 13:02:18 +00:00
Thibault Delavallée c6207a38b6 [IMP] mail: allow to specify a new parent when using message_change_thread
Purpose of this commit is to allow to attach moved messages from a thread
to a new parent. This allows notably to keep references if message
hierarchy is not kept as it is.

LINKS

Task ID-2083049
COM PR odoo/odoo#49129
ENT PR odoo/enterprise#9715
UPG PR odoo/upgrade#1883

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-11-05 08:12:21 +00:00
Xavier Dubuc b2d9170aef [FIX] mail: fix "New messages" separator and channel_seen behaviour
- channel_seen is now called even for own message and only when needed
- channel_seen is now called with a message_id which transfer the
  decision of what is seen to the client which makes more sense

task-2282235
task-2282248

closes odoo/odoo#57956

X-original-commit: 04edfa50ccea305050d017c4a1996e561bc7bd57
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2020-09-17 13:45:35 +00:00
Raphael Collet 317765c8f3 [IMP] core: deprecate method cr.after()
Use the more convenient `cr.postcommit.add()` instead.

closes odoo/odoo#57043

X-original-commit: e9e37091a65d5ae2caa9eb6728abaffb7c9555a8
Related: odoo/enterprise#12928
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-09-03 14:29:39 +00:00
Raphael Collet e8f7cfd00a [FIX] core: cursor hooks API and implementation
Python 3.8 changed the equality rules for bound methods to be based on
the *identity* of the receiver (`__self__`) rather than its *equality*.
This means that in 3.7, methods from different instances will compare
(and hash) equal, thereby landing in the same map "slot", but that isn't
the case in 3.8.

While it's usually not relevant, it's an issue for `GroupCalls` which is
indexed by a function: in 3.7, that being a method from recordsets
comparing equal will deduplicate them, but not anymore in 3.8, leading
to duplicated callbacks (exactly the thing GroupCalls aims to avoid).

Also, the API of `GroupCalls` turned out to be unusual and weird.  The
bug above is fixed by using a plain list for callbacks, thereby avoiding
comparisons between registered functions.  The API is now:

    callbacks.add(func)     # add func to callbacks
    callbacks.run()         # run all callbacks in addition order
    callbacks.clear()       # remove all callbacks

In order to handle aggregated data, the `callbacks` object provides a
dictionary `callbacks.data` that any callback function can freely use.
For the sake of consistency, the `callbacks.data` dict is automatically
cleared upon execution of callbacks.

Discovered by @william-andre

Related to odoo#56583

References:

* https://bugs.python.org/issue1617161
* python/cpython#7848
* https://docs.python.org/3/whatsnew/changelog.html#python-3-8-0-alpha-1
  (no direct link because individual entries are not linkable, look for
  bpo-1617161)

X-original-commit: d4b2e9224839aed8fc160ebe5a89e0f7d4c6a5bb
2020-09-03 14:29:39 +00:00
Thibault Delavallée cc5ccf972d [IMP] mail: subscribe creator of document through mail gateway if not superuser
Document creation or update is still done without auto subscribe. Indeed user
running mailgateway or owning alias is not necessarily linked to the email
author. That way we avoid auto subscription of irrelevant people.

Posting message based on incoming email is now allowing auto subscription if
there is an author found during email parsing. We also ensure this author is
not root, to be sure he is not added in followers of documents.

LINKS

Task ID-2326281
PR odoo/odoo#56560
Closes odoo/odoo#38383

X-original-commit: fe27f9fe0cf9581c15a2a9e45125abe82dd303ad
2020-08-28 14:53:46 +00:00
Thibault Delavallée 285aa27da4 [IMP] mail: do not auto-subscribe inactive partners
Tested flows

  * posting a message through an inactive partner (like automated actions
    posting a message on behalf of an inactive partner);
  * automatic subscription based on parent record (like an archived user and
    partner following a project that should not be added as follower of sub
    tasks);
  * automatic subscription based on responsible field: this is already fixed
    as user has to be active to receive a notification and be added in
    followers;

LINKS

Task ID-2326281
PR odoo/odoo#56560

X-original-commit: 42910ce25f06a31af3cfbc8d5d41e443ee754c34
2020-08-28 14:53:46 +00:00
Dharmraj Jhala 610ba98539 [FIX] mail, crm: do not display body in creation message when having a subtype
Right now on few business objects (like leads, invoices, tasks, helpdesk
tickets etc) creation message contains
  * subtype description;
  * generic creation message;

This looks like multiple creation message on chatter after creation of the
record as you generally have "Task Created - Task created" (subtype description
then generic message).

This happens when we provide custom subtype on creation by by overriding
`_creation_subtype` method.

This commit fixes the issue by only using provided creation subtype and
removing default body. If creation subtype is not provided default creation
message is posted as before.

In this commit we also fix subtype for Lead/Opportunity creation and make
it generic ('Lead/Opportunity created') to avoid inconsistent behavior.

Finally some cleaning is made in method naming. Semi followup of 92e9e84b63

LINKS

Task ID-2288458
PR odoo/odoo#56631
PR odoo/enterprise#12707

closes odoo/odoo#56688

X-original-commit: 2ebbeb4b5443c6405dd9a3b202a1eee9c5c67ebb
Related: odoo/enterprise#12728
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-08-28 07:59:24 +00:00
Thibault Delavallée f5c6f14bb1 [REF] mail: move generic methods from thread to BaseModel
PURPOSE

Since v13 some commits added code in mail thread file. This file is already
quite long and keeping it organized allow to understand its content.

SPECIFICATIONS

Some methods defined on mail.thread may actually be called on models
not inheriting from mail.thread . Instead of having model methods on mail
thread receiving a records parameter it seems better to have those available
directly on BaseModel.

Move static_message_track on BaseModel in models.py. This method is now called
_mail_track, to be coherent with othe rmail-related naming. It is used in
accounting to track values in line model that does not inherit from mail.
thread. Update accounting accordingly (followup of d862965).

Move _message_get_default_recipients_on_records in models.py. Renaming it
_message_get_default_recipients() allow to be compatible with current behavior
and current override available in some addons (like CRM, event, ...).

Move _notify_get_reply_to_on_records in models.py. Renaming it
_notify_get_reply_to() allows to be shorter and coherent.

Move _alias_check_contact_on_record in models.py. Renaming it
_alias_check_contact_() allows to be shorter and coherent. Its override in
hr is also moved on BaseModel.

LINKS

Task ID-2327096 (code cleaning)
PR #56631

X-original-commit: f5df1ed912455e5ed52a65df3149f30a9d424de0
2020-08-28 07:59:23 +00:00
Thibault Delavallée 371ab515bb [REF] mail: reorganize a bit 13+ thread code and set some methods private
PURPOSE

Since v13 some commits added code in mail thread file. This file is already
quite long and keeping it organized allow to understand its content.

SPECIFICATIONS

Clearly separate CRUD / CRUD HELPERS / TRACKING / ... . Notably tracking
code was split accross two code sections.

Make some internal tools methods private. They do not require to be public
  * with_lang: does not makes sense to be available outside of odoo. It is
    renamed to _fallback_lang as it does not allow to set a specific lang in
    the environment like with_user. It is used to fallback on user's lang
    in context;
  * get_mail_message_access: purely internal method used for access rights;

LINKS

Task ID-2327096 (code cleaning)
PR #56631

X-original-commit: 4a5fc70cfc3c86da33e2480fbd59c8f6d575c6e9
2020-08-28 07:59:23 +00:00
Simon Genin (ges) 8d02a85c1d [IMP] project: fix mail alias
Update mail alias layout, makes email address
clickable (mailto) and fix a couple of typos.

Task ID 2287394

closes odoo/odoo#53960

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2020-07-03 08:53:36 +00:00
Martin Trigaux 80e97e98ce [IMP] *: use named placeholders in translated message
When more than one parameter is present in a message, it helps the
translation to use named placeholder. This way, the order can be
changed. It also helps the comprehension of the message.
2020-06-18 13:03:34 +02:00
Martin Trigaux ba244cef01 [IMP] *: replace to new _() syntax
Using a few regex like
\((_\(.*%s.*)(\) % )([\w\[\]][\w .\[\]\(\)'"]*)\)
($1, $3))

Old syntax is still compatible but starts the migration to the new
syntax that catches error.
2020-06-18 13:03:34 +02:00
Julien Castiaux 696a5ecfdd [FIX] mail: cannot route catchall bounced email
Configure a catchall address in Odoo, send an email to that very
address, it should bounce back to the user asking him not to send any
email to the catchall but the email is never sent.

Internally, Odoo reply to the user using the `To` header of the original
email as `From` of the bounced email. It should never use the catchall
address as it is not a valid email to send email from.

closes odoo/odoo#53036

Task: 2277661
X-original-commit: 86c8f0960f709692aa787ae62d446b4427a7c312
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-06-16 09:33:07 +00:00
3fea5b2136 [REF] mail, *: refactor messaging with OWL
This commit is a significant rewriting of client-side discuss, chatter,
chat window, and messaging menu using OWL. The behavior should be broadly
the same, with some slight functional changes here and there.

From a technical standpoint, the code of messaging is mainly organized in 2
main groups of modules:

- models, which are logical entities that depict the client-side state of
  messaging as a whole.
- components, which are in charge of displaying information from models.

This refactoring also introduces new JS guidelines regarding folder structure
(/static) and naming rules for JS modules.

Community PR: https://github.com/odoo/odoo/pull/39023
Enterprise PR: https://github.com/odoo/enterprise/pull/6249

Task-1914207

This PR is a collaborative work by Alexandre, Julien, Sébastien and Xavier,
with the precious help of Lucas to speed it up towards the end.

closes odoo/odoo#39023

Related: odoo/enterprise#6249
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Co-authored-by: Alexandre Kühn <aku@odoo.com>
Co-authored-by: Julien Giannone <jgi@odoo.com>
Co-authored-by: Lucas Perais <lpe@odoo.com>
Co-authored-by: Sébastien Theys <seb@odoo.com>
Co-authored-by: Xavier Dubuc <xdu@odoo.com>
2020-06-15 18:12:21 +00:00
std-odoo 635519ae29 [FIX] mail: fix tracked field with groups
Bug
===
Since 0bd14547a7,
When editing a record which has a tracked field with a group, and if
the current user is not in the group, an error is raised.

Technical
=========
When we get the tracked fields, we must care about the group of the
current user and keep only the tracked fields the user have access to.

To do that, we use `fields_get`, which will return only fields accessible
by the current user group.

The method `_get_tracked_fields` is cached, but it need to depend on
the current user (and also if we are in sudo mode or not), because the
function will return different results, depending on the group of the
user.

Task-2250070

closes odoo/odoo#51915

X-original-commit: c7010058a93ca2fd3b65ac978d8333b273f04fac
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-05-27 05:53:13 +00:00
c5d3a109f5 [REF] ir.autovacuum: declarative garbage collector registration
The ir.autovacuum model purpose is to run several garbage collecting
operations like removing files from the filestore when no attachment
references them anymore.

The precedent strategy to register new garbage collection tasks was to
override the `power_on` method and to imperatively execute a vacuum
cleaning method on a given model. All calls were executed in a single
SQL transaction without any error handling, meaning a single fail during
any call resulted in a complete failure of the entire vacuum cleaning
chain.

We introduce a new `@autovacuum` api decorator, its purpose it to
register garbage collecting methods that will be safely executed in
their own transaction by the vacuum cleaner. In order to ensure this
new strategy is used, we deprecate `power_on` extensions.

By the way, garbage-collecting methods can be quite heavy and we don't
want users to directly call them. We now ensure they are private.

closes odoo/odoo#47842

Task: 2154079
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Co-authored-by: Raphael Collet <rco@odoo.com>
Co-authored-by: Olivier Dony <odo@odoo.com>
2020-05-19 13:38:19 +00:00
Martin Trigaux d9287caf94 [IMP] *: convert to private methods
render, render_template, load, activity_schedule_with_view,
get_website_pages should all be private:
It should not be possible to render an aribtrary template only with
its name or id

Still need to render some qweb views from js so the method
render_template is kept public.
This explains why the website editor still need read access on
ir.ui.view as we want to allow any snippet to be rendered.
2020-05-14 13:59:10 +02:00
Jorge Pinna Puissant 5faf3ce15e [FIX] mail: unlink user notifications with related record
Message with type user_notification are special "invisible"
notifications that are not accessible to users normally. That's why they
were excluded from the automatic message deletion in
mail.thread.unlink(), to avoid permission errors. But this caused
orphans leftover notifications in the database, and the fix here is to
instead do the deletion of messages in sudo mode, and make sure
user_notification messages are deleted as well.

Doing this is not a security risk because the deletion of the record
itself (the super call) is still done without sudo, and if it fails,
the whole transaction will be rolled back. And it is part of the
expected ACLs for messages that if you can delete a record you are
allowed delete its messages. The fact that user_notification messages
are not accessible by normal users is for usability reasons (noise in
chatter), not security reasons.

opw-2234282

closes odoo/odoo#51010

X-original-commit: 094559aef4fdfebcba43a089cec4da5f4028a8f2
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
2020-05-11 10:06:05 +00:00
Thibault Delavallée f7e9a24962 [IMP] mail: add some docstrings and helpers
PURPOSE

Prepare code cleaning and optimization in mail, mass_mailing and SMS by
cleaning models for readability and code complexity and footprint reduction.

LINKS

Prepares task ID 2238597 (notification and trace models cleaning)
Task ID 1906925 (mass mailing tests cleaning)
PR #50169
2020-04-24 15:35:43 +00:00
mreficent b1a5bf95f8 [IMP] mail: add a hook in _notify_record_by_email to add model-specific values
PURPOSE

Be able to customize notification email values in a given model by overriding
a simple method instead of having to hijack the email creation process.

SPECIFICATIONS

Add a hook in mail.thread that can be overridden in specific addons, either
by model or globally by inheriting mail.thread.

Include _notify_email_headers in it so that it is correctly embedded in
model-specific values computation.

This removes the need to replace _notify_record_by_email long method in a
custom module.

Closes odoo/odoo#48213
Closes odoo/odoo#50097

closes odoo/odoo#50129

X-original-commit: 1ba8712d7a797cf2e821ae881cb1f1c4ea2fc11d
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-04-24 09:30:55 +00:00
Raphael Collet 1b1b2142f1 [IMP] fields: add validation of parameter names 2020-04-07 09:25:08 +00:00
Raphael Collet 892e3df701 [IMP] core: compute field_computed lazily
This is a simple refactoring.

X-original-commit: 634775bff6d9eba9d4548cc801071a942895a719
2020-04-03 11:40:28 +00:00
Adrian Torres 5952928b42 [REM] *: remove various unused import shims
Before this commit, a lot of leftover import shims existed in the
codebase for py2-py3 compatibility, these are no longer needed since
Odoo 13.0+ doesn't support Python 2 anymore and is (finally) in EOL.

With this commit, these shims are dropped, making the code cleaner,
easier to read and with one less dependency.

Queue -> queue -> py2-py3 compatibility
xmlrpclib -> xmlrpc.client -> py2-py3 compatibility
ConfigParser -> configparser -> py2-py3 compatibility
itertools.izip_longest -> itertools.zip_longest -> py2-py3 compatibility
urllib -> urllib.request -> py2-py3 compatibility
__builtins__ -> builtins -> py2-py3 compatibility
_winreg -> winreg -> py2-py3 compatibility

mock -> unittest.mock -> merged into CPython

The debian/fedora packages and requirements.txt have been updated accordingly

closes odoo/odoo#44601

Related: odoo/enterprise#8141
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-04-01 12:45:40 +00:00
Thibault Delavallée 3d86a29aeb [MOV] mail, various: move replace_local_links to render mixin
PURPOSE

Move links shortening tools on mail.render.mixin to have rendering and
post procesing tools available on that mixin.

LINKS

Task ID 1963529
Community PR odoo/odoo#32397
2020-03-24 10:24:44 +00:00