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

feat(auth-admin): New delegation hnipp #16176

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e5eebdc
send hnipp when delegation is created
magnearun Sep 23, 2024
d928140
tweaks for user notifications
magnearun Sep 23, 2024
f3b76e9
adds translations for domain name
magnearun Sep 24, 2024
905484c
send hnipp to fromNationalId about delegation created
magnearun Sep 25, 2024
d199c97
chore: nx format:write update dirty files
andes-it Sep 26, 2024
943d4bf
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Sep 26, 2024
6bd2a73
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Sep 26, 2024
25f838c
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Sep 27, 2024
46eab26
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Sep 27, 2024
c178b89
Merge remote-tracking branch 'origin/main' into feat/new-delegation-h…
magnearun Oct 2, 2024
f9fc77c
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 3, 2024
20edb6e
fix logger type
magnearun Oct 3, 2024
fdf4ffa
Merge branch 'feat/new-delegation-hnipp' of github.com:island-is/isla…
magnearun Oct 3, 2024
eecdf2a
chore: nx format:write update dirty files
andes-it Oct 3, 2024
97a4b2a
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 3, 2024
83ff119
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 3, 2024
4e4e389
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 3, 2024
19f6f05
fix error logs
magnearun Oct 3, 2024
29af81e
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 4, 2024
ff2853e
do not await notification when creating delegation
magnearun Oct 4, 2024
7bfe35c
Merge branch 'feat/new-delegation-hnipp' of github.com:island-is/isla…
magnearun Oct 4, 2024
f9b159e
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 4, 2024
80d98f5
Merge remote-tracking branch 'origin/main' into feat/new-delegation-h…
magnearun Oct 25, 2024
0cc1cf9
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 25, 2024
81e60a3
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 29, 2024
7341945
Merge branch 'main' into feat/new-delegation-hnipp
magnearun Oct 30, 2024
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
9 changes: 8 additions & 1 deletion apps/services/auth/admin-api/infra/auth-admin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions apps/services/auth/admin-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { TenantsModule } from './v2/tenants/tenants.module'
XRoadConfig,
IdsClientConfig,
SyslumennClientConfig,
DelegationApiUserSystemNotificationConfig,
],
envFilePath: ['.env', '.env.secret'],
}),
Expand Down
1 change: 1 addition & 0 deletions charts/identity-server/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions charts/identity-server/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions charts/identity-server/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 3 additions & 1 deletion infra/src/uber-charts/identity-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions infra/src/uber-charts/islandis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ const sessionsService = sessionsServiceSetup()
const sessionsWorker = sessionsWorkerSetup()
const sessionsCleanupWorker = sessionsCleanupWorkerSetup()

const authAdminApi = authAdminApiSetup()

const universityGatewayService = universityGatewaySetup()
const universityGatewayWorker = universityGatewayWorkerSetup()

const userNotificationService = userNotificationServiceSetup({
userProfileApi: servicePortalApi,
})

const authAdminApi = authAdminApiSetup({
userNotification: userNotificationService,
})
const api = apiSetup({
appSystemApi,
servicePortalApi,
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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'

@Injectable()
Expand All @@ -42,10 +53,82 @@ 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,
)

magnearun marked this conversation as resolved.
Show resolved Hide resolved
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`,
e,
)
}
magnearun marked this conversation as resolved.
Show resolved Hide resolved

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`,
e,
)
}
magnearun marked this conversation as resolved.
Show resolved Hide resolved
}

private getNationalIdsFromZendeskTicket(ticket: Ticket): {
fromReferenceId: string
toReferenceId: string
Expand Down Expand Up @@ -212,6 +295,13 @@ export class DelegationAdminCustomService {
// Index delegations for the toNationalId
void this.indexDelegations(delegation.toNationalId, user)

await this.notifyDelegationCreated({
user,
delegation: newDelegation,
fromName: fromDisplayName,
toName,
})

return newDelegation.toDTO(AuthDelegationType.GeneralMandate)
magnearun marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
4 changes: 4 additions & 0 deletions libs/auth-api-lib/src/lib/delegations/constants/hnipp.ts
Original file line number Diff line number Diff line change
@@ -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'
Loading