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

[IP-387] Upgrade fp-ts #165

Merged
merged 74 commits into from
Sep 21, 2021
Merged
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
1e775ae
update dependencies
balanza Sep 6, 2021
a8edf51
[#ip-387] update utils/orchestrator.tsgst
balanza Sep 6, 2021
9855f22
[#ip-387] update utils/random.tsgst
balanza Sep 6, 2021
3bd2341
[#ip-387] update utils/sessionApiClient.ts
balanza Sep 15, 2021
4c138cb
[#ip-387] update utils/subscription_feed.tsgst
balanza Sep 6, 2021
456f86c
[#ip-387] update utils/middlewaresgst
balanza Sep 6, 2021
22b0e74
[#ip-387] update utils/featureFlags.tsgst
balanza Sep 6, 2021
8a84112
[#ip-387] update utils/extensions/modelsgst
balanza Sep 6, 2021
72f9616
[#ip-387] update utils/conversions.tsgst
balanza Sep 6, 2021
ab1bea7
[#ip-387] [#ip-387] update utils/config.ts
balanza Sep 6, 2021
dc1ef08
[#ip-387] update utils/appinsights.ts
balanza Sep 6, 2021
c801e8f
[#ip-387] update utils/apim.ts
balanza Sep 7, 2021
9048311
[#ip-387] update UserDataProcessingTrigger
balanza Sep 7, 2021
6c77f34
[#ip-387] update UserDataProcessingRecoveryOrchestrator
balanza Sep 7, 2021
39f9233
[#ip-387] update UserDataProcessingProcessFailedRecords
balanza Sep 7, 2021
41b4f13
[#ip-387] update UserDataProcessingFindFailureReasonActivity
balanza Sep 7, 2021
1e31b83
[#ip-387] update __mocks__
balanza Sep 7, 2021
13aa5b7
[#ip-387] update UserDataProcessingCheckLastStatusActivity
balanza Sep 7, 2021
765e2d3
[#ip-387] update UserDataDownloadOrchestrator
balanza Sep 7, 2021
188e43a
[#ip-387] update UserDataDeleteOrchestratorV2
balanza Sep 7, 2021
ea02635
[#ip-387] update UserDataDeleteOrchestrator
balanza Sep 7, 2021
16f6a9c
[#ip-387] update UpsertServiceOrchestrator
balanza Sep 7, 2021
b2e4444
[#ip-387] update UploadServiceLogo
balanza Sep 9, 2021
a45bb84
[#ip-387] [#ip-387] update UploadOrganizationLogo
balanza Sep 9, 2021
214ca59
[#ip-387] update UpdateVisibleServicesCacheOrchestrator
balanza Sep 9, 2021
f36fd76
[#ip-387] update UpdateVisibleServicesCacheActivity
balanza Sep 9, 2021
4d7a482
[#ip-387] update UpdateVisibleServicesCache
balanza Sep 9, 2021
743baa3
[#ip-387] [#ip-387] update UpdateVisibleServicesActivity
balanza Sep 9, 2021
c33b8d0
[#ip-387] update UpdateUserGroups
balanza Sep 9, 2021
ad5ae4b
[#ip-387] update UpdateUser
balanza Sep 9, 2021
18b3fa1
[#ip-387] update UpdateSubscriptionsFeedActivity
balanza Sep 9, 2021
c7bbf1d
[#ip-387] update UpdateService
balanza Sep 9, 2021
c0fd570
[#ip-387] update SetUserSessionLockActivity
balanza Sep 9, 2021
bca6339
[#ip-387] update SetUserDataProcessingStatusActivity
balanza Sep 9, 2021
5bf8390
[#ip-387] update SetUserDataProcessingStatus
balanza Sep 9, 2021
263496f
[#ip-387] update SendUserDataDownloadMessageActivity
balanza Sep 9, 2021
317a0a1
[#ip-387] update SendUserDataDeleteEmailActivity
balanza Sep 10, 2021
22feac6
[#ip-387] update RegenerateSubscriptionKeys
balanza Sep 10, 2021
1fa1cac
[#ip-387] update IsFailedUserDataProcessingActivity
balanza Sep 10, 2021
db18172
[#ip-387] update Info
balanza Sep 10, 2021
23fce0c
[#ip-387] update GetUsers
balanza Sep 10, 2021
8191a8c
[#ip-387] update GetUserDataProcessingActivity
balanza Sep 10, 2021
99b3662
[#ip-387] update GetUser
balanza Sep 13, 2021
6dbeb14
[#ip-387] update GetSubscriptionKeys
balanza Sep 13, 2021
c126814
[#ip-387] update GetServicesPreferencesActivity
balanza Sep 13, 2021
d2b2dba
[#ip-387] update GetServices
balanza Sep 13, 2021
3de1e20
[#ip-387] update GetService
balanza Sep 13, 2021
9089b48
[#ip-387] update GetProfileActivity
balanza Sep 13, 2021
69ac9a0
[#ip-387] update GetFailedUserDataProcessingList
balanza Sep 13, 2021
730d10f
[#ip-387] update GetFailedUserDataProcessing
balanza Sep 13, 2021
b849aab
[#ip-387] update ExtractUserDataActivity
balanza Sep 13, 2021
4d8efe1
[#ip-387] [#ip-387] update DeleteUserDataActivity
balanza Sep 13, 2021
78a0951
[#ip-387] update CreateUser
balanza Sep 13, 2021
68ae861
[#ip-387] update CreateSubscription
balanza Sep 14, 2021
1b9c198
[#ip-387] update CreateService
balanza Sep 14, 2021
b76131d
[#ip-387] update CreateDevelopmentProfile
balanza Sep 14, 2021
f78dd8d
[#ip-387] fix after review
balanza Sep 15, 2021
1c8838d
fix after review
balanza Sep 15, 2021
80cd1c6
fix after review
balanza Sep 15, 2021
18d69f9
[#ip-387] fix after review
balanza Sep 15, 2021
7b2b7e0
[#ip-387] lint fix
balanza Sep 15, 2021
1381aae
[#ip-387] fix after review
balanza Sep 15, 2021
afa6858
[#ip-387] fix after review
balanza Sep 15, 2021
0eb3db8
[#ip-387] fix after review
balanza Sep 15, 2021
67fd68c
[#ip-387] fix after review
balanza Sep 15, 2021
179c051
[#ip-387] Revert "fix after review"
balanza Sep 16, 2021
409be2e
[#ip-387] [#ip-387] fix after review
balanza Sep 16, 2021
e44eb01
[#ip-387] fix after review
balanza Sep 16, 2021
928cf9c
[#ip-387] fix after review
balanza Sep 16, 2021
f2418a3
[#ip-387] fix after review
balanza Sep 17, 2021
1ecf36d
[#ip-387] fix after review
balanza Sep 17, 2021
4470544
[#ip-387] fix after review
balanza Sep 17, 2021
2c8dd17
[#ip-387] [#ip-387] fix after review
balanza Sep 20, 2021
b4441e9
Merge branch 'master' into ip-387--upgrade-fp-ts
Sep 21, 2021
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
145 changes: 82 additions & 63 deletions UpdateUser/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { GraphRbacManagementClient } from "@azure/graph";
import { User } from "@azure/graph/esm/models";
import * as express from "express";
import { toError } from "fp-ts/lib/Either";
import { identity } from "fp-ts/lib/function";
import { fromEither, TaskEither, tryCatch } from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/function";
import * as TE from "fp-ts/lib/TaskEither";
import * as E from "fp-ts/lib/Either";

import {
AzureApiAuthMiddleware,
IAzureApiAuthorization,
Expand Down Expand Up @@ -41,51 +43,64 @@ type IUpdateUserHandler = (

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const getUserFromList = (client: GraphRbacManagementClient, email: string) =>
tryCatch(
() =>
client.users.list({
filter: `signInNames/any(x:x/value eq '${email}')`
}),
toError
).map(userList => userList[0]);
pipe(
TE.tryCatch(
() =>
client.users.list({
filter: `signInNames/any(x:x/value eq '${email}')`
}),
toError
),
TE.map(userList => userList[0])
);

const updateUser = (
client: GraphRbacManagementClient,
email: EmailAddress,
user: User,
adb2cTokenAttributeName: string,
userPayload: UserUpdatePayload
): TaskEither<Error, UserUpdated> =>
tryCatch(
() =>
client.users.update(
user.userPrincipalName,
withoutUndefinedValues({
displayName:
userPayload.first_name && userPayload.last_name
? `${userPayload.first_name} ${userPayload.last_name}`
: undefined,
givenName: userPayload.first_name,
surname: userPayload.last_name,
// eslint-disable-next-line sort-keys
[adb2cTokenAttributeName]: userPayload.token_name
})
),
toError
).chain(() =>
getUserFromList(client, email).chain(userResponse =>
fromEither(
UserUpdated.decode({
email,
first_name: userPayload.first_name,
id: userResponse.objectId,
last_name: userPayload.last_name,
token_name: userPayload.token_name
}).mapLeft(
errs =>
new Error(
`Error decoding UserUpdated ERROR=${readableReport(errs)}`
): TE.TaskEither<Error, UserUpdated> =>
pipe(
TE.tryCatch(
() =>
client.users.update(
user.userPrincipalName,
withoutUndefinedValues({
displayName:
userPayload.first_name && userPayload.last_name
? `${userPayload.first_name} ${userPayload.last_name}`
: undefined,
givenName: userPayload.first_name,
surname: userPayload.last_name,
// eslint-disable-next-line sort-keys
[adb2cTokenAttributeName]: userPayload.token_name
})
),
toError
),
TE.chain(() =>
pipe(
getUserFromList(client, email),
TE.chain(userResponse =>
TE.fromEither(
pipe(
{
email,
first_name: userPayload.first_name,
id: userResponse.objectId,
last_name: userPayload.last_name,
token_name: userPayload.token_name
},
UserUpdated.decode,
E.mapLeft(
errs =>
new Error(
`Error decoding UserUpdated ERROR=${readableReport(errs)}`
)
)
balanza marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
balanza marked this conversation as resolved.
Show resolved Hide resolved
)
)
Expand All @@ -106,38 +121,42 @@ export function UpdateUserHandler(
error,
errorMessage
);
return getGraphRbacManagementClient(adb2cCredentials)
.mapLeft(error =>
return pipe(
getGraphRbacManagementClient(adb2cCredentials),
TE.mapLeft(error =>
internalErrorHandler("Could not get the ADB2C client", error)
)
.chain(graphRbacManagementClient =>
getUserFromList(graphRbacManagementClient, email)
.mapLeft(userFromListError =>
),
TE.chain(graphRbacManagementClient =>
pipe(
getUserFromList(graphRbacManagementClient, email),
TE.mapLeft(userFromListError =>
internalErrorHandler(
"Could not retrieve user from list on the ADB2C",
userFromListError
)
)
.chain(user =>
updateUser(
graphRbacManagementClient,
email,
user,
adb2cTokenAttributeName,
userPayload
).mapLeft(updateUserError =>
internalErrorHandler(
"Could not update the user on the ADB2C",
new Error(JSON.stringify(updateUserError))
),
TE.chain(user =>
pipe(
updateUser(
graphRbacManagementClient,
email,
user,
adb2cTokenAttributeName,
userPayload
),
TE.mapLeft(updateUserError =>
internalErrorHandler(
"Could not update the user on the ADB2C",
new Error(JSON.stringify(updateUserError))
)
)
)
)
)
.fold<IResponseSuccessJson<UserUpdated> | IResponseErrorInternal>(
identity,
updatedUser => ResponseSuccessJson(updatedUser)
)
.run();
)
),
TE.map(updatedUser => ResponseSuccessJson(updatedUser)),
TE.toUnion
)();
};
}

Expand Down