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(ids-api): Filter delegated national registry scopes by delegation types. #17354

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -19,13 +19,15 @@ const domainName = faker.random.word()
const identityResources = ['id1', 'id2']

const legalGuardianScopes = ['lg1', 'lg2']
const legalGuardianMinorScopes = ['lgm1', 'lgm2']
const procurationHolderScopes = ['ph1', 'ph2']
const customScopes1 = ['cu1', 'cu2']
const customScopes2 = ['cu3', 'cu4']
const legalRepresentativeScopes = ['lr1', 'lr2']

const apiScopes = [
...legalGuardianScopes,
...legalGuardianMinorScopes,
...procurationHolderScopes,
...customScopes1,
...customScopes2,
Expand All @@ -44,6 +46,9 @@ const supportedDelegationTypes = (scopeName: string): AuthDelegationType[] => {
if (legalGuardianScopes.includes(scopeName)) {
result.push(AuthDelegationType.LegalGuardian)
}
if (legalGuardianMinorScopes.includes(scopeName)) {
result.push(AuthDelegationType.LegalGuardianMinor)
}
if (procurationHolderScopes.includes(scopeName)) {
result.push(AuthDelegationType.ProcurationHolder)
}
Expand Down Expand Up @@ -108,6 +113,18 @@ const testCases: Record<string, TestCase> = {
delegationType: [AuthDelegationType.LegalRepresentative],
expected: [...legalRepresentativeScopes, ...identityResources],
},
'8': {
fromNationalId: createNationalId('person'),
delegationType: [
AuthDelegationType.LegalGuardian,
AuthDelegationType.LegalGuardianMinor,
],
expected: [
...legalGuardianScopes,
...legalGuardianMinorScopes,
...identityResources,
],
},
}

const user = createCurrentUser({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ConfigType } from '@nestjs/config'
import { InjectModel } from '@nestjs/sequelize'
import addDays from 'date-fns/addDays'
import startOfDay from 'date-fns/startOfDay'
import * as kennitala from 'kennitala'
import { Op, Transaction } from 'sequelize'
import { uuid } from 'uuidv4'
import * as kennitala from 'kennitala'

import { SyslumennService } from '@island.is/clients/syslumenn'
import { logger } from '@island.is/logging'
Expand All @@ -21,16 +21,16 @@ import { ApiScope } from '../resources/models/api-scope.model'
import { IdentityResource } from '../resources/models/identity-resource.model'
import { DelegationProviderService } from './delegation-provider.service'
import { DelegationConfig } from './DelegationConfig'
import { ApiScopeInfo } from './delegations-incoming.service'
import { DelegationsIndexService } from './delegations-index.service'
import { UpdateDelegationScopeDTO } from './dto/delegation-scope.dto'
import { DelegationDelegationType } from './models/delegation-delegation-type.model'
import { DelegationScope } from './models/delegation-scope.model'
import { DelegationTypeModel } from './models/delegation-type.model'
import { Delegation } from './models/delegation.model'
import { ApiScopeInfo } from './delegations-incoming.service'
import filterByCustomScopeRule from './utils/filterByScopeCustomScopeRule'

import type { User } from '@island.is/auth-nest-tools'
import filterByCustomScopeRule from './utils/filterByScopeCustomScopeRule'

@Injectable()
export class DelegationScopeService {
Expand Down Expand Up @@ -238,7 +238,9 @@ export class DelegationScopeService {
)
}

private async findAllNationalRegistryScopes(): Promise<string[]> {
private async findAllNationalRegistryScopes(
delegationTypes: string[],
): Promise<string[]> {
const apiScopes = await this.apiScopeModel.findAll({
include: [
{
Expand All @@ -249,6 +251,7 @@ export class DelegationScopeService {
model: DelegationTypeModel,
where: {
provider: AuthDelegationProvider.NationalRegistry,
id: delegationTypes,
},
},
],
Expand Down Expand Up @@ -416,7 +419,7 @@ export class DelegationScopeService {
await this.delegationProviderService.findProviders(delegationTypes)

if (providers.includes(AuthDelegationProvider.NationalRegistry)) {
scopePromises.push(this.findAllNationalRegistryScopes())
scopePromises.push(this.findAllNationalRegistryScopes(delegationTypes))
}

if (providers.includes(AuthDelegationProvider.CompanyRegistry)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export class FixtureFactory {
case AuthDelegationType.Custom:
return AuthDelegationProvider.Custom
case AuthDelegationType.LegalGuardian:
case AuthDelegationType.LegalGuardianMinor:
return AuthDelegationProvider.NationalRegistry
case AuthDelegationType.ProcurationHolder:
return AuthDelegationProvider.CompanyRegistry
Expand Down
Loading