Skip to content

Commit

Permalink
change domain_url setting to default to SITE_DOMAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
claire-peters committed Aug 14, 2024
1 parent 18321e6 commit a26bab4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions coldfront/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CENTER_HELP_URL = ENV.str('CENTER_HELP_URL', default='{% url help-page %}')
CENTER_PROJECT_RENEWAL_HELP_URL = ENV.str('CENTER_PROJECT_RENEWAL_HELP_URL', default='')
CENTER_BASE_URL = ENV.str('CENTER_BASE_URL', default='')
SITE_DOMAIN = ENV.str('SITE_DOMAIN', default='')

#------------------------------------------------------------------------------
# Enable Project Review
Expand Down
11 changes: 2 additions & 9 deletions coldfront/core/allocation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from coldfront.core.project.models import (Project, ProjectPermission,
ProjectUserStatusChoice)
from coldfront.core.resource.models import Resource
from coldfront.core.utils.common import get_domain_url, import_from_settings
from coldfront.core.utils.common import import_from_settings
from coldfront.core.utils.mail import send_allocation_admin_email, send_allocation_customer_email


Expand Down Expand Up @@ -393,8 +393,7 @@ def post(self, request, *args, **kwargs):
)

send_allocation_customer_email(
allocation_obj, 'Allocation Activated',
'email/allocation_activated.txt', domain_url=get_domain_url(self.request)
allocation_obj, 'Allocation Activated', 'email/allocation_activated.txt'
)
if action == 'approve':
messages.success(request, 'Allocation Activated!')
Expand Down Expand Up @@ -425,7 +424,6 @@ def post(self, request, *args, **kwargs):
allocation_obj,
f'Allocation {allocation_obj.status.name}',
f'email/allocation_{allocation_obj.status.name.lower()}.txt',
domain_url=get_domain_url(self.request),
)
messages.success(request, f'Allocation {allocation_obj.status.name}!')
else:
Expand Down Expand Up @@ -748,7 +746,6 @@ def form_valid(self, form):
allocation_obj,
'New Allocation Request',
'email/new_allocation_request.txt',
domain_url=get_domain_url(self.request),
url_path=reverse('allocation-detail', kwargs={'pk': allocation_obj.pk}),
other_vars=other_vars,
)
Expand Down Expand Up @@ -1420,7 +1417,6 @@ def post(self, request, *args, **kwargs):
allocation_obj,
'Allocation Renewed',
'email/allocation_renewed.txt',
domain_url=get_domain_url(self.request),
)

messages.success(request, 'Allocation renewed successfully')
Expand Down Expand Up @@ -1946,7 +1942,6 @@ def post(self, request, *args, **kwargs):
alloc_change_obj.allocation,
'Allocation Change Denied',
'email/allocation_change_denied.txt',
domain_url=get_domain_url(self.request),
)
save_and_redirect = True

Expand Down Expand Up @@ -2056,7 +2051,6 @@ def post(self, request, *args, **kwargs):
alloc_change_obj.allocation,
'Allocation Change Approved',
'email/allocation_change_approved.txt',
domain_url=get_domain_url(self.request),
)

message = make_allocation_change_message(alloc_change_obj, 'APPROVED')
Expand Down Expand Up @@ -2293,7 +2287,6 @@ def post(self, request, *args, **kwargs):
'allocation-change-detail',
kwargs={'pk': allocation_change_request_obj.pk},
),
domain_url=get_domain_url(self.request),
other_vars=email_vars,
)
return HttpResponseRedirect(reverse('allocation-detail', kwargs={'pk': pk}))
Expand Down
3 changes: 2 additions & 1 deletion coldfront/core/utils/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
EMAIL_SIGNATURE = import_from_settings('EMAIL_SIGNATURE')
EMAIL_CENTER_NAME = import_from_settings('CENTER_NAME')
CENTER_BASE_URL = import_from_settings('CENTER_BASE_URL')
SITE_DOMAIN = import_from_settings('SITE_DOMAIN')


def send_email(subject, body, sender, receiver_list, cc=[]):
Expand Down Expand Up @@ -80,7 +81,7 @@ def email_template_context(extra_context=None):


def build_link(url_path, domain_url=''):
domain_url = domain_url or CENTER_BASE_URL
domain_url = domain_url or SITE_DOMAIN
return f'{domain_url}{url_path}'


Expand Down
4 changes: 2 additions & 2 deletions coldfront/core/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
email_template_context,
send_allocation_admin_email,
send_allocation_customer_email,
CENTER_BASE_URL,
build_link,
logger
)
Expand All @@ -21,6 +20,7 @@
@patch('coldfront.core.utils.mail.EMAIL_SENDER', '[email protected]')
@patch('coldfront.core.utils.mail.EMAIL_TICKET_SYSTEM_ADDRESS', '[email protected]')
@patch('coldfront.core.utils.mail.EMAIL_CENTER_NAME', 'HPC Center')
@patch('coldfront.core.utils.mail.SITE_DOMAIN', 'sitedomain.org')
@patch('coldfront.core.utils.mail.EMAIL_SIGNATURE', 'HPC Center Team')
# @patch('coldfront.config.base.INSTALLED_APPS', 'coldfront.plugins')
class EmailFunctionsTestCase(TestCase):
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_build_link(self):
domain_url = 'https://example.com'
expected_url = f'{domain_url}{url_path}'
self.assertEqual(build_link(url_path, domain_url), expected_url)
self.assertEqual(build_link(url_path), f'{CENTER_BASE_URL}{url_path}')
self.assertEqual(build_link(url_path), f'sitedomain.org{url_path}')

def test_allocation_reaching_capacity_operations(self):
allocation_obj = MagicMock()
Expand Down

0 comments on commit a26bab4

Please sign in to comment.