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(signature-colletion): remove candidate if all lists removed #16425

Merged
merged 6 commits into from
Oct 16, 2024
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
Expand Up @@ -7,7 +7,6 @@ import {
Collection,
CreateParliamentaryCandidacyInput,
MandateType,
ReasonKey,
SignatureCollectionClientService,
} from '@island.is/clients/signature-collection'
import { errorMessages } from '@island.is/application/templates/signature-collection/parliamentary-list-creation'
Expand Down Expand Up @@ -53,13 +52,11 @@ export class ParliamentaryListCreationService extends BaseTemplateApiService {
405,
)
}
const contactNationalId = isCompany(auth.nationalId)
? auth.actor?.nationalId ?? auth.nationalId
: auth.nationalId
// Candidates are stored on user national id never the actors so should be able to check just the auth national id

if (
currentCollection.candidates.some(
(c) => c.nationalId.replace('-', '') === contactNationalId,
(c) => c.nationalId.replace('-', '') === auth.nationalId,
)
) {
throw new TemplateApiError(errorMessages.alreadyCandidate, 412)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { defineTemplateApi } from '@island.is/application/types'

export const CandidateApi = defineTemplateApi({
action: 'candidate',
order: 0,
})

export const ParliamentaryCollectionApi = defineTemplateApi({
action: 'parliamentaryCollection',
order: 1,
})

export const ParliamentaryIdentityApi = defineTemplateApi({
action: 'parliamentaryIdentity',
order: 2,
})
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const errorMessages = {
},
summary: {
id: 'plc.application:error.alreadyCandidate.summary',
defaultMessage: 'Þú ert nú þegar með framboð',
defaultMessage:
'Þú ert nú þegar með framboð. Þú getur nálgast nánari upplýsingar um þína meðmælasöfnun á Mínum Síðum.',
description: '',
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,21 @@ export class SignatureCollectionClientService {
}),
),
)
// If no lists remain remove Candidate so that they can start a new collection through applications again
await this.checkIfRemoveCandidate(candidate.id, auth)

return { success: true }
}

private async checkIfRemoveCandidate(id: string, auth: User) {
const { ownedLists, candidate } = await this.getSignee(auth)
if ((!ownedLists || ownedLists.length === 0) && candidate?.id) {
await this.getApiWithAuth(this.candidateApi, auth).frambodIDDelete({
iD: parseInt(id),
})
}
}

async getSignedList(auth: User): Promise<SignedList[] | null> {
const { signatures } = await this.getSignee(auth)
const { endTime, isPresidential } = await this.currentCollection()
Expand Down Expand Up @@ -404,7 +416,7 @@ export class SignatureCollectionClientService {
}: CanSignInput): Promise<Success> {
// User is not allowed to have more than one signature
// They are marked as invalid but count as participation
const noInvalidSignature = !signatures?.find((s) => !s.valid) ?? true
const noInvalidSignature = !signatures?.find((s) => !s.valid)

const reasons = mapReasons({
...canSignInfo,
Expand Down
Loading