-
Notifications
You must be signed in to change notification settings - Fork 12
feat: add configuration, custom Auth and event handlers for Diamond Light Source #1497
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
1f422ec
Add custom DLS user auth class based off OAuthAuthorization
GrantDLS ef6f9c8
Add DLS configuration files
GrantDLS 923e51f
Add DLS email handler.
GrantDLS 07c5904
Add Diamond logo
GrantDLS 43d9eba
Add DLS dependency config to switch statement
GrantDLS 2d04712
Add new dependency mapping to DLS config
GrantDLS 7d7a8db
Add Promise.all to asynchronously call configuration database calls.
GrantDLS f6ff971
Use proper casing for DLS in file/class names
GrantDLS 21bf273
Clarify repeated use of given_name
GrantDLS deeeb8d
Remove unnecessary newlines
GrantDLS a865e76
Asynchronously run settings application functions
GrantDLS 8e1441f
Refactor DSL email handler
GrantDLS ef474e9
Update to use live UOS fallback domain for email template
GrantDLS 7adfb62
Add helper to get base url
GrantDLS 191c39f
Throw error if no email handler for event type.
GrantDLS bb53a81
Add DLS email handler tests
GrantDLS 9bfb61c
Remove unnecessary comment.
GrantDLS 06b2f59
Remove more unnecessary comments
GrantDLS 3eec14b
Refactors following PR comments
GrantDLS 27ecb9b
Change upsert user to protected and override in DLSUserAuth class.
GrantDLS e545713
Merge branch 'develop' into dls-config
GrantDLS 115ea34
Merge branch 'develop' into dls-config
bolmsten 420012f
Merge branch 'develop' into dls-config
yoganandaness 19c0834
Merge branch 'develop' into dls-config
yoganandaness 1a0fe5f
Merge branch 'develop' into dls-config
yoganandaness a5b78fb
Use default logging handler
GrantDLS e85a603
Merge branch 'develop' into dls-config
yoganandaness 98646e4
Merge branch 'develop' into dls-config
GrantDLS 45598ca
Merge branch 'develop' into dls-config
zacharyjhankin 7e615ea
Merge branch 'develop' into dls-config
yoganandaness 41e4666
Remove dependency on new environment variable for UAS url
GrantDLS 529bb3c
Merge branch 'develop' into dls-config
yoganandaness File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import 'reflect-metadata'; | ||
|
|
||
| import { logger } from '@user-office-software/duo-logger'; | ||
| import { OpenIdClient } from '@user-office-software/openid'; | ||
| import { ValidTokenSet } from '@user-office-software/openid/lib/model/ValidTokenSet'; | ||
| import { ValidUserInfo } from '@user-office-software/openid/lib/model/ValidUserInfo'; | ||
|
|
||
| import { OAuthAuthorization } from './OAuthAuthorization'; | ||
| import { User, UserRole } from '../models/User'; | ||
| import { GetOrCreateInstitutionInput } from '../resolvers/mutations/UpsertUserMutation'; | ||
|
|
||
| export class DLSUserAuthorization extends OAuthAuthorization { | ||
| constructor() { | ||
| super(); | ||
| } | ||
|
|
||
| protected async upsertUser( | ||
| userInfo: ValidUserInfo, | ||
| tokenSet: ValidTokenSet | ||
| ): Promise<User> { | ||
| const client = await OpenIdClient.getInstance(); | ||
| let institutionInput: GetOrCreateInstitutionInput = null; | ||
| if (userInfo.institution_ror_id) { | ||
| institutionInput = userInfo.institution_ror_id as string; | ||
| } else if (userInfo.institution_name && userInfo.institution_country) { | ||
| institutionInput = { | ||
| country: userInfo.institution_country as string, | ||
| name: userInfo.institution_name as string, | ||
| }; | ||
| } | ||
|
|
||
| const userId = this.getUniqueId(userInfo); | ||
| const userWithOAuthSubMatch = | ||
| await this.userDataSource.getByOIDCSub(userId); | ||
|
|
||
| const userWithEmailMatch = await this.userDataSource.getByEmail( | ||
| userInfo.email | ||
| ); | ||
|
|
||
| const user = userWithOAuthSubMatch ?? userWithEmailMatch; | ||
|
|
||
| if (user) { | ||
|
GrantDLS marked this conversation as resolved.
|
||
| const updatedUser = await this.userDataSource.update({ | ||
| ...user, | ||
| email: userInfo.email, | ||
| oauthIssuer: client.issuer.metadata.issuer, | ||
| oauthRefreshToken: tokenSet.refresh_token ?? '', | ||
| oidcSub: userId, | ||
| }); | ||
|
|
||
| return updatedUser; | ||
| } else { | ||
| const institution = | ||
| await this.getOrCreateUserInstitution(institutionInput); | ||
| const newUser = await this.userDataSource.create( | ||
| (userInfo.title as string) ?? 'unspecified', | ||
| userInfo.given_name, | ||
| userInfo.family_name, | ||
| userInfo.given_name ?? '', // Using given_name as preferred_name from the oauth provider is a federation id | ||
| userId, | ||
| tokenSet.refresh_token ?? '', | ||
| client.issuer.metadata.issuer, | ||
| institution?.id ?? 1, | ||
| userInfo.email | ||
| ); | ||
|
|
||
| const roleID = this.getUserRole(newUser); | ||
|
|
||
| await this.userDataSource.addUserRole({ | ||
| userID: newUser.id, | ||
| roleID, | ||
| }); | ||
|
|
||
| if (roleID === UserRole.USER_OFFICER) { | ||
| logger.logInfo('Initial User Officer created', { | ||
| email: newUser.email, | ||
| }); | ||
| } | ||
|
|
||
| return newUser; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import { ConsoleLogger, setLogger } from '@user-office-software/duo-logger'; | ||
|
|
||
| import 'reflect-metadata'; | ||
| import { Tokens } from './Tokens'; | ||
| import { DataAccessUsersAuthorization } from '../auth/DataAccessUsersAuthorization'; | ||
| import { DLSUserAuthorization } from '../auth/DLSUserAuthorization'; | ||
| import { ProposalAuthorization } from '../auth/ProposalAuthorization'; | ||
| import { VisitAuthorization } from '../auth/VisitAuthorization'; | ||
| import { VisitRegistrationAuthorization } from '../auth/VisitRegistrationAuthorization'; | ||
| import { configureDLSEnvironment } from './dls/configureDLSEnvironment'; | ||
| import { mapClass, mapValue } from './utils'; | ||
| import { PostgresAdminDataSourceWithAutoUpgrade } from '../datasources/postgres/AdminDataSource'; | ||
| import PostgresCallDataSource from '../datasources/postgres/CallDataSource'; | ||
| import PostgresCoProposerClaimDataSource from '../datasources/postgres/CoProposerClaimDataSource'; | ||
| import PostgresDataAccessUsersDataSource from '../datasources/postgres/DataAccessUsersDataSource'; | ||
| import PostgresEmailTemplateDataSource from '../datasources/postgres/EmailTemplateDataSource'; | ||
| import PostgresEventLogsDataSource from '../datasources/postgres/EventLogsDataSource'; | ||
| import PostgresExperimentDataSource from '../datasources/postgres/ExperimentDataSource'; | ||
| import PostgresExperimentSafetyPdfTemplateDataSource from '../datasources/postgres/ExperimentSafetyPdfTemplateDataSource'; | ||
| import PostgresFapDataSource from '../datasources/postgres/FapDataSource'; | ||
| import PostgresFeedbackDataSource from '../datasources/postgres/FeedbackDataSource'; | ||
| import PostgresFileDataSource from '../datasources/postgres/FileDataSource'; | ||
| import PostgresGenericTemplateDataSource from '../datasources/postgres/GenericTemplateDataSource'; | ||
| import PostgresInstrumentDataSource from '../datasources/postgres/InstrumentDataSource'; | ||
| import PostgresInternalReviewDataSource from '../datasources/postgres/InternalReviewDataSource'; | ||
| import PostgresInviteDataSource from '../datasources/postgres/InviteDataSource'; | ||
| import PostgresPredefinedMessageDataSource from '../datasources/postgres/PredefinedMessageDataSource'; | ||
| import PostgresProposalDataSource from '../datasources/postgres/ProposalDataSource'; | ||
| import PostgresProposalInternalCommentsDataSource from '../datasources/postgres/ProposalInternalCommentsDataSource'; | ||
| import PostgresProposalPdfTemplateDataSource from '../datasources/postgres/ProposalPdfTemplateDataSource'; | ||
| import PostgresQuestionaryDataSource from '../datasources/postgres/QuestionaryDataSource'; | ||
| import PostgresReviewDataSource from '../datasources/postgres/ReviewDataSource'; | ||
| import PostgresRoleClaimDataSource from '../datasources/postgres/RoleClaimsDataSource'; | ||
| import PostgresRoleDataSource from '../datasources/postgres/RoleDataSource'; | ||
| import PostgresSampleDataSource from '../datasources/postgres/SampleDataSource'; | ||
| import PostgresShipmentDataSource from '../datasources/postgres/ShipmentDataSource'; | ||
| import PostgresStatusActionsDataSource from '../datasources/postgres/StatusActionsDataSource'; | ||
| import StatusActionsLogsDataSource from '../datasources/postgres/StatusActionsLogsDataSource'; | ||
| import PostgresStatusDataSource from '../datasources/postgres/StatusDataSource'; | ||
| import PostgresSystemDataSource from '../datasources/postgres/SystemDataSource'; | ||
| import PostgresTagDataSource from '../datasources/postgres/TagDataSource'; | ||
| import PostgresTechniqueDataSource from '../datasources/postgres/TechniqueDataSource'; | ||
| import PostgresTemplateDataSource from '../datasources/postgres/TemplateDataSource'; | ||
| import PostgresUnitDataSource from '../datasources/postgres/UnitDataSource'; | ||
| import PostgresUserDataSource from '../datasources/postgres/UserDataSource'; | ||
| import PostgresVisitDataSource from '../datasources/postgres/VisitDataSource'; | ||
| import PostgresVisitRegistrationClaimDataSource from '../datasources/postgres/VisitRegistrationClaimDataSource'; | ||
| import PostgresWorkflowDataSource from '../datasources/postgres/WorkflowDataSource'; | ||
| import { DLSEmailHandler } from '../eventHandlers/email/DLS/DLSEmailHandler'; | ||
| import createLoggingHandler from '../eventHandlers/logging'; | ||
| import { SMTPMailService } from '../eventHandlers/MailService/SMTP/SMTPMailService'; | ||
| import { | ||
| createListenToRabbitMQHandler, | ||
| createPostToRabbitMQHandler, | ||
| } from '../eventHandlers/messageBroker'; | ||
| import { createApplicationEventBus } from '../events'; | ||
| import { FapDataColumns } from '../factory/xlsx/FapDataColumns'; | ||
| import { | ||
| callFapPopulateRow, | ||
| getDataRow, | ||
| populateRow, | ||
| } from '../factory/xlsx/FapDataRow'; | ||
| import BasicUserDetailsLoader from '../loaders/BasicUserDetailsLoader'; | ||
| import { SkipAssetRegistrar } from '../services/assetRegistrar/skip/SkipAssetRegistrar'; | ||
|
|
||
| mapClass(Tokens.AdminDataSource, PostgresAdminDataSourceWithAutoUpgrade); | ||
| mapClass(Tokens.CoProposerClaimDataSource, PostgresCoProposerClaimDataSource); | ||
| mapClass(Tokens.DataAccessUsersDataSource, PostgresDataAccessUsersDataSource); | ||
| mapClass(Tokens.CallDataSource, PostgresCallDataSource); | ||
| mapClass(Tokens.EventLogsDataSource, PostgresEventLogsDataSource); | ||
| mapClass(Tokens.FeedbackDataSource, PostgresFeedbackDataSource); | ||
| mapClass(Tokens.FileDataSource, PostgresFileDataSource); | ||
| mapClass(Tokens.GenericTemplateDataSource, PostgresGenericTemplateDataSource); | ||
| mapClass(Tokens.InstrumentDataSource, PostgresInstrumentDataSource); | ||
| mapClass(Tokens.InviteDataSource, PostgresInviteDataSource); | ||
| mapClass(Tokens.RoleDataSource, PostgresRoleDataSource); | ||
| mapClass(Tokens.RoleClaimDataSource, PostgresRoleClaimDataSource); | ||
| mapClass(Tokens.InternalReviewDataSource, PostgresInternalReviewDataSource); | ||
| mapClass( | ||
| Tokens.ProposalPdfTemplateDataSource, | ||
| PostgresProposalPdfTemplateDataSource | ||
| ); | ||
|
|
||
| mapClass( | ||
| Tokens.ExperimentSafetyPdfTemplateDataSource, | ||
| PostgresExperimentSafetyPdfTemplateDataSource | ||
| ); | ||
| mapClass(Tokens.ProposalDataSource, PostgresProposalDataSource); | ||
| mapClass( | ||
| Tokens.ProposalInternalCommentsDataSource, | ||
| PostgresProposalInternalCommentsDataSource | ||
| ); | ||
| mapClass(Tokens.StatusActionsDataSource, PostgresStatusActionsDataSource); | ||
| mapClass(Tokens.QuestionaryDataSource, PostgresQuestionaryDataSource); | ||
| mapClass(Tokens.ReviewDataSource, PostgresReviewDataSource); | ||
| mapClass(Tokens.FapDataSource, PostgresFapDataSource); | ||
| mapClass(Tokens.SampleDataSource, PostgresSampleDataSource); | ||
| mapClass(Tokens.ShipmentDataSource, PostgresShipmentDataSource); | ||
| mapClass(Tokens.SystemDataSource, PostgresSystemDataSource); | ||
| mapClass(Tokens.TemplateDataSource, PostgresTemplateDataSource); | ||
| mapClass(Tokens.UnitDataSource, PostgresUnitDataSource); | ||
| mapClass(Tokens.UserDataSource, PostgresUserDataSource); | ||
| mapClass(Tokens.VisitDataSource, PostgresVisitDataSource); | ||
| mapClass( | ||
| Tokens.VisitRegistrationClaimDataSource, | ||
| PostgresVisitRegistrationClaimDataSource | ||
| ); | ||
| mapClass(Tokens.VisitAuthorization, VisitAuthorization); | ||
| mapClass(Tokens.VisitRegistrationAuthorization, VisitRegistrationAuthorization); | ||
| mapClass(Tokens.TechniqueDataSource, PostgresTechniqueDataSource); | ||
| mapClass( | ||
| Tokens.PredefinedMessageDataSource, | ||
| PostgresPredefinedMessageDataSource | ||
| ); | ||
| mapClass(Tokens.StatusActionsLogsDataSource, StatusActionsLogsDataSource); | ||
| mapClass(Tokens.WorkflowDataSource, PostgresWorkflowDataSource); | ||
| mapClass(Tokens.StatusDataSource, PostgresStatusDataSource); | ||
| mapClass(Tokens.ExperimentDataSource, PostgresExperimentDataSource); | ||
| mapClass(Tokens.TagDataSource, PostgresTagDataSource); | ||
|
|
||
| mapClass(Tokens.UserAuthorization, DLSUserAuthorization); | ||
| mapClass(Tokens.ProposalAuthorization, ProposalAuthorization); | ||
| mapClass(Tokens.DataAccessUsersAuthorization, DataAccessUsersAuthorization); | ||
|
|
||
| mapClass(Tokens.AssetRegistrar, SkipAssetRegistrar); | ||
|
|
||
| mapClass(Tokens.MailService, SMTPMailService); | ||
|
|
||
| mapValue(Tokens.FapDataColumns, FapDataColumns); | ||
| mapValue(Tokens.FapDataRow, getDataRow); | ||
| mapValue(Tokens.PopulateRow, populateRow); | ||
| mapValue(Tokens.PopulateCallRow, callFapPopulateRow); | ||
|
|
||
| mapValue(Tokens.EmailEventHandler, DLSEmailHandler); | ||
| mapClass(Tokens.EmailTemplateDataSource, PostgresEmailTemplateDataSource); | ||
|
|
||
| mapValue(Tokens.PostToMessageQueue, createPostToRabbitMQHandler()); | ||
| mapValue(Tokens.LoggingHandler, createLoggingHandler()); | ||
| mapValue(Tokens.EventBus, createApplicationEventBus()); | ||
| mapValue(Tokens.ListenToMessageQueue, createListenToRabbitMQHandler()); | ||
|
|
||
| mapValue(Tokens.ConfigureEnvironment, configureDLSEnvironment); | ||
|
GrantDLS marked this conversation as resolved.
|
||
| mapValue(Tokens.ConfigureLogger, () => setLogger(new ConsoleLogger())); | ||
|
|
||
| mapClass(Tokens.BasicUserDetailsLoader, BasicUserDetailsLoader); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.