-
Notifications
You must be signed in to change notification settings - Fork 14
Student admin #1063
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
base: development
Are you sure you want to change the base?
Student admin #1063
Changes from 22 commits
064415d
378f998
7d19f29
bd4bf0b
8600142
148cbfb
86b43a3
ec5bf44
d81bc7c
1d505db
227866a
0bd4a63
2f401f8
7554fb3
2d08374
ffcf2c9
379e7ae
c9cbad0
8ff3aa9
293bd19
60c7431
ad4fca6
4b9c752
d1a2433
740f6b8
d5a2f74
a340704
bd4d1fd
c54bf3b
e50ca71
7d90425
cc64881
9bf62ff
5edb6cd
329d1d3
419d2a3
1e44a8c
807d724
4600233
86efbc6
1415951
44d1927
6381d44
f560f80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,13 +44,12 @@ 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'])) | ||
|
|
||
| return redirect(request.referrer) | ||
|
|
||
|
|
||
| @admin_bp.route('/eventTemplates') | ||
| def templateSelect(): | ||
| if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentStaff: | ||
| if g.current_user.isAdmin: | ||
| allprograms = getAllowedPrograms(g.current_user) | ||
| visibleTemplates = getAllowedTemplates(g.current_user) | ||
| return render_template("/events/template_selector.html", | ||
|
|
@@ -148,7 +147,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): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the |
||
| 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, | ||
|
|
@@ -172,8 +171,7 @@ def eventDisplay(eventId): | |
| except DoesNotExist as e: | ||
| 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 and event.program_id != 5) or g.current_user.isProgramManagerForEvent(event)) | ||
| if 'edit' in request.url_rule.rule and notPermitted: | ||
| abort(403) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| from app.controllers.admin import admin_bp | ||
| from app.models.user import User | ||
| from app.models.program import Program | ||
| from app.logic.userManagement import addCeltsAdmin,addCeltsStudentStaff,removeCeltsAdmin,removeCeltsStudentStaff | ||
| from app.logic.userManagement import addCeltsAdmin,addCeltsStudentStaff,addCeltsStudentAdmin ,removeCeltsAdmin,removeCeltsStudentStaff, removeCeltsStudentAdmin | ||
| from app.logic.userManagement import changeProgramInfo | ||
| from app.logic.utils import selectSurroundingTerms | ||
| from app.logic.term import addNextTerm, changeCurrentTerm | ||
|
|
@@ -40,12 +40,24 @@ def manageUsers(): | |
| else: | ||
| addCeltsStudentStaff(user) | ||
| flash(user.firstName + " " + user.lastName + " has been added as a CELTS Student Staff", 'success') | ||
| elif method == "addCeltsStudentAdmin": | ||
| if not user.isStudent: | ||
| flash(username + " cannot be added as CELTS Student Admin", 'danger') | ||
| else: | ||
| if user.isCeltsStudentAdmin: | ||
| flash(user.firstName + " " + user.lastName + " is already a CELTS Student Admin", 'danger') | ||
| else: | ||
| addCeltsStudentAdmin(user) | ||
| flash(user.firstName + " " + user.lastName + " has been added as a CELTS Student Admin", 'success') | ||
| elif method == "removeCeltsAdmin": | ||
| removeCeltsAdmin(user) | ||
| flash(user.firstName + " " + user.lastName + " is no longer a CELTS Admin ", 'success') | ||
| elif method == "removeCeltsStudentStaff": | ||
| removeCeltsStudentStaff(user) | ||
| flash(user.firstName + " " + user.lastName + " is no longer a CELTS Student Staff", 'success') | ||
| elif method == "removeCeltsStudentAdmin": | ||
| removeCeltsStudentAdmin(user) | ||
| flash(user.firstName + " " + user.lastName + " is no longer a CELTS Student Admin", 'success') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these flash messages should end in a period. Also, it might be good to change all of the flashes into f strings and use the |
||
| return ("success") | ||
|
|
||
| @admin_bp.route('/addProgramManagers', methods=['POST']) | ||
|
|
@@ -72,7 +84,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,12 +106,14 @@ 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: | ||
| currentStudentAdmin = list(User.select().where(User.isCeltsStudentAdmin)) | ||
| if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin: | ||
| return render_template('admin/userManagement.html', | ||
| terms = terms, | ||
| programs = list(current_programs), | ||
| currentAdmins = currentAdmins, | ||
| currentStudentStaff = currentStudentStaff, | ||
| currentStudentAdmin = currentStudentAdmin, | ||
| ) | ||
| abort(403) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,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)): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. the |
||
| abort(403) | ||
|
|
||
| eventParticipantData = list(EventParticipant.select(EventParticipant, User).join(User).where(EventParticipant.event==event)) | ||
|
|
@@ -109,7 +109,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))): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And again here |
||
| abort(403) | ||
|
|
||
| eventRsvpData = list(EventRsvp.select(EmergencyContact, EventRsvp) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,19 +20,29 @@ def addCeltsStudentStaff(user): | |
| user.save() | ||
| createAdminLog(f'Made {user.firstName} {user.lastName} a CELTS student staff member.') | ||
|
|
||
| def addCeltsStudentAdmin(user): | ||
| user = User.get_by_id(user) | ||
| user.isCeltsStudentAdmin = True | ||
| user.save() | ||
| createAdminLog(f'Made {user.firstName} {user.lastName} a CELTS student Admin member.') | ||
|
|
||
| def removeCeltsAdmin(user): | ||
| user = User.get_by_id(user) | ||
| user.isCeltsAdmin = False | ||
| user.save() | ||
| createAdminLog(f'Removed {user.firstName} {user.lastName} from CELTS admins.') | ||
|
|
||
|
|
||
| def removeCeltsStudentStaff(user): | ||
| user = User.get_by_id(user) | ||
| user.isCeltsStudentStaff = False | ||
| user.save() | ||
| createAdminLog(f'Removed {user.firstName} {user.lastName} from a CELTS student staff member.') | ||
|
|
||
| def removeCeltsStudentAdmin(user): | ||
| user = User.get_by_id(user) | ||
| user.isCeltsStudentAdmin = False | ||
| user.save() | ||
| createAdminLog(f'Removed {user.firstName} {user.lastName} from a CELTS student Admin member.') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to use the |
||
|
|
||
| def changeProgramInfo(newProgramName, newContactEmail, newContactName, newLocation, programId): | ||
| """Updates the program info with a new sender and email.""" | ||
|
|
@@ -54,14 +64,16 @@ def getAllowedPrograms(currentUser): | |
| """Returns a list of all visible programs depending on who the current user is.""" | ||
| if currentUser.isCeltsAdmin: | ||
| return Program.select().order_by(Program.programName) | ||
| elif currentUser.isCeltsStudentAdmin: | ||
| return Program.select().where(Program.id !=5).order_by(Program.programName) | ||
| else: | ||
| return Program.select().join(ProgramManager).where(ProgramManager.user==currentUser).order_by(Program.programName) | ||
|
|
||
|
|
||
|
|
||
| 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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this allow them to see Bonner events? |
||
| return EventTemplate.select().where(EventTemplate.isVisible==True).order_by(EventTemplate.name) | ||
| else: | ||
| return [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,64 +17,86 @@ | |
|
|
||
| <h1 class="text-center mb-5">Admin Management</h1> | ||
| <div class="accordion" id="adminManagement"> | ||
| <div class="accordion-item"> | ||
| <h3 class="accordion-header" id="headingOne"> | ||
| {% set focus = "open" if not visibleAccordion or visibleAccordion == "user" else "collapsed" %} | ||
| <button class="accordion-button {{focus}} " type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> | ||
| User Management | ||
| </button> | ||
| </h3> | ||
| {% set show = "show" if not visibleAccordion or visibleAccordion == "user" %} | ||
| <div id="collapseOne" class="accordion-collapse collapse {{show}}" aria-labelledby="headingOne" data-bs-parent="#adminManagement"> | ||
| <div class="accordion-body"> | ||
| <div class="container-fluid col-10"> | ||
| <div class="row d-flex justify-content-center mb-3"> | ||
| <div class="col-md-6 mb-3"> | ||
| <div> | ||
| {{createInputsButtons("searchCeltsAdminInput", "Add Celts Admin")}}<br> | ||
| {% if g.current_user.isCeltsAdmin and not g.current_user.isCeltsStudentAdmin %} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you excluding
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We excluded the student admins here, as we felt they shouldn't possess the ability to add/remove admins or other student admins. Do you want us to provide that access?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's an ok assumption, that the student admins shouldn't be able to mess with that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everyone with |
||
| <div class="accordion-item"> | ||
| <h3 class="accordion-header" id="headingOne"> | ||
| {% set focus = "open" if not visibleAccordion or visibleAccordion == "user" else "collapsed" %} | ||
| <button class="accordion-button {{focus}} " type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> | ||
| User Management | ||
| </button> | ||
| </h3> | ||
| {% set show = "show" if not visibleAccordion or visibleAccordion == "user" %} | ||
| <div id="collapseOne" class="accordion-collapse collapse {{show}}" aria-labelledby="headingOne" data-bs-parent="#adminManagement"> | ||
| <div class="accordion-body"> | ||
| <div class="container-fluid col-10"> | ||
| <div class="row d-flex mb-3"> | ||
| <div class="col-md-6 mb-3"> | ||
| <div> | ||
| {{createInputsButtons("searchCeltsAdminInput", "Add Celts Admin")}}<br> | ||
| </div> | ||
| <table class="table mb-3"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col">Current Admin</th> | ||
| <th scope="col"></th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for admin in currentAdmins %} | ||
| <tr> | ||
| <td id="{{admin.username}}">{{admin.firstName}} {{admin.lastName}}</td> | ||
| <td><button data-username="{{admin.username}}" type="button" class="btn btn-danger view removeAdmin">Remove</button></td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| <table class="table mb-3"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col">Current Admin</th> | ||
| <th scope="col"></th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for admin in currentAdmins %} | ||
| <tr> | ||
| <td id="{{admin.username}}">{{admin.firstName}} {{admin.lastName}}</td> | ||
| <td><button data-username="{{admin.username}}" type="button" class="btn btn-danger view removeAdmin">Remove</button></td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| <div class="col-md-6 mb-3"> | ||
| <div> | ||
| {{createInputsButtons("searchCeltsStudentStaffInput", "Add Celts Student Staff")}}<br> | ||
| </div> | ||
| <table class="table mb-3"> | ||
| <thead> | ||
| <tr> | ||
| <th colspan="2" scope="col">Current Student Staff</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for studentStaff in currentStudentStaff %} | ||
| <tr> | ||
| <td id="{{studentStaff.username}}">{{studentStaff.firstName}} {{studentStaff.lastName}}</td> | ||
| <td><button data-username="{{studentStaff.username}}" type="button" class="btn btn-danger view removeStudentStaff">Remove</button></td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| <div class="col-md-6 mb-3"> | ||
| <div> | ||
| {{createInputsButtons("searchCeltsStudentStaffInput", "Add Celts Student Staff")}}<br> | ||
| </div> | ||
| <table class="table mb-3"> | ||
| <thead> | ||
| <tr> | ||
| <th colspan="2" scope="col">Current Student Staff</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for studentStaff in currentStudentStaff %} | ||
| <div class="col-md-6 mb-3"> | ||
| <div> | ||
| {{createInputsButtons("searchCeltsStudentAdminInput", "Add Celts Student Admin")}}<br> | ||
| </div> | ||
| <table class="table mb-3"> | ||
| <thead> | ||
| <tr> | ||
| <td id="{{studentStaff.username}}">{{studentStaff.firstName}} {{studentStaff.lastName}}</td> | ||
| <td><button data-username="{{studentStaff.username}}" type="button" class="btn btn-danger view removeStudentStaff">Remove</button></td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| <th colspan="2" scope="col">Current Student Admin</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for studentAdmin in currentStudentAdmin %} | ||
| <tr> | ||
| <td id="{{studentAdmin.username}}">{{studentAdmin.firstName}} {{studentAdmin.lastName}}</td> | ||
| <td><button data-username="{{studentAdmin.username}}" type="button" class="btn btn-danger view removeStudentAdmin">Remove</button></td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endif %} | ||
| <div class="accordion-item"> | ||
| <h3 class="accordion-header" id="headingTwo"> | ||
| {% set focus = "open" if visibleAccordion == "term" else "collapsed" %} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 and eventData["program"].id != 5) or (g.current_user.isCeltsStudentStaff and g.current_user.isProgramManagerFor(eventData['program'])) %} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have a flag you can use here instead of id. |
||
|
|
||
| <div class="btn-group"> | ||
| <ul class="nav nav-tabs nav-fill mx-3 mb-3" id="pills-tab" role="tablist"> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.