Skip to content

Commit 0aca4cc

Browse files
authored
Merge pull request #2205 from asmacdo/dandi-admin-email-setting
Move admin email into Django setting
2 parents 0f084f7 + e318b2c commit 0aca4cc

File tree

8 files changed

+18
-13
lines changed

8 files changed

+18
-13
lines changed

.github/workflows/backend-ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ jobs:
5959
DJANGO_DANDI_API_URL: http://localhost:8000
6060
DJANGO_DANDI_JUPYTERHUB_URL: https://hub.dandiarchive.org/
6161
DJANGO_DANDI_DEV_EMAIL: test@example.com
62+
DJANGO_DANDI_ADMIN_EMAIL: test-admin@example.com
6263
DANDI_ALLOW_LOCALHOST_URLS: 1

.github/workflows/frontend-ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ jobs:
6767
DJANGO_DANDI_API_URL: http://localhost:8000
6868
DJANGO_DANDI_JUPYTERHUB_URL: https://hub.dandiarchive.org/
6969
DJANGO_DANDI_DEV_EMAIL: test@example.com
70+
DJANGO_DANDI_ADMIN_EMAIL: test-admin@example.com
7071
DANDI_ALLOW_LOCALHOST_URLS: 1
7172

7273
# Web client env vars
@@ -179,6 +180,7 @@ jobs:
179180
DJANGO_DANDI_API_URL: http://localhost:8000
180181
DJANGO_DANDI_JUPYTERHUB_URL: https://hub.dandiarchive.org/
181182
DJANGO_DANDI_DEV_EMAIL: test@example.com
183+
DJANGO_DANDI_ADMIN_EMAIL: test-admin@example.com
182184
DANDI_ALLOW_LOCALHOST_URLS: 1
183185

184186
# Web client env vars

dandiapi/api/mail.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
'dandi_web_app_url': settings.DANDI_WEB_APP_URL,
2626
}
2727

28-
# TODO: turn this into a Django setting
29-
ADMIN_EMAIL = 'info@dandiarchive.org'
30-
3128

3229
def user_greeting_name(user: User, socialaccount: SocialAccount = None) -> str:
3330
"""Return a suitable name to greet the user with in an email."""
@@ -105,7 +102,7 @@ def build_registered_message(user: User, socialaccount: SocialAccount):
105102
'api/mail/registered_message.txt',
106103
{'greeting_name': user_greeting_name(user, socialaccount)},
107104
),
108-
to=[ADMIN_EMAIL, user.email],
105+
to=[settings.DANDI_ADMIN_EMAIL, user.email],
109106
)
110107

111108

@@ -125,7 +122,7 @@ def build_new_user_messsage(user: User, socialaccount: SocialAccount = None):
125122
return build_message(
126123
subject=f'DANDI: Review new user: {user.username}',
127124
message=render_to_string('api/mail/new_user_message.txt', render_context),
128-
to=[ADMIN_EMAIL],
125+
to=[settings.DANDI_ADMIN_EMAIL],
129126
)
130127

131128

@@ -146,7 +143,7 @@ def build_approved_user_message(user: User, socialaccount: SocialAccount = None)
146143
'greeting_name': user_greeting_name(user, socialaccount),
147144
},
148145
),
149-
to=[ADMIN_EMAIL, user.email],
146+
to=[settings.DANDI_ADMIN_EMAIL, user.email],
150147
)
151148

152149

@@ -167,7 +164,7 @@ def build_rejected_user_message(user: User, socialaccount: SocialAccount = None)
167164
'rejection_reason': user.metadata.rejection_reason,
168165
},
169166
),
170-
to=[ADMIN_EMAIL, user.email],
167+
to=[settings.DANDI_ADMIN_EMAIL, user.email],
171168
)
172169

173170

@@ -183,12 +180,12 @@ def build_pending_users_message(users: Iterable[User]):
183180
return build_message(
184181
subject='DANDI: new user registrations to review',
185182
message=render_to_string('api/mail/pending_users_message.txt', render_context),
186-
to=[ADMIN_EMAIL],
183+
to=[settings.DANDI_ADMIN_EMAIL],
187184
)
188185

189186

190187
def send_pending_users_message(users: Iterable[User]):
191-
logger.info('Sending pending users message to admins at %s', ADMIN_EMAIL)
188+
logger.info('Sending pending users message to admins at %s', settings.DANDI_ADMIN_EMAIL)
192189
messages = [build_pending_users_message(users)]
193190
with mail.get_connection() as connection:
194191
connection.send_messages(messages)
@@ -233,7 +230,7 @@ def build_dandiset_unembargo_failed_message(dandiset: Dandiset):
233230
html_message=html_message,
234231
to=[owner.email for owner in get_dandiset_owners(dandiset)],
235232
bcc=[settings.DANDI_DEV_EMAIL],
236-
reply_to=[ADMIN_EMAIL],
233+
reply_to=[settings.DANDI_ADMIN_EMAIL],
237234
)
238235

