Skip to content

Commit 3aa4349

Browse files
[IMP] Added functionality, removes all followers but sent to partner email addresses that are not internal users
1 parent 9c38502 commit 3aa4349

File tree

4 files changed

+63
-37
lines changed

4 files changed

+63
-37
lines changed

mail_external_confirmation/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ Mail External Confirmation
33
==========================
44
This module will show confirmation dialog while sending message
55
from chatter when any one follower of the record is not internal user.
6+
7+
Displays a confirmation dialog when mentioning (@) an external user
8+
in chatter messages or internal notes.
9+
10+
Triggers a confirmation popup when all followers are removed,but the message
11+
is still being sent to partner email addresses that are not internal users.

mail_external_confirmation/__manifest__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
"summary": """
55
This module will show confirmation dialog while sending message
66
from chatter when any one follower of the record is not internal user.
7+
- Pupup the message when anyone mension in chatter or notes
8+
Displays a confirmation dialog when mentioning (@) an external user
9+
in chatter messages or internal notes.
10+
- Triggers a confirmation popup when all followers are removed,
11+
but the message is still being sent to partner email addresses
12+
that are not internal users.
713
""",
814
"author": "Nitrokey GmbH",
915
"license": "LGPL-3",

mail_external_confirmation/controllers/main.py

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,47 @@
88

99
class MessageExternalUserController(http.Controller):
1010
@http.route("/message/external_users/check", type="json", auth="user")
11-
def check_external_users(self, rec_id, model, mentioned_partner_ids=None):
11+
def check_external_users(
12+
self, rec_id, model, msg_type=False, mentioned_partner_ids=None
13+
):
1214
"""To check for external users exist in record followers"""
1315
confirmation_message = (
1416
"Your message will be sent to external partners (e.g. customers)."
1517
)
16-
# Check thread followers
17-
if not mentioned_partner_ids:
18-
record = request.env[model].browse(rec_id)
19-
followers = record.message_follower_ids
20-
for follower in followers:
21-
partner = follower.partner_id
18+
popup_confirmation_msg = {
19+
"needs_confirmation": True,
20+
"confirmation_message": confirmation_message,
21+
}
22+
# Check mentioned partners (Note)
23+
if mentioned_partner_ids:
24+
partners = request.env["res.partner"].browse(mentioned_partner_ids).exists()
2225

26+
for partner in partners:
2327
# If partner has no users at all, they're external
2428
if not partner.user_ids:
25-
return {
26-
"needs_confirmation": True,
27-
"confirmation_message": confirmation_message,
28-
}
29+
return popup_confirmation_msg
2930

3031
# Check if any user is not internal
3132
for user in partner.user_ids:
3233
if not user.has_group("base.group_user"):
33-
return {
34-
"needs_confirmation": True,
35-
"confirmation_message": confirmation_message,
36-
}
34+
return popup_confirmation_msg
3735

38-
# Check mentioned partners
39-
if mentioned_partner_ids:
40-
partners = request.env["res.partner"].browse(mentioned_partner_ids).exists()
36+
# Check thread followers (Messages)
37+
if msg_type != "note":
38+
record = request.env[model].browse(rec_id)
39+
followers = record.message_follower_ids
40+
for follower in followers:
41+
partner = follower.partner_id
4142

42-
for partner in partners:
4343
# If partner has no users at all, they're external
4444
if not partner.user_ids:
45-
return {
46-
"needs_confirmation": True,
47-
"confirmation_message": confirmation_message,
48-
}
45+
return popup_confirmation_msg
4946

5047
# Check if any user is not internal
5148
for user in partner.user_ids:
5249
if not user.has_group("base.group_user"):
53-
return {
54-
"needs_confirmation": True,
55-
"confirmation_message": confirmation_message,
56-
}
50+
return popup_confirmation_msg
51+
5752
return {
5853
"needs_confirmation": False,
5954
"confirmation_message": "",

mail_external_confirmation/static/src/core/common/composer.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,38 @@ patch(Composer.prototype, {
2929
const checkData = {
3030
rec_id: res_id,
3131
model: model,
32+
msg_type: this.props.type,
33+
mentioned_partner_ids: [],
3234
};
3335

34-
// Add mentioned partner IDs for notes
35-
if (this.props.type === "note") {
36-
var mentionedPartners = this.props.composer?.mentionedPartners || null;
37-
const partnerIds = this._extractPartnerIds(mentionedPartners);
36+
// Add mentioned partner IDs in notes/messages
37+
var mentionedPartners = this.props.composer?.mentionedPartners || null;
38+
const partnerIds = this._extractPartnerIds(mentionedPartners);
3839

39-
if (partnerIds.length > 0) {
40-
checkData.mentioned_partner_ids = partnerIds;
41-
} else {
42-
super.sendMessage();
43-
return;
44-
}
40+
if (partnerIds.length > 0) {
41+
checkData.mentioned_partner_ids.push(...partnerIds);
42+
} else {
43+
// Don't have any menssion partners
44+
}
45+
if (this.props.type === "note" && partnerIds.length === 0) {
46+
super.sendMessage();
47+
return;
48+
}
49+
50+
// Remove all followers and check checkbox of the partner email
51+
const checkedPartnerIds = this.props.composer.thread.suggestedRecipients
52+
.filter(
53+
(recipient) =>
54+
recipient.checked &&
55+
recipient.partner_id &&
56+
this.props.type === "message"
57+
)
58+
.map((recipient) => recipient.partner_id);
59+
// This.props.composer.thread.followersCount //followers exist or not
60+
if (checkedPartnerIds.length > 0) {
61+
checkData.mentioned_partner_ids.push(...checkedPartnerIds);
62+
} else {
63+
// Don't have any suggestedRecipients checked
4564
}
4665

4766
// Make a single RPC call to check everything

0 commit comments

Comments
 (0)