Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update admin pages #468

Merged
merged 3 commits into from
Oct 14, 2024
Merged
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
35 changes: 30 additions & 5 deletions allocations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
from .models import Allocation, Charge


class AllocationAdmin(admin.ModelAdmin):
def has_change_permission(self, request, obj=None):
return False
class ChargeInline(admin.TabularInline):
model = Charge
extra = 1
fields = ["region_name", "user"]


class AllocationAdmin(admin.ModelAdmin):
def project_description(self, obj):
return str(obj.project.description)

Expand All @@ -25,7 +28,7 @@ def pi_institution(self, obj):
keycloak_client = KeycloakClient()
uname = obj.project.pi.username
user = keycloak_client.get_user_by_username(uname)
return user["attributes"].get("affiliationInstitution", "")
return user.get("attributes", {}).get("affiliationInstitution", "")

list_display = (
"project_title",
Expand All @@ -51,9 +54,31 @@ def pi_institution(self, obj):
"date_reviewed",
"start_date",
"expiration_date",
"su_allocated",
)
readonly_fields = [
"pi_name",
"pi_email",
"pi_institution",
"project",
"project_title",
"project_description",
"justification",
"status",
"requestor",
"decision_summary",
"reviewer",
"date_requested",
"date_reviewed",
]
ordering = ["-date_requested"]
search_fields = [
"project__charge_code",
"project__pi__first_name",
"project__pi__last_name",
]
list_filter = ["status", "date_requested"]
inlines = [ChargeInline]


admin.site.register(Charge)
admin.site.register(Allocation, AllocationAdmin)
8 changes: 6 additions & 2 deletions appliance_catalog/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def clean_kvm_tacc_appliance_id(self):
return None


class ApplianceTaggingInline(admin.TabularInline):
model = ApplianceTagging


class ApplianceAdmin(admin.ModelAdmin):
list_display = (
"name",
Expand All @@ -34,8 +38,9 @@ class ApplianceAdmin(admin.ModelAdmin):
"project_supported",
)
ordering = ["-created_date"]
list_filter = ["needs_review"]
list_filter = ["needs_review", "project_supported"]
actions = [make_reviewed]
inlines = [ApplianceTaggingInline]
form = ApplianceAdminForm


Expand All @@ -49,4 +54,3 @@ class ApplianceTaggingAdmin(admin.ModelAdmin):

admin.site.register(Keyword, KeywordAdmin)
admin.site.register(Appliance, ApplianceAdmin)
admin.site.register(ApplianceTagging, ApplianceTaggingAdmin)
8 changes: 6 additions & 2 deletions blog_comments/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.contrib import admin
from .models import Comment

# Register your models here.
admin.site.register(Comment)

class CommentAdmin(admin.ModelAdmin):
list_display = ["created_date", "post", "author", "text"]


admin.site.register(Comment, CommentAdmin)
2 changes: 1 addition & 1 deletion chameleon/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PIEligibilityAdmin(ModelAdmin):
ordering = ["-status", "-request_date", "-review_date"]

list_display = ("requestor", "status", "request_date")
list_filter = ("status",)
list_filter = ("status", "request_date")
search_fields = ["requestor__username"]

def _notify_user(self, pi_request, host):
Expand Down
119 changes: 96 additions & 23 deletions projects/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from django.contrib import admin
from django.utils.html import format_html

from allocations.models import Allocation
from projects.models import (
ChameleonPublication,
Funding,
Invitation,
Project,
Publication,
PublicationSource,
)
Expand Down Expand Up @@ -54,35 +56,15 @@ class PublicationAdmin(ProjectFields, admin.ModelAdmin):
"year",
"status",
)
list_filter = ["status", "year", "checked_for_duplicates", "publication_type"]
search_fields = ["title", "project_charge_code", "author", "forum"]


class ChameleonPublicationAdmin(admin.ModelAdmin):
fields = ("title", "ref")
list_display = ("title", "ref")


class FundingAdmin(ProjectFields, admin.ModelAdmin):
readonly_fields = [
"project_charge_code",
]

fields = (
"project_charge_code",
"is_active",
"agency",
"award",
"grant_name",
)

ordering = ["project__charge_code"]
list_display = ("project_charge_code", "agency", "award", "grant_name")

def get_form(self, request, obj=None, **kwargs):
form = super(FundingAdmin, self).get_form(request, obj, **kwargs)
form.base_fields["award"].required = False
return form


class PublicationFields:
def publication_id(self, model):
"""Obtain the publication id attribute from the `publication` relation"""
Expand Down Expand Up @@ -141,6 +123,8 @@ class InvitationAdmin(admin.ModelAdmin):
"date_accepted",
"status",
]
list_filter = ["status", "date_issued"]
search_fields = ["project__charge_code"]
actions = ["resend_invitation"]

def invite_link(self, obj):
Expand All @@ -161,9 +145,98 @@ def resend_invitation(self, request, invitations):

resend_invitation.short_description = "Resend Invitations"

def has_add_permission(self, request, obj=None):
return False


class ProjectPublicationInline(admin.TabularInline):
model = Publication
exclude = ["tas_project_id"]
extra = 1


