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

Co-authored-by: Pierre Lehnen <pierre.lehnen@rocket.chat>
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
pull/25276/head^2
Diego Sampaio 4 years ago committed by GitHub
parent 1b4cdf4c3f
commit d8f938f8f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      apps/meteor/app/api/server/api.d.ts
  2. 2
      apps/meteor/app/api/server/index.ts
  3. 8
      apps/meteor/app/api/server/v1/videoConference.ts
  4. 42
      apps/meteor/app/authorization/server/functions/canSendMessage.ts
  5. 2
      packages/rest-typings/src/index.ts
  6. 9
      packages/rest-typings/src/v1/videoConference.ts

@ -205,3 +205,8 @@ export declare const API: {
default: APIClass;
helperMethods: Map<string, (...args: any[]) => unknown>;
};
export declare const defaultRateLimiterOptions: {
numRequestsAllowed: number;
intervalTimeInMS: number;
};

@ -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';

@ -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 });
},
},
);

@ -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';
@ -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');
}
@ -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));
}

@ -28,6 +28,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';
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/interface-name-prefix
@ -56,6 +57,7 @@ export interface Endpoints
PermissionsEndpoints,
InstancesEndpoints,
VoipEndpoints,
VideoConferenceEndpoints,
InvitesEndpoints,
E2eEndpoints,
CustomSoundEndpoint {}

@ -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;
};
};
};
Loading…
Cancel
Save