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): Delegation-admin webhook auditlog #16335

Merged
merged 10 commits into from
Oct 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,24 @@ export class DelegationAdminController {
async createByZendeskId(
@Body() { id }: ZendeskWebhookInputDto,
): Promise<void> {
await this.delegationAdminService.createDelegationByZendeskId(id)
await this.auditService.auditPromise<DelegationDTO>(
{
system: true,
namespace,
action: 'createByZendeskId',
resources: (res) => {
return `id: ${res.id ?? 'Unknown'}, toNationalId: ${
res.toNationalId ?? 'Unknown'
}, fromNationalId: ${
res.fromNationalId ?? 'Unknown'
}, createdByNationalId: ${res.createdByNationalId ?? 'Unknown'}`
},
meta: {
id,
},
},
this.delegationAdminService.createDelegationByZendeskId(id),
)
}

@Delete(':delegationId')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import request from 'supertest'
import bodyParser from 'body-parser'

import {
getRequestMethod,
Expand All @@ -12,8 +11,11 @@ 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 { DelegationDTO, SequelizeConfigService } from '@island.is/auth-api-lib'
import { DelegationAdminCustomService } from '@island.is/auth-api-lib'
import {
DelegationAdminCustomService,
DelegationDTO,
SequelizeConfigService,
} from '@island.is/auth-api-lib'

import { AppModule } from '../../../app.module'
import { includeRawBodyMiddleware } from '@island.is/infra-nest-server'
Expand Down Expand Up @@ -159,7 +161,16 @@ describe('withoutAuth and permissions', () => {

jest
.spyOn(delegationAdminService, 'createDelegationByZendeskId')
.mockImplementation(() => Promise.resolve())
.mockImplementation(() =>
Promise.resolve({
id: '123',
fromNationalId: '1234567890',
fromName: 'Test',
toNationalId: '0987654321',
toName: 'Test',
createdByNationalId: '0101010101',
} as DelegationDTO),
)
})

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class DelegationIndexController {
{
auth: auth,
action: 'createOrUpdateDelegationIndexItem',
namespace,
resources: delegationIndexId,
meta: {
...parsedDelegationInfo,
Expand Down Expand Up @@ -123,6 +124,7 @@ export class DelegationIndexController {
await this.auditService.auditPromise(
{
auth: auth,
namespace,
action: 'removeDelegationIndexItem',
resources: delegationIndexId,
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class DelegationAdminCustomService {
}
}

async createDelegationByZendeskId(zendeskId: string): Promise<void> {
async createDelegationByZendeskId(zendeskId: string): Promise<DelegationDTO> {
const zendeskCase = await this.zendeskService.getTicket(zendeskId)

const {
Expand Down Expand Up @@ -181,13 +181,15 @@ export class DelegationAdminCustomService {

this.verifyTicketCompletion(zendeskCase)

await this.insertDelegation({
const resp = await this.insertDelegation({
fromNationalId,
toNationalId,
referenceId: zendeskId,
validTo: this.formatZendeskDate(validTo),
createdBy: createdByNationalId,
})

return resp.toDTO(AuthDelegationType.GeneralMandate)
}

async createDelegation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ export class DelegationsIndexService {
const [updatedDelegation] = await this.auditService.auditPromise(
{
auth,
action:
'@island.is/auth/delegation-index/create-or-update-delegation-record',
action: 'create-or-update-delegation-record',
namespace: '@island.is/auth/delegation-index',
resources: delegation.toNationalId,
alsoLog: true,
meta: {
Expand All @@ -334,7 +334,8 @@ export class DelegationsIndexService {
await this.auditService.auditPromise(
{
auth,
action: '@island.is/auth/delegation-index/remove-delegation-record',
action: 'remove-delegation-record',
namespace: '@island.is/auth/delegation-index',
resources: delegation.toNationalId,
alsoLog: true,
meta: {
Expand Down Expand Up @@ -438,7 +439,8 @@ export class DelegationsIndexService {
// is the common place to audit updates in the index.
this.auditService.audit({
auth,
action: '@island.is/auth/delegation-index/save-to-index',
action: 'save-to-index',
namespace: '@island.is/auth/delegation-index',
alsoLog: true,
resources: nationalId,
meta: {
Expand Down
Loading