class FundingInline(admin.TabularInline):
model = Funding
extra = 1


class InvitationInline(admin.TabularInline):
model = Invitation
readonly_fields = [
"email_address",
"status",
"invite_link",
"user_issued",
"date_issued",
"user_accepted",
"date_accepted",
"date_expires",
"duration",
]

def invite_link(self, obj):
if obj.status == Invitation.STATUS_ISSUED:
url = obj.get_invite_url()
return format_html(f'<a href="{url}" target="_blank">Invite Link</a>')
return ""

def has_add_permission(self, req, obj):
return False


class AllocationInline(admin.TabularInline):
model = Allocation
fields = [
"date_requested",
"status",
"start_date",
"expiration_date",
"su_used",
"su_allocated",
]
readonly_fields = [
"date_requested",
"status",
"start_date",
"expiration_date",
"su_used",
"su_allocated",
]

def has_add_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False


class ProjectAdmin(admin.ModelAdmin):
list_display = ["charge_code", "pi", "nickname", "title"]
search_fields = ["charge_code", "pi__username", "pi__email", "nickname", "title"]
list_filter = ["tag"]
readonly_fields = ["charge_code", "automatically_tagged", "join_url"]

def join_url(self, obj):
return format_html(
f'<a href="{obj.join_link.get_url()}" target="_blank">Join Link</a>'
)

inlines = [
ProjectPublicationInline,
FundingInline,
InvitationInline,
AllocationInline,
]

def has_add_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False


admin.site.register(Project, ProjectAdmin)
admin.site.register(Publication, PublicationAdmin)
admin.site.register(Invitation, InvitationAdmin)
admin.site.register(Funding, FundingAdmin)
admin.site.register(ChameleonPublication, ChameleonPublicationAdmin)
admin.site.register(PublicationSource, PublicationSourceAdmin)
9 changes: 5 additions & 4 deletions projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ class JoinLink(models.Model):
)
secret = models.CharField(max_length=26, default=_generate_secret, unique=True)

def get_url(self, request):
return request.build_absolute_uri(
reverse("projects:reqeust_to_join", args=[self.secret])
)
def get_url(self, request=None):
rel_url = reverse("projects:reqeust_to_join", args=[self.secret])
if request:
return request.build_absolute_uri(rel_url)
return rel_url

def has_join_request(self, user):
return self.join_requests.filter(user=user).exists()
Expand Down
41 changes: 26 additions & 15 deletions projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
from django.core.validators import validate_email
from django.db import DataError, transaction
from django.forms.models import model_to_dict
from django.http import (Http404, HttpResponseForbidden, HttpResponseRedirect,
JsonResponse)
from django.http import (
Http404,
HttpResponseForbidden,
HttpResponseRedirect,
JsonResponse,
)
from django.shortcuts import render
from django.urls import reverse
from django.utils import timezone
Expand All @@ -31,10 +35,18 @@
from util.project_allocation_mapper import ProjectAllocationMapper

from . import membership
from .forms import (AddBibtexPublicationForm, AllocationCreateForm,
ConsentForm, EditNicknameForm, EditPIForm, EditTagForm,
FundingFormset, ProjectAddBulkUserForm, ProjectAddUserForm,
ProjectCreateForm)
from .forms import (
AddBibtexPublicationForm,
AllocationCreateForm,
ConsentForm,
EditNicknameForm,
EditPIForm,
EditTagForm,
FundingFormset,
ProjectAddBulkUserForm,
ProjectAddUserForm,
ProjectCreateForm,
)
from .models import Invitation, Project, ProjectExtras
from .util import email_exists_on_project, get_charge_code, get_project_members

Expand All @@ -47,7 +59,7 @@ class UserNotPIEligible(Exception):
pass


class UserPermissions():
class UserPermissions:
manage: bool
manage_membership: bool

Expand All @@ -60,9 +72,6 @@ def _get_user_project_role_scopes(keycloak_client, username, project):
role, scopes = keycloak_client.get_user_project_role_scopes(
username, get_charge_code(project)
)
logger.info("SCOPES===")
logger.info(role)
logger.info(scopes)
return role, scopes

@staticmethod
Expand All @@ -79,13 +88,13 @@ def _parse_scopes(scopes):
@staticmethod
def get_user_permissions(keycloak_client, username, project):
_, scopes = UserPermissions._get_user_project_role_scopes(
keycloak_client, username, project)
keycloak_client, username, project
)
return UserPermissions._parse_scopes(scopes)

@staticmethod
def get_manager_projects(keycloak_client, username):
"""Gets project names for all project this user is a manager of
"""
"""Gets project names for all project this user is a manager of"""
return [
project["groupName"]
for project in keycloak_client.get_user_roles(username)
Expand Down Expand Up @@ -1229,9 +1238,11 @@ def get_project_membership_managers(project):
users = get_project_members(project)
keycloak_client = KeycloakClient()
return [
user for user in users
user
for user in users
if UserPermissions.get_user_permissions(
keycloak_client, user.username, project).manage_membership
keycloak_client, user.username, project
).manage_membership
]


Expand Down
Loading
Loading