Skip to content

Commit

Permalink
add notification for affiliations changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnetordoff committed Jan 23, 2025
1 parent 3f17b5c commit 5727103
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion api/institutions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_institutions_to_add_remove(institutions, new_institutions):
return insts_to_add, diff['remove'].values()


def update_institutions(resource, new_institutions, user, post=False):
def update_institutions(resource, new_institutions, user, post=False, notify=True):
add, remove = get_institutions_to_add_remove(
institutions=resource.affiliated_institutions,
new_institutions=new_institutions,
Expand All @@ -38,6 +38,18 @@ def update_institutions(resource, new_institutions, user, post=False):
raise exceptions.PermissionDenied(detail=f'User needs to be affiliated with {inst.name}')
resource.add_affiliated_institution(inst, user)

if notify:
from website import mails

for user in resource.get_admin_contributors_recursive(unique_users=True):
mails.send_mail(
user.username,
mails.PROJECT_AFFILIATION_CHANGED,
**{
'institution_added': add,
'institution_removed': remove,
},
)

def update_institutions_if_user_associated(resource, desired_institutions_data, user):
"""Update institutions only if the user is associated with the institutions. Otherwise, raise an exception."""
Expand Down
5 changes: 5 additions & 0 deletions website/mails/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,3 +619,8 @@ def get_english_article(word):
'user_message_institutional_access_request',
subject='Message from Institutional Admin'
)

PROJECT_AFFILIATION_CHANGED = Mail(
'project_affiliation_changed',
subject='Project Affiliation Changed'
)
15 changes: 15 additions & 0 deletions website/templates/emails/project_affiliation_changed.html.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%inherit file="notify_base.mako" />

<%def name="content()">
<tr>
<td style="border-collapse: collapse;">
Hello ${user.fullname},<br>
<br>
The The afilliation of your project has changed from ${} to ${}.<br>
<br>
Sincerely yours,<br>
<br>
The OSF Robot<br>
</tr>
</%def>

0 comments on commit 5727103

Please sign in to comment.