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

feat(admin-api): Get delegation providers #14943

Merged
merged 33 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c855e2c
created personal representative delegation type and conencted it to g…
GunnlaugurG May 3, 2024
a1e8633
WIP
GunnlaugurG May 8, 2024
895577b
destroy PRDT on PR delete
GunnlaugurG May 8, 2024
530293f
fix tests and CRUD ready
GunnlaugurG May 13, 2024
12c71a2
fix build error for creationOptional
GunnlaugurG May 13, 2024
152c9d0
Fix delegation tests
GunnlaugurG May 14, 2024
b504b94
Fix promise in PersRep tests
GunnlaugurG May 14, 2024
32351ef
Fixing long pg query identifier in personal representative.
saevarma May 14, 2024
fbe8070
fix broken tests
GunnlaugurG May 15, 2024
d895f3c
fix actor delegation tests
GunnlaugurG May 15, 2024
abc2a0b
clear test db in afterAll
GunnlaugurG May 15, 2024
c0402e6
fix pr-public-api tests
GunnlaugurG May 16, 2024
c109cf9
chore: nx format:write update dirty files
andes-it May 16, 2024
83f9c35
Merge branch 'main' into feat/PR-Delegation-Type
GunnlaugurG May 16, 2024
aec2b1f
improved testing for personal represetative
GunnlaugurG May 16, 2024
3a326f3
personal-representative-public.dto.ts ready for prDelegationType
GunnlaugurG May 16, 2024
816f61c
personal-representative-public.dto.ts ready for prDelegationType
GunnlaugurG May 16, 2024
7411d0e
personal-representative-public.dto.ts ready for prDelegationType
GunnlaugurG May 16, 2024
d89c631
cleanup
GunnlaugurG May 16, 2024
5f6a440
pr comment changes
GunnlaugurG May 21, 2024
aff3d94
pr comment changes
GunnlaugurG May 21, 2024
e6eba48
pr comment changes
GunnlaugurG May 21, 2024
c6899ef
fix codegen
GunnlaugurG May 21, 2024
f592eb9
fix failing test
GunnlaugurG May 21, 2024
24d5b06
fix service auth public api tests
GunnlaugurG May 21, 2024
cf3ae76
fix service auth public api tests
GunnlaugurG May 21, 2024
d9d7df6
Initial getProviderAndType changes
GunnlaugurG May 23, 2024
2887604
Pr comment changes
GunnlaugurG May 23, 2024
808d9ef
merged with main
GunnlaugurG May 23, 2024
3215127
move provider controller to admin-api
GunnlaugurG May 27, 2024
7ce7886
removed unused code
GunnlaugurG May 27, 2024
01cc0cc
Merge branch 'main' into feat/getProviderAndType
GunnlaugurG May 27, 2024
00b676c
Merge branch 'main' into feat/getProviderAndType
kodiakhq[bot] May 28, 2024
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
2 changes: 2 additions & 0 deletions apps/services/auth/admin-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ClientsModule as ClientsV2Module } from './v2/clients/clients.module'
import { ClientSecretsModule } from './v2/secrets/client-secrets.module'
import { TenantsModule } from './v2/tenants/tenants.module'
import { ScopesModule } from './v2/scopes/scopes.module'
import { ProvidersModule } from './v2/providers/providers.module'

