Skip to content

Commit 26adeb7

Browse files
authored
feat(serviceResource): add delegable flag to service resource to determine whether the resource itself is delegable (#3826)
1 parent 163014f commit 26adeb7

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
query getServiceResources(
2-
$ids: [String!]
3-
$resourceType: [String]
4-
$org: [String]
5-
$onlySelfIdentifiedUserEnabled: Boolean
6-
) {
7-
serviceResources(
8-
resourceType: $resourceType
9-
ids: $ids
10-
org: $org
11-
onlySelfIdentifiedUserEnabled: $onlySelfIdentifiedUserEnabled
12-
) {
1+
query getServiceResources($ids: [String!], $resourceType: [String], $org: [String]) {
2+
serviceResources(resourceType: $resourceType, ids: $ids, org: $org) {
133
id
144
title {
155
nb
166
nn
177
en
188
}
199
org
10+
delegable
2011
}
2112
}

packages/bff/src/graphql/types/serviceResources/serviceResources.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { logger } from '@altinn/dialogporten-node-logger';
2-
import { booleanArg, extendType, list, objectType, stringArg } from 'nexus';
2+
import { extendType, list, objectType, stringArg } from 'nexus';
33
import config from '../../../config.js';
44
import type { LocalizedText, Resource } from './resourceRegistry.ts';
55
import { getEnvironmentConfig } from './serviceResourcesConfig.js';
@@ -9,10 +9,10 @@ interface TransformedServiceResource {
99
title: LocalizedText;
1010
org: string;
1111
resourceType: string;
12-
selfIdentifiedUserEnabled: boolean;
12+
delegable: boolean;
1313
}
1414

15-
const serviceResourcesRedisKey = 'arbeidsflate-service-resources:v3';
15+
const serviceResourcesRedisKey = 'arbeidsflate-service-resources:v4';
1616
let refreshTimer: NodeJS.Timeout | null = null;
1717

1818
async function fetchServiceResources(): Promise<Resource[]> {
@@ -48,8 +48,6 @@ export interface ResourceFilters {
4848
excludeOrgCodes?: string[];
4949
/** Filter by resource IDs - exclude these specific resource IDs */
5050
excludeIds?: string[];
51-
/** Only include resources that are enabled for self-identified users */
52-
onlySelfIdentifiedUserEnabled?: boolean;
5351
/** Only include resources that are visible */
5452
onlyVisible?: boolean;
5553
/** Only include resources that are delegable */
@@ -103,13 +101,6 @@ export async function storeServiceResourcesInRedis(filters?: ResourceFilters): P
103101
}
104102
}
105103

106-
// Filter by self-identified user enabled
107-
if (filters.onlySelfIdentifiedUserEnabled === true) {
108-
if (!resource.selfIdentifiedUserEnabled) {
109-
return false;
110-
}
111-
}
112-
113104
// Filter by visible resources only
114105
if (filters.onlyVisible === true) {
115106
if (!resource.visible) {
@@ -165,7 +156,7 @@ export async function storeServiceResourcesInRedis(filters?: ResourceFilters): P
165156
''
166157
).toLowerCase(),
167158
resourceType: resource.resourceType,
168-
selfIdentifiedUserEnabled: resource.selfIdentifiedUserEnabled || false,
159+
delegable: resource.delegable,
169160
}));
170161

171162
await redisClient.set(serviceResourcesRedisKey, JSON.stringify(transformedResources), 'EX', 60 * 60 * 24); // Store for 24 hours
@@ -182,7 +173,6 @@ export async function getServiceResourcesFromRedis(filters?: {
182173
resourceType?: string[];
183174
ids?: string[];
184175
org?: string[];
185-
onlySelfIdentifiedUserEnabled?: boolean;
186176
}): Promise<TransformedServiceResource[]> {
187177
try {
188178
const { default: redisClient } = await import('../../../redisClient.ts');
@@ -210,9 +200,6 @@ export async function getServiceResourcesFromRedis(filters?: {
210200
filters.org!.some((org) => org.toLowerCase() === resource.org.toLowerCase()),
211201
);
212202
}
213-
if (filters.onlySelfIdentifiedUserEnabled === true) {
214-
resources = resources.filter((resource) => resource.selfIdentifiedUserEnabled);
215-
}
216203
}
217204

218205
return resources;
@@ -307,6 +294,13 @@ export const ServiceResource = objectType({
307294
return resource.title;
308295
},
309296
});
297+
t.field('delegable', {
298+
type: 'Boolean',
299+
description: 'Whether the service resource is delegable',
300+
resolve: (resource) => {
301+
return resource.delegable;
302+
},
303+
});
310304
t.string('org', {
311305
description: 'Organization (=service owner) code for the service resource',
312306
resolve: (resource) => {
@@ -344,17 +338,12 @@ export const ServiceResourceQuery = extendType({
344338
description: 'Filter by organization codes',
345339
}),
346340
),
347-
onlySelfIdentifiedUserEnabled: booleanArg({
348-
description: 'Show only resources enabled for self-identified users',
349-
default: false,
350-
}),
351341
},
352342
resolve: async (_, args) => {
353343
const filters: {
354344
resourceType?: string[];
355345
ids?: string[];
356346
org?: string[];
357-
onlySelfIdentifiedUserEnabled?: boolean;
358347
} = {};
359348

360349
if (args.resourceType) {
@@ -375,10 +364,6 @@ export const ServiceResourceQuery = extendType({
375364
);
376365
}
377366

378-
if (args.onlySelfIdentifiedUserEnabled) {
379-
filters.onlySelfIdentifiedUserEnabled = true;
380-
}
381-
382367
return await getServiceResourcesFromRedis(Object.keys(filters).length > 0 ? filters : undefined);
383368
},
384369
});

packages/frontend/src/api/hooks/useServiceResource.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ interface UseServiceResourceProps {
1919

2020
export const useServiceResource = (props: UseServiceResourceProps = {}): UseServiceResourceOutput => {
2121
const { resourceType, ids } = props;
22-
const { isSelfIdentifiedUser, selectedParties } = useParties();
22+
const { selectedParties } = useParties();
2323
const isServiceFilterEnabled = useFeatureFlag<boolean>('filters.enableServiceFilter');
2424

2525
const normalizedIds = useMemo(() => (ids?.length ? [...ids].sort((a, b) => a.localeCompare(b)) : undefined), [ids]);
2626

27-
const variables = useMemo(() => {
28-
const v: GetServiceResourcesQueryVariables = {};
29-
if (isSelfIdentifiedUser) v.onlySelfIdentifiedUserEnabled = true;
30-
if (resourceType) v.resourceType = resourceType;
31-
if (normalizedIds?.length) v.ids = normalizedIds;
32-
return Object.keys(v).length ? v : undefined;
33-
}, [isSelfIdentifiedUser, resourceType, normalizedIds]);
27+
const variables = useMemo<GetServiceResourcesQueryVariables | undefined>(() => {
28+
if (!resourceType && !normalizedIds?.length) {
29+
return undefined;
30+
}
31+
32+
return {
33+
...(resourceType && { resourceType }),
34+
...(normalizedIds?.length && { ids: normalizedIds }),
35+
};
36+
}, [resourceType, normalizedIds]);
3437

3538
const enabled = isServiceFilterEnabled && selectedParties.length > 0;
3639

3740
const { data, isLoading, isSuccess } = useAuthenticatedQuery<GetServiceResourcesQuery>({
38-
queryKey: [
39-
QUERY_KEYS.SERVICE_RESOURCES,
40-
{ resourceType: resourceType ?? null, ids: normalizedIds ?? null, self: isSelfIdentifiedUser },
41-
],
41+
queryKey: [QUERY_KEYS.SERVICE_RESOURCES, { resourceType: resourceType ?? null, ids: normalizedIds ?? null }],
4242
queryFn: () => fetchServiceResources(variables),
4343
retry: 3,
4444
staleTime: 1000 * 60 * 20,

0 commit comments

Comments
 (0)