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

Student admin #1063

Draft
wants to merge 44 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
064415d
initail commit
qasema Aug 31, 2023
378f998
update student admin
qasema Sep 1, 2023
7d19f29
update student admin
qasema Sep 1, 2023
bd4bf0b
update nav bar
qasema Sep 1, 2023
8600142
new updates
qasema Sep 1, 2023
148cbfb
update student admin role in test data
qasema Sep 1, 2023
86b43a3
Modified conditional logic for Student Admin in different areas.
ojmakinde Sep 6, 2023
ec5bf44
refactor Celts Admins
qasema Sep 6, 2023
d81bc7c
update event list
qasema Sep 6, 2023
1d505db
Merge branch 'development' into studentAdmin
AndersonStettner Sep 7, 2023
227866a
update permoissions
qasema Sep 7, 2023
0bd4a63
update user managment
qasema Sep 8, 2023
2f401f8
remove space
qasema Sep 8, 2023
7554fb3
remove debugging statement
qasema Sep 8, 2023
2d08374
Corrected conditional logic for edit event view
ojmakinde Sep 18, 2023
ffcf2c9
Corrected eventNav functionality for student admins
ojmakinde Sep 19, 2023
379e7ae
Merge branch 'development' into studentAdmin
AndersonStettner Sep 19, 2023
c9cbad0
Created test stubs
ojmakinde Sep 20, 2023
8ff3aa9
Added myself to test data and wrote a unit test for studentAdmin logic
ojmakinde Sep 21, 2023
293bd19
Merge branch 'studentAdmin' of github.com:BCStudentSoftwareDevTeam/ce…
ojmakinde Sep 21, 2023
60c7431
Corrected eligibilty view error
ojmakinde Sep 27, 2023
ad4fca6
Merge branch 'development' into studentAdmin
ojmakinde Oct 23, 2023
4b9c752
Merge branch 'development' into studentAdmin
AndersonStettner Oct 26, 2023
d1a2433
Corrected capitaliztion and string formatting on flash messages
ojmakinde Nov 8, 2023
740f6b8
Corrected capitaliztion and string formatting on flash messages
ojmakinde Nov 8, 2023
d5a2f74
fix conditions
qasema Nov 13, 2023
a340704
merge development
qasema Nov 13, 2023
bd4d1fd
bonnerscholars
qasema Nov 13, 2023
c54bf3b
fix expressions
qasema Nov 13, 2023
e50ca71
fix a bug
qasema Nov 13, 2023
7d90425
resolve merge conflict
qasema Nov 15, 2023
cc64881
Removed Finn Bledsoe as faculty
ojmakinde Dec 4, 2023
9bf62ff
remove condition
qasema Dec 4, 2023
5edb6cd
merge
qasema Dec 4, 2023
329d1d3
Merge branch 'development' into studentAdmin
AndersonStettner Jan 17, 2024
419d2a3
refactored the function to be more logical
azabeli Mar 1, 2024
1e44a8c
Merge branch 'studentAdmin' of github.com:BCStudentSoftwareDevTeam/ce…
azabeli Mar 1, 2024
807d724
resolved conflicts
bledsoef Mar 1, 2024
4600233
Merge branch 'studentAdmin' of github.com:BCStudentSoftwareDevTeam/ce…
bledsoef Mar 1, 2024
86efbc6
updated test data and removed unused routes
bledsoef Mar 11, 2024
1415951
did a little refactoring and added some typing
bledsoef Mar 11, 2024
44d1927
added some more typing and did a little more refactoring
bledsoef Mar 11, 2024
6381d44
changing tests and reformatting logic/controllers to make them more t…
bledsoef Mar 11, 2024
f560f80
rewrote many tests
bledsoef Mar 11, 2024
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
9 changes: 4 additions & 5 deletions app/controllers/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -145,7 +144,8 @@ def createEvent(templateid, programid):
@admin_bp.route('/event/<eventId>/rsvp', methods=['GET'])
def rsvpLogDisplay(eventId):
event = Event.get_by_id(eventId)
if g.current_user.isCeltsAdmin or (g.current_user.isCeltsStudentStaff and g.current_user.isProgramManagerFor(event.program)):
isProgramManager = g.current_user.isProgramManagerFor(event.program)
if g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or 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,
Expand All @@ -168,8 +168,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)

