Skip to content

Commit 2821cc4

Browse files
committed
fix USER.paperless_approval
1 parent e3aefa0 commit 2821cc4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

backend/common/models.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,29 @@ def facility(self):
107107

108108
@property
109109
def paperless_approval(self):
110+
"""
111+
This will return 'True' if both PI and User email addresses share the same host
112+
We'll be using email spoofing from within VM, the MTA was set by IT.
113+
This assumes that EMAIL_HOST config variable has the form of "mail.server.tld"
114+
and the user and PI addresses are "@server.tld"...
115+
"""
116+
email_host = ".".join(settings.EMAIL_HOST.split(".")[1:])
110117
result_user = False
111118
result_pi = False
112119
if self.pi is not None and self.pi.email != "Unset":
113-
if (
114-
not ('"' in self.pi.email)
115-
and self.pi.email.split("@")[1] == settings.EMAIL_HOST
116-
):
120+
if not ('"' in self.pi.email) and self.pi.email.split("@")[1] == email_host:
117121
result_pi = True
118-
if (
119-
not ('"' in self.email)
120-
and self.email.split("@")[1] == settings.EMAIL_HOST
121-
):
122+
if not ('"' in self.email) and self.email.split("@")[1] == email_host:
122123
result_user = True
123124
return result_user and result_pi
124125

125126
def __str__(self):
127+
email_host = ".".join(settings.EMAIL_HOST.split(".")[1:])
126128
this_user_email = self.email
127129
if not '"' in this_user_email:
128130
# email addresses are valid with more than one 'at' symbol, only if enquoted,
129131
# we avoid the following in such cases. See: https://stackoverflow.com/a/12355882
130-
if this_user_email.split("@")[1] == settings.EMAIL_HOST:
132+
if this_user_email.split("@")[1] == email_host:
131133
this_user_email = this_user_email.split("@")[0] + "@~"
132134
if self.phone is not None:
133135
this_user = (

0 commit comments

Comments
 (0)