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): View delegation and refactor access card #16243

Merged
merged 34 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
19f96d3
refactor AccessCard component and make change to modal to view delega…
magnearun Oct 2, 2024
0296d1f
remove unused createdBy
magnearun Oct 2, 2024
512ba57
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 2, 2024
7290910
chore: nx format:write update dirty files
andes-it Oct 2, 2024
8cee9be
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 3, 2024
e91f452
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 3, 2024
2303c7d
refactor
magnearun Oct 3, 2024
6959a33
fix typo
magnearun Oct 3, 2024
c84172e
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 3, 2024
bde8db5
chore: nx format:write update dirty files
andes-it Oct 3, 2024
ce27735
fix type
magnearun Oct 3, 2024
0da454c
Merge branch 'feat/view-delegation-and-refactor-access-card' of githu…
magnearun Oct 3, 2024
4d049bf
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 3, 2024
caedd71
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 3, 2024
64a1340
small refactor
magnearun Oct 4, 2024
1a26eec
fix delete function
magnearun Oct 4, 2024
c5d0ec0
chore: nx format:write update dirty files
andes-it Oct 4, 2024
a7dba72
Adds delete modal
magnearun Oct 7, 2024
31170ed
Merge branch 'feat/view-delegation-and-refactor-access-card' of githu…
magnearun Oct 7, 2024
a139245
chore: nx format:write update dirty files
andes-it Oct 7, 2024
28e3a1b
Update DelegationDeleteModal.tsx
magnearun Oct 7, 2024
c6da799
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 7, 2024
497f618
adds loading to create modal
magnearun Oct 7, 2024
3fd7778
Merge branch 'feat/view-delegation-and-refactor-access-card' of githu…
magnearun Oct 7, 2024
338d608
chore: nx format:write update dirty files
andes-it Oct 7, 2024
c4f800b
small fixes and use view delegation modal in admin portal
magnearun Oct 8, 2024
33d0b14
Update AccessCard.tsx
magnearun Oct 8, 2024
937c10e
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 8, 2024
09f8e28
chore: nx format:write update dirty files
andes-it Oct 8, 2024
34d9e2d
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 8, 2024
31fd8d9
fix query and types
magnearun Oct 9, 2024
e7596c1
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
magnearun Oct 9, 2024
7895f49
chore: nx format:write update dirty files
andes-it Oct 9, 2024
1d9272b
Merge branch 'main' into feat/view-delegation-and-refactor-access-card
kodiakhq[bot] Oct 9, 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 @@ -91,6 +91,17 @@ export class DelegationAdminResolver {
return identityLoader.load(customDelegation.toNationalId)
}

@ResolveField('createdBy', () => Identity, { nullable: true })
resolveCreatedByIdentity(
@Loader(IdentityLoader) identityLoader: IdentityDataLoader,
@Parent() customDelegation: DelegationDTO,
) {
if (!customDelegation.createdByNationalId) {
return null
}
return identityLoader.load(customDelegation.createdByNationalId)
}

