-
Notifications
You must be signed in to change notification settings - Fork 4
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
OGD invite user flow #1239
base: master
Are you sure you want to change the base?
OGD invite user flow #1239
Changes from 250 commits
b0ae207
54d59a8
9d335c3
1a9a764
ad2f0bd
cf69998
212c45b
f460ca7
6624276
dd15a64
fb76eb0
ffdda23
a71ab4a
a216ee4
6ee93fc
35c9b20
edcd45f
d5d4618
23f9243
853d5f5
fe98716
93c21dc
399a606
debeec8
72a4621
0025a04
804f53c
7260f7f
d78fed5
b781201
a803b8f
f9b32f4
1f25833
54ad2ac
7156cd7
bac1602
79dd3ac
f8ab1b9
ae1d73f
f99588b
3422491
7433ace
caac76f
9bdd935
7fec49f
16cf13d
187310c
16dfac2
e325a8b
66a0a71
9a4f418
1db078b
3499698
50abf5e
fb2f7b5
b974ca9
ce177ff
d48835a
d8a46bd
731f00f
1081890
4949b2e
c793f49
7c8a0a2
dd903e2
8a3e65e
3129264
cc4c5d2
8bb4cda
28fbd14
50fd11f
52ff33d
2877f51
f451cf6
d56fb52
7621769
2c16941
848f680
a2607aa
471c9a6
1cac975
9340ace
57ea5de
bb61cc9
a68ef77
8abc2cc
1b15ccd
c639e86
4a63bba
94f208c
3c01da3
d67140e
0be6fa8
0d4be38
dc1c80f
9de8d41
10375ac
9937fb4
beae772
8fe237c
ddc6a32
4d4a2c6
c5397f5
a85e6eb
3e2e17d
84cc4cc
e6b12b0
1530d7c
c2dd057
a9d0274
bfa36d0
adf3b22
d62dc5a
8a15b52
9f6e4f5
143fd32
e97c030
9e3a0df
0e95180
d20bb97
d8d5b87
021885f
905b0e3
f52363d
428293f
9fb761b
015b436
99d76cd
66b17b0
3af220c
30d7c0e
27bc71e
8ff08c8
c6ff67d
1624fb8
e8a0760
f98c9dc
2bcde8e
cecc047
74d9ec7
d926f5b
7f846b5
2b0a74c
1c9a456
2d350db
e85526f
0d73bcf
4551d28
6b71b94
22cb6d6
c44b410
c434ad8
6f65d1c
475443f
68e1a39
4f49218
bb652a9
d1f4504
7b710d5
49657a6
8ee2e44
2c578e6
7bbccbc
62fb874
75d7f89
8c24849
d156daf
b237e43
c2d5ee1
e3500e6
c429016
55eaeea
55d2bfd
1d11289
38965fc
eed7aad
45683d6
eb108cd
4ae3fb8
4e374dd
022147c
0fa51f2
a1630af
a68176d
09bea66
f2b5332
b62fc71
4920d74
ef078e3
52a0760
dbd6e24
cec5bc2
cf5c21c
5e7e8ab
b7fd76f
941b04e
7fec0fe
ecd8cad
d276f98
4a9389f
e2296e0
63e522f
db2d273
a72eed2
bc21810
47b706f
59d5541
4952776
29214be
57d2bb0
19ee6bd
ee2d617
4a5203a
cdb8d57
dfd26b0
c94f1fe
2d1e7e7
4ba553f
d1c58ec
3cbca55
96b50b9
e69bc98
ad6db6b
4776d20
967323e
f6ae937
c16bdba
bb7c3ea
7018769
fed0273
56b373f
d9fc77e
ee3446f
d5bc05f
f13b896
58d56cf
ee3cb24
7c9f5ff
3357919
fe116c6
bed5a3b
59a6586
a47a79c
e1d067a
9c4e93a
99cfc6b
b7a4bf7
925f77b
53f8c9f
85a9d3a
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ export async function handleAllUserListRoute(req: Request, res: Response) { | |
try { | ||
const rdProfessionalApiPath = getConfigValue(SERVICES_RD_PROFESSIONAL_API_PATH); | ||
const response = await req.http.get(getRefdataAllUserListUrl(rdProfessionalApiPath)); | ||
logger.info('response::', response.data); | ||
logger.info('response::', JSON.stringify(response.data)); | ||
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 know it was already there, but this needs to be removed before release. It will put PII into the logs, because the user data has names, emails etc 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. Removed comment in commit: |
||
res.send(response.data); | ||
} catch (error) { | ||
logger.error('error', error); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Request, Response, Router } from 'express'; | ||
import { compareAccessTypes } from '../retrieveAccessTypes'; | ||
import { inviteUserRouteOGD } from '../inviteUser'; | ||
import { ogdEditUserRoute } from '../editUserPermissions'; | ||
import { refreshUser } from '../refresh-user'; | ||
import * as log4jui from '../lib/log4jui'; | ||
|
||
export const router = Router({ mergeParams: true }); | ||
const logger = log4jui.getLogger('OGD-FLOW'); | ||
|
||
export async function ogdInvite(req: Request, res: Response) { | ||
try { | ||
logger.info('ogdInvite:: Invite Request received'); | ||
const userPayload = req.body.userPayload; | ||
if (userPayload.roles.includes('pui-caa')) { | ||
const compareResult = await compareAccessTypes(req); | ||
req.body.userPayload = { ...userPayload, ...compareResult }; | ||
} | ||
const operationResult = await inviteUserRouteOGD(req); | ||
const userId = operationResult.userIdentifier; | ||
req.body = { userId }; | ||
await refreshUser(req); | ||
res.send(operationResult); | ||
} catch (error) { | ||
logger.error('ogdInvite:: Error ', error); | ||
res.status(error.apiStatusCode || 500).json(error); | ||
} | ||
} | ||
|
||
export async function ogdUpdate(req: Request, res: Response) { | ||
try { | ||
logger.info('ogdUpdate:: Edit User Request received'); | ||
const userPayload = req.body.userPayload; | ||
const userId = req.params.userId; | ||
const compareResult = await compareAccessTypes(req); | ||
req.body = { ...userPayload, ...compareResult }; | ||
const operationResult = await ogdEditUserRoute(req); | ||
req.body = { userId }; | ||
await refreshUser(req); | ||
res.send(operationResult); | ||
} catch (error) { | ||
logger.error('ogdUpdate:: Error ', error); | ||
res.status(error.apiStatusCode || 500).json(error); | ||
} | ||
} | ||
|
||
router.post('/invite', ogdInvite); | ||
router.put('/update/:userId', ogdUpdate); | ||
|
||
export default router; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Request, Router } from 'express'; | ||
import { getConfigValue } from '../configuration'; | ||
import { SERVICES_ROLE_ASSIGNMENT_API_PATH } from '../configuration/references'; | ||
import * as log4jui from '../lib/log4jui'; | ||
import { exists, valueOrNull } from '../lib/util'; | ||
|
||
const logger = log4jui.getLogger('refresh-user'); | ||
|
||
export async function refreshUser(req: Request) { | ||
const payload = req.body; | ||
try { | ||
const serviceApiBasePath = getConfigValue(SERVICES_ROLE_ASSIGNMENT_API_PATH); | ||
const userId = payload.userId; | ||
const reqUrl = `${serviceApiBasePath}/am/role-mapping/professional/refresh?userId=${userId}`; | ||
logger.info('REFRESH USER: request URL:: ', reqUrl); | ||
const response = await req.http.post(reqUrl); | ||
logger.info('response::', response.data); | ||
return response.data; | ||
} catch (error) { | ||
logger.error('error', error); | ||
const status = exists(error, 'status') ? error.status : 500; | ||
const errReport = { | ||
apiError: valueOrNull(error, 'data.errorMessage'), | ||
apiStatusCode: status, | ||
message: valueOrNull(error, 'data.errorDescription') | ||
}; | ||
throw (errReport); | ||
} | ||
} | ||
|
||
export const router = Router({ mergeParams: true }); | ||
router.post('/', refreshUser); | ||
export default router; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Function to compare the users accessType selections with the most recently obtained ones | ||
export function processAccessTypes(currentOrganisationAccessTypes, userAccessTypeOptions) { | ||
const processedAccessTypes = []; | ||
const accessTypesMap = new Map(); | ||
currentOrganisationAccessTypes.forEach((jurisdiction) => { | ||
jurisdiction.accessTypes.forEach((accessType) => { | ||
const key = `${jurisdiction.jurisdictionId}-${accessType.organisationProfileId}-${accessType.accessTypeId}`; | ||
accessTypesMap.set(key, accessType); | ||
}); | ||
}); | ||
|
||
userAccessTypeOptions.userAccessTypes.forEach((userAccessType) => { | ||
const key = `${userAccessType.jurisdictionId}-${userAccessType.organisationProfileId}-${userAccessType.accessTypeId}`; | ||
const accessType = accessTypesMap.get(key); | ||
|
||
if (accessType && accessType.display) { | ||
if (accessType.accessMandatory && accessType.accessDefault) { | ||
// If access type is mandatory and default is true, set it to true | ||
processedAccessTypes.push({ | ||
jurisdictionId: userAccessType.jurisdictionId, | ||
organisationProfileId: userAccessType.organisationProfileId, | ||
accessTypeId: userAccessType.accessTypeId, | ||
enabled: true | ||
}); | ||
} else { | ||
// For non-mandatory access types or mandatory with default false, use user's selection | ||
processedAccessTypes.push(userAccessType); | ||
} | ||
} | ||
|
||
// Remove the processed access type from the map | ||
accessTypesMap.delete(key); | ||
}); | ||
|
||
accessTypesMap.forEach((accessType, key) => { | ||
if (accessType.display) { | ||
const [jurisdictionId, organisationProfileId, accessTypeId] = key.split('-'); | ||
processedAccessTypes.push({ | ||
jurisdictionId, | ||
organisationProfileId, | ||
accessTypeId, | ||
enabled: accessType.accessDefault | ||
}); | ||
} | ||
}); | ||
|
||
return { | ||
...userAccessTypeOptions, | ||
userAccessTypes: processedAccessTypes | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Request, Response, Router } from 'express'; | ||
import { getConfigValue } from '../configuration'; | ||
import { SERVICES_CCD_DEFINITION_STORE_API_PATH } from '../configuration/references'; | ||
import * as log4jui from '../lib/log4jui'; | ||
import { exists, valueOrNull } from '../lib/util'; | ||
import { processAccessTypes } from './accessTypesComparison'; | ||
|
||
const logger = log4jui.getLogger('retrive-access-types'); | ||
|
||
async function fetchAccessTypes(req: Request, payload: any): Promise<any> { | ||
try { | ||
const ccdDefinitionStore = getConfigValue(SERVICES_CCD_DEFINITION_STORE_API_PATH); | ||
const url = `${ccdDefinitionStore}/retrieve-access-types`; | ||
logger.info('RETRIEVE ACCESS TYPES: request URL:: ', url); | ||
const response = await req.http.post(url, payload); | ||
return response.data; | ||
} catch (error) { | ||
logger.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
export async function handleRetrieveAccessTypes(req: Request, res: Response) { | ||
const payload = req.body; | ||
try { | ||
const data = await fetchAccessTypes(req, payload); | ||
res.send(data); | ||
} catch (error) { | ||
const status = exists(error, 'status') ? error.status : 500; | ||
const errReport = { | ||
apiError: valueOrNull(error, 'data.errorMessage'), | ||
apiStatusCode: status, | ||
message: valueOrNull(error, 'data.errorDescription') | ||
}; | ||
res.status(status).send(errReport); | ||
} | ||
} | ||
|
||
export async function compareAccessTypes(req: Request) { | ||
try { | ||
const orgIdPayload = { organisationProfileIds: req.body.orgIdsPayload }; | ||
const userAccessTypesPayload = req.body.userPayload; | ||
const accessTypes = await fetchAccessTypes(req, orgIdPayload); | ||
const comparedUserSelections = processAccessTypes(accessTypes.jurisdictions, userAccessTypesPayload); | ||
return (comparedUserSelections); | ||
} catch (error) { | ||
logger.error('Error in compareAccessTypes:', error); | ||
return ({ error: 'An error occurred while processing your request.' }); | ||
} | ||
} | ||
|
||
export const router = Router({ mergeParams: true }); | ||
|
||
router.post('/', handleRetrieveAccessTypes); | ||
router.post('/compare', compareAccessTypes); | ||
export default router; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified that these changes are overriden by the "production" config section below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes