@@ -983,13 +983,21 @@ async function setStaffInstituteTypeIdentifierAndRedirectToSchool(req, res, scho
983
983
}
984
984
}
985
985
986
- async function setInstituteTypeIdentifierAndRedirectToDistrict ( req , res , districtID , sdcDistrictCollectionID ) {
986
+ async function setInstituteTypeIdentifierAndRedirectToDistrict ( req , res , districtID , sdcDistrictCollectionID , directToGrad , isGradAdmin ) {
987
987
log . info ( 'Set InstituteTypeIdentifierAndRedirectToDistrict And Redirect called' ) ;
988
988
989
989
if ( sdcDistrictCollectionID && districtID ) {
990
990
log . info ( 'Staff user logged in, redirecting to selected school' ) ;
991
991
setSessionInstituteIdentifiers ( req , districtID , 'DISTRICT' ) ;
992
992
res . redirect ( config . get ( 'server:frontend' ) + '/open-district-collection-summary/' + districtID ) ;
993
+ } else if ( directToGrad && districtID && isGradAdmin ) {
994
+ log . info ( 'Staff admin user logged in, redirecting to selected district' ) ;
995
+ setGradStaffAdminSessionInstituteIdentifiers ( req , districtID , 'DISTRICT' ) ;
996
+ res . redirect ( config . get ( 'server:frontend' ) + '/graduation/' + districtID ) ;
997
+ } else if ( directToGrad && districtID && ! isGradAdmin ) {
998
+ log . info ( 'Staff viewer user logged in, redirecting to selected district' ) ;
999
+ setGradStaffViewerSessionInstituteIdentifiers ( req , districtID , 'DISTRICT' ) ;
1000
+ res . redirect ( config . get ( 'server:frontend' ) + '/graduation/' + districtID ) ;
993
1001
} else {
994
1002
log . info ( 'User has no associated schools or districts redirecting to Unauthorized Page' ) ;
995
1003
res . redirect ( config . get ( 'server:frontend' ) + '/unauthorized' ) ;
@@ -1042,7 +1050,7 @@ function getAndSetupStaffUserAndRedirectWithSchoolCollectionLink(req, res, acces
1042
1050
}
1043
1051
}
1044
1052
1045
- function getAndSetupStaffUserAndRedirectWithDistrictCollectionLink ( req , res , accessToken , districtID , sdcDistrictCollectionID ) {
1053
+ function getAndSetupStaffUserAndRedirectWithDistrictCollectionLink ( req , res , accessToken , districtID , sdcDistrictCollectionID , directToGrad ) {
1046
1054
let roles = req . session . passport . user . _json . realm_access . roles ;
1047
1055
if ( roles . includes ( 'EDX_ADMIN' ) ) {
1048
1056
Promise . all ( [
@@ -1063,9 +1071,24 @@ function getAndSetupStaffUserAndRedirectWithDistrictCollectionLink(req, res, acc
1063
1071
res . redirect ( config . get ( 'server:frontend' ) + '/unauthorizedNoEDXUser' ) ;
1064
1072
return ;
1065
1073
}
1066
- await setInstituteTypeIdentifierAndRedirectToDistrict ( req , res , districtID , sdcDistrictCollectionID ) ;
1074
+ await setInstituteTypeIdentifierAndRedirectToDistrict ( req , res , districtID , sdcDistrictCollectionID , directToGrad , false ) ;
1067
1075
} ) ;
1068
- } else {
1076
+ } else if ( ( roles . includes ( 'GRAD_DATA_COLLECTION_ADMIN' ) || ( roles . includes ( 'GRAD_DATA_COLLECTION_VIEWER' ) ) ) && directToGrad ) {
1077
+ Promise . all ( [
1078
+ getData ( accessToken , config . get ( 'edx:edxUsersURL' ) + '/user-districts' , req . session . correlationID )
1079
+ ] )
1080
+ . then ( async ( [ userDistricts ] ) => {
1081
+ req . session . userDistrictIDs = userDistricts ?. filter ( ( el ) => {
1082
+ return ! ! isDistrictActive ( cacheService . getDistrictJSONByDistrictID ( el ) ) ;
1083
+ } ) ; //this is list of active districtIDs associated to the user
1084
+
1085
+ if ( roles . includes ( 'GRAD_DATA_COLLECTION_ADMIN' ) ) {
1086
+ await setInstituteTypeIdentifierAndRedirectToDistrict ( req , res , districtID , sdcDistrictCollectionID , directToGrad , true ) ;
1087
+ } else {
1088
+ await setInstituteTypeIdentifierAndRedirectToDistrict ( req , res , districtID , sdcDistrictCollectionID , directToGrad , false ) ;
1089
+ }
1090
+ } ) ;
1091
+ } else {
1069
1092
log . info ( 'IDIR user logged in without EDX_ADMIN role; redirecting to Unauthorized Page' ) ;
1070
1093
res . redirect ( config . get ( 'server:frontend' ) + '/unauthorized' ) ;
1071
1094
}
@@ -1133,7 +1156,11 @@ function setGradStaffAdminSessionInstituteIdentifiers(req, activeInstituteIdenti
1133
1156
let permissionsArray = [ ] ;
1134
1157
1135
1158
if ( req . session . passport . user . _json . idir_guid ) {
1136
- permissionsArray = cacheService . getGradStaffSchoolAdminPermissions ( ) ;
1159
+ if ( activeInstituteType === 'SCHOOL' ) {
1160
+ permissionsArray = cacheService . getGradStaffSchoolAdminPermissions ( ) ;
1161
+ } else {
1162
+ permissionsArray = cacheService . getGradStaffDistrictAdminPermissions ( ) ;
1163
+ }
1137
1164
}
1138
1165
1139
1166
req . session . activeInstitutePermissions = permissionsArray ;
@@ -1145,7 +1172,11 @@ function setGradStaffViewerSessionInstituteIdentifiers(req, activeInstituteIdent
1145
1172
let permissionsArray = [ ] ;
1146
1173
1147
1174
if ( req . session . passport . user . _json . idir_guid ) {
1148
- permissionsArray = cacheService . getGradStaffSchoolViewerPermissions ( ) ;
1175
+ if ( activeInstituteType === 'SCHOOL' ) {
1176
+ permissionsArray = cacheService . getGradStaffSchoolViewerPermissions ( ) ;
1177
+ } else {
1178
+ permissionsArray = cacheService . getGradStaffDistrictViewerPermissions ( ) ;
1179
+ }
1149
1180
}
1150
1181
1151
1182
req . session . activeInstitutePermissions = permissionsArray ;
0 commit comments