Expand Down
57 changes: 26 additions & 31 deletions app/controllers/admin/userManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,55 +24,48 @@ def manageUsers():

if method == "addCeltsAdmin":
if user.isStudent and not user.isCeltsStudentStaff:
flash(user.firstName + " " + user.lastName + " cannot be added as a CELTS-Link admin", 'danger')
flash(f"{user.fullName} cannot be added as a CELTS-Link Admin.", 'danger')
else:
if user.isCeltsAdmin:
flash(user.firstName + " " + user.lastName + " is already a CELTS-Link Admin", 'danger')
flash(f"{user.fullName} is already a CELTS-Link Admin.", 'danger')
else:
addCeltsAdmin(user)
flash(user.firstName + " " + user.lastName + " has been added as a CELTS-Link Admin", 'success')
flash(f"{user.fullName} has been added as a CELTS-Link Admin.", 'success')
elif method == "addCeltsStudentStaff":
if not user.isStudent:
flash(username + " cannot be added as CELTS Student Staff", 'danger')
flash(username + " cannot be added as CELTS Student Staff.", 'danger')
else:
if user.isCeltsStudentStaff:
flash(user.firstName + " " + user.lastName + " is already a CELTS Student Staff", 'danger')
flash(f"{user.fullName} is already a CELTS Student Staff.", 'danger')
else:
addCeltsStudentStaff(user)
flash(user.firstName + " " + user.lastName + " has been added as a CELTS Student Staff", 'success')
flash(f"{user.fullName} has been added as a CELTS Student Staff.", 'success')
elif method == "addCeltsStudentAdmin":
if user.isStudent:
addCeltsStudentAdmin(user)
flash(f"{user.fullName} has been added as a CELTS Student Admin.", 'success')

elif user.isCeltsStudentAdmin:
flash(f"{user.fullName} is already a CELTS Student Admin.", 'danger')
else:
flash(username + " cannot be added as CELTS Student Admin.", 'danger')

elif method == "removeCeltsAdmin":
removeCeltsAdmin(user)
flash(user.firstName + " " + user.lastName + " is no longer a CELTS Admin ", 'success')
flash(f"{user.fullName} 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')
flash(f"{user.fullName} is no longer a CELTS Student Staff.", 'success')
elif method == "removeCeltsStudentAdmin":
removeCeltsStudentAdmin(user)
flash(f"{user.fullName} is no longer a CELTS Student Admin.", 'success')
return ("success")

@admin_bp.route('/addProgramManagers', methods=['POST'])
def addProgramManagers():
eventData = request.form
try:
return addProgramManager(eventData['username'],int(eventData['programID']))
except Exception as e:
print(e)
flash('Error while trying to add a manager.','warning')
abort(500,"'Error while trying to add a manager.'")

@admin_bp.route('/removeProgramManagers', methods=['POST'])
def removeProgramManagers():
eventData = request.form
try:
return removeProgramManager(eventData['username'],int(eventData['programID']))
except Exception as e:
print(e)
flash('Error while removing a manager.','warning')
abort(500,"Error while trying to remove a manager.")

@admin_bp.route('/admin/updateProgramInfo/<programID>', methods=['POST'])
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"],
Expand All @@ -94,12 +87,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)

Expand Down
69 changes: 37 additions & 32 deletions app/controllers/admin/volunteers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,42 @@ def manageVolunteersPage(eventID):
if not (g.current_user.isCeltsAdmin or (g.current_user.isCeltsStudentStaff and g.current_user.isProgramManagerForEvent(event))):
abort(403)

