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

fix(application-plc): Fixes 16.10 batch 2 #16436

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
Injectable,
NotFoundException,
UnauthorizedException,
} from '@nestjs/common'
import { Injectable, NotFoundException } from '@nestjs/common'
import { SignatureCollectionSuccess } from './models/success.model'
import { SignatureCollection } from './models/collection.model'
import {
Expand All @@ -19,11 +15,8 @@ import { User } from '@island.is/auth-nest-tools'
import { SignatureCollectionCancelListsInput } from './dto/cencelLists.input'
import { SignatureCollectionIdInput } from './dto/collectionId.input'
import { SignatureCollectionAddListsInput } from './dto/addLists.input'
import { SignatureCollectionOwnerInput } from './dto/owner.input'
import { SignatureCollectionListBulkUploadInput } from './dto/bulkUpload.input'
import { SignatureCollectionUploadPaperSignatureInput } from './dto/uploadPaperSignature.input'
import { SignatureCollectionCanSignFromPaperInput } from './dto/canSignFromPaper.input'
import { SignatureCollectionCandidateIdInput } from './dto/candidateId.input'
import { SignatureCollectionCollector } from './models/collector.model'

@Injectable()
Expand Down
1 change: 1 addition & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ export const buildMessageWithLinkButtonField = (
): MessageWithLinkButtonField => {
const { id, title, url, message, buttonTitle, marginBottom, marginTop } = data
return {
...extractCommonFields(data),
children: undefined,
id,
title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FetchError } from '@island.is/clients/middlewares'
import { NationalRegistryClientService } from '@island.is/clients/national-registry-v2'
import { isCompany } from 'kennitala'
import { coreErrorMessages } from '@island.is/application/core'
import { AuthDelegationType } from '@island.is/shared/types'

@Injectable()
export class ParliamentaryListCreationService extends BaseTemplateApiService {
Expand Down Expand Up @@ -84,6 +85,15 @@ export class ParliamentaryListCreationService extends BaseTemplateApiService {
return identity
}

async delegatedToCompany({ auth }: TemplateApiModuleActionProps) {
const data = {
delegatedToCompany:
auth.delegationType?.includes(AuthDelegationType.ProcurationHolder) ??
false,
}
return data
}

async submit({ application, auth }: TemplateApiModuleActionProps) {
const answers = application.answers as CreateListSchema
const parliamentaryCollection = application.externalData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,41 @@ export class ParliamentaryListSigningService extends BaseTemplateApiService {
}

async canSign({ auth }: TemplateApiModuleActionProps) {
const signee = await this.signatureCollectionClientService.getSignee(auth)
const { canSign, canSignInfo } = signee
if (canSign) {
return signee
}
if (!canSignInfo) {
// canCreateInfo will always be defined if canCreate is false but we need to check for typescript
try {
const signee = await this.signatureCollectionClientService.getSignee(auth)
const { canSign, canSignInfo } = signee
if (canSign) {
return signee
}
if (!canSignInfo) {
// canCreateInfo will always be defined if canCreate is false but we need to check for typescript
throw new TemplateApiError(errorMessages.deniedByService, 400)
}
const errors: ProviderErrorReason[] = canSignInfo?.map((key) => {
switch (key) {
case ReasonKey.UnderAge:
return errorMessages.age
case ReasonKey.NoCitizenship:
return errorMessages.citizenship
case ReasonKey.NotISResidency:
return errorMessages.residency
case ReasonKey.CollectionNotOpen:
return errorMessages.active
case ReasonKey.AlreadySigned:
return errorMessages.signer
case ReasonKey.noInvalidSignature:
return errorMessages.invalidSignature
default:
return errorMessages.deniedByService
}
})
throw new TemplateApiError(errors, 405)
} catch (error) {
if (error.status === 404) {
throw new TemplateApiError(errorMessages.singeeNotFound, 404)
}
throw new TemplateApiError(errorMessages.deniedByService, 400)
}
const errors: ProviderErrorReason[] = canSignInfo?.map((key) => {
switch (key) {
case ReasonKey.UnderAge:
return errorMessages.age
case ReasonKey.NoCitizenship:
return errorMessages.citizenship
case ReasonKey.NotISResidency:
return errorMessages.residency
case ReasonKey.CollectionNotOpen:
return errorMessages.active
case ReasonKey.AlreadySigned:
return errorMessages.signer
case ReasonKey.noInvalidSignature:
return errorMessages.invalidSignature
default:
return errorMessages.deniedByService
}
})
throw new TemplateApiError(errors, 405)
}

async getList({ auth, application }: TemplateApiModuleActionProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export const ParliamentaryIdentityApi = defineTemplateApi({
action: 'parliamentaryIdentity',
order: 2,
})

export const IsDelegatedToCompanyApi = defineTemplateApi({
action: 'delegatedToCompany',
})
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,33 @@ export const Done: Form = buildForm({
component: 'CopyLink',
}),
buildMessageWithLinkButtonField({
condition: (_, externalData) => {
return !(
externalData?.delegatedToCompany.data as {
delegatedToCompany: boolean
}
).delegatedToCompany
},
id: 'done.goToServicePortal',
title: '',
url: '/minarsidur/min-gogn/listar/althingis-medmaelasofnun',
buttonTitle: m.linkFieldButtonTitle,
message: m.linkFieldMessage,
}),
buildMessageWithLinkButtonField({
condition: (_, externalData) => {
return (
externalData?.delegatedToCompany.data as {
delegatedToCompany: boolean
}
).delegatedToCompany
},
id: 'done.goToServicePortalCompany',
title: '',
url: '/minarsidur/fyrirtaeki/listar/althingis-medmaelasofnun',
buttonTitle: m.linkFieldButtonCompanyTitle,
message: m.linkFieldCompanyMessage,
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ParliamentaryCollectionApi,
CandidateApi,
ParliamentaryIdentityApi,
IsDelegatedToCompanyApi,
} from '../dataProviders'

export const Prerequisites: Form = buildForm({
Expand Down Expand Up @@ -90,6 +91,11 @@ export const Prerequisites: Form = buildForm({
title: '',
subTitle: '',
}),
buildDataProviderItem({
provider: IsDelegatedToCompanyApi,
title: '',
subTitle: '',
}),
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ParliamentaryCollectionApi,
CandidateApi,
ParliamentaryIdentityApi,
IsDelegatedToCompanyApi,
} from '../dataProviders'
import { AuthDelegationType } from '@island.is/shared/types'

Expand Down Expand Up @@ -81,6 +82,7 @@ const createListTemplate: ApplicationTemplate<
CandidateApi,
ParliamentaryCollectionApi,
ParliamentaryIdentityApi,
IsDelegatedToCompanyApi,
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,20 @@ export const m = defineMessages({
linkFieldMessage: {
id: 'plc.application:linkFieldMessage',
defaultMessage:
'Á mínum síðum sést hve mörgum meðmælum hefur verið safnað í hverjum landsfjórðungi.',
'Á mínum síðum sést hve mörgum meðmælum hefur verið safnað í hverju kjördæmi.',
description: '',
},
linkFieldButtonCompanyTitle: {
id: 'plc.application:linkFieldButtonCompanyTitle',
defaultMessage: 'Mínar síður (fyrirtæki)',
description: '',
},
linkFieldCompanyMessage: {
id: 'plc.application:linkFieldCompanyMessage',
defaultMessage:
'Á mínum síðum fyrirtækja sést hve mörgum meðmælum hefur verið safnað í hverju kjördæmi.',
description: '',
},

/* Action Card logs */
logListCreated: {
id: 'plc.application:logListCreated',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const errorMessages = {
active: defineMessages({
title: {
id: 'pls.application:error.active.title',
defaultMessage: 'Ekki er hægt að mæla með framboði.',
defaultMessage: 'Ekki er hægt að mæla með framboði',
description: '',
},
summary: {
Expand Down Expand Up @@ -101,7 +101,7 @@ export const errorMessages = {
maxReached: defineMessages({
title: {
id: 'pls.application:error.maxReached.title',
defaultMessage: 'Framboð hefur náð hámarksfjölda meðmæla.',
defaultMessage: 'Framboð hefur náð hámarksfjölda meðmæla',
description: '',
},
summary: {
Expand All @@ -122,4 +122,18 @@ export const errorMessages = {
description: '',
},
}),
singeeNotFound: defineMessages({
title: {
id: 'pls.application:error.singeeNotFound.title',
defaultMessage:
'Notandi uppfyllir ekki skilyrði til að framkvæma þessa aðgerð',
description: '',
},
summary: {
id: 'pls.application:error.singeeNotFound.summary',
defaultMessage:
'Hægt er að hafa samband við Þjóðskrá fyrir nánari upplýsingar.',
description: '',
},
}),
}
Loading
Loading