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(auth-admin): Create paper delegation #15992

Merged
merged 87 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
f6cbeb4
created new admin module for paper delegations and get route
GunnlaugurG Aug 23, 2024
a1d6e8d
field resolver DelegationAdminModel
GunnlaugurG Aug 23, 2024
9a8be88
lookup for delegations with detailed view
GunnlaugurG Aug 29, 2024
66f54e2
Cleanup and rest and graphql for DeleteDelegation
GunnlaugurG Sep 3, 2024
00e7c32
small cleanup
GunnlaugurG Sep 3, 2024
eef306e
merge conflict resolved
GunnlaugurG Sep 3, 2024
8023226
chore: nx format:write update dirty files
andes-it Sep 3, 2024
7e1526d
move delegationAdmin service to admin-api from delegation-api
GunnlaugurG Sep 9, 2024
ee0bf10
adds getTicket function to Zendesk service
magnearun Sep 9, 2024
e740714
Adds create delegation route
magnearun Sep 9, 2024
33597a7
chore: nx format:write update dirty files
andes-it Sep 9, 2024
8a11aca
fix config value
GunnlaugurG Sep 9, 2024
f2ca10c
chore: charts update dirty files
andes-it Sep 9, 2024
c6fb163
fix api build issues
GunnlaugurG Sep 9, 2024
0250930
wip gql for create delegation
magnearun Sep 9, 2024
1f47340
fix pr comments
GunnlaugurG Sep 10, 2024
3fc09a5
delegation reference id added
GunnlaugurG Sep 10, 2024
83aef23
added back the spec files
GunnlaugurG Sep 10, 2024
d20a0f2
validate form data and show error messages
magnearun Sep 10, 2024
85b81ee
Merge remote-tracking branch 'origin/feat/delegation-admin-module' in…
magnearun Sep 10, 2024
413a3ef
fix get tests
GunnlaugurG Sep 10, 2024
b43219d
chore: nx format:write update dirty files
andes-it Sep 10, 2024
f996ad8
test for delete
GunnlaugurG Sep 10, 2024
0949237
post method to create delegation between two national id's
GunnlaugurG Sep 10, 2024
e492755
resolve conflict with main
GunnlaugurG Sep 11, 2024
f49506b
Merge remote-tracking branch 'origin/main' into feat/delegation-ui-gql
magnearun Sep 11, 2024
fee4601
Merge branch 'feat/delegation-ui-gql' of github.com:island-is/island.…
magnearun Sep 11, 2024
b1db9f8
zendesk integration complete
GunnlaugurG Sep 12, 2024
3076a2c
remove console log
GunnlaugurG Sep 13, 2024
1494d8f
merged with main
GunnlaugurG Sep 13, 2024
d108d9d
merged with main
GunnlaugurG Sep 13, 2024
f171571
chore: charts update dirty files
andes-it Sep 13, 2024
6518722
chore: nx format:write update dirty files
andes-it Sep 13, 2024
c30579f
adds CreateDelegationConfirm modal and prefills Create form with valu…
magnearun Sep 16, 2024
a80c2bb
Merge remote-tracking branch 'origin/main' into feat/delegation-ui-gql
magnearun Sep 16, 2024
6d546c9
chore: nx format:write update dirty files
andes-it Sep 16, 2024
8daac07
use identity resolver
magnearun Sep 16, 2024
90dd5e5
Merge branch 'feat/delegation-ui-gql' of github.com:island-is/island.…
magnearun Sep 16, 2024
dcef48c
chore: nx format:write update dirty files
andes-it Sep 16, 2024
df0b8ba
created delegation-delegation-type.model.ts and updated findAllScopes…
GunnlaugurG Sep 16, 2024
a99e144
fix broken tests
GunnlaugurG Sep 16, 2024
3d3781c
tests for findAllScopesTo
GunnlaugurG Sep 17, 2024
e6d9fba
added validTo to delegationDelegationType
GunnlaugurG Sep 17, 2024
1753fe1
set general mandate as type in ids select account prompt
GunnlaugurG Sep 18, 2024
062a582
Get general mandate to delegations-to on service-portal
GunnlaugurG Sep 18, 2024
6588ab8
Merge branch 'refs/heads/main' into feat/delegation-delegation-type
GunnlaugurG Sep 19, 2024
7ccc113
remove duplicate case
GunnlaugurG Sep 19, 2024
9daa1f1
small refactor
GunnlaugurG Sep 19, 2024
b16d95f
chore: nx format:write update dirty files
andes-it Sep 19, 2024
884e10e
Mask nationalId in url
magnearun Sep 19, 2024
09d4b6e
format national id
magnearun Sep 19, 2024
707cedd
fix tests after merge with main
GunnlaugurG Sep 19, 2024
9e00806
chore: nx format:write update dirty files
andes-it Sep 19, 2024
713ce21
Merge branch 'main' into feat/delegation-ui-gql
magnearun Sep 19, 2024
880b763
Merge branch 'refs/heads/main' into feat/create-paper-delegation
GunnlaugurG Sep 19, 2024
7907c55
fix duplicate referenceId's
GunnlaugurG Sep 19, 2024
98847f1
fix import
magnearun Sep 20, 2024
e275d90
Merge branch 'feat/delegation-ui-gql' of github.com:island-is/island.…
magnearun Sep 20, 2024
82c5d02
remove console log and unused variables
magnearun Sep 20, 2024
c189682
chore: nx format:write update dirty files
andes-it Sep 20, 2024
f1d8720
Merge remote-tracking branch 'origin/main' into feat/delegation-ui-gql
magnearun Sep 20, 2024
d652ba7
move general mandate tests to new file
GunnlaugurG Sep 20, 2024
1286f75
add zendesk validation
GunnlaugurG Sep 20, 2024
7796b06
feat(auth-admin): Delete delegation UI (#16073)
magnearun Sep 20, 2024
b04cb43
feat(auth-admin): Create paper delegation zendesk integration (#16074)
magnearun Sep 20, 2024
ffc1406
Merge branch 'refs/heads/feat/delegation-ui-gql' into feat/create-pap…
GunnlaugurG Sep 20, 2024
7c1648e
Merge branch 'refs/heads/feat/delegation-delegation-type' into feat/c…
GunnlaugurG Sep 20, 2024
a065c40
connect changes and modify incoming delegations for new ddt table
GunnlaugurG Sep 21, 2024
76f6a98
fix comments from PR
GunnlaugurG Sep 23, 2024
ace2149
fix pr comment
GunnlaugurG Sep 23, 2024
a4f298c
Merge branch 'refs/heads/feat/delegation-delegation-type' into feat/c…
GunnlaugurG Sep 23, 2024
401326d
chore: nx format:write update dirty files
andes-it Sep 23, 2024
d4ab170
chore: nx format:write update dirty files
andes-it Sep 23, 2024
7cd4249
fix pr comment
GunnlaugurG Sep 23, 2024
b65b63b
Merge branch 'refs/heads/main' into feat/create-paper-delegation
GunnlaugurG Sep 23, 2024
113c60c
Merge branch 'refs/heads/feat/delegation-delegation-type' into feat/c…
GunnlaugurG Sep 23, 2024
edb9cce
add tests for create
GunnlaugurG Sep 24, 2024
838df23
Merge branch 'refs/heads/main' into feat/create-paper-delegation
GunnlaugurG Sep 24, 2024
7911fc9
fix pr comments
GunnlaugurG Sep 24, 2024
ef97225
simplify var names
GunnlaugurG Sep 24, 2024
97d41da
Merge branch 'refs/heads/main' into feat/create-paper-delegation
GunnlaugurG Sep 24, 2024
1890e27
chore: nx format:write update dirty files
andes-it Sep 24, 2024
616902d
add index for general mandate
GunnlaugurG Sep 25, 2024
dcdb379
fix pr comments
GunnlaugurG Sep 25, 2024
f132e05
fix pr comments
GunnlaugurG Sep 25, 2024
d060e2b
Merge branch 'main' into feat/create-paper-delegation
kodiakhq[bot] Sep 25, 2024
c694048
Merge branch 'main' into feat/create-paper-delegation
kodiakhq[bot] Sep 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Post,
UseGuards,
Delete,
Query,
} from '@nestjs/common'
import { ApiSecurity, ApiTags } from '@nestjs/swagger'

Expand Down Expand Up @@ -74,7 +75,7 @@ export class MeClientsController {
@CurrentUser() user: User,
@Param('tenantId') tenantId: string,
@Param('clientId') clientId: string,
@Param('includeArchived') includeArchived?: boolean,
@Query('includeArchived') includeArchived?: boolean,
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved
): Promise<AdminClientDto> {
return this.clientsService.findByTenantIdAndClientId(
tenantId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
Body,
Controller,
Delete,
Get,
Headers,
Param,
Post,
UseGuards,
} from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
Expand All @@ -16,8 +18,10 @@ import {
User,
} from '@island.is/auth-nest-tools'
import {
CreatePaperDelegationDto,
DelegationAdminCustomDto,
DelegationAdminCustomService,
DelegationDTO,
} from '@island.is/auth-api-lib'
import { Documentation } from '@island.is/nest/swagger'
import { Audit, AuditService } from '@island.is/nest/audit'
Expand Down Expand Up @@ -65,6 +69,28 @@ export class DelegationAdminController {
)
}

@Post()
@Scopes(DelegationAdminScopes.admin)
@Documentation({
response: { status: 201, type: DelegationDTO },
})
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved
create(
@CurrentUser() user: User,
@Body() delegation: CreatePaperDelegationDto,
): Promise<DelegationDTO> {
return this.auditService.auditPromise(
{
auth: user,
namespace,
action: 'create',
resources: (result) => {
return result?.id ?? undefined
},
},
this.delegationAdminService.createDelegation(user, delegation),
)
}
GunnlaugurG marked this conversation as resolved.
Show resolved Hide resolved

@Delete(':delegationId')
@Scopes(DelegationAdminScopes.admin)
@Documentation({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import request from 'supertest'

import {
getRequestMethod,
setupApp,
setupAppWithoutAuth,
TestApp,
TestEndpointOptions,
} from '@island.is/testing/nest'
import { User } from '@island.is/auth-nest-tools'
import { FixtureFactory } from '@island.is/services/auth/testing'
import { createCurrentUser } from '@island.is/testing/fixtures'
import { DelegationAdminScopes } from '@island.is/auth/scopes'
import { SequelizeConfigService } from '@island.is/auth-api-lib'

import { AppModule } from '../../../app.module'

describe('withoutAuth and permissions', () => {
async function formatUrl(app: TestApp, endpoint: string, user?: User) {
if (!endpoint.includes(':delegation')) {
return endpoint
}
const factory = new FixtureFactory(app)
const domain = await factory.createDomain({
name: 'd1',
apiScopes: [{ name: 's1' }],
})
const delegation = await factory.createCustomDelegation({
fromNationalId: user?.nationalId,
domainName: domain.name,
scopes: [{ scopeName: 's1' }],
})
return endpoint.replace(':delegation', encodeURIComponent(delegation.id))
}

it.each`
method | endpoint
${'GET'} | ${'/delegation-admin'}
${'DELETE'} | ${'/delegation-admin/:delegation'}
`(
'$method $endpoint should return 401 when user is not authenticated',
async ({ method, endpoint }) => {
// Arrange
const app = await setupAppWithoutAuth({
AppModule,
SequelizeConfigService,
dbType: 'postgres',
})
const server = request(app.getHttpServer())
const url = await formatUrl(app, endpoint)

// Act
const res = await getRequestMethod(server, method)(url)

// Assert
expect(res.status).toEqual(401)
expect(res.body).toMatchObject({
status: 401,
type: 'https://httpstatuses.org/401',
title: 'Unauthorized',
})
},
)

it.each`
method | endpoint
${'GET'} | ${'/delegation-admin'}
${'DELETE'} | ${'/delegation-admin/:delegation'}
`(
'$method $endpoint should return 403 Forbidden when user does not have the correct scope',
async ({ method, endpoint }: TestEndpointOptions) => {
// Arrange
const user = createCurrentUser()
const app = await setupApp({
AppModule,
SequelizeConfigService,
user,
dbType: 'postgres',
})
const server = request(app.getHttpServer())
const url = await formatUrl(app, endpoint, user)

// Act
const res = await getRequestMethod(server, method)(url)

// Assert
expect(res.status).toEqual(403)
expect(res.body).toMatchObject({
status: 403,
type: 'https://httpstatuses.org/403',
title: 'Forbidden',
detail: 'Forbidden resource',
})

// CleanUp
app.cleanUp()
},
)

it.each`
method | endpoint
${'DELETE'} | ${'/delegation-admin/:delegation'}
`(
'$method $endpoint should return 403 Forbidden when user does not have the admin scope',
async ({ method, endpoint }: TestEndpointOptions) => {
// Arrange
const user = createCurrentUser({
scope: [DelegationAdminScopes.read],
})
const app = await setupApp({
AppModule,
SequelizeConfigService,
user,
dbType: 'postgres',
})
const server = request(app.getHttpServer())
const url = await formatUrl(app, endpoint, user)

// Act
const res = await getRequestMethod(server, method)(url)

// Assert
expect(res.status).toEqual(403)
expect(res.body).toMatchObject({
status: 403,
type: 'https://httpstatuses.org/403',
title: 'Forbidden',
detail: 'Forbidden resource',
})

// CleanUp
app.cleanUp()
},
)
})
Loading
Loading