Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions coldfront/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -114,3 +108,9 @@
If you do not have an active HPC account, please refer to
<a href="https://services.rt.nyu.edu/docs/hpc/getting_started/getting_and_renewing_an_account/"> instructions on our website</a>.
"""

# ------------------------------------------------------------------------------
# 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)
13 changes: 10 additions & 3 deletions coldfront/core/user/templates/user/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ <h2>User Profile</h2>
{% elif not user == viewed_user %}
<span class="badge badge-danger"><i class="fas fa-times" aria-hidden="true"></i><span class="sr-only">No</span></span>
{% else %}
<div class="form-group mb-2">
<span class="badge badge-danger"><i class="fas fa-times" aria-hidden="true"></i><span class="sr-only">No</span></span>
</div>
<form class="form-inline" method="post" action="{% url 'user-upgrade' %}">
<div class="form-group mb-2">
<span class="badge badge-danger"><i class="fas fa-times" aria-hidden="true"></i><span class="sr-only">No</span></span>
</div>
<div class="form-group mx-sm-3 mb-2">
{% csrf_token %}
<button class="btn btn-secondary" type="submit"><i class="fas fa-chevron-circle-up" aria-hidden="true"></i>
Upgrade Account</button>
</div>
</form>
{% endif %}
</td>
</tr>
Expand Down
40 changes: 18 additions & 22 deletions coldfront/core/user/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import httpx

from django.contrib import messages
from django.contrib.auth.decorators import login_required
Expand All @@ -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")

Expand All @@ -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)
Expand Down Expand Up @@ -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"))
Expand All @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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] = []

Expand Down
Loading