From 5861af47271d97eb0cd2f2085c2fda4a7c37160e Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Fri, 9 May 2025 10:58:20 -0300 Subject: [PATCH] refactor: remove add oauth service meteor call (#35921) --- apps/meteor/app/api/server/v1/settings.ts | 3 ++- .../app/lib/server/methods/addOAuthService.ts | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/meteor/app/api/server/v1/settings.ts b/apps/meteor/app/api/server/v1/settings.ts index 438fda41850..6f669ca470f 100644 --- a/apps/meteor/app/api/server/v1/settings.ts +++ b/apps/meteor/app/api/server/v1/settings.ts @@ -22,6 +22,7 @@ import { updateAuditedByUser } from '../../../../server/settings/lib/auditedSett import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; import { disableCustomScripts } from '../../../lib/server/functions/disableCustomScripts'; import { notifyOnSettingChanged, notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener'; +import { addOAuthServiceMethod } from '../../../lib/server/methods/addOAuthService'; import { SettingsEvents, settings } from '../../../settings/server'; import { setValue } from '../../../settings/server/raw'; import { API } from '../api'; @@ -123,7 +124,7 @@ API.v1.addRoute( throw new Meteor.Error('error-name-param-not-provided', 'The parameter "name" is required'); } - await Meteor.callAsync('addOAuthService', this.bodyParams.name, this.userId); + await addOAuthServiceMethod(this.userId, this.bodyParams.name); return API.v1.success(); }, diff --git a/apps/meteor/app/lib/server/methods/addOAuthService.ts b/apps/meteor/app/lib/server/methods/addOAuthService.ts index 09287bb9bb7..1df8d63aa9b 100644 --- a/apps/meteor/app/lib/server/methods/addOAuthService.ts +++ b/apps/meteor/app/lib/server/methods/addOAuthService.ts @@ -12,6 +12,17 @@ declare module '@rocket.chat/ddp-client' { } } +export const addOAuthServiceMethod = async (userId: string, name: string): Promise => { + if ((await hasPermissionAsync(userId, 'add-oauth-service')) !== true) { + throw new Meteor.Error('error-action-not-allowed', 'Adding OAuth Services is not allowed', { + method: 'addOAuthService', + action: 'Adding_OAuth_Services', + }); + } + + await addOAuthService(name); +}; + Meteor.methods({ async addOAuthService(name) { check(name, String); @@ -22,13 +33,6 @@ Meteor.methods({ throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'addOAuthService' }); } - if ((await hasPermissionAsync(userId, 'add-oauth-service')) !== true) { - throw new Meteor.Error('error-action-not-allowed', 'Adding OAuth Services is not allowed', { - method: 'addOAuthService', - action: 'Adding_OAuth_Services', - }); - } - - await addOAuthService(name); + return addOAuthServiceMethod(userId, name); }, });