Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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 .changeset/healthy-news-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Deprecates `insertOrUpdateSound` and `uploadCustomSound` Meteor methods
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { RocketChatFileCustomSoundsInstance } from '../startup/custom-sounds';

export type ICustomSoundData = {
Expand All @@ -27,8 +28,10 @@ declare module '@rocket.chat/ddp-client' {
}
}

// TODO remove custom-sounds Meteor methods on 9.0.0
Meteor.methods<ServerMethods>({
async insertOrUpdateSound(soundData) {
methodDeprecationLogger.method('insertOrUpdateSound', '9.0.0', ['/v1/custom-sounds.create', '/v1/custom-sounds.update']);
if (!this.userId || !(await hasPermissionAsync(this.userId, 'manage-sounds'))) {
throw new Meteor.Error('not_authorized');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Meteor } from 'meteor/meteor';
import type { ICustomSoundData } from './insertOrUpdateSound';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { RocketChatFile } from '../../../file/server';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { RocketChatFileCustomSoundsInstance } from '../startup/custom-sounds';

declare module '@rocket.chat/ddp-client' {
Expand All @@ -15,8 +16,10 @@ declare module '@rocket.chat/ddp-client' {
}
}

// TODO remove custom-sounds Meteor methods on 9.0.0
Meteor.methods<ServerMethods>({
async uploadCustomSound(binaryContent, contentType, soundData) {
methodDeprecationLogger.method('uploadCustomSound', '9.0.0', ['/v1/custom-sounds.create', '/v1/custom-sounds.update']);
if (!this.userId || !(await hasPermissionAsync(this.userId, 'manage-sounds'))) {
throw new Meteor.Error('not_authorized');
}
Expand Down
14 changes: 8 additions & 6 deletions apps/meteor/app/lib/server/lib/deprecationWarningLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ export const apiDeprecationLogger = ((logger) => {
};
})(deprecationLogger.section('API'));

type DeprecationPath<T> = T extends `/${string}` ? (T extends PathPattern ? T : never) : string;

type DeprecationInfo<T> = DeprecationPath<T> | Array<DeprecationPath<T>>;

export const methodDeprecationLogger = ((logger) => {
return {
method: <T extends string | PathPattern>(
method: string,
version: DeprecationLoggerNextPlannedVersion,
info: T extends `/${string}` ? (T extends PathPattern ? T : never) : string,
) => {
const replacement = typeof info === 'string' ? info : `Use the ${info} endpoint instead`;
method: <T extends string | PathPattern>(method: string, version: DeprecationLoggerNextPlannedVersion, info: DeprecationInfo<T>) => {
const infoArray = Array.isArray(info) ? info : [info];
const paths = infoArray.map((p) => (typeof p === 'string' && p.startsWith('/') ? `"${p}"` : p)).join(' or ');
const replacement = infoArray.length > 0 ? `Use the ${paths} endpoint${infoArray.length > 1 ? 's' : ''} instead` : '';
const message = `The method "${method}" is deprecated and will be removed on version ${version}${replacement ? ` (${replacement})` : ''}`;
if (process.env.TEST_MODE === 'true') {
throw new Error(message);
Expand Down
Loading