Skip to content

Commit

Permalink
fixed double mail sending
Browse files Browse the repository at this point in the history
  • Loading branch information
bodintsov committed Jan 14, 2025
1 parent 83a6049 commit 8f79cfd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api_tests/requests/views/test_node_request_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ def test_requests_disabled_list(self, app, url, create_payload, project, admin):
res = app.get(url, create_payload, auth=admin.auth, expect_errors=True)
assert res.status_code == 403

@mock.patch('website.mails.mails.send_mail')
@mock.patch('website.mails.send_mail')
def test_email_sent_to_all_admins_on_submit(self, mock_mail, app, project, noncontrib, url, create_payload, second_admin):
project.is_public = True
project.save()
res = app.post_json_api(url, create_payload, auth=noncontrib.auth)
assert res.status_code == 201
assert mock_mail.call_count == 2

@mock.patch('website.mails.mails.send_mail')
@mock.patch('website.mails.send_mail')
def test_email_not_sent_to_parent_admins_on_submit(self, mock_mail, app, project, noncontrib, url, create_payload, second_admin):
component = NodeFactory(parent=project, creator=second_admin)
component.is_public = True
Expand Down
18 changes: 9 additions & 9 deletions osf/utils/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ def notify_submit(self, ev):
context = self.get_context()
context['contributors_url'] = f'{self.machineable.target.absolute_url}contributors/'
context['project_settings_url'] = f'{self.machineable.target.absolute_url}settings/'

for admin in self.machineable.target.get_users_with_perm(permissions.ADMIN):
mails.send_mail(
admin.username,
mails.ACCESS_REQUEST_SUBMITTED,
admin=admin,
osf_contact_email=OSF_CONTACT_EMAIL,
**context
)
if not self.machineable.request_type == NodeRequestTypes.INSTITUTIONAL_REQUEST.value:
for admin in self.machineable.target.get_users_with_perm(permissions.ADMIN):
mails.send_mail(
admin.username,
mails.ACCESS_REQUEST_SUBMITTED,
admin=admin,
osf_contact_email=OSF_CONTACT_EMAIL,
**context
)

def notify_resubmit(self, ev):
""" Notify admins that someone is requesting access again
Expand Down

0 comments on commit 8f79cfd

Please sign in to comment.