-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
144 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,8 @@ | ||
// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors | ||
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on("Mail Alias", { | ||
setup(frm) { | ||
frm.trigger("set_queries"); | ||
}, | ||
// frappe.ui.form.on("Mail Alias", { | ||
// refresh(frm) { | ||
|
||
set_queries(frm) { | ||
frm.set_query("domain_name", () => ({ | ||
filters: { | ||
enabled: 1, | ||
is_verified: 1, | ||
}, | ||
})); | ||
|
||
frm.set_query("mailbox", "mailboxes", (doc) => { | ||
let filters = { | ||
domain_name: doc.domain_name || " ", | ||
incoming: 1, | ||
}; | ||
|
||
let selected_mailboxes = frm.doc.mailboxes.map((d) => d.mailbox); | ||
if (selected_mailboxes.length) { | ||
filters.name = ["not in", selected_mailboxes]; | ||
} | ||
|
||
return { | ||
filters: filters, | ||
}; | ||
}); | ||
}, | ||
}); | ||
// }, | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,54 @@ | ||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors | ||
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
import frappe | ||
from frappe import _ | ||
from frappe.model.document import Document | ||
|
||
from mail.utils.validation import ( | ||
is_valid_email_for_domain, | ||
validate_domain_is_enabled_and_verified, | ||
validate_mailbox_for_incoming, | ||
from mail.mail.doctype.mail_agent_job.mail_agent_job import ( | ||
create_alias_on_agents, | ||
delete_alias_from_agents, | ||
patch_alias_on_agents, | ||
) | ||
from mail.utils.validation import is_valid_email_for_domain, validate_domain_is_enabled_and_verified | ||
|
||
|
||
class MailAlias(Document): | ||
def autoname(self) -> None: | ||
self.alias = self.alias.strip().lower() | ||
self.name = self.alias | ||
self.email = self.email.strip().lower() | ||
self.name = self.email | ||
|
||
def validate(self) -> None: | ||
self.validate_alias_for_name() | ||
self.validate_domain() | ||
self.validate_alias() | ||
self.validate_mailboxes() | ||
self.validate_email() | ||
|
||
def validate_domain(self) -> None: | ||
"""Validates the domain.""" | ||
def on_update(self) -> None: | ||
if self.has_value_changed("email"): | ||
create_alias_on_agents(self.alias_for_name, self.email) | ||
return | ||
|
||
validate_domain_is_enabled_and_verified(self.domain_name) | ||
if self.has_value_changed("alias_for_name"): | ||
patch_alias_on_agents(self.alias_for_name, self.get_doc_before_save().alias_for_name, self.email) | ||
|
||
def validate_alias(self) -> None: | ||
"""Validates the alias.""" | ||
def on_trash(self) -> None: | ||
delete_alias_from_agents(self.alias_for_name, self.email) | ||
|
||
is_valid_email_for_domain(self.alias, self.domain_name, raise_exception=True) | ||
def validate_alias_for_name(self) -> None: | ||
"""Validates the alias for name.""" | ||
|
||
def validate_mailboxes(self) -> None: | ||
"""Validates the mailboxes.""" | ||
if not frappe.db.get_value(self.alias_for_type, self.alias_for_name, "enabled"): | ||
frappe.throw( | ||
frappe._("The {0} {1} is disabled.").format( | ||
self.alias_for_type, frappe.bold(self.alias_for_name) | ||
) | ||
) | ||
|
||
mailboxes = [] | ||
def validate_domain(self) -> None: | ||
"""Validates the domain.""" | ||
|
||
for mailbox in self.mailboxes: | ||
if mailbox.mailbox == self.alias: | ||
frappe.throw(_("Row #{0}: Mailbox cannot be the same as the alias.").format(mailbox.idx)) | ||
elif mailbox.mailbox in mailboxes: | ||
frappe.throw( | ||
_("Row #{0}: Duplicate mailbox {1}.").format(mailbox.idx, frappe.bold(mailbox.mailbox)) | ||
) | ||
validate_domain_is_enabled_and_verified(self.domain_name) | ||
|
||
def validate_email(self) -> None: | ||
"""Validates the email address.""" | ||
|
||
validate_mailbox_for_incoming(mailbox.mailbox) | ||
mailboxes.append(mailbox.mailbox) | ||
is_valid_email_for_domain(self.email, self.domain_name, raise_exception=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors | ||
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors | ||
# See license.txt | ||
|
||
# import frappe | ||
from frappe.tests.utils import FrappeTestCase | ||
from frappe.tests import IntegrationTestCase, UnitTestCase | ||
|
||
# On IntegrationTestCase, the doctype test records and all | ||
# link-field test record dependencies are recursively loaded | ||
# Use these module variables to add/remove to/from that list | ||
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] | ||
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"] | ||
|
||
|
||
class UnitTestMailAlias(UnitTestCase): | ||
""" | ||
Unit tests for MailAlias. | ||
Use this class for testing individual functions and methods. | ||
""" | ||
|
||
pass | ||
|
||
|
||
class IntegrationTestMailAlias(IntegrationTestCase): | ||
""" | ||
Integration tests for MailAlias. | ||
Use this class for testing interactions between multiple components. | ||
""" | ||
|
||
class TestMailAlias(FrappeTestCase): | ||
pass |