Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
203 lines
5.0 KiB
TypeScript
203 lines
5.0 KiB
TypeScript
import type { IRoom, IRoomAbacRedaction, ISubscription, RoomAdminFieldsType, RoomType } from '@rocket.chat/core-typings';
|
|
import { Rooms, Subscriptions } from '@rocket.chat/models';
|
|
import type { FindOptions, Sort } from 'mongodb';
|
|
|
|
import { scopeAdminRoomsForAbac } from './scopeAdminRoomsForAbac';
|
|
import { adminFields } from '../../../lib/rooms/adminFields';
|
|
import { hasAtLeastOnePermissionAsync, hasPermissionAsync } from '../../lib/authorization/hasPermission';
|
|
import { stripABACManagedFieldsForAdmin } from '../../lib/authorization/isABACManagedRoom';
|
|
|
|
export async function findAdminRooms({
|
|
uid,
|
|
filter,
|
|
types = [],
|
|
pagination: { offset, count, sort },
|
|
}: {
|
|
uid: string;
|
|
filter: string;
|
|
types: Array<RoomType | 'discussions' | 'teams'>;
|
|
pagination: { offset: number; count: number; sort: Sort };
|
|
}): Promise<{
|
|
rooms: Array<Pick<IRoom, RoomAdminFieldsType> & IRoomAbacRedaction>;
|
|
count: number;
|
|
offset: number;
|
|
total: number;
|
|
}> {
|
|
if (!(await hasPermissionAsync(uid, 'view-room-administration'))) {
|
|
throw new Error('error-not-authorized');
|
|
}
|
|
const name = filter?.trim();
|
|
const discussion = types?.includes('discussions');
|
|
const includeTeams = types?.includes('teams');
|
|
const typesToRemove = ['discussions', 'teams'];
|
|
const showTypes = Array.isArray(types) ? types.filter((type): type is RoomType => !typesToRemove.includes(type)) : [];
|
|
const options: FindOptions<IRoom> = {
|
|
projection: adminFields,
|
|
skip: offset,
|
|
limit: count,
|
|
};
|
|
|
|
const result = Rooms.findByNameOrFnameContainingAndTypes(name, showTypes, discussion, includeTeams, options);
|
|
|
|
const { cursor, totalCount } = result;
|
|
|
|
const [rooms, total] = await Promise.all([
|
|
cursor
|
|
.sort(sort || { default: -1, name: 1 })
|
|
.map(stripABACManagedFieldsForAdmin)
|
|
.toArray(),
|
|
totalCount,
|
|
]);
|
|
|
|
return {
|
|
rooms: await scopeAdminRoomsForAbac(rooms, uid),
|
|
count: rooms.length,
|
|
offset,
|
|
total,
|
|
};
|
|
}
|
|
|
|
export async function findAdminRoom({
|
|
uid,
|
|
rid,
|
|
}: {
|
|
uid: string;
|
|
rid: string;
|
|
}): Promise<(Pick<IRoom, RoomAdminFieldsType> & IRoomAbacRedaction) | null> {
|
|
if (!(await hasPermissionAsync(uid, 'view-room-administration'))) {
|
|
throw new Error('error-not-authorized');
|
|
}
|
|
|
|
const room = await Rooms.findOneById(rid, { projection: adminFields });
|
|
if (!room) {
|
|
return null;
|
|
}
|
|
|
|
const [scoped] = await scopeAdminRoomsForAbac([stripABACManagedFieldsForAdmin(room)], uid);
|
|
return scoped ?? null;
|
|
}
|
|
|
|
export async function findChannelAndPrivateAutocomplete({ uid, selector }: { uid: string; selector: { name: string } }): Promise<{
|
|
items: IRoom[];
|
|
}> {
|
|
const options: FindOptions<IRoom> = {
|
|
projection: {
|
|
_id: 1,
|
|
fname: 1,
|
|
name: 1,
|
|
t: 1,
|
|
avatarETag: 1,
|
|
encrypted: 1,
|
|
},
|
|
limit: 10,
|
|
sort: {
|
|
name: 1,
|
|
},
|
|
};
|
|
|
|
const userRoomsIds = (await Subscriptions.findByUserId(uid, { projection: { rid: 1 } }).toArray()).map(
|
|
(item: Pick<ISubscription, 'rid'>) => item.rid,
|
|
);
|
|
|
|
const rooms = await Rooms.findRoomsWithoutDiscussionsByRoomIds(selector.name, userRoomsIds, options).toArray();
|
|
|
|
return {
|
|
items: rooms,
|
|
};
|
|
}
|
|
|
|
export async function findAdminRoomsAutocomplete({ uid, selector }: { uid: string; selector: { name: string } }): Promise<{
|
|
items: IRoom[];
|
|
}> {
|
|
if (!(await hasAtLeastOnePermissionAsync(uid, ['view-room-administration', 'can-audit']))) {
|
|
throw new Error('error-not-authorized');
|
|
}
|
|
const options: FindOptions<IRoom> = {
|
|
projection: {
|
|
_id: 1,
|
|
fname: 1,
|
|
name: 1,
|
|
t: 1,
|
|
avatarETag: 1,
|
|
encrypted: 1,
|
|
},
|
|
limit: 10,
|
|
sort: {
|
|
name: 1,
|
|
},
|
|
};
|
|
|
|
const rooms = await Rooms.findRoomsByNameOrFnameStarting(selector.name, options).toArray();
|
|
|
|
return {
|
|
items: rooms,
|
|
};
|
|
}
|
|
|
|
export async function findChannelAndPrivateAutocompleteWithPagination({
|
|
uid,
|
|
selector,
|
|
pagination: { offset, count, sort },
|
|
}: {
|
|
uid: string;
|
|
selector: { name: string };
|
|
pagination: { offset: number; count: number; sort: Sort };
|
|
}): Promise<{
|
|
items: IRoom[];
|
|
total: number;
|
|
}> {
|
|
const userRoomsIds = (await Subscriptions.findByUserId(uid, { projection: { rid: 1 } }).toArray()).map(
|
|
(item: Pick<ISubscription, 'rid'>) => item.rid,
|
|
);
|
|
|
|
const options: FindOptions<IRoom> = {
|
|
projection: {
|
|
_id: 1,
|
|
fname: 1,
|
|
name: 1,
|
|
t: 1,
|
|
avatarETag: 1,
|
|
},
|
|
sort: sort || { name: 1 },
|
|
skip: offset,
|
|
limit: count,
|
|
};
|
|
|
|
const { cursor, totalCount } = Rooms.findPaginatedRoomsWithoutDiscussionsByRoomIds(selector.name, userRoomsIds, options);
|
|
|
|
const [rooms, total] = await Promise.all([cursor.toArray(), totalCount]);
|
|
|
|
return {
|
|
items: rooms,
|
|
total,
|
|
};
|
|
}
|
|
|
|
export async function findRoomsAvailableForTeams({ uid, name }: { uid: string; name?: string }): Promise<{
|
|
items: IRoom[];
|
|
}> {
|
|
const options: FindOptions<IRoom> = {
|
|
projection: {
|
|
_id: 1,
|
|
fname: 1,
|
|
name: 1,
|
|
t: 1,
|
|
avatarETag: 1,
|
|
},
|
|
limit: 10,
|
|
sort: {
|
|
name: 1,
|
|
},
|
|
};
|
|
|
|
const userRooms = (
|
|
(await Subscriptions.findByUserIdAndRoles(uid, ['owner'], { projection: { rid: 1 } }).toArray()) as Pick<ISubscription, 'rid'>[]
|
|
).map((item) => item.rid);
|
|
|
|
const rooms = await Rooms.findChannelAndGroupListWithoutTeamsByNameStartingByOwner(name, userRooms, options).toArray();
|
|
|
|
return {
|
|
items: rooms,
|
|
};
|
|
}
|