Skip to content

Commit

Permalink
chore(inao-pp-cem): dataverse check and template-api-module adjustmen…
Browse files Browse the repository at this point in the history
…ts (#16958)

* feat: add in the dataverse check before you enter the application

* feat: adjust cemetery client

* chore: remove console.dir

* chore: remove unused imports

* chore: remove console.log

* chore: remove unused imports

* chore: change codeowners of inao client

* fix: remove delegation check once you are in the application

* chore: remove fakeUser, not used any more

* chore: add documentation

* chore: edit not allowed permissions

* feat: change financial-statements codeowner to Norda by Programm request

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
jonnigs and kodiakhq[bot] authored Nov 22, 2024
1 parent 9997637 commit 20768c5
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 170 deletions.
8 changes: 4 additions & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ codemagic.yaml
/libs/application/template-api-modules/src/lib/modules/templates/general-fishing-license/ @island-is/norda
/libs/application/template-api-modules/src/lib/modules/templates/data-protection-complaint/ @island-is/norda
/libs/shared/form-fields/ @island-is/norda @island-is/island-ui
/libs/clients/financial-statements-inao @island-is/norda
/libs/api/domains/financial-statements-inao/ @island-is/norda
/libs/application/templates/financial-statements-inao/ @island-is/norda
/libs/application/template-api-modules/src/lib/modules/templates/financial-statements-inao @island-is/norda

/libs/portals/my-pages/applications/ @island-is/norda-applications
/libs/portals/admin/application-system/ @island-is/norda-applications
Expand Down Expand Up @@ -315,10 +319,6 @@ codemagic.yaml

/apps/services/auth/personal-representative/ @island-is/programm @island-is/aranja
/apps/services/auth/personal-representative-public/ @island-is/programm @island-is/aranja
/libs/api/domains/financial-statements-inao/ @island-is/programm
/libs/clients/financial-statements-inao @island-is/programm
/libs/application/templates/financial-statements-inao/ @island-is/programm
/libs/application/template-api-modules/src/lib/modules/templates/financial-statements-inao @island-is/programm

/libs/application/templates/criminal-record/ @island-is/origo
/libs/application/template-api-modules/src/lib/modules/templates/criminal-record-submission/ @island-is/origo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { LOGGER_PROVIDER } from '@island.is/logging'
import {
CemeteryFinancialStatementValues,
FinancialStatementsInaoClientService,
ClientRoles,
} from '@island.is/clients/financial-statements-inao'
import {
ApplicationTypes,
Expand Down Expand Up @@ -33,16 +32,14 @@ export interface DataResponse {
}

export const getCurrentUserType = (
answers: Application['answers'],
_answers: Application['answers'],
externalData: Application['externalData'],
) => {
const fakeUserType: any = getValueViaPath(answers, 'fakeData.options')

const currentUserType: any = getValueViaPath(
const currentUserType = getValueViaPath<number>(
externalData,
'getUserType.data.value',
)
return fakeUserType ?? currentUserType
return currentUserType
}

export class FinancialStatementCemeteryTemplateService extends BaseTemplateApiService {
Expand Down Expand Up @@ -86,9 +83,7 @@ export class FinancialStatementCemeteryTemplateService extends BaseTemplateApiSe
async getUserType({ auth }: TemplateApiModuleActionProps) {
const { nationalId } = auth
if (kennitala.isPerson(nationalId)) {
return this.financialStatementClientService.getClientType(
ClientRoles.Individual,
)
return null
} else {
return this.financialStatementClientService.getUserClientType(nationalId)
}
Expand All @@ -97,63 +92,51 @@ export class FinancialStatementCemeteryTemplateService extends BaseTemplateApiSe
async submitApplication({ application, auth }: TemplateApiModuleActionProps) {
const { nationalId, actor } = auth
const answers = application.answers
const externalData = application.externalData
const currentUserType = getCurrentUserType(answers, externalData)

// Todo test before this goes live
// if (currentUserType !== FSIUSERTYPE.CEMETRY) {
// throw new Error('Application submission failed')
// }

if (!actor) {
return new Error('Enginn umboðsmaður fannst')
}

const values: CemeteryFinancialStatementValues =
mapValuesToCemeterytype(answers)

const values = this.prepareValues(application)
const client = { nationalId }
const { year, actorsName, contactsAnswer, clientPhone, clientEmail, file } =
getNeededCemeteryValues(answers)

const digitalSignee = mapDigitalSignee(clientEmail, clientPhone)
const fileName = file ? await this.getAttachments(application) : undefined

const client = { nationalId }

const contacts = mapContactsAnswersToContacts(
actor,
actorsName,
contactsAnswer,
)
const digitalSignee = mapDigitalSignee(clientEmail, clientPhone)

const result: DataResponse = await this.financialStatementClientService
.postFinancialStatementForCemetery(
client,
contacts,
digitalSignee,
year,
'',
values,
fileName,
)
.then((data) => {
if (data === true) {
return { success: true }
} else {
return { success: false }
}
})
.catch((e) => {
return {
success: false,
errorMessages: e.message,
}
})

if (!result.success) {
throw new Error('Application submission failed')
try {
const result =
await this.financialStatementClientService.postFinancialStatementForCemetery(
client,
contacts,
digitalSignee,
year,
'',
values,
fileName,
)

if (!result) {
throw new Error('Application submission failed')
}

return { success: true }
} catch (error) {
this.logger.error('Error submitting application', error)
return {
success: false,
message: error.message,
}
}
}

return { success: result.success }
private prepareValues(
application: Application,
): CemeteryFinancialStatementValues {
return mapValuesToCemeterytype(application.answers)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ export interface DataResponse {
}

export const getCurrentUserType = (
answers: Application['answers'],
_answers: Application['answers'],
externalData: Application['externalData'],
) => {
const currentUserType = getValueViaPath<number>(
externalData,
'getUserType.data.value',
)

const fakeUserType = getValueViaPath<number>(answers, 'fakeData.options')

return fakeUserType ?? currentUserType
return currentUserType
}

@Injectable()
Expand Down Expand Up @@ -89,7 +87,7 @@ export class FinancialStatementPoliticalPartyTemplateService extends BaseTemplat
async getUserType({ auth }: TemplateApiModuleActionProps) {
const { nationalId } = auth
if (kennitala.isPerson(nationalId)) {
return this.financialStatementClientService.getClientType('Einstaklingur')
return null
} else {
return this.financialStatementClientService.getUserClientType(nationalId)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export { KeyNumbersCapital } from './KeyNumbersCapital'
export { CemeteryEquities } from './CemeteryEquities'
export { OperatingYear } from './OperatingYear'
export { PowerOfAttorneyFields } from './PowerOfAttorney'
export { DelegationCheck } from './DelegationCheck'
export { CemeteryOverview } from './CemeteryOverview'
export { Success } from './Success'
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ export const clientInfoSection = buildSection({
return userProfile.mobilePhoneNumber
},
}),
buildCustomField({
id: 'delegation check',
component: 'DelegationCheck',
title: '',
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { buildForm } from '@island.is/application/core'
import { notAllowedSection } from './notAllowedSection'
import Logo from '../../components/Logo'

export const notAllowedForm = buildForm({
id: 'notAllowedForm',
title: '',
logo: Logo,
children: [notAllowedSection],
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
buildDescriptionField,
buildSection,
} from '@island.is/application/core'
import { m } from '../../lib/messages'

export const notAllowedSection = buildSection({
id: 'notAllowedSection',
title: '',
children: [
buildDescriptionField({
id: 'notAllowedDescription',
title: m.notAllowedTitle,
description: m.notAllowedDescription,
}),
],
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
DefaultStateLifeCycle,
pruneAfterDays,
getValueViaPath,
} from '@island.is/application/core'

import {
ApplicationTemplate,
ApplicationTypes,
Expand All @@ -17,7 +17,6 @@ import {
import { m } from './messages'
import { AuthDelegationType } from '@island.is/shared/types'
import { dataSchema } from './dataSchema'

import {
CurrentUserTypeProvider,
IndentityApiProvider,
Expand All @@ -26,6 +25,7 @@ import {
} from '../dataProviders'
import { ApiActions, Events, Roles, States } from '../types/types'
import { Features } from '@island.is/feature-flags'
import { CEMETERY_USER_TYPE } from '../utils/constants'

const configuration =
ApplicationConfigurations[ApplicationTypes.FINANCIAL_STATEMENT_CEMETERY]
Expand All @@ -50,6 +50,10 @@ const FinancialStatementCemeteryTemplate: ApplicationTemplate<
name: States.PREREQUISITES,
progress: 0,
status: 'draft',
onEntry: defineTemplateApi({
action: ApiActions.getUserType,
shouldPersistToExternalData: true,
}),
actionCard: {
pendingAction: {
title: '',
Expand Down Expand Up @@ -80,6 +84,14 @@ const FinancialStatementCemeteryTemplate: ApplicationTemplate<
UserInfoApi,
],
},
{
id: Roles.NOTALLOWED,
formLoader: () =>
import('../forms/notAllowed').then((val) =>
Promise.resolve(val.notAllowedForm),
),
read: 'all',
},
],
},
on: {
Expand Down Expand Up @@ -136,13 +148,18 @@ const FinancialStatementCemeteryTemplate: ApplicationTemplate<
},
},
mapUserToRole(
nationalId: string,
_nationalId: string,
application: Application,
): ApplicationRole | undefined {
if (application.applicant === nationalId) {
const userType = getValueViaPath<number>(
application.externalData,
'getUserType.data.value',
)

if (userType === CEMETERY_USER_TYPE) {
return Roles.APPLICANT
}
return undefined
return Roles.NOTALLOWED
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,16 @@ export const m = defineMessages({
defaultMessage: 'Áfram',
description: 'continue',
},
notAllowedTitle: {
id: 'fsc.application:notAllowedTitle',
defaultMessage:
'Þessi kennitala er ekki skráð sem kirkjugarður hjá Ríkisendurskoðun',
description: 'Title when user is not allowed to apply',
},
notAllowedDescription: {
id: 'fsc.application:notAllowedDescription',
defaultMessage:
'Ef þú telur að þessi kennitala ætti að vera skráð sem kirkjugarður þá bendum við þér á að hafa samband við Ríkisendurskoðun í síma 448 8800',
description: 'Descriptionwhen user is not allowed to apply',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export enum States {

export enum Roles {
APPLICANT = 'applicant',
NOTALLOWED = 'notAllowed',
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const PartiesBackwardLimit = 'PartiesBackwardLimit'
export const CemeteriesBackwardLimit = 'CemeteriesBackwardLimit'
export const PartiesYearAllowed = 'PartiesYearAllowed'
export const CemeteriesYearAllowed = 'CemeteriesYearAllowed'
export const CEMETERY_USER_TYPE = 150000002 // Number that comes from the INAO API

// error helpers
export const VALIDATOR = 'validator'
Expand Down
Loading

0 comments on commit 20768c5

Please sign in to comment.