Skip to content

Commit

Permalink
feat(signature-collection-api): Expose canSign/info (#16061)
Browse files Browse the repository at this point in the history
* feat(signature-collection-api): Expose canSign/info

* Add success
  • Loading branch information
kksteini authored Sep 19, 2024
1 parent 1cd87ee commit 3716660
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IsString } from 'class-validator'
import { Field, InputType } from '@nestjs/graphql'

@InputType()
export class SignatureCollectionCanSignInput {
@Field()
@IsString()
signeeNationalId!: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ReasonKey } from '@island.is/clients/signature-collection'
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql'

registerEnumType(ReasonKey, { name: 'ReasonKey' })
@ObjectType()
export class CanSignInfo {
@Field(() => [ReasonKey])
reasons?: ReasonKey[]

@Field(() => Boolean)
success!: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CurrentSignee } from './decorators/signee.decorator'
import { ApiScope } from '@island.is/auth/scopes'
import { SignatureCollectionCancelListsInput } from './dto/cencelLists.input'
import { SignatureCollectionIdInput } from './dto/collectionId.input'
import { SignatureCollectionCanSignInput } from './dto/canSign.input'
import { SignatureCollectionAddListsInput } from './dto/addLists.input'
@UseGuards(IdsUserGuard, ScopesGuard, UserAccessGuard)
@Resolver()
Expand Down Expand Up @@ -126,6 +127,19 @@ export class SignatureCollectionResolver {
return signee
}

@Scopes(ApiScope.signatureCollection)
@Query(() => Boolean)
@AccessRequirement(OwnerAccess.AllowActor)
@Audit()
async signatureCollectionCanSign(
@Args('input') input: SignatureCollectionCanSignInput,
@CurrentUser() user: User,
): Promise<boolean> {
return (
await this.signatureCollectionService.signee(user, input.signeeNationalId)
).canSign
}

@Scopes(ApiScope.signatureCollection)
@AccessRequirement(UserAccess.RestrictActor)
@Mutation(() => SignatureCollectionSuccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import { SignatureCollectionNationalIdInput } from './dto/nationalId.input'
import { SignatureCollectionSignatureIdInput } from './dto/signatureId.input'
import { SignatureCollectionIdInput } from './dto/collectionId.input'
import { SignatureCollectionCandidateIdInput } from './dto/candidateId.input'
import { SignatureCollectionCanSignInput } from './dto/canSign.input'
import { ReasonKey } from '@island.is/clients/signature-collection'
import { CanSignInfo } from './models/canSignInfo.model'

@UseGuards(IdsUserGuard, ScopesGuard)
@Scopes(AdminPortalScope.signatureCollectionProcess)
Expand All @@ -42,6 +45,27 @@ export class SignatureCollectionAdminResolver {
private signatureCollectionManagerService: SignatureCollectionManagerService,
) {}

@Query(() => CanSignInfo, { nullable: true })
@Scopes(
AdminPortalScope.signatureCollectionManage,
AdminPortalScope.signatureCollectionProcess,
)
async signatureCollectionAdminCanSignInfo(
@CurrentUser()
user: User,
@Args('input') input: SignatureCollectionCanSignInput,
): Promise<CanSignInfo> {
const canSignInfo = await this.signatureCollectionService.getCanSignInfo(
user,
input.signeeNationalId,
)

return {
reasons: canSignInfo,
success: true,
}
}

@Query(() => SignatureCollection)
@Scopes(
AdminPortalScope.signatureCollectionManage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
import { SignatureCollectionBulk } from './models/bulk.model'
import { SignatureCollectionCandidateLookUp } from './models/signee.model'
import { SignatureCollectionListInput } from './dto/singatureList.input'
import { SignatureCollectionAdminClientService } from '@island.is/clients/signature-collection'
import {
ReasonKey,
SignatureCollectionAdminClientService,
SignatureCollectionClientService,
} from '@island.is/clients/signature-collection'
import { SignatureCollectionExtendDeadlineInput } from './dto/extendDeadline.input'
import { User } from '@island.is/auth-nest-tools'
import { SignatureCollectionListBulkUploadInput } from './dto/bulkUpload.input'
Expand All @@ -22,6 +26,7 @@ import { SignatureCollectionIdInput } from './dto/collectionId.input'
export class SignatureCollectionAdminService {
constructor(
private signatureCollectionClientService: SignatureCollectionAdminClientService,
private signatureCollectionBasicService: SignatureCollectionClientService,
) {}

async currentCollection(user: User): Promise<SignatureCollection> {
Expand All @@ -39,6 +44,15 @@ export class SignatureCollectionAdminService {
return await this.signatureCollectionClientService.getList(listId, user)
}

async getCanSignInfo(
auth: User,
nationalId: string,
): Promise<ReasonKey[] | undefined> {
return (
await this.signatureCollectionBasicService.getSignee(auth, nationalId)
).canSignInfo
}

async signatures(
listId: string,
user: User,
Expand Down

0 comments on commit 3716660

Please sign in to comment.