From 08ca1ee353fe2a21cf1103af0da641c4872b1b1b Mon Sep 17 00:00:00 2001 From: sorja Date: Mon, 6 Jan 2025 10:23:12 +0200 Subject: [PATCH 1/3] 4196 - Show invited users in country collaborators --- src/meta/tablePaginated/tablePaginated.ts | 3 ++- src/server/api/user/getMany.ts | 5 ++++- .../repository/public/user/utils/getPropsToQueryParams.ts | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/meta/tablePaginated/tablePaginated.ts b/src/meta/tablePaginated/tablePaginated.ts index 14574d3568..b3e32e8a09 100644 --- a/src/meta/tablePaginated/tablePaginated.ts +++ b/src/meta/tablePaginated/tablePaginated.ts @@ -1,5 +1,5 @@ import { CountryIso } from 'meta/area' -import { RoleName } from 'meta/user' +import { RoleName, UserStatus } from 'meta/user' export enum TablePaginatedOrderByDirection { asc = 'asc', @@ -30,4 +30,5 @@ export type UserFilters = { fullName?: string roles?: Array disabled?: boolean + statuses?: Array } diff --git a/src/server/api/user/getMany.ts b/src/server/api/user/getMany.ts index f8e0067e4f..28328c762d 100644 --- a/src/server/api/user/getMany.ts +++ b/src/server/api/user/getMany.ts @@ -1,6 +1,8 @@ import { Response } from 'express' import { CycleRequest } from 'meta/api/request' +import { UserFilters } from 'meta/tablePaginated' +import { UserStatus } from 'meta/user' import { AssessmentController } from 'server/controller/assessment' import { UserController } from 'server/controller/user' @@ -13,7 +15,8 @@ export const getMany = async (req: CycleRequest<{ print: string }>, res: Respons const { assessment, cycle } = await AssessmentController.getOneWithCycle({ assessmentName, cycleName }) - let users = await UserController.getMany({ assessment, cycle, countryIso }) + const filters: UserFilters = { statuses: [UserStatus.active, UserStatus.invitationPending] } + let users = await UserController.getMany({ assessment, cycle, countryIso, filters }) if (print && print === 'true') users = users.filter((user) => !ProcessEnv.fraReportCollaboratorsExcluded.includes(user.email)) diff --git a/src/server/repository/public/user/utils/getPropsToQueryParams.ts b/src/server/repository/public/user/utils/getPropsToQueryParams.ts index 919fd23181..1a9d410c49 100644 --- a/src/server/repository/public/user/utils/getPropsToQueryParams.ts +++ b/src/server/repository/public/user/utils/getPropsToQueryParams.ts @@ -11,7 +11,10 @@ export const getPropsToQueryParams = (props: UsersGetManyProps): Returned => { const { countryIso, filters = {}, limit, offset } = props const { administrators, countries, fullName, roles, disabled } = filters - const statuses = disabled ? [UserStatus.disabled] : [UserStatus.active] + + // Only return users with active status, unless other statuses specified outside + const defaultStatuses = props.filters.statuses ?? [UserStatus.active] + const statuses = disabled ? [UserStatus.disabled] : defaultStatuses const queryParams: UserQueryParams = {} From 13b894f4bbc5b9a334d955c6097be259886c65e4 Mon Sep 17 00:00:00 2001 From: sorja Date: Mon, 6 Jan 2025 10:26:10 +0200 Subject: [PATCH 2/3] deepscan --- .../public/user/utils/getPropsToQueryParams.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/server/repository/public/user/utils/getPropsToQueryParams.ts b/src/server/repository/public/user/utils/getPropsToQueryParams.ts index 1a9d410c49..fd8a51337f 100644 --- a/src/server/repository/public/user/utils/getPropsToQueryParams.ts +++ b/src/server/repository/public/user/utils/getPropsToQueryParams.ts @@ -10,10 +10,16 @@ type Returned = { whereConditions: Array; queryParams: UserQueryParams } export const getPropsToQueryParams = (props: UsersGetManyProps): Returned => { const { countryIso, filters = {}, limit, offset } = props - const { administrators, countries, fullName, roles, disabled } = filters + const { + administrators, + countries, + fullName, + roles, + disabled, + statuses: defaultStatuses = [UserStatus.active], + } = filters // Only return users with active status, unless other statuses specified outside - const defaultStatuses = props.filters.statuses ?? [UserStatus.active] const statuses = disabled ? [UserStatus.disabled] : defaultStatuses const queryParams: UserQueryParams = {} From 619a0ce2f1a097cb6599be1fe7a34c9ddde9d881 Mon Sep 17 00:00:00 2001 From: sorja Date: Mon, 6 Jan 2025 13:23:15 +0200 Subject: [PATCH 3/3] 4196 - Admin/Collaborators: Hide invitations --- src/client/pages/AdminCollaborators/hooks/useFilters.tsx | 7 +++++++ src/meta/tablePaginated/tablePaginated.ts | 3 ++- .../public/user/utils/getPropsToQueryParams.ts | 9 +++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/client/pages/AdminCollaborators/hooks/useFilters.tsx b/src/client/pages/AdminCollaborators/hooks/useFilters.tsx index 1295b05372..30a66d646d 100644 --- a/src/client/pages/AdminCollaborators/hooks/useFilters.tsx +++ b/src/client/pages/AdminCollaborators/hooks/useFilters.tsx @@ -33,6 +33,13 @@ export const useFilters = (): Returned => { label: '', type: TablePaginatedFilterType.SWITCH, }, + { + defaultValue: false, + fieldName: 'invitations', + hidden: true, + label: '', + type: TablePaginatedFilterType.SWITCH, + }, { fieldName: 'roles', label: t('common.role'), diff --git a/src/meta/tablePaginated/tablePaginated.ts b/src/meta/tablePaginated/tablePaginated.ts index b3e32e8a09..abeb6a260d 100644 --- a/src/meta/tablePaginated/tablePaginated.ts +++ b/src/meta/tablePaginated/tablePaginated.ts @@ -27,8 +27,9 @@ export type TablePaginatedFilterValues = boolean | string | Array export type UserFilters = { administrators?: boolean countries?: Array + disabled?: boolean fullName?: string + invitations?: boolean roles?: Array - disabled?: boolean statuses?: Array } diff --git a/src/server/repository/public/user/utils/getPropsToQueryParams.ts b/src/server/repository/public/user/utils/getPropsToQueryParams.ts index fd8a51337f..4c0559413d 100644 --- a/src/server/repository/public/user/utils/getPropsToQueryParams.ts +++ b/src/server/repository/public/user/utils/getPropsToQueryParams.ts @@ -13,9 +13,10 @@ export const getPropsToQueryParams = (props: UsersGetManyProps): Returned => { const { administrators, countries, + disabled, fullName, + invitations = true, roles, - disabled, statuses: defaultStatuses = [UserStatus.active], } = filters @@ -41,13 +42,13 @@ export const getPropsToQueryParams = (props: UsersGetManyProps): Returned => { if (!Objects.isNil(limit)) queryParams.limit = limit if (!Objects.isNil(offset)) queryParams.offset = offset + const withInvitations = invitations ? `or (invitation is not null and invitation ->> 'role' in ($(roles:list)))` : '' + const whereConditions = [ fullName && `full_name ilike '%' || $(fullName) || '%'`, selectedRoles && `( - (role is not null and role ->> 'role' in ($(roles:list))) - or - (invitation is not null and invitation ->> 'role' in ($(roles:list))) + (role is not null and role ->> 'role' in ($(roles:list))) ${withInvitations} )`, countryIso && `country_iso = $(countryIso)`, hasCountries && `country_iso in ($(countries:list))`,