1313
1414INTRO_REALM = 'https://sso.csh.rit.edu/auth/realms/intro'
1515
16+
1617def before_request (func ):
1718 """
1819 Credit to Liam Middlebrook and Ram Zallan
1920 https://github.com/liam-middlebrook/gallery
2021 """
22+
2123 @wraps (func )
2224 def wrapped_function (* args , ** kwargs ):
2325 uid = str (session ['userinfo' ].get ('preferred_username' , '' ))
24- member = ldap_get_member (uid )
25-
2626 if session ['id_token' ]['iss' ] == INTRO_REALM :
2727 info = {
2828 'realm' : 'intro' ,
2929 'uid' : uid ,
30- 'onfloor' : is_freshman_on_floor (uid )
30+ 'onfloor' : is_freshman_on_floor (uid ),
31+ 'admin' : False # It's always false if frosh
3132 }
3233 else :
34+ member = ldap_get_member (uid )
3335 info = {
3436 'realm' : 'csh' ,
3537 'uid' : uid ,
@@ -58,6 +60,7 @@ def packet_auth(func):
5860 """
5961 Decorator for easily configuring oidc
6062 """
63+
6164 @auth .oidc_auth ('app' )
6265 @wraps (func )
6366 def wrapped_function (* args , ** kwargs ):
@@ -76,6 +79,7 @@ def admin_auth(func):
7679 """
7780 Decorator for easily configuring oidc
7881 """
82+
7983 @auth .oidc_auth ('app' )
8084 @wraps (func )
8185 def wrapped_function (* args , ** kwargs ):
@@ -85,6 +89,8 @@ def wrapped_function(*args, **kwargs):
8589 if not ldap_is_evals (member ) and not ldap_is_rtp (member ):
8690 app .logger .warn ('Stopped member {} from accessing admin UI' .format (username ))
8791 return redirect (app .config ['PROTOCOL' ] + app .config ['PACKET_UPPER' ], code = 301 )
92+ else :
93+ return redirect (app .config ['PROTOCOL' ] + app .config ['PACKET_INTRO' ], code = 301 )
8894
8995 return func (* args , ** kwargs )
9096
@@ -100,7 +106,7 @@ def notify_slack(name: str):
100106 return
101107
102108 msg = f':pizza-party: { name } got :100: on packet! :pizza-party:'
103- requests .put (app .config ['SLACK_WEBHOOK_URL' ], json = {'text' :msg })
109+ requests .put (app .config ['SLACK_WEBHOOK_URL' ], json = {'text' : msg })
104110 app .logger .info ('Posted 100% notification to slack for ' + name )
105111
106112
@@ -111,7 +117,8 @@ def sync_freshman(freshmen_list):
111117 if list_freshman .rit_username not in freshmen_in_db :
112118 # This is a new freshman so add them to the DB
113119 freshmen_in_db [list_freshman .rit_username ] = Freshman (rit_username = list_freshman .rit_username ,
114- name = list_freshman .name , onfloor = list_freshman .onfloor )
120+ name = list_freshman .name ,
121+ onfloor = list_freshman .onfloor )
115122 db .session .add (freshmen_in_db [list_freshman .rit_username ])
116123 else :
117124 # This freshman is already in the DB so just update them
@@ -133,9 +140,9 @@ def sync_freshman(freshmen_list):
133140 # pylint: disable=cell-var-from-loop
134141 current_fresh_sigs = set (map (lambda fresh_sig : fresh_sig .freshman_username , packet .fresh_signatures ))
135142 for list_freshman in filter (lambda list_freshman : list_freshman .rit_username not in current_fresh_sigs and
136- list_freshman .onfloor and
137- list_freshman .rit_username != packet .freshman_username ,
138- freshmen_list .values ()):
143+ list_freshman .onfloor and
144+ list_freshman .rit_username != packet .freshman_username ,
145+ freshmen_list .values ()):
139146 db .session .add (FreshSignature (packet = packet , freshman = freshmen_in_db [list_freshman .rit_username ]))
140147
141148 db .session .commit ()
0 commit comments