diff --git a/coldfront/config/core.py b/coldfront/config/core.py index c9bdac8f9..3a2e058b5 100644 --- a/coldfront/config/core.py +++ b/coldfront/config/core.py @@ -33,23 +33,17 @@ # ------------------------------------------------------------------------------ # Allocation related # ------------------------------------------------------------------------------ -ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT = ENV.bool( - "ALLOCATION_ENABLE_CHANGE_REQUESTS", default=True -) +ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT = ENV.bool("ALLOCATION_ENABLE_CHANGE_REQUESTS", default=True) ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS = ENV.list( "ALLOCATION_CHANGE_REQUEST_EXTENSION_DAYS", cast=int, default=[30, 60, 90] ) -ALLOCATION_ENABLE_ALLOCATION_RENEWAL = ENV.bool( - "ALLOCATION_ENABLE_ALLOCATION_RENEWAL", default=True -) +ALLOCATION_ENABLE_ALLOCATION_RENEWAL = ENV.bool("ALLOCATION_ENABLE_ALLOCATION_RENEWAL", default=True) ALLOCATION_FUNCS_ON_EXPIRE = [ "coldfront.core.allocation.utils.test_allocation_function", ] # This is in days -ALLOCATION_DEFAULT_ALLOCATION_LENGTH = ENV.int( - "ALLOCATION_DEFAULT_ALLOCATION_LENGTH", default=365 -) +ALLOCATION_DEFAULT_ALLOCATION_LENGTH = ENV.int("ALLOCATION_DEFAULT_ALLOCATION_LENGTH", default=365) # ------------------------------------------------------------------------------ @@ -114,3 +108,9 @@ If you do not have an active HPC account, please refer to instructions on our website. """ + +# ------------------------------------------------------------------------------ +# Enable Open OnDemand integration +# ------------------------------------------------------------------------------ +PI_STATUS_UPGRADE_URL = ENV.str("PI_STATUS_UPGRADE_URL", default=None) +PI_STATUS_UPGRADE_API_KEY = ENV.str("PI_STATUS_UPGRADE_API_KEY", default=None) diff --git a/coldfront/core/user/templates/user/user_profile.html b/coldfront/core/user/templates/user/user_profile.html index 1a0500be6..cb564b46d 100644 --- a/coldfront/core/user/templates/user/user_profile.html +++ b/coldfront/core/user/templates/user/user_profile.html @@ -41,9 +41,16 @@

User Profile

{% elif not user == viewed_user %} No {% else %} -
- No -
+
+
+ No +
+
+ {% csrf_token %} + +
+
{% endif %} diff --git a/coldfront/core/user/views.py b/coldfront/core/user/views.py index 802c6a05d..aed1b677c 100644 --- a/coldfront/core/user/views.py +++ b/coldfront/core/user/views.py @@ -1,4 +1,5 @@ import logging +import httpx from django.contrib import messages from django.contrib.auth.decorators import login_required @@ -22,6 +23,8 @@ logger = logging.getLogger(__name__) EMAIL_ENABLED = import_from_settings("EMAIL_ENABLED", False) +PI_STATUS_UPGRADE_URL = import_from_settings("PI_STATUS_UPGRADE_URL") +PI_STATUS_UPGRADE_API_KEY = import_from_settings("PI_STATUS_UPGRADE_API_KEY") if EMAIL_ENABLED: EMAIL_TICKET_SYSTEM_ADDRESS = import_from_settings("EMAIL_TICKET_SYSTEM_ADDRESS") @@ -41,16 +44,12 @@ def dispatch(self, request, *args, viewed_username=None, **kwargs): # error if they tried to do something naughty if not request.user.username == viewed_username: - messages.error( - request, "You aren't allowed to view other user profiles!" - ) + messages.error(request, "You aren't allowed to view other user profiles!") # if they used their own username, no need to provide an error - just redirect return HttpResponseRedirect(reverse("user-profile")) - return super().dispatch( - request, *args, viewed_username=viewed_username, **kwargs - ) + return super().dispatch(request, *args, viewed_username=viewed_username, **kwargs) def get_context_data(self, viewed_username=None, **kwargs): context = super().get_context_data(**kwargs) @@ -81,9 +80,7 @@ def dispatch(self, request, *args, viewed_username=None, **kwargs): # error if they tried to do something naughty if not request.user.username == viewed_username: - messages.error( - request, "You aren't allowed to view projects for other users!" - ) + messages.error(request, "You aren't allowed to view projects for other users!") # if they used their own username, no need to provide an error - just redirect return HttpResponseRedirect(reverse("user-projects-managers")) @@ -94,9 +91,7 @@ def dispatch(self, request, *args, viewed_username=None, **kwargs): else: self.viewed_user = self.request.user - return super().dispatch( - request, *args, viewed_username=viewed_username, **kwargs - ) + return super().dispatch(request, *args, viewed_username=viewed_username, **kwargs) def get_queryset(self, *args, **kwargs): viewed_user = self.viewed_user @@ -221,14 +216,15 @@ def dispatch(self, request, *args, **kwargs): return super().dispatch(request, *args, **kwargs) def post(self, request): - if EMAIL_ENABLED: - send_email_template( - "Upgrade Account Request", - "email/upgrade_account_request.txt", - {"user": request.user}, - request.user.email, - [EMAIL_TICKET_SYSTEM_ADDRESS], + try: + httpx.post( + PI_STATUS_UPGRADE_URL, + data={"Authorization": PI_STATUS_UPGRADE_API_KEY, "netid": request.user.username}, + timeout=10, ) + except Exception as e: + logger.error(f"Could not send PI upgrade request due to {e}") + logger.info(f"Sent PI status upgrade request for {request.user.username}") messages.success(request, "Your request has been sent") return HttpResponseRedirect(reverse("user-profile")) @@ -277,9 +273,9 @@ def get_context_data(self, *args, **kwargs): for project in Project.objects.filter(pi=self.request.user): for allocation in project.allocation_set.filter(status__name="Active"): - for allocation_user in allocation.allocationuser_set.filter( - status__name="Active" - ).order_by("user__username"): + for allocation_user in allocation.allocationuser_set.filter(status__name="Active").order_by( + "user__username" + ): if allocation_user.user not in user_dict: user_dict[allocation_user.user] = []