# ------- Grab the different lists of participants -------
trainedParticipantsForProgramAndTerm = trainedParticipants(event.program, event.term)

bannedUsersForProgram = [bannedUser.user for bannedUser in getBannedUsers(event.program)]

eventNonAttendedData, eventWaitlistData, eventVolunteerData, eventParticipants = sortParticipantsByStatus(event)

allRelevantUsers = [participant.user for participant in (eventParticipants + eventNonAttendedData + eventWaitlistData)]

# ----------- Get miscellaneous data -----------

participationStatusForTrainings = getParticipationStatusForTrainings(event.program, allRelevantUsers, event.term)

eventLengthInHours = getEventLengthInHours(event.timeStart, event.timeEnd, event.startDate)

recurringVolunteers = getPreviousRecurringEventData(event.recurringId)

currentRsvpAmount = getEventRsvpCount(event.id)

# ----------- Render template with all of the data ------------
return render_template("/events/manageVolunteers.html",
eventVolunteerData = eventVolunteerData,
eventNonAttendedData = eventNonAttendedData,
eventWaitlistData = eventWaitlistData,
eventLength = eventLengthInHours,
event = event,
recurringVolunteers = recurringVolunteers,
bannedUsersForProgram = bannedUsersForProgram,
trainedParticipantsForProgramAndTerm = trainedParticipantsForProgramAndTerm,
participationStatusForTrainings = participationStatusForTrainings,
currentRsvpAmount = currentRsvpAmount)
isProgramManager = g.current_user.isProgramManagerForEvent(event)

if not (g.current_user.isCeltsAdmin or g.current_user.isCeltsStudentAdmin or isProgramManager):
abort(403)
# ------- Grab the different lists of participants -------
trainedParticipantsForProgramAndTerm = trainedParticipants(event.program, event.term)

bannedUsersForProgram = [bannedUser.user for bannedUser in getBannedUsers(event.program)]

eventNonAttendedData, eventWaitlistData, eventVolunteerData, eventParticipants = sortParticipantsByStatus(event)

allRelevantUsers = [participant.user for participant in (eventParticipants + eventNonAttendedData + eventWaitlistData)]

# ----------- Get miscellaneous data -----------

participationStatusForTrainings = getParticipationStatusForTrainings(event.program, allRelevantUsers, event.term)

eventLengthInHours = getEventLengthInHours(event.timeStart, event.timeEnd, event.startDate)

recurringVolunteers = getPreviousRecurringEventData(event.recurringId)

currentRsvpAmount = getEventRsvpCount(event.id)

# ----------- Render template with all of the data ------------

return render_template("/events/manageVolunteers.html",
eventVolunteerData = eventVolunteerData,
eventNonAttendedData = eventNonAttendedData,
eventWaitlistData = eventWaitlistData,
eventLength = eventLengthInHours,
event = event,
recurringVolunteers = recurringVolunteers,
bannedUsersForProgram = bannedUsersForProgram,
trainedParticipantsForProgramAndTerm = trainedParticipantsForProgramAndTerm,
participationStatusForTrainings = participationStatusForTrainings,
currentRsvpAmount = currentRsvpAmount)

@admin_bp.route('/event/<eventID>/volunteer_details', methods=['GET'])
def volunteerDetailsPage(eventID):
Expand All @@ -97,7 +102,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.isProgramManagerForEvent(event)):
abort(403)

