Skip to content

Commit

Permalink
feat(delegation-api): Add GeneralMandate delegations to accessControl (
Browse files Browse the repository at this point in the history
…#16170)

* delegation-to for access control

* performance fixes

* fix zendesk constants

* small refactor

* small refactor

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
GunnlaugurG and kodiakhq[bot] authored Sep 27, 2024
1 parent 55d69bb commit 3a56c8c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 40 deletions.
4 changes: 2 additions & 2 deletions libs/auth-api-lib/src/lib/delegations/constants/zendesk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const DELEGATION_TAG = 'umsokn_um_umboð_a_mínum_síðum'
export const ZENDESK_CUSTOM_FIELDS = {
DelegationFromReferenceId: 21401464004498,
DelegationToReferenceId: 21401435545234,
DelegationToReferenceId: 21401464004498,
DelegationFromReferenceId: 21401435545234,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { InjectModel } from '@nestjs/sequelize'
import { and, Op, WhereOptions } from 'sequelize'
import { isUuid, uuid } from 'uuidv4'
import startOfDay from 'date-fns/startOfDay'

import { User } from '@island.is/auth-nest-tools'
import { NoContentException } from '@island.is/nest/problem'
Expand Down Expand Up @@ -39,6 +40,8 @@ import {
import { Features } from '@island.is/feature-flags'
import { FeatureFlagService } from '@island.is/nest/feature-flags'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { DelegationDelegationType } from './models/delegation-delegation-type.model'
import { AuthDelegationType } from '@island.is/shared/types'

/**
* Service class for outgoing delegations.
Expand Down Expand Up @@ -68,42 +71,71 @@ export class DelegationsOutgoingService {
if (otherUser) {
return this.findByOtherUser(user, otherUser, domainName)
}
const delegations = await this.delegationModel.findAll({
where: and(
{

const [delegations, delegationTypesDelegations] = await Promise.all([
this.delegationModel.findAll({
where: and(
{
fromNationalId: user.nationalId,
},
domainName ? { domainName } : {},
getDelegationNoActorWhereClause(user),
...(await this.delegationResourceService.apiScopeFilter({
user,
prefix: 'delegationScopes->apiScope',
direction: DelegationDirection.OUTGOING,
})),
),
include: [
{
model: DelegationScope,
include: [
{
attributes: ['displayName'],
model: ApiScope,
required: true,
include: [
...this.delegationResourceService.apiScopeInclude(
user,
DelegationDirection.OUTGOING,
),
],
},
],
required: validity !== DelegationValidity.ALL,
where: getScopeValidityWhereClause(validity),
},
],
}),
this.delegationModel.findAll({
where: {
fromNationalId: user.nationalId,
},
domainName ? { domainName } : {},
getDelegationNoActorWhereClause(user),
...(await this.delegationResourceService.apiScopeFilter({
user,
prefix: 'delegationScopes->apiScope',
direction: DelegationDirection.OUTGOING,
})),
),
include: [
{
model: DelegationScope,
include: [
{
attributes: ['displayName'],
model: ApiScope,
required: true,
include: [
...this.delegationResourceService.apiScopeInclude(
user,
DelegationDirection.OUTGOING,
),
],
include: [
{
model: DelegationDelegationType,
where: {
delegationTypeId: AuthDelegationType.GeneralMandate,
validTo: {
[Op.or]: {
[Op.gte]: startOfDay(new Date()),
[Op.is]: null,
},
},
},
],
required: validity !== DelegationValidity.ALL,
where: getScopeValidityWhereClause(validity),
},
],
})
required: true,
},
],
}),
])

const delegationTypesDTO = delegationTypesDelegations.map((d) =>
d.toDTO(AuthDelegationType.GeneralMandate),
)

const delegationsDTO = delegations.map((d) => d.toDTO())

return delegations.map((d) => d.toDTO())
return [...delegationsDTO, ...delegationTypesDTO]
}

async findByOtherUser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import * as kennitala from 'kennitala'

import {
Box,
Text,
Stack,
Tag,
Inline,
Button,
Icon,
IconMapIcon as IconType,
Button,
Inline,
Stack,
Tag,
Text,
Tooltip,
} from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
Expand Down Expand Up @@ -182,7 +182,9 @@ export const AccessCard = ({
<Box display="flex" justifyContent="spaceBetween" alignItems="flexStart">
<Stack space="smallGutter">
<Box display="flex" columnGap={2} alignItems="center">
{(isAdminView || !isOutgoing) && (
{(isAdminView ||
!isOutgoing ||
delegation.type === AuthDelegationType.GeneralMandate) && (
<>
{renderDelegationTypeLabel(delegation.type)}
{delegation.domain?.name && (
Expand Down

0 comments on commit 3a56c8c

Please sign in to comment.