Skip to content

Commit

Permalink
4196 - Show invited users in country collaborators (#4198)
Browse files Browse the repository at this point in the history
* 4196 - Show invited users in country collaborators

* deepscan

* 4196 - Admin/Collaborators: Hide invitations
  • Loading branch information
sorja authored Jan 6, 2025
1 parent cb9dcf5 commit 6ed3839
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/client/pages/AdminCollaborators/hooks/useFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
6 changes: 4 additions & 2 deletions src/meta/tablePaginated/tablePaginated.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -27,7 +27,9 @@ export type TablePaginatedFilterValues = boolean | string | Array<string>
export type UserFilters = {
administrators?: boolean
countries?: Array<CountryIso>
disabled?: boolean
fullName?: string
invitations?: boolean
roles?: Array<RoleName>
disabled?: boolean
statuses?: Array<UserStatus>
}
5 changes: 4 additions & 1 deletion src/server/api/user/getMany.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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))
Expand Down
20 changes: 15 additions & 5 deletions src/server/repository/public/user/utils/getPropsToQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ type Returned = { whereConditions: Array<string>; queryParams: UserQueryParams }
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]
const {
administrators,
countries,
disabled,
fullName,
invitations = true,
roles,
statuses: defaultStatuses = [UserStatus.active],
} = filters

// Only return users with active status, unless other statuses specified outside
const statuses = disabled ? [UserStatus.disabled] : defaultStatuses

const queryParams: UserQueryParams = {}

Expand All @@ -32,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))`,
Expand Down

0 comments on commit 6ed3839

Please sign in to comment.