239236

dandiapi/api/tests/test_users.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import json
44
from typing import TYPE_CHECKING, Any
55

6+
from django.conf import settings
67
from django.urls.base import reverse
78
import pytest
89
from pytest_django.asserts import assertContains
910
from rest_framework.exceptions import ErrorDetail
1011

11-
from dandiapi.api.mail import ADMIN_EMAIL
1212
from dandiapi.api.models import UserMetadata
1313
from dandiapi.api.views.auth import COLLECT_USER_NAME_QUESTIONS, NEW_USER_QUESTIONS, QUESTIONS
1414
from dandiapi.api.views.users import user_to_dict
@@ -49,13 +49,13 @@ def test_user_registration_email_content(
4949

5050
email = mailoutbox[0]
5151
assert email.subject == f'DANDI: New user registered: {user.email}'
52-
assert email.to == [ADMIN_EMAIL, user.email]
52+
assert email.to == [settings.DANDI_ADMIN_EMAIL, user.email]
5353
assert '<p>' not in email.body
5454
assert all(len(_) < 100 for _ in email.body.splitlines())
5555

5656
email = mailoutbox[1]
5757
assert email.subject == f'DANDI: Review new user: {user.username}'
58-
assert email.to == [ADMIN_EMAIL]
58+
assert email.to == [settings.DANDI_ADMIN_EMAIL]
5959
assert '<p>' not in email.body
6060
assert all(len(_) < 100 for _ in email.body.splitlines())
6161

dandiapi/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def mutate_configuration(configuration: type[ComposedConfiguration]):
109109
DANDI_API_URL = values.URLValue(environ_required=True)
110110
DANDI_JUPYTERHUB_URL = values.URLValue(environ_required=True)
111111
DANDI_DEV_EMAIL = values.EmailValue(environ_required=True)
112+
DANDI_ADMIN_EMAIL = values.EmailValue(environ_required=True)
112113

113114
DANDI_VALIDATION_JOB_INTERVAL = values.IntegerValue(environ=True, default=60)
114115

dev/.env.docker-compose

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ DJANGO_DANDI_DANDISETS_EMBARGO_LOG_BUCKET_NAME=dandiapi-embargo-dandisets-logs
1212
DJANGO_DANDI_WEB_APP_URL=http://localhost:8085
1313
DJANGO_DANDI_API_URL=http://localhost:8000
1414
DJANGO_DANDI_JUPYTERHUB_URL=https://hub.dandiarchive.org/
15+
DJANGO_DANDI_ADMIN_EMAIL="admin@test.mail"
1516
DJANGO_DANDI_DEV_EMAIL=test@example.com
1617
DANDI_ALLOW_LOCALHOST_URLS=1

dev/.env.docker-compose-native

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ DJANGO_DANDI_DANDISETS_EMBARGO_LOG_BUCKET_NAME=dandiapi-embargo-dandisets-logs
1212
DJANGO_DANDI_WEB_APP_URL=http://localhost:8085
1313
DJANGO_DANDI_API_URL=http://localhost:8000
1414
DJANGO_DANDI_JUPYTERHUB_URL=https://hub.dandiarchive.org/
15+
DJANGO_DANDI_ADMIN_EMAIL="admin@test.mail"
1516
DJANGO_DANDI_DEV_EMAIL=test@example.com
1617
DANDI_ALLOW_LOCALHOST_URLS=1

tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ passenv =
4646
DJANGO_DANDI_JUPYTERHUB_URL
4747
DJANGO_DANDI_DEV_EMAIL
4848
DJANGO_DANDI_LOG_LEVEL
49+
DJANGO_DANDI_ADMIN_EMAIL
4950
DANDI_ALLOW_LOCALHOST_URLS
5051
extras =
5152
dev
@@ -67,6 +68,7 @@ passenv =
6768
DJANGO_DANDI_API_URL
6869
DJANGO_DANDI_JUPYTERHUB_URL
6970
DJANGO_DANDI_DEV_EMAIL
71+
DJANGO_DANDI_ADMIN_EMAIL
7072
DJANGO_DANDI_LOG_LEVEL
7173
extras =
7274
dev

0 commit comments

Comments
 (0)