-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
send mails to notify about access requests
closes #19
- Loading branch information
Torsten Rehn
committed
Apr 6, 2015
1 parent
0fe3a73
commit dd5723d
Showing
5 changed files
with
126 additions
and
0 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
12 changes: 12 additions & 0 deletions
12
src/teamvault/apps/secrets/templates/secrets/mail_access_request_approved.txt
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
The request from | ||
|
||
{{ username }} | ||
|
||
to access | ||
|
||
{{ secret_name }} | ||
{{ base_url }}{{ secret_url }} | ||
|
||
has been approved by | ||
|
||
{{ approved_by }} |
17 changes: 17 additions & 0 deletions
17
src/teamvault/apps/secrets/templates/secrets/mail_access_request_denied.txt
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
The request from | ||
|
||
{{ username }} | ||
|
||
to access | ||
|
||
{{ secret_name }} | ||
{{ base_url }}{{ secret_url }} | ||
|
||
has been denied by | ||
|
||
{{ denied_by }} | ||
{% if reason %} | ||
with reason | ||
|
||
{{ reason }} | ||
{% endif %} |
12 changes: 12 additions & 0 deletions
12
src/teamvault/apps/secrets/templates/secrets/mail_access_request_review.txt
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Please review this access request: | ||
|
||
{{ username }} | ||
|
||
has requested access to | ||
|
||
{{ secret_name }} | ||
{{ base_url }}{{ secret_url }} | ||
|
||
You can approve or deny this request here: | ||
|
||
{{ base_url }}{{ access_request_url }} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.core.mail import EmailMultiAlternatives | ||
from django.template import Context | ||
from django.template.loader import get_template, TemplateDoesNotExist | ||
from django.utils import translation | ||
|
||
|
||
def send_mail(users_to, subject, template, | ||
user_from=None, context={}, lang="en", | ||
attachments=None): | ||
if attachments is None: | ||
attachments = [] | ||
c = Context(context) | ||
translation.activate(lang) | ||
text_mail = get_template(template + ".txt").render(c) | ||
|
||
msg = EmailMultiAlternatives( | ||
subject, | ||
text_mail, | ||
user_from.email, | ||
[user.email for user in users_to], | ||
) | ||
|
||
try: | ||
html_mail = get_template(template + ".html").render(c) | ||
msg.attach_alternative(html_mail, "text/html") | ||
except TemplateDoesNotExist: | ||
pass | ||
|
||
for filename, data, content_type in attachments: | ||
msg.attach(filename, data, content_type) | ||
|
||
msg.send() |