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(
{
system: true,
namespace,
action: 'createByZendeskId',
resources: (res) => {
return `id: ${res.id}, 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
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
4 changes: 4 additions & 0 deletions libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
@ApiProperty()
toNationalId!: string

@IsString()
@ApiPropertyOptional()
createdByNationalId?: string

@IsString()
@ApiPropertyOptional({ nullable: true, type: String })
toName?: string | null
Expand All @@ -71,7 +75,7 @@
@IsOptional()
@ApiPropertyOptional({ type: [DelegationScopeDTO] })
@IsArray()
scopes?: DelegationScopeDTO[]

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Duplicate identifier 'createdByNationalId'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Subsequent property declarations must have the same type. Property 'createdByNationalId' must be of type 'string | undefined', but here has type 'string | null | undefined'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Duplicate identifier 'createdByNationalId'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Subsequent property declarations must have the same type. Property 'createdByNationalId' must be of type 'string | undefined', but here has type 'string | null | undefined'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Duplicate identifier 'createdByNationalId'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Subsequent property declarations must have the same type. Property 'createdByNationalId' must be of type 'string | undefined', but here has type 'string | null | undefined'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Duplicate identifier 'createdByNationalId'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Subsequent property declarations must have the same type. Property 'createdByNationalId' must be of type 'string | undefined', but here has type 'string | null | undefined'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Duplicate identifier 'createdByNationalId'.

Check failure on line 78 in libs/auth-api-lib/src/lib/delegations/dto/delegation.dto.ts

View workflow job for this annotation

GitHub Actions / prepare

Subsequent property declarations must have the same type. Property 'createdByNationalId' must be of type 'string | undefined', but here has type 'string | null | undefined'.

@IsString()
@ApiPropertyOptional({ type: String, nullable: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export class Delegation extends Model<
fromNationalId: this.fromNationalId,
toNationalId: this.toNationalId,
toName: this.toName,
createdByNationalId: this.createdByNationalId,
validTo: this.validTo,
scopes: this.delegationScopes
? this.delegationScopes.map((scope) => scope.toDTO())
Expand Down
Loading