From 064415d8bf4f1d23bd314fe2a451398ac8238b84 Mon Sep 17 00:00:00 2001 From: qasema Date: Thu, 31 Aug 2023 17:09:08 -0400 Subject: [PATCH 01/32] initail commit --- app/controllers/admin/routes.py | 8 ++++---- app/controllers/main/routes.py | 2 +- app/logic/userManagement.py | 2 +- app/models/user.py | 1 + app/templates/sidebar.html | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/routes.py b/app/controllers/admin/routes.py index 98e2088c0..e9d1a012d 100644 --- a/app/controllers/admin/routes.py +++ b/app/controllers/admin/routes.py @@ -46,7 +46,7 @@ def switchUser(): @admin_bp.route('/eventTemplates') def templateSelect(): - if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentStaff: + if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentStaff or g.current_user.isCeltsStudentAdmin : allprograms = getAllowedPrograms(g.current_user) visibleTemplates = getAllowedTemplates(g.current_user) return render_template("/events/template_selector.html", @@ -59,7 +59,7 @@ def templateSelect(): @admin_bp.route('/eventTemplates///create', methods=['GET','POST']) def createEvent(templateid, programid): - if not (g.current_user.isAdmin or g.current_user.isProgramManagerFor(programid)): + if not (g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin or g.current_user.isProgramManagerFor(programid)): abort(403) # Validate given URL @@ -268,7 +268,7 @@ def eventDisplay(eventId): @admin_bp.route('/event//cancel', methods=['POST']) def cancelRoute(eventId): - if g.current_user.isAdmin: + if g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin: try: cancelEvent(eventId) return redirect(request.referrer) @@ -330,7 +330,7 @@ def userProfile(): @admin_bp.route('/search_student', methods=['GET']) def studentSearchPage(): - if g.current_user.isAdmin: + if g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin: return render_template("/admin/searchStudentPage.html") abort(403) diff --git a/app/controllers/main/routes.py b/app/controllers/main/routes.py index bf53ebac0..909a33098 100644 --- a/app/controllers/main/routes.py +++ b/app/controllers/main/routes.py @@ -113,7 +113,7 @@ def viewUsersProfile(username): else: abort(403) # Error 403 if non admin/student-staff user trys to access via url - if (g.current_user == volunteer) or g.current_user.isAdmin: + if (g.current_user == volunteer) or g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin: upcomingEvents = getUpcomingEventsForUser(volunteer) participatedEvents = getParticipatedEventsForUser(volunteer) programs = Program.select() diff --git a/app/logic/userManagement.py b/app/logic/userManagement.py index 8b3df68c9..38fda2469 100644 --- a/app/logic/userManagement.py +++ b/app/logic/userManagement.py @@ -52,7 +52,7 @@ def changeProgramInfo(newProgramName, newContactEmail, newContactName, newLocati def getAllowedPrograms(currentUser): """Returns a list of all visible programs depending on who the current user is.""" - if currentUser.isCeltsAdmin: + if currentUser.isCeltsAdmin or g.current_user.isCeltsStudentAdmin: return Program.select().order_by(Program.programName) else: return Program.select().join(ProgramManager).where(ProgramManager.user==currentUser).order_by(Program.programName) diff --git a/app/models/user.py b/app/models/user.py index 103602ed2..effb69d98 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -15,6 +15,7 @@ class User(baseModel): isStaff = BooleanField(default = False) isCeltsAdmin = BooleanField(default =False) isCeltsStudentStaff = BooleanField(default = False) + isCeltsStudentAdmin = BooleanField(default = False) dietRestriction = TextField(null=True) # override BaseModel's __init__ so that we can set up an instance attribute for cache diff --git a/app/templates/sidebar.html b/app/templates/sidebar.html index 952890c2a..6af360fa9 100644 --- a/app/templates/sidebar.html +++ b/app/templates/sidebar.html @@ -26,7 +26,7 @@ {% endif %} - {% if g.current_user.isAdmin %} + {% if g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin %}
  • Create Event @@ -38,7 +38,7 @@
  • - {% if not g.current_user.isCeltsStudentStaff %} + {% if not g.current_user.isCeltsStudentStaff or g.current_user.isCeltsStudentAdmin %} Course Proposals From 378f998f76fdff915b90fb3f3a3be2e529ccd5aa Mon Sep 17 00:00:00 2001 From: qasema Date: Fri, 1 Sep 2023 15:46:41 -0400 Subject: [PATCH 02/32] update student admin --- app/controllers/admin/routes.py | 4 ++-- app/templates/sidebar.html | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/routes.py b/app/controllers/admin/routes.py index e9d1a012d..f1b810a23 100644 --- a/app/controllers/admin/routes.py +++ b/app/controllers/admin/routes.py @@ -40,7 +40,7 @@ def switchUser(): print(f"Switching user from {g.current_user} to",request.form['newuser']) session['current_user'] = model_to_dict(User.get_by_id(request.form['newuser'])) - + print("======ss") return redirect(request.referrer) @@ -144,7 +144,7 @@ def rsvpLogDisplay(eventId): eventData = model_to_dict(event, recurse=False) eventData['program'] = event.program isProgramManager = g.current_user.isProgramManagerFor(eventData['program']) - if g.current_user.isCeltsAdmin or (g.current_user.isCeltsStudentStaff and isProgramManager): + if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or (g.current_user.isCeltsStudentStaff and isProgramManager): allLogs = EventRsvpLog.select(EventRsvpLog, User).join(User).where(EventRsvpLog.event_id == eventId).order_by(EventRsvpLog.createdOn.desc()) return render_template("/events/rsvpLog.html", event = event, diff --git a/app/templates/sidebar.html b/app/templates/sidebar.html index 6af360fa9..17a4ab2b5 100644 --- a/app/templates/sidebar.html +++ b/app/templates/sidebar.html @@ -82,6 +82,7 @@
    Current User: {{g.current_user.username}}
    From ec5bf44cf4ce8db2004c354f03954a215e5256a7 Mon Sep 17 00:00:00 2001 From: qasema Date: Wed, 6 Sep 2023 16:26:52 -0400 Subject: [PATCH 08/32] refactor Celts Admins --- app/controllers/admin/routes.py | 10 +-- app/controllers/admin/userManagement.py | 4 +- app/controllers/admin/volunteers.py | 4 +- app/logic/userManagement.py | 4 +- app/templates/admin/userManagement.html | 102 ++++++++++++------------ app/templates/eventNav.html | 4 +- app/templates/eventView.html | 2 +- app/templates/sidebar.html | 29 ++++--- 8 files changed, 83 insertions(+), 76 deletions(-) diff --git a/app/controllers/admin/routes.py b/app/controllers/admin/routes.py index c8727df23..76cd699a9 100644 --- a/app/controllers/admin/routes.py +++ b/app/controllers/admin/routes.py @@ -58,7 +58,7 @@ def templateSelect(): @admin_bp.route('/eventTemplates///create', methods=['GET','POST']) def createEvent(templateid, programid): - if not (g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin or g.current_user.isProgramManagerFor(programid)): + if not (g.current_user.isAdmin or g.current_user.isProgramManagerFor(programid)): abort(403) # Validate given URL @@ -143,7 +143,7 @@ def rsvpLogDisplay(eventId): eventData = model_to_dict(event, recurse=False) eventData['program'] = event.program isProgramManager = g.current_user.isProgramManagerFor(eventData['program']) - if g.current_user.isCeltsAdmin or (g.current_user.isCeltsStudentStaff and isProgramManager): + if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or (g.current_user.isCeltsStudentStaff and isProgramManager): allLogs = EventRsvpLog.select(EventRsvpLog, User).join(User).where(EventRsvpLog.event_id == eventId).order_by(EventRsvpLog.createdOn.desc()) return render_template("/events/rsvpLog.html", event = event, @@ -168,7 +168,7 @@ def eventDisplay(eventId): print(f"Unknown event: {eventId}") abort(404) - notPermitted = not (g.current_user.isCeltsAdmin or g.current_user.isProgramManagerForEvent(event)) + notPermitted = not (g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or g.current_user.isProgramManagerForEvent(event)) if 'edit' in request.url_rule.rule and notPermitted: abort(403) @@ -267,7 +267,7 @@ def eventDisplay(eventId): @admin_bp.route('/event//cancel', methods=['POST']) def cancelRoute(eventId): - if g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin: + if g.current_user.isAdmin: try: cancelEvent(eventId) return redirect(request.referrer) @@ -329,7 +329,7 @@ def userProfile(): @admin_bp.route('/search_student', methods=['GET']) def studentSearchPage(): - if g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin: + if g.current_user.isAdmin: return render_template("/admin/searchStudentPage.html") abort(403) diff --git a/app/controllers/admin/userManagement.py b/app/controllers/admin/userManagement.py index 224304752..7235ff68a 100644 --- a/app/controllers/admin/userManagement.py +++ b/app/controllers/admin/userManagement.py @@ -72,7 +72,7 @@ def removeProgramManagers(): def updateProgramInfo(programID): """Grabs info and then outputs it to logic function""" programInfo = request.form # grabs user inputs - if g.current_user.isCeltsAdmin: + if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin: try: changeProgramInfo(programInfo["programName"], #calls logic function to add data to database programInfo["contactEmail"], @@ -94,7 +94,7 @@ def userManagement(): current_programs = Program.select() currentAdmins = list(User.select().where(User.isCeltsAdmin)) currentStudentStaff = list(User.select().where(User.isCeltsStudentStaff)) - if g.current_user.isCeltsAdmin: + if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin: return render_template('admin/userManagement.html', terms = terms, programs = list(current_programs), diff --git a/app/controllers/admin/volunteers.py b/app/controllers/admin/volunteers.py index af8aa6fe1..ed57c608c 100644 --- a/app/controllers/admin/volunteers.py +++ b/app/controllers/admin/volunteers.py @@ -54,7 +54,7 @@ def manageVolunteersPage(eventID): isProgramManager = g.current_user.isProgramManagerForEvent(event) bannedUsers = [row.user for row in getBannedUsers(event.program)] - if not (g.current_user.isCeltsAdmin or (g.current_user.isCeltsStudentStaff and isProgramManager)): + if not (g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or (g.current_user.isCeltsStudentStaff and isProgramManager)): abort(403) eventParticipantData = list(EventParticipant.select(EventParticipant, User).join(User).where(EventParticipant.event==event)) @@ -108,7 +108,7 @@ def volunteerDetailsPage(eventID): print(f"No event found for {eventID}", e) abort(404) - if not (g.current_user.isCeltsAdmin or (g.current_user.isCeltsStudentStaff and g.current_user.isProgramManagerForEvent(event))): + if not (g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or (g.current_user.isCeltsStudentStaff and g.current_user.isProgramManagerForEvent(event))): abort(403) eventRsvpData = list(EventRsvp.select().where(EventRsvp.event==event)) diff --git a/app/logic/userManagement.py b/app/logic/userManagement.py index 38fda2469..eb29ab371 100644 --- a/app/logic/userManagement.py +++ b/app/logic/userManagement.py @@ -52,7 +52,7 @@ def changeProgramInfo(newProgramName, newContactEmail, newContactName, newLocati def getAllowedPrograms(currentUser): """Returns a list of all visible programs depending on who the current user is.""" - if currentUser.isCeltsAdmin or g.current_user.isCeltsStudentAdmin: + if currentUser.isCeltsAdmin or currentUser.isCeltsStudentAdmin : return Program.select().order_by(Program.programName) else: return Program.select().join(ProgramManager).where(ProgramManager.user==currentUser).order_by(Program.programName) @@ -61,7 +61,7 @@ def getAllowedPrograms(currentUser): def getAllowedTemplates(currentUser): """Returns a list of all visible templates depending on who the current user is. If they are not an admin it should always be none.""" - if currentUser.isCeltsAdmin: + if currentUser.isCeltsAdmin or currentUser.isCeltsStudentAdmin: return EventTemplate.select().where(EventTemplate.isVisible==True).order_by(EventTemplate.name) else: return [] \ No newline at end of file diff --git a/app/templates/admin/userManagement.html b/app/templates/admin/userManagement.html index f196df1c5..1fc80ce4f 100644 --- a/app/templates/admin/userManagement.html +++ b/app/templates/admin/userManagement.html @@ -17,64 +17,66 @@

    Admin Management

    -
    -

    - {% set focus = "open" if not visibleAccordion or visibleAccordion == "user" else "collapsed" %} - -

    - {% set show = "show" if not visibleAccordion or visibleAccordion == "user" %} -
    -
    -
    -
    -
    -
    - {{createInputsButtons("searchCeltsAdminInput", "Add Celts Admin")}}
    + {% if g.current_user.isCeltsAdmin and not g.current_user.isCeltsStudentAdmin %} +
    +

    + {% set focus = "open" if not visibleAccordion or visibleAccordion == "user" else "collapsed" %} + +

    + {% set show = "show" if not visibleAccordion or visibleAccordion == "user" %} +
    +
    +
    +
    +
    +
    + {{createInputsButtons("searchCeltsAdminInput", "Add Celts Admin")}}
    +
    + + + + + + + + + {% for admin in currentAdmins %} + + + + + {% endfor %} + +
    Current Admin
    {{admin.firstName}} {{admin.lastName}}
    - - - - - - - - - {% for admin in currentAdmins %} - - - - - {% endfor %} - +
    +
    + {{createInputsButtons("searchCeltsStudentStaffInput", "Add Celts Student Staff")}}
    +
    +
    Current Admin
    {{admin.firstName}} {{admin.lastName}}
    + + + + + + + {% for studentStaff in currentStudentStaff %} + + + + + {% endfor %} +
    Current Student Staff
    {{studentStaff.firstName}} {{studentStaff.lastName}}
    -
    -
    -
    - {{createInputsButtons("searchCeltsStudentStaffInput", "Add Celts Student Staff")}}
    - - - - - - - - {% for studentStaff in currentStudentStaff %} - - - - - {% endfor %} - -
    Current Student Staff
    {{studentStaff.firstName}} {{studentStaff.lastName}}
    -
    + {% endif %}

    {% set focus = "open" if visibleAccordion == "term" else "collapsed" %} diff --git a/app/templates/eventNav.html b/app/templates/eventNav.html index e9f1a2415..cf6bcf2c2 100644 --- a/app/templates/eventNav.html +++ b/app/templates/eventNav.html @@ -15,7 +15,7 @@ {% block app_content %} {% block content_pageHeading %}
    - {% if g.current_user.isAdmin or g.current_user.isCeltsStudentAdmin %} + {% if g.current_user.isAdmin %} {{ eventheader(page_title, eventData, 'large', isNewEvent) }} {% endif %} {% set alertClass = "alert-danger" if eventPast else "alert-warning"%} @@ -33,7 +33,7 @@ {% endblock %} {% block navbar %} - {% if g.current_user.isCeltsAdmin or (g.current_user.isCeltsStudentStaff and g.current_user.isProgramManagerFor(eventData['program'])) %} + {% if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or (g.current_user.isCeltsStudentStaff and g.current_user.isProgramManagerFor(eventData['program'])) %}