@@ -2,7 +2,6 @@ import type { IOAuthApps } from '@rocket.chat/core-typings';
22import { OAuthApps } from '@rocket.chat/models' ;
33import {
44 ajv ,
5- isUpdateOAuthAppParams ,
65 isOauthAppsGetParams ,
76 validateUnauthorizedErrorResponse ,
87 validateBadRequestErrorResponse ,
@@ -59,6 +58,37 @@ const OauthAppsAddParamsSchema = {
5958
6059const isOauthAppsAddParams = ajv . compile < OauthAppsAddParams > ( OauthAppsAddParamsSchema ) ;
6160
61+ type UpdateOAuthAppParams = {
62+ appId : string ;
63+ name : string ;
64+ active : boolean ;
65+ clientId ?: string | undefined ;
66+ clientSecret ?: string | undefined ;
67+ redirectUri : string ;
68+ } ;
69+
70+ const UpdateOAuthAppParamsSchema = {
71+ type : 'object' ,
72+ properties : {
73+ appId : {
74+ type : 'string' ,
75+ } ,
76+ name : {
77+ type : 'string' ,
78+ } ,
79+ active : {
80+ type : 'boolean' ,
81+ } ,
82+ redirectUri : {
83+ type : 'string' ,
84+ } ,
85+ } ,
86+ required : [ 'appId' , 'name' , 'active' , 'redirectUri' ] ,
87+ additionalProperties : false ,
88+ } ;
89+
90+ const isUpdateOAuthAppParams = ajv . compile < UpdateOAuthAppParams > ( UpdateOAuthAppParamsSchema ) ;
91+
6292const oauthAppsEndpoints = API . v1
6393 . get (
6494 'oauth-apps.list' ,
@@ -156,6 +186,38 @@ const oauthAppsEndpoints = API.v1
156186
157187 return API . v1 . success ( { application } ) ;
158188 } ,
189+ )
190+ . post (
191+ 'oauth-apps.update' ,
192+ {
193+ authRequired : true ,
194+ body : isUpdateOAuthAppParams ,
195+ permissionsRequired : [ 'manage-oauth-apps' ] ,
196+ response : {
197+ 400 : validateBadRequestErrorResponse ,
198+ 401 : validateUnauthorizedErrorResponse ,
199+ 403 : validateForbiddenErrorResponse ,
200+ 200 : ajv . compile < IOAuthApps | null > ( {
201+ allOf : [
202+ { anyOf : [ { $ref : '#/components/schemas/IOAuthApps' } , { type : 'null' } ] } ,
203+ {
204+ type : 'object' ,
205+ properties : {
206+ success : { type : 'boolean' , enum : [ true ] } ,
207+ } ,
208+ required : [ 'success' ] ,
209+ } ,
210+ ] ,
211+ } ) ,
212+ } ,
213+ } ,
214+ async function action ( ) {
215+ const { appId } = this . bodyParams ;
216+
217+ const result = await updateOAuthApp ( this . userId , appId , this . bodyParams ) ;
218+
219+ return API . v1 . success ( result ) ;
220+ } ,
159221 ) ;
160222
161223API . v1 . addRoute (
@@ -185,24 +247,6 @@ API.v1.addRoute(
185247 } ,
186248) ;
187249
188- API . v1 . addRoute (
189- 'oauth-apps.update' ,
190- {
191- authRequired : true ,
192- validateParams : isUpdateOAuthAppParams ,
193- permissionsRequired : [ 'manage-oauth-apps' ] ,
194- } ,
195- {
196- async post ( ) {
197- const { appId } = this . bodyParams ;
198-
199- const result = await updateOAuthApp ( this . userId , appId , this . bodyParams ) ;
200-
201- return API . v1 . success ( result ) ;
202- } ,
203- } ,
204- ) ;
205-
206250export type OauthAppsEndpoints = ExtractRoutesFromAPI < typeof oauthAppsEndpoints > ;
207251
208252declare module '@rocket.chat/rest-typings' {
0 commit comments