diff --git a/apps/services/auth/admin-api/infra/auth-admin-api.ts b/apps/services/auth/admin-api/infra/auth-admin-api.ts index 0fc25a62d5d4..cd31946663a2 100644 --- a/apps/services/auth/admin-api/infra/auth-admin-api.ts +++ b/apps/services/auth/admin-api/infra/auth-admin-api.ts @@ -18,7 +18,9 @@ const REDIS_NODE_CONFIG = { ]), } -export const serviceSetup = (): ServiceBuilder<'services-auth-admin-api'> => { +export const serviceSetup = (services: { + userNotification: ServiceBuilder<'user-notification'> +}): ServiceBuilder<'services-auth-admin-api'> => { return service('services-auth-admin-api') .namespace('identity-server-admin') .image('services-auth-admin-api') @@ -53,6 +55,11 @@ export const serviceSetup = (): ServiceBuilder<'services-auth-admin-api'> => { }, XROAD_NATIONAL_REGISTRY_REDIS_NODES: REDIS_NODE_CONFIG, XROAD_RSK_PROCURING_REDIS_NODES: REDIS_NODE_CONFIG, + USER_NOTIFICATION_API_URL: { + dev: ref((h) => `http://${h.svc(services.userNotification)}`), + staging: ref((h) => `http://${h.svc(services.userNotification)}`), + prod: 'https://user-notification.internal.island.is', + }, COMPANY_REGISTRY_XROAD_PROVIDER_ID: { dev: 'IS-DEV/GOV/10006/Skatturinn/ft-v1', staging: 'IS-TEST/GOV/5402696029/Skatturinn/ft-v1', diff --git a/apps/services/auth/admin-api/src/app/app.module.ts b/apps/services/auth/admin-api/src/app/app.module.ts index 305deb6362b6..c18248413aef 100644 --- a/apps/services/auth/admin-api/src/app/app.module.ts +++ b/apps/services/auth/admin-api/src/app/app.module.ts @@ -65,6 +65,7 @@ import { TenantsModule } from './v2/tenants/tenants.module' XRoadConfig, IdsClientConfig, SyslumennClientConfig, + DelegationApiUserSystemNotificationConfig, ], envFilePath: ['.env', '.env.secret'], }), diff --git a/charts/identity-server/values.dev.yaml b/charts/identity-server/values.dev.yaml index c9f3dca4c65a..d218db6acc58 100644 --- a/charts/identity-server/values.dev.yaml +++ b/charts/identity-server/values.dev.yaml @@ -227,6 +227,7 @@ services-auth-admin-api: SERVERSIDE_FEATURES_ON: '' SYSLUMENN_HOST: 'https://api.syslumenn.is/staging' SYSLUMENN_TIMEOUT: '3000' + USER_NOTIFICATION_API_URL: 'http://web-user-notification.user-notification.svc.cluster.local' XROAD_BASE_PATH: 'http://securityserver.dev01.devland.is' XROAD_BASE_PATH_WITH_ENV: 'http://securityserver.dev01.devland.is/r1/IS-DEV' XROAD_CLIENT_ID: 'IS-DEV/GOV/10000/island-is-client' diff --git a/charts/identity-server/values.prod.yaml b/charts/identity-server/values.prod.yaml index 58e9d76a535b..5e7cc7fc4de0 100644 --- a/charts/identity-server/values.prod.yaml +++ b/charts/identity-server/values.prod.yaml @@ -224,6 +224,7 @@ services-auth-admin-api: SERVERSIDE_FEATURES_ON: 'driving-license-use-v1-endpoint-for-v2-comms' SYSLUMENN_HOST: 'https://api.syslumenn.is/api' SYSLUMENN_TIMEOUT: '3000' + USER_NOTIFICATION_API_URL: 'https://user-notification.internal.island.is' XROAD_BASE_PATH: 'http://securityserver.island.is' XROAD_BASE_PATH_WITH_ENV: 'http://securityserver.island.is/r1/IS' XROAD_CLIENT_ID: 'IS/GOV/5501692829/island-is-client' diff --git a/charts/identity-server/values.staging.yaml b/charts/identity-server/values.staging.yaml index 07afb0776b4c..e782a8209a4b 100644 --- a/charts/identity-server/values.staging.yaml +++ b/charts/identity-server/values.staging.yaml @@ -227,6 +227,7 @@ services-auth-admin-api: SERVERSIDE_FEATURES_ON: '' SYSLUMENN_HOST: 'https://api.syslumenn.is/staging' SYSLUMENN_TIMEOUT: '3000' + USER_NOTIFICATION_API_URL: 'http://web-user-notification.user-notification.svc.cluster.local' XROAD_BASE_PATH: 'http://securityserver.staging01.devland.is' XROAD_BASE_PATH_WITH_ENV: 'http://securityserver.staging01.devland.is/r1/IS-TEST' XROAD_CLIENT_ID: 'IS-TEST/GOV/5501692829/island-is-client' diff --git a/infra/src/uber-charts/identity-server.ts b/infra/src/uber-charts/identity-server.ts index c1c8d803159d..3d77f6fc7f28 100644 --- a/infra/src/uber-charts/identity-server.ts +++ b/infra/src/uber-charts/identity-server.ts @@ -21,7 +21,9 @@ const userNotification = userNotificationServiceSetup({ const authIdsApi = authIdsApiSetup() const identityServer = identityServerSetup({ authIdsApi }) const authAdminWeb = authAdminWebSetup() -const authAdminApi = authAdminApiSetup() +const authAdminApi = authAdminApiSetup({ + userNotification, +}) const authPublicApi = authPublicApiSetup() const authDelegationApi = authDelegationApiSetup({ userNotification, diff --git a/infra/src/uber-charts/islandis.ts b/infra/src/uber-charts/islandis.ts index 548a918b3613..da4635b89d0e 100644 --- a/infra/src/uber-charts/islandis.ts +++ b/infra/src/uber-charts/islandis.ts @@ -94,11 +94,13 @@ const sessionsService = sessionsServiceSetup() const sessionsWorker = sessionsWorkerSetup() const sessionsCleanupWorker = sessionsCleanupWorkerSetup() -const authAdminApi = authAdminApiSetup() - const universityGatewayService = universityGatewaySetup() const universityGatewayWorker = universityGatewayWorkerSetup() +const authAdminApi = authAdminApiSetup({ + userNotification: userNotificationService, +}) + const api = apiSetup({ appSystemApi, servicePortalApi, diff --git a/libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts b/libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts index 5cbb11d913b5..4fc35f08119e 100644 --- a/libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts +++ b/libs/auth-api-lib/src/lib/delegations/admin/delegation-admin-custom.service.ts @@ -1,4 +1,4 @@ -import { BadRequestException, HttpStatus, Injectable } from '@nestjs/common' +import { BadRequestException, Inject, Injectable } from '@nestjs/common' import { InjectModel } from '@nestjs/sequelize' import { Sequelize } from 'sequelize-typescript' import kennitala from 'kennitala' @@ -28,6 +28,17 @@ import { DELEGATION_TAG, ZENDESK_CUSTOM_FIELDS } from '../constants/zendesk' import { DelegationDelegationType } from '../models/delegation-delegation-type.model' import { DelegationsIncomingCustomService } from '../delegations-incoming-custom.service' import { DelegationValidity } from '../types/delegationValidity' +import { + DOMAIN_NAME_EN, + DOMAIN_NAME_IS, + NEW_DELEGATION_FROM_TEMPLATE_ID, + NEW_DELEGATION_TEMPLATE_ID, +} from '../constants/hnipp' +import { LOGGER_PROVIDER } from '@island.is/logging' +import type { Logger } from '@island.is/logging' +import { NotificationsApi } from '../../user-notification' +import { Features } from '@island.is/feature-flags' +import { FeatureFlagService } from '@island.is/nest/feature-flags' import { ErrorCodes } from '@island.is/shared/utils' import { Op } from 'sequelize' @@ -43,9 +54,81 @@ export class DelegationAdminCustomService { private delegationsIncomingCustomService: DelegationsIncomingCustomService, private delegationIndexService: DelegationsIndexService, private delegationScopeService: DelegationScopeService, + private notificationsApi: NotificationsApi, private namesService: NamesService, + private featureFlagService: FeatureFlagService, private sequelize: Sequelize, + @Inject(LOGGER_PROVIDER) + private logger: Logger, ) {} + + private async notifyDelegationCreated({ + user, + delegation, + fromName, + toName, + }: { + user: User + delegation: Delegation + fromName: string + toName: string + }) { + const allowDelegationNotification = await this.featureFlagService.getValue( + Features.isDelegationNotificationEnabled, + false, + user, + ) + + if (!allowDelegationNotification) { + return + } + + try { + // Notify toNationalId of new delegation + await this.notificationsApi.notificationsControllerCreateHnippNotification( + { + createHnippNotificationDto: { + args: [ + { key: 'name', value: fromName }, + { + key: 'domainNameIs', + value: DOMAIN_NAME_IS, + }, + { + key: 'domainNameEn', + value: DOMAIN_NAME_EN, + }, + ], + recipient: delegation.toNationalId, + templateId: NEW_DELEGATION_TEMPLATE_ID, + }, + }, + ) + } catch (e) { + this.logger.error( + `Failed to send delegation notification to delegation representative`, + { error: e.message }, + ) + } + + try { + // Notify fromNationalId of new delegation + await this.notificationsApi.notificationsControllerCreateHnippNotification( + { + createHnippNotificationDto: { + args: [{ key: 'name', value: toName }], + recipient: delegation.fromNationalId, + templateId: NEW_DELEGATION_FROM_TEMPLATE_ID, + }, + }, + ) + } catch (e) { + this.logger.error( + `Failed to send delegation notification to delegation provider`, + { error: e.message }, + ) + } + } private getZendeskCustomFields(ticket: Ticket): { fromReferenceId: string @@ -220,6 +303,13 @@ export class DelegationAdminCustomService { // Index delegations for the toNationalId void this.indexDelegations(delegation.toNationalId, user) + void this.notifyDelegationCreated({ + user, + delegation: newDelegation, + fromName: fromDisplayName, + toName, + }) + return newDelegation.toDTO(AuthDelegationType.GeneralMandate) } diff --git a/libs/auth-api-lib/src/lib/delegations/constants/hnipp.ts b/libs/auth-api-lib/src/lib/delegations/constants/hnipp.ts index 26ea249a12c8..79b5d6c12ae5 100644 --- a/libs/auth-api-lib/src/lib/delegations/constants/hnipp.ts +++ b/libs/auth-api-lib/src/lib/delegations/constants/hnipp.ts @@ -1,2 +1,6 @@ export const NEW_DELEGATION_TEMPLATE_ID = 'HNIPP.UMBOD.NYTT' +export const NEW_DELEGATION_FROM_TEMPLATE_ID = 'HNIPP.UMBOD.NYTT.FRA' export const UPDATED_DELEGATION_TEMPLATE_ID = 'HNIPP.UMBOD.UPPFAERT' + +export const DOMAIN_NAME_IS = 'opinberar stafrænar þjónustur' +export const DOMAIN_NAME_EN = 'public digital services'