77 isKosuIam ,
88 isUniversityWideIam ,
99 isDoctoralIam ,
10- iamToOrganisationCode ,
10+ isFeedbackLiaisonIam ,
11+ joryIamToOrganisationCode ,
1112 isEmployeeIam ,
1213 iamToDoctoralSchool ,
1314 kosuIamToFaculties ,
@@ -22,7 +23,7 @@ import { Programme } from '../organisation/types'
2223
2324type AccessSpecialGroupFunction = ( hyGroups : string [ ] ) => {
2425 access ?: { [ programmeCode : string ] : OrganisationAccess }
25- specialGroup ?: { [ key : string ] : boolean }
26+ specialGroup ?: { [ key : string ] : boolean | string [ ] }
2627}
2728
2829/**
@@ -55,7 +56,7 @@ const getSuperAdmin: AccessSpecialGroupFunction = (hyGroups) => {
5556}
5657
5758/**
58- * NOT USED
59+ * NOT USED (wait is this used?)
5960 * Grant admin rights if the user has correct iams (eg. grp-ospa)
6061 * @returns admin special group
6162 */
@@ -106,6 +107,26 @@ const getJory: AccessSpecialGroupFunction = (hyGroups) => {
106107 return { }
107108}
108109
110+ /**
111+ * Needed primarily for Norppa
112+ * Grant feedback liaison special group if the user has feedback liaison iam AND jory iam
113+ * The feedbackLiaison special group contains a list of programme keys that the user is jory in
114+ * @returns feedback liaison special group
115+ */
116+ const getFeedbackLiaison : AccessSpecialGroupFunction = ( hyGroups ) => {
117+ const isFeedbackLiaison = hyGroups . some ( isFeedbackLiaisonIam )
118+
119+ const joryIams = hyGroups . filter ( isJoryIam )
120+ const joryProgrammes = joryIams
121+ . map ( joryIamToOrganisationCode )
122+ . flatMap ( ( codes ) => codes . map ( mapToDegreeCode ) )
123+
124+ if ( isFeedbackLiaison && joryProgrammes . length > 0 ) {
125+ return { specialGroup : { feedbackLiaison : joryProgrammes } }
126+ }
127+ return { }
128+ }
129+
109130/**
110131 * Needed for Oodikone
111132 * Grant kosu special group if the user has kosu iams (eg. hy-ypa-opa-kosu-kumpula)
@@ -125,7 +146,15 @@ const getKosu: AccessSpecialGroupFunction = (hyGroups) => {
125146const getSpecialGroups : AccessSpecialGroupFunction = ( hyGroups ) => {
126147 let specialGroup = { }
127148
128- ; [ getAdmin , getSuperAdmin , getOpenUni , getHyOne , getJory , getKosu ]
149+ ; [
150+ getAdmin ,
151+ getSuperAdmin ,
152+ getOpenUni ,
153+ getHyOne ,
154+ getJory ,
155+ getKosu ,
156+ getFeedbackLiaison ,
157+ ]
129158 . map ( ( f ) => f ( hyGroups ) )
130159 . forEach ( ( { specialGroup : newSpecialGroup } ) => {
131160 specialGroup = { ...specialGroup , ...newSpecialGroup }
@@ -230,7 +259,7 @@ const getDoctoralSchoolAccess: AccessSpecialGroupFunction = (hyGroups) => {
230259const getProgrammeAdminAccess : AccessSpecialGroupFunction = ( hyGroups ) => {
231260 const orgCodes = hyGroups
232261 . filter ( ( iam ) => isStudyLeaderGroup ( iam , hyGroups ) )
233- . map ( ( iam ) => iamToOrganisationCode ( iam ) )
262+ . map ( ( iam ) => joryIamToOrganisationCode ( iam ) )
234263 . filter ( Boolean )
235264
236265 const degreeCodes = orgCodes . flatMap ( ( codes ) => codes . map ( mapToDegreeCode ) )
@@ -257,7 +286,7 @@ const getProgrammeAdminAccess: AccessSpecialGroupFunction = (hyGroups) => {
257286const getProgrammeWriteAccess : AccessSpecialGroupFunction = ( hyGroups ) => {
258287 if ( ! hyGroups . some ( isEmployeeIam ) ) return { }
259288 const orgCodes = hyGroups
260- . map ( ( iam ) => iamToOrganisationCode ( iam ) )
289+ . map ( ( iam ) => joryIamToOrganisationCode ( iam ) )
261290 . filter ( Boolean )
262291 const degreeCodes = orgCodes . flatMap ( ( codes ) => codes . map ( mapToDegreeCode ) )
263292 const access = { }
@@ -274,7 +303,7 @@ const getProgrammeWriteAccess: AccessSpecialGroupFunction = (hyGroups) => {
274303 */
275304const getProgrammeReadAccess : AccessSpecialGroupFunction = ( hyGroups ) => {
276305 const orgCodes = hyGroups
277- . map ( ( iam ) => iamToOrganisationCode ( iam ) )
306+ . map ( ( iam ) => joryIamToOrganisationCode ( iam ) )
278307 . filter ( Boolean )
279308 const degreeCodes = orgCodes . flatMap ( ( codes ) => codes . map ( mapToDegreeCode ) )
280309 const access = { }
0 commit comments