mirror of
https://github.com/docmost/docmost.git
synced 2026-05-18 15:34:05 +08:00
fix: don't show existing members when adding to groups and spaces (WIP)
This commit is contained in:
@@ -145,7 +145,7 @@ export class SearchService {
|
||||
const query = suggestion.query.toLowerCase().trim();
|
||||
|
||||
if (suggestion.includeUsers) {
|
||||
const userQuery = this.db
|
||||
let userQuery = this.db
|
||||
.selectFrom('users')
|
||||
.select(['id', 'name', 'email', 'avatarUrl'])
|
||||
.where('workspaceId', '=', workspaceId)
|
||||
@@ -159,14 +159,25 @@ export class SearchService {
|
||||
),
|
||||
eb(sql`users.email`, 'ilike', sql`f_unaccent(${`%${query}%`})`),
|
||||
]),
|
||||
)
|
||||
.limit(limit);
|
||||
);
|
||||
|
||||
// Filter out users who are already members of the space
|
||||
if (suggestion.spaceId) {
|
||||
userQuery = userQuery.where('users.id', 'not in', (eb) =>
|
||||
eb
|
||||
.selectFrom('spaceMembers')
|
||||
.select('userId')
|
||||
.where('spaceId', '=', suggestion.spaceId)
|
||||
.where('userId', 'is not', null),
|
||||
);
|
||||
}
|
||||
|
||||
userQuery = userQuery.limit(limit);
|
||||
users = await userQuery.execute();
|
||||
}
|
||||
|
||||
if (suggestion.includeGroups) {
|
||||
groups = await this.db
|
||||
let groupQuery = this.db
|
||||
.selectFrom('groups')
|
||||
.select(['id', 'name', 'description'])
|
||||
.where((eb) =>
|
||||
@@ -176,9 +187,21 @@ export class SearchService {
|
||||
sql`LOWER(f_unaccent(${`%${query}%`}))`,
|
||||
),
|
||||
)
|
||||
.where('workspaceId', '=', workspaceId)
|
||||
.limit(limit)
|
||||
.execute();
|
||||
.where('workspaceId', '=', workspaceId);
|
||||
|
||||
// Filter out groups that are already members of the space
|
||||
if (suggestion.spaceId) {
|
||||
groupQuery = groupQuery.where('groups.id', 'not in', (eb) =>
|
||||
eb
|
||||
.selectFrom('spaceMembers')
|
||||
.select('groupId')
|
||||
.where('spaceId', '=', suggestion.spaceId)
|
||||
.where('groupId', 'is not', null),
|
||||
);
|
||||
}
|
||||
|
||||
groupQuery = groupQuery.limit(limit);
|
||||
groups = await groupQuery.execute();
|
||||
}
|
||||
|
||||
if (suggestion.includePages) {
|
||||
|
||||
@@ -23,4 +23,8 @@ export class PaginationOptions {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
query: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
groupId?: string;
|
||||
}
|
||||
|
||||
@@ -162,6 +162,15 @@ export class UserRepo {
|
||||
);
|
||||
}
|
||||
|
||||
if (pagination.groupId) {
|
||||
query = query.where('users.id', 'not in', (eb) =>
|
||||
eb
|
||||
.selectFrom('groupUsers')
|
||||
.select('userId')
|
||||
.where('groupId', '=', pagination.groupId),
|
||||
);
|
||||
}
|
||||
|
||||
const result = executeWithPagination(query, {
|
||||
page: pagination.page,
|
||||
perPage: pagination.limit,
|
||||
|
||||
Reference in New Issue
Block a user