Skip to content

Commit dd351c7

Browse files
committed
Fixing affiliation guidance group display
1 parent d2b2c20 commit dd351c7

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/resolvers/affiliation.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,31 @@ export const resolvers: Resolvers = {
160160
guidanceGroups: async (parent: Affiliation, _, context: MyContext): Promise<GuidanceGroup[]> => {
161161
const reference = 'Affiliation.guidanceGroups resolver';
162162
try {
163-
// The affiliation foreign key stored on GuidanceGroup is the affiliation's URI.
164-
const affiliationUri = parent?.uri;
165-
if (!affiliationUri) return [];
166-
return await GuidanceGroup.findByAffiliationId(reference, context, affiliationUri);
163+
// Require authentication
164+
const requester = context?.token;
165+
if (!requester) {
166+
throw AuthenticationError();
167+
}
168+
169+
// Fetch all guidance groups for the affiliation
170+
const groups = await GuidanceGroup.findByAffiliationId(reference, context, parent.uri);
171+
172+
// Determine once whether the requester can see ALL groups for this affiliation:
173+
// - Super-admin can see everything
174+
// - Admin for the target affiliation can see everything for that affiliation
175+
const canSeeAll = isSuperAdmin(requester) || (isAdmin(requester) && requester.affiliationId === parent.uri);
176+
177+
if (canSeeAll) {
178+
return groups;
179+
}
180+
181+
// Non-admin users or non-admins for group's affiliation: filter to published only
182+
const publishedOnly = groups.filter(g => {
183+
const isPublished = Boolean((g as any).latestPublishedDate || (g as any).published);
184+
return isPublished;
185+
}) as GuidanceGroup[];
186+
187+
return publishedOnly;
167188
} catch (err) {
168189
context.logger.error(prepareObjectForLogs(err), `Failure in ${reference}`);
169190
throw InternalServerError();

0 commit comments

Comments
 (0)