From b1a0d7e64313398dee1d1a10752aad406c52d422 Mon Sep 17 00:00:00 2001 From: Ryan Trinh Date: Sat, 7 Jun 2025 00:45:12 -0700 Subject: [PATCH 1/2] Added committee-based permissions --- hknweb/settings/common.py | 24 +++++++++++- hknweb/studentservices/views.py | 5 ++- hknweb/templates/about/people.html | 30 ++++++++------- hknweb/templates/committees.html | 13 ++++--- .../studentservices/course_description.html | 2 +- hknweb/tutoring/views/courses.py | 5 ++- hknweb/tutoring/views/tutoringportal.py | 5 ++- hknweb/utils.py | 20 ++++++++++ hknweb/views/people.py | 14 +++++-- hknweb/views/users.py | 37 ++++++++++++++----- 10 files changed, 114 insertions(+), 41 deletions(-) diff --git a/hknweb/settings/common.py b/hknweb/settings/common.py index ac01a86a..9d2e813b 100644 --- a/hknweb/settings/common.py +++ b/hknweb/settings/common.py @@ -15,6 +15,8 @@ from hknweb.utils import DATETIME_12_HOUR_FORMAT +from enum import Enum + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -179,7 +181,27 @@ CAND_GROUP = "candidate" OFFICER_GROUP = "officer" EXEC_GROUP = "exec" - +MEMBER_GROUP = "member" + +# committee groups +ACT_GROUP = "act" +BRIDGE_GROUP = "bridge" +COMPSEV_GROUP = "compserv" +DECAL_GROUP = "decal" +INDREL_GROUP = "indrel" +PRODEV_GROUP = "prodev" +SERV_GROUP = "serv" +STUDREL_GROUP = "studrel" +TUTORING_GROUP = "tutoring" + +# exec groups +CSEC_GROUP = "csec" +PRES_GROUP = "pres" +RSEC_GROUP = "rsec" +TRES_GROUP = "tres" +IVP_GROUP = "ivp" +EVP_GROUP = "evp" +DEPREL_GROUP = "deprel" # Note: both candidate and officer group should have permission to add officer challenges diff --git a/hknweb/studentservices/views.py b/hknweb/studentservices/views.py index c5ce4b9b..8dba1ac0 100644 --- a/hknweb/studentservices/views.py +++ b/hknweb/studentservices/views.py @@ -13,6 +13,7 @@ allow_public_access, login_and_access_level, GROUP_TO_ACCESSLEVEL, + login_and_committee, ) from hknweb.studentservices.models import ( CourseGuideNode, @@ -192,7 +193,7 @@ def course_description(request, slug): return render(request, "studentservices/course_description.html", context=context) -@login_and_access_level(GROUP_TO_ACCESSLEVEL["officer"]) +@login_and_committee(settings.TUTORING_GROUP) def edit_description(request, slug): course = get_object_or_404(CourseDescription, slug=slug) if request.method == "GET": @@ -211,7 +212,7 @@ def edit_description(request, slug): return render(request, "studentservices/course_edit.html", context=context) -@login_and_access_level(GROUP_TO_ACCESSLEVEL["officer"]) +@login_and_committee(settings.TUTORING_GROUP) def delete_description(request, slug): course = get_object_or_404(CourseDescription, slug=slug) diff --git a/hknweb/templates/about/people.html b/hknweb/templates/about/people.html index 6ba5a987..e0c3f978 100644 --- a/hknweb/templates/about/people.html +++ b/hknweb/templates/about/people.html @@ -17,22 +17,24 @@ } @@ -53,7 +55,7 @@ {% block content %}
- {% if is_officer %} + {% if viewer_in_bridge %}