diff --git a/scripts/apps/search/SavedSearch.ts b/scripts/apps/search/SavedSearch.ts index bb85488a83..070f34021b 100644 --- a/scripts/apps/search/SavedSearch.ts +++ b/scripts/apps/search/SavedSearch.ts @@ -68,7 +68,7 @@ export const isUserSubscribedToSavedSearch = ( if (subscribers.desk_subscriptions.some((subscription) => { const desk: IDesk = getDesk(subscription.desk); - return desk.members.includes(userId); + return desk.members.some((member) => member.user === userId); })) { return true; } else { diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index 3acd6f1bd8..73d2eb95d2 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -1330,7 +1330,7 @@ declare module 'superdesk-api' { export interface IDesk extends IBaseRestApiResponse { name: string; description?: string; - members: Array; + members: Array<{user: IUser['_id']}>; incoming_stage: IStage['_id']; working_stage: IStage['_id']; content_expiry?: number; @@ -2091,6 +2091,7 @@ declare module 'superdesk-api' { horizontalSpacing?: boolean; valueTemplate?: React.ComponentType<{option: IUser}>; clearable: boolean; + deskId?: string } export interface IDropdownTreeGroup { diff --git a/scripts/core/ui/components/SelectUser.tsx b/scripts/core/ui/components/SelectUser.tsx index d910ecad8f..4d7935df18 100644 --- a/scripts/core/ui/components/SelectUser.tsx +++ b/scripts/core/ui/components/SelectUser.tsx @@ -6,6 +6,7 @@ import {UserAvatar} from 'apps/users/components/UserAvatar'; import {SelectWithTemplate, Spacer} from 'superdesk-ui-framework/react'; import {httpRequestJsonLocal} from 'core/helpers/network'; import {SuperdeskReactComponent} from 'core/SuperdeskReactComponent'; +import {sdApi} from 'api'; interface IState { selectedUser: IUser | null | 'loading'; @@ -112,6 +113,7 @@ export class SelectUser extends SuperdeskReactComponent 0 - ? getUserSearchMongoQuery(searchString) - : {}, - ); + let query = {$and: []}; + const desk = sdApi.desks.getDeskById(this.props.deskId); + const deskMemberIds = (desk?.members ?? []).map((member) => member.user); + + if (this.props.deskId != null && this.props.deskId != '') { + query.$and.push({_id: {$in: deskMemberIds}}); + } + + if (searchString != null && searchString.length > 0) { + query.$and.push(getUserSearchMongoQuery(searchString)); + } + + const urlParams = {max_results: 50}; + + if (query.$and.length > 0) { + urlParams['where'] = query; + } // Wrapping into additional promise in order to avoid having to handle rejected promise // in `SelectWithTemplate` component. The component takes a generic promise @@ -133,10 +147,7 @@ export class SelectUser extends SuperdeskReactComponent>({ method: 'GET', path: '/users', - urlParams: { - where: query, - max_results: 50, - }, + urlParams, abortSignal: this.abortController.signal, }).then((res) => { resolve(res._items);