Skip to content

Commit

Permalink
fix(auth-admin): Hotfix: Auditlog for webhook and minor UI fixes (#16414
Browse files Browse the repository at this point in the history
)

* feat(auth-admin): Delegation-admin webhook auditlog (#16335)

* audit log delegation-admin webhook

* log the response in resource and request in meta

* remove audit in decorator

* make createdBy optional

* attempt to fix pipe

* attempt to fix pipe

* merge with main

* fix tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(service-portal): Delete and view delegation in service portal form me list (#16400)

* fixes wrong validTo date in DelegationViewModal and show delete button for outgoing delegation

* remove log

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <[email protected]>

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Magnea Rún Vignisdóttir <[email protected]>
Co-authored-by: andes-it <[email protected]>
  • Loading branch information
4 people authored Oct 16, 2024
1 parent 2c47fc0 commit 415c1e1
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const DelegationViewModal = ({
<IdentityCard
label={formatMessage(m.validTo)}
title={
delegation?.validTo && isValid(delegation.validTo)
delegation?.validTo && isValid(new Date(delegation.validTo))
? format(new Date(delegation?.validTo), 'dd.MM.yyyy')
: formatMessage(m.noValidToDate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,11 @@ export const DelegationsOutgoing = () => {
<AccessCard
key={delegation.id}
delegation={delegation}
onDelete={
!isGeneralMandate
? (delegation) => {
setDelegation(
delegation as AuthCustomDelegationOutgoing,
)
}
: undefined
}
onDelete={(delegation) => {
setDelegation(
delegation as AuthCustomDelegationOutgoing,
)
}}
onEdit={
!isGeneralMandate
? (delegation) =>
Expand Down

0 comments on commit 415c1e1

Please sign in to comment.