Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add /v1/video-conference endpoint types #25278

Merged
merged 4 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/meteor/app/api/server/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,8 @@ export declare const API: {
default: APIClass;
helperMethods: Map<string, (...args: any[]) => unknown>;
};

export declare const defaultRateLimiterOptions: {
numRequestsAllowed: number;
intervalTimeInMS: number;
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import './v1/settings';
import './v1/stats';
import './v1/subscriptions';
import './v1/users';
import './v1/video-conference';
import './v1/videoConference';
import './v1/autotranslate';
import './v1/webdav';
import './v1/oauthapps';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ API.v1.addRoute(
return API.v1.failure('Room does not exist!');
}

try {
const jitsiTimeout = Meteor.runAsUser(this.userId, () => Meteor.call('jitsi:updateTimeout', roomId, Boolean(joiningNow)));
return API.v1.success({ jitsiTimeout });
} catch (error) {
return API.v1.failure(error.message);
}
const jitsiTimeout = Meteor.runAsUser(this.userId, () => Meteor.call('jitsi:updateTimeout', roomId, Boolean(joiningNow)));
return API.v1.success({ jitsiTimeout });
},
},
);
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IRoom, IUser } from '@rocket.chat/core-typings';

import { canAccessRoomAsync } from './canAccessRoom';
import { hasPermissionAsync } from './hasPermission';
import { Subscriptions, Rooms } from '../../../models/server/raw';
Expand All @@ -11,12 +13,16 @@ const subscriptionOptions = {
},
};

export const validateRoomMessagePermissionsAsync = async (room, { uid, username, type }, extraData) => {
async function validateRoomMessagePermissionsAsync(
room: IRoom,
{ uid, username, type }: { uid: IUser['_id']; username: IUser['username']; type: IUser['type'] },
extraData: Record<string, any>,
): Promise<void> {
if (!room) {
throw new Error('error-invalid-room');
}

if (type !== 'app' && !(await canAccessRoomAsync(room, { _id: uid, username }, extraData))) {
if (type !== 'app' && !(await canAccessRoomAsync(room, { _id: uid }, extraData))) {
throw new Error('error-not-allowed');
}

Expand All @@ -29,23 +35,37 @@ export const validateRoomMessagePermissionsAsync = async (room, { uid, username,

if (room.ro === true && !(await hasPermissionAsync(uid, 'post-readonly', room._id))) {
// Unless the user was manually unmuted
if (!(room.unmuted || []).includes(username)) {
if (username && !(room.unmuted || []).includes(username)) {
throw new Error("You can't send messages because the room is readonly.");
}
}

if (room?.muted?.includes(username)) {
if (username && room?.muted?.includes(username)) {
throw new Error('You_have_been_muted');
}
};
}

export const canSendMessageAsync = async (rid, { uid, username, type }, extraData) => {
export async function canSendMessageAsync(
rid: IRoom['_id'],
{ uid, username, type }: { uid: IUser['_id']; username: IUser['username']; type: IUser['type'] },
extraData: Record<string, any>,
): Promise<IRoom> {
const room = await Rooms.findOneById(rid);
await validateRoomMessagePermissionsAsync(room, { uid, username, type }, extraData);
return room;
};
}

export const canSendMessage = (rid, { uid, username, type }, extraData) =>
Promise.await(canSendMessageAsync(rid, { uid, username, type }, extraData));
export const validateRoomMessagePermissions = (room, { uid, username, type }, extraData) =>
Promise.await(validateRoomMessagePermissionsAsync(room, { uid, username, type }, extraData));
export function canSendMessage(
rid: IRoom['_id'],
{ uid, username, type }: { uid: IUser['_id']; username: IUser['username']; type: IUser['type'] },
extraData: Record<string, any>,
): IRoom {
return Promise.await(canSendMessageAsync(rid, { uid, username, type }, extraData));
}
export function validateRoomMessagePermissions(
room: IRoom,
{ uid, username, type }: { uid: IUser['_id']; username: IUser['username']; type: IUser['type'] },
extraData: Record<string, any>,
): void {
return Promise.await(validateRoomMessagePermissionsAsync(room, { uid, username, type }, extraData));
}
2 changes: 2 additions & 0 deletions packages/rest-typings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { SettingsEndpoints } from "./v1/settings";
import type { StatisticsEndpoints } from "./v1/statistics";
import type { TeamsEndpoints } from "./v1/teams";
import type { UsersEndpoints } from "./v1/users";
import type { VideoConferenceEndpoints } from "./v1/videoConference";
import type { VoipEndpoints } from "./v1/voip";

type CommunityEndpoints = BannersEndpoints &
Expand All @@ -53,6 +54,7 @@ type CommunityEndpoints = BannersEndpoints &
PermissionsEndpoints &
InstancesEndpoints &
VoipEndpoints &
VideoConferenceEndpoints &
InvitesEndpoints &
E2eEndpoints &
CustomSoundEndpoint;
Expand Down
9 changes: 9 additions & 0 deletions packages/rest-typings/src/v1/videoConference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { IRoom } from '@rocket.chat/core-typings';

export type VideoConferenceEndpoints = {
'video-conference/jitsi.update-timeout': {
POST: (params: { roomId: IRoom['_id'], joiningNow?: boolean }) => {
jitsiTimeout: number;
};
};
};