eventRsvpData = list(EventRsvp.select(EmergencyContact, EventRsvp)
Expand Down
21 changes: 16 additions & 5 deletions app/logic/userManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@ def addCeltsAdmin(user):
user = User.get_by_id(user)
user.isCeltsAdmin = True
user.save()
createAdminLog(f'Made {user.firstName} {user.lastName} a CELTS admin member.')
createAdminLog(f'Made f"{user.fullName} a CELTS admin member.')


def addCeltsStudentStaff(user):
user = User.get_by_id(user)
user.isCeltsStudentStaff = True
user.save()
createAdminLog(f'Made {user.firstName} {user.lastName} a CELTS student staff member.')
createAdminLog(f'Made f"{user.fullName} a CELTS student staff member.')

def addCeltsStudentAdmin(user):
user = User.get_by_id(user)
user.isCeltsStudentAdmin = True
user.save()
createAdminLog(f'Made {user.fullName} 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.')

createAdminLog(f'Removed f"{user.fullName} from CELTS admins.')

def removeCeltsStudentStaff(user):
user = User.get_by_id(user)
Expand All @@ -38,6 +42,11 @@ def removeCeltsStudentStaff(user):
createAdminLog(f'Removed {user.firstName} {user.lastName} from a CELTS student staff member'+
(f', and as a manager of {programManagerRoles}.' if programManagerRoles else "."))

def removeCeltsStudentAdmin(user):
user = User.get_by_id(user)
user.isCeltsStudentAdmin = False
user.save()
createAdminLog(f'Removed f"{user.fullName} from a CELTS student admin member.')

def changeProgramInfo(newProgramName, newContactEmail, newContactName, newLocation, programId):
"""Updates the program info with a new sender and email."""
Expand All @@ -59,14 +68,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:
Copy link
Contributor

Choose a reason for hiding this comment

The 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 []
3 changes: 2 additions & 1 deletion app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class User(baseModel):
isStaff = BooleanField(default = False)
isCeltsAdmin = BooleanField(default =False)
isCeltsStudentStaff = BooleanField(default = False)
isCeltsStudentAdmin = BooleanField(default = False)
dietRestriction = TextField(null=True)
minorInterest = BooleanField(default=False)

Expand All @@ -28,7 +29,7 @@ def __init__(self,*args, **kwargs):

@property
def isAdmin(self):
return (self.isCeltsAdmin or self.isCeltsStudentStaff)
return (self.isCeltsAdmin or self.isCeltsStudentAdmin or self.isCeltsStudentStaff)
qasema marked this conversation as resolved.
Show resolved Hide resolved

@property
def isBonnerScholar(self):
Expand Down
16 changes: 15 additions & 1 deletion app/static/js/userManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ function callbackAdmin(selected){
function callbackStudentStaff(selected){
submitRequest("addCeltsStudentStaff", selected.username)
}
function callbackStudentAdmin(selected){
submitRequest("addCeltsStudentAdmin", selected.username)
}
$(document).ready(function(){
// Admin Management
$("#searchCeltsAdminInput").on("input", function(){
Expand All @@ -14,6 +17,10 @@ $(document).ready(function(){
$("#searchCeltsStudentStaffInput").on("input", function(){
searchUser("searchCeltsStudentStaffInput", callbackStudentStaff, false, null, "student")
});

$("#searchCeltsStudentAdminInput").on("input", function(){
searchUser("searchCeltsStudentAdminInput", callbackStudentAdmin, false, null, "student")
});
$("#addNewTerm").on("click",function(){
addNewTerm();
});
Expand All @@ -23,6 +30,9 @@ $(document).ready(function(){
$(".removeStudentStaff").on("click",function(){
submitRequest("removeCeltsStudentStaff", $(this).data("username"));
});
$(".removeStudentAdmin").on("click",function(){
submitRequest("removeCeltsStudentAdmin", $(this).data("username"));
});
$('#searchCeltsAdminInput').keydown(function(e){
if (e.key === "Enter"){
submitRequest("addCeltsAdmin", $(this).val())
Expand All @@ -33,7 +43,11 @@ $(document).ready(function(){
submitRequest("addCeltsStudentStaff", $(this).val())
}
});

$('#searchCeltsStudentAdminInput').keydown(function(e){
if (e.key === "Enter"){
submitRequest("addCeltsStudentAdmin", $(this).val())
}
});
for (var i = 1; i <= $('#currentTermList .term-btn').length; i++){
$("#termFormID_" + i).on("click", function(){
$(".term-btn").removeClass("active");
Expand Down
Loading
Loading