@Module({
imports: [
Expand All @@ -43,6 +44,7 @@ import { ScopesModule } from './v2/scopes/scopes.module'
ClientsV2Module,
ClientSecretsModule,
ProblemModule,
ProvidersModule,
ScopesModule,
ConfigModule.forRoot({
isGlobal: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Controller, Get, UseGuards } from '@nestjs/common'
import {
Auth,
CurrentAuth,
IdsUserGuard,
Scopes,
ScopesGuard,
} from '@island.is/auth-nest-tools'
import { idsAdminScopes } from '@island.is/auth/scopes'
import { ApiSecurity, ApiTags } from '@nestjs/swagger'
import { Documentation } from '@island.is/nest/swagger'
import {
DelegationProviderService,
PaginatedDelegationProviderDto,
} from '@island.is/auth-api-lib'
import { AuditService } from '@island.is/nest/audit'

@UseGuards(IdsUserGuard, ScopesGuard)
@Scopes(...idsAdminScopes)
@ApiSecurity('ias', idsAdminScopes)
@ApiTags('admin')
@Controller({
path: '/providers',
version: ['2'],
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved
})
export class ProvidersController {
constructor(
private readonly auditService: AuditService,
private readonly delegationProviderService: DelegationProviderService,
) {}

@Get()
@Documentation({
description: 'Fetch all delegationProviders and their delegationTypes',
response: { status: 200, type: PaginatedDelegationProviderDto },
})
async getDelegationProviders(
@CurrentAuth() auth: Auth,
): Promise<PaginatedDelegationProviderDto> {
return this.auditService.auditPromise(
{
auth,
action: 'getDelegationProviders',
resources: (delegations) => delegations.data.map((d) => d.id),
},
this.delegationProviderService.findAll(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common'
import {
ClientsModule,
DelegationProviderService,
} from '@island.is/auth-api-lib'
import { ProvidersController } from './providers.controller'

@Module({
imports: [ClientsModule],
controllers: [ProvidersController],
providers: [DelegationProviderService],
})
export class ProvidersModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { setupApp, TestApp } from '@island.is/testing/nest'
import request from 'supertest'
import { FixtureFactory } from '@island.is/services/auth/testing'
import {
DelegationProviderDto,
SequelizeConfigService,
} from '@island.is/auth-api-lib'
import { AppModule } from '../../../app.module'
import { createCurrentUser } from '@island.is/testing/fixtures'
import { AdminPortalScope } from '@island.is/auth/scopes'

const path = '/v2/providers'

const delegationProviderTypesData = [
{
id: 'custom',
delegationTypes: [
{
id: 'custom:1',
name: 'custom:1',
},
],
},
{
id: 'procuration',
delegationTypes: [
{
id: 'procuration:1',
name: 'procuration:1',
},
{
id: 'procuration:2',
name: 'procuration:2',
},
],
},
]

describe('ProverController', () => {
let app: TestApp
let server: request.SuperTest<request.Test>
let factory: FixtureFactory

describe('authentication and authorization', () => {
it('user with no scopes should not have access to /providers', async () => {
app = await setupApp({
AppModule,
SequelizeConfigService,
user: createCurrentUser(),
dbType: 'postgres',
})
server = request(app.getHttpServer())
factory = new FixtureFactory(app)

const response = await server.get(path)

expect(response.status).toBe(403)
})
})

describe('getDelegationProviders', () => {
beforeAll(async () => {
const user = createCurrentUser({
scope: [AdminPortalScope.idsAdmin],
})

app = await setupApp({
AppModule,
SequelizeConfigService,
user,
dbType: 'postgres',
})
server = request(app.getHttpServer())
factory = new FixtureFactory(app)

for (const { id: dpId, delegationTypes } of delegationProviderTypesData) {
for (const _ of delegationTypes) {
await factory.createDelegationType({ providerId: dpId })
}
}
})

afterAll(async () => {
await app.cleanUp()
})

it('should return all delegation providers and their delegation types', async () => {
// Act
const response = await server.get(path)

// Assert
expect(response.status).toBe(200)
expect(response.body.totalCount).toBe(delegationProviderTypesData.length)
expect(response.body.data.length).toBe(delegationProviderTypesData.length)

response.body.data.forEach((dp: DelegationProviderDto) => {
const expectedDp = delegationProviderTypesData.find(
({ id }) => id === dp.id,
)

expect(expectedDp).toBeDefined()
expect(dp.delegationTypes.length).toBe(
expectedDp?.delegationTypes.length,
)
})
})
})

afterAll(async () => {
await app?.cleanUp()
})
})
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions libs/auth-api-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export * from './lib/delegations/delegations.service'
export * from './lib/delegations/delegations-outgoing.service'
export * from './lib/delegations/delegations-incoming.service'
export * from './lib/delegations/delegations-index.service'
export * from './lib/delegations/delegation-provider.service'
export * from './lib/delegations/delegation-scope.service'
export * from './lib/delegations/delegation-dto.mapper'
export * from './lib/delegations/names.service'
Expand All @@ -41,6 +42,8 @@ export * from './lib/delegations/types/delegationValidity'
export * from './lib/delegations/dto/delegation-scope.dto'
export * from './lib/delegations/dto/delegation.dto'
export * from './lib/delegations/dto/delegation-index.dto'
export * from './lib/delegations/dto/paginated-delegation-provider.dto'
export * from './lib/delegations/dto/delegation-provider.dto'
export * from './lib/delegations/dto/merged-delegation.dto'
export * from './lib/delegations/models/delegation.model'
export * from './lib/delegations/models/delegation.model'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/sequelize'
import { PaginatedDelegationProviderDto } from './dto/paginated-delegation-provider.dto'
import { DelegationProviderModel } from './models/delegation-provider.model'
import { DelegationTypeModel } from './models/delegation-type.model'

@Injectable()
export class DelegationProviderService {
constructor(
@InjectModel(DelegationProviderModel)
private delegationProviderModel: typeof DelegationProviderModel,
@InjectModel(DelegationTypeModel)
private delegationTypeModel: typeof DelegationTypeModel,
) {}

async findAll(): Promise<PaginatedDelegationProviderDto> {
const delegationProviders = await this.delegationProviderModel.findAll({
include: [
{
model: this.delegationTypeModel,
as: 'delegationTypes',
},
],
})

return {
totalCount: delegationProviders.length,
data: delegationProviders.map((dp) => dp.toDTO()),
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: '',
endCursor: '',
},
}
}
}
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions libs/auth-api-lib/src/lib/delegations/delegations.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { DelegationsIndexService } from './delegations-index.service'
import { UserIdentitiesModule } from '../user-identities/user-identities.module'
import { DelegationTypeModel } from './models/delegation-type.model'
import { DelegationProviderModel } from './models/delegation-provider.model'
import { DelegationProviderService } from './delegation-provider.service'

@Module({
imports: [
Expand Down Expand Up @@ -65,13 +66,15 @@ import { DelegationProviderModel } from './models/delegation-provider.model'
DelegationsIncomingCustomService,
DelegationsIncomingRepresentativeService,
DelegationsIndexService,
DelegationProviderService,
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved
],
exports: [
DelegationsService,
DelegationsOutgoingService,
DelegationsIncomingService,
DelegationScopeService,
DelegationsIndexService,
DelegationProviderService,
],
})
export class DelegationsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IsString } from 'class-validator'
import { ApiProperty } from '@nestjs/swagger'
import { DelegationTypeDto } from './delegation-type.dto'

export class DelegationProviderDto {
@IsString()
@ApiProperty()
id!: string

@IsString()
@ApiProperty()
name!: string

@IsString()
@ApiProperty()
description!: string

@ApiProperty({ type: [DelegationTypeDto] })
delegationTypes!: DelegationTypeDto[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsNumber } from 'class-validator'
import { PageInfoDto } from '@island.is/nest/pagination'
import { DelegationProviderDto } from './delegation-provider.dto'

export class PaginatedDelegationProviderDto {
@ApiProperty({ type: [DelegationProviderDto], nullable: true })
data!: DelegationProviderDto[]

@ApiProperty()
pageInfo!: PageInfoDto

@IsNumber()
@ApiProperty()
totalCount!: number
}
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
UpdatedAt,
} from 'sequelize-typescript'
import { DelegationTypeModel } from './delegation-type.model'
import { DelegationProviderDto } from '../dto/delegation-provider.dto'

@Table({
tableName: 'delegation_provider',
Expand Down Expand Up @@ -51,4 +52,13 @@ export class DelegationProviderModel extends Model<

@UpdatedAt
readonly modified?: Date

toDTO(): DelegationProviderDto {
return {
id: this.id,
name: this.name,
description: this.description,
delegationTypes: this.delegationTypes.map((type) => type.toDTO()),
}
}
}
Loading