@ResolveField('validTo', () => Date, { nullable: true })
resolveValidTo(@Parent() delegation: DelegationDTO): Date | undefined {
if (!delegation.validTo) {
Expand Down
3 changes: 3 additions & 0 deletions libs/api/domains/auth/src/lib/models/delegation.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export abstract class Delegation {
@Field(() => Identity)
to!: Identity

@Field(() => Identity, { nullable: true })
createdBy?: Identity

@Field(() => AuthDelegationType)
type!: AuthDelegationType

Expand Down
11 changes: 11 additions & 0 deletions libs/api/domains/auth/src/lib/resolvers/delegation.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ export class DelegationResolver {
)
}

@ResolveField('createdBy', () => Identity, { nullable: true })
async resolveCreatedBy(
@Parent() delegation: DelegationDTO,
): Promise<Identity | null> {
if (!delegation.createdByNationalId) {
return null
}

return this.identityService.getIdentity(delegation.createdByNationalId)
}

@ResolveField('validTo', () => Date, { nullable: true })
resolveValidTo(@Parent() delegation: DelegationDTO): Date | undefined {
if (!delegation.validTo) {
Expand Down
5 changes: 5 additions & 0 deletions libs/api/mocks/src/domains/auth/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const customDelegation = factory<AuthCustomDelegation>({
name: faker.name.findName(),
type: 'Person',
}),
createdBy: () => ({
nationalId: createNationalId('person'),
name: faker.name.findName(),
type: 'Person',
}),
type: 'Custom',
provider: 'delegationdb',
scopes: () => delegationScope.list(5),
Expand Down
5 changes: 5 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 @@ -68,6 +68,11 @@ export class DelegationDTO {
@IsString()
referenceId?: string | null

@IsOptional()
@IsString()
@ApiPropertyOptional({ nullable: true, type: String })
createdByNationalId?: string | null

@IsOptional()
@ApiPropertyOptional({ type: [DelegationScopeDTO] })
@IsArray()
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,25 @@ const DelegationList = ({ delegationsList, direction }: DelegationProps) => {
{delegationsList.map((delegation) => {
return (
<AccessCard
canModify={!!delegation.referenceId} // only allow deletion of paper delegations
direction={direction}
key={delegation.id}
delegation={delegation}
isAdminView={true}
onDelete={async () => {
const { data } = await deleteCustomDelegationAdminMutation({
variables: {
id: delegation.id as string,
},
})
if (data) {
revalidate()
}
}}
isAdminView
variant={direction}
onDelete={
delegation.referenceId
? async () => {
const { data } =
await deleteCustomDelegationAdminMutation({
variables: {
id: delegation.id as string,
},
})
if (data) {
revalidate()
}
}
: undefined
}
/>
)
})}
Expand Down
2 changes: 1 addition & 1 deletion libs/portals/admin/delegation-admin/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const m = defineMessages({
},
noEndDate: {
id: 'admin.delegationAdmin:noEndDate',
defaultMessage: 'Gildis tími óendanlegur',
defaultMessage: 'Gildistími óendanlegur',
},
validTo: {
id: 'admin.delegationAdmin:validTo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const getTags = (delegation: AuthCustomDelegation) =>
sortBy(
uniqBy(
delegation.scopes?.map((scope) => ({
name: scope?.apiScope ? getTagName(scope?.apiScope) : scope.displayName,
name: scope?.apiScope
? getTagName(scope?.apiScope as AuthApiScope)
: scope.displayName,
isExpired: isDateExpired(scope.validTo),
})),
'name',
Expand All @@ -48,15 +50,12 @@ const getTags = (delegation: AuthCustomDelegation) =>
interface AccessCardProps {
delegation: AuthCustomDelegation

onDelete(delegation: AuthCustomDelegation): void

onView?(delegation: AuthCustomDelegation): void
onDelete?: (delegation: AuthCustomDelegation) => void
onEdit?: (delegation: AuthCustomDelegation) => void
onView?: (delegation: AuthCustomDelegation) => void
onRenew?: (delegation: AuthCustomDelegation) => void

variant?: 'outgoing' | 'incoming'
direction?: 'incoming' | 'outgoing'

canModify?: boolean
href?: string

isAdminView?: boolean
}
Expand All @@ -65,15 +64,12 @@ export const AccessCard = ({
delegation,
onDelete,
onView,
onEdit,
onRenew,
variant = 'outgoing',
direction = 'outgoing',
canModify = true,
href,
isAdminView = false,
}: AccessCardProps) => {
const { formatMessage } = useLocale()
const navigate = useNavigate()

const tags = useMemo(() => getTags(delegation), [delegation])

const hasTags = tags.length > 0
Expand Down Expand Up @@ -165,15 +161,7 @@ export const AccessCard = ({
return <Tooltip placement="bottom" as="button" text={text} />
}

const showActions =
canModify &&
(isOutgoing ||
delegation.type === AuthDelegationType.Custom ||
delegation.type === AuthDelegationType.GeneralMandate)

const canDelete =
isOutgoing || (!isOutgoing && delegation.type === AuthDelegationType.Custom)

const hasActions = onView || onEdit || onDelete
return (
<Box
paddingY={[2, 3, 4]}
Expand Down Expand Up @@ -218,7 +206,7 @@ export const AccessCard = ({
</Box>
<VisuallyHidden>{formatMessage(m.accessHolder)}</VisuallyHidden>
<Text variant="h3" as="h2" color={isExpired ? 'dark300' : 'dark400'}>
{direction === 'outgoing'
{isOutgoing
? (delegation as AuthCustomDelegationOutgoing)?.to?.name
: (delegation as AuthCustomDelegationIncoming)?.from?.name}
</Text>
Expand All @@ -242,7 +230,7 @@ export const AccessCard = ({
)}
</Inline>
</Box>
<Box marginTop={hasTags && showActions ? 2 : 0}>
<Box marginTop={hasTags && hasActions ? 2 : 0}>
<Box
display="flex"
justifyContent={hasTags ? 'spaceBetween' : 'flexEnd'}
Expand All @@ -266,57 +254,61 @@ export const AccessCard = ({
</Inline>
</Box>
)}
{showActions && (
{hasActions && (
<Box
display="flex"
alignItems="center"
justifyContent={['spaceBetween', 'flexEnd']}
marginTop={[2, 0]}
marginLeft={[0, 3]}
>
{canDelete && (
{onDelete && (
<Button
variant="text"
icon="trash"
iconType="outline"
size="small"
colorScheme="destructive"
onClick={() => onDelete(delegation)}
onClick={() => onDelete?.(delegation)}
magnearun marked this conversation as resolved.
Show resolved Hide resolved
magnearun marked this conversation as resolved.
Show resolved Hide resolved
nowrap
>
{formatMessage(coreMessages.buttonDestroy)}
</Button>
)}
<Box marginLeft={3}>
{!isOutgoing && onView ? (
{onView && (
<Button
size="small"
variant="utility"
onClick={() => onView(delegation)}
>
{formatMessage(coreMessages.view)}
</Button>
) : !isExpired && href ? (
)}
{!isExpired && onEdit ? (
<Button
icon="pencil"
iconType="outline"
size="small"
variant="utility"
onClick={() => navigate(href)}
onClick={() => onEdit(delegation)}
>
{formatMessage(coreMessages.buttonEdit)}
</Button>
) : href ? (
<Button
icon="reload"
iconType="outline"
size="small"
variant="utility"
onClick={() => navigate(href)}
>
{formatMessage(coreMessages.buttonRenew)}
</Button>
) : null}
) : (
isExpired &&
onRenew && (
<Button
icon="reload"
iconType="outline"
size="small"
variant="utility"
onClick={() => onRenew?.(delegation)}
magnearun marked this conversation as resolved.
Show resolved Hide resolved
>
{formatMessage(coreMessages.buttonRenew)}
</Button>
)
)}
</Box>
</Box>
)}
Expand Down
Loading