@@ -5,6 +5,7 @@ import { check } from 'meteor/check';
55import { Meteor } from 'meteor/meteor' ;
66
77import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission' ;
8+ import { methodDeprecationLogger } from '../lib/deprecationWarningLogger' ;
89import { notifyOnSettingChangedById } from '../lib/notifyListener' ;
910
1011declare module '@rocket.chat/ddp-client' {
@@ -14,8 +15,58 @@ declare module '@rocket.chat/ddp-client' {
1415 }
1516}
1617
18+ export const removeOAuthServiceMethod = async ( userId : string , name : string ) : Promise < void > => {
19+ if ( ( await hasPermissionAsync ( userId , 'add-oauth-service' ) ) !== true ) {
20+ throw new Meteor . Error ( 'error-not-allowed' , 'Not allowed' , { method : 'removeOAuthService' } ) ;
21+ }
22+
23+ const normalized = capitalize ( name . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 _ ] / g, '' ) ) ;
24+
25+ const settingsIds = [
26+ `Accounts_OAuth_Custom-${ normalized } ` ,
27+ `Accounts_OAuth_Custom-${ normalized } -url` ,
28+ `Accounts_OAuth_Custom-${ normalized } -token_path` ,
29+ `Accounts_OAuth_Custom-${ normalized } -identity_path` ,
30+ `Accounts_OAuth_Custom-${ normalized } -authorize_path` ,
31+ `Accounts_OAuth_Custom-${ normalized } -scope` ,
32+ `Accounts_OAuth_Custom-${ normalized } -access_token_param` ,
33+ `Accounts_OAuth_Custom-${ normalized } -token_sent_via` ,
34+ `Accounts_OAuth_Custom-${ normalized } -identity_token_sent_via` ,
35+ `Accounts_OAuth_Custom-${ normalized } -id` ,
36+ `Accounts_OAuth_Custom-${ normalized } -secret` ,
37+ `Accounts_OAuth_Custom-${ normalized } -button_label_text` ,
38+ `Accounts_OAuth_Custom-${ normalized } -button_label_color` ,
39+ `Accounts_OAuth_Custom-${ normalized } -button_color` ,
40+ `Accounts_OAuth_Custom-${ normalized } -login_style` ,
41+ `Accounts_OAuth_Custom-${ normalized } -key_field` ,
42+ `Accounts_OAuth_Custom-${ normalized } -username_field` ,
43+ `Accounts_OAuth_Custom-${ normalized } -email_field` ,
44+ `Accounts_OAuth_Custom-${ normalized } -name_field` ,
45+ `Accounts_OAuth_Custom-${ normalized } -avatar_field` ,
46+ `Accounts_OAuth_Custom-${ normalized } -roles_claim` ,
47+ `Accounts_OAuth_Custom-${ normalized } -merge_roles` ,
48+ `Accounts_OAuth_Custom-${ normalized } -roles_to_sync` ,
49+ `Accounts_OAuth_Custom-${ normalized } -merge_users` ,
50+ `Accounts_OAuth_Custom-${ normalized } -show_button` ,
51+ `Accounts_OAuth_Custom-${ normalized } -groups_claim` ,
52+ `Accounts_OAuth_Custom-${ normalized } -channels_admin` ,
53+ `Accounts_OAuth_Custom-${ normalized } -map_channels` ,
54+ `Accounts_OAuth_Custom-${ normalized } -groups_channel_map` ,
55+ `Accounts_OAuth_Custom-${ normalized } -merge_users_distinct_services` ,
56+ ] ;
57+
58+ const promises = settingsIds . map ( ( id ) => Settings . removeById ( id ) ) ;
59+
60+ ( await Promise . all ( promises ) ) . forEach ( ( value , index ) => {
61+ if ( value ?. deletedCount ) {
62+ void notifyOnSettingChangedById ( settingsIds [ index ] , 'removed' ) ;
63+ }
64+ } ) ;
65+ } ;
66+
1767Meteor . methods < ServerMethods > ( {
1868 async removeOAuthService ( name ) {
69+ methodDeprecationLogger . method ( 'removeOAuthService' , '9.0.0' , '/v1/settings.removeCustomOAuth' ) ;
1970 check ( name , String ) ;
2071
2172 const userId = Meteor . userId ( ) ;
@@ -26,52 +77,6 @@ Meteor.methods<ServerMethods>({
2677 } ) ;
2778 }
2879
29- if ( ( await hasPermissionAsync ( userId , 'add-oauth-service' ) ) !== true ) {
30- throw new Meteor . Error ( 'error-not-allowed' , 'Not allowed' , { method : 'removeOAuthService' } ) ;
31- }
32-
33- name = name . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 _ ] / g, '' ) ;
34- name = capitalize ( name ) ;
35-
36- const settingsIds = [
37- `Accounts_OAuth_Custom-${ name } ` ,
38- `Accounts_OAuth_Custom-${ name } -url` ,
39- `Accounts_OAuth_Custom-${ name } -token_path` ,
40- `Accounts_OAuth_Custom-${ name } -identity_path` ,
41- `Accounts_OAuth_Custom-${ name } -authorize_path` ,
42- `Accounts_OAuth_Custom-${ name } -scope` ,
43- `Accounts_OAuth_Custom-${ name } -access_token_param` ,
44- `Accounts_OAuth_Custom-${ name } -token_sent_via` ,
45- `Accounts_OAuth_Custom-${ name } -identity_token_sent_via` ,
46- `Accounts_OAuth_Custom-${ name } -id` ,
47- `Accounts_OAuth_Custom-${ name } -secret` ,
48- `Accounts_OAuth_Custom-${ name } -button_label_text` ,
49- `Accounts_OAuth_Custom-${ name } -button_label_color` ,
50- `Accounts_OAuth_Custom-${ name } -button_color` ,
51- `Accounts_OAuth_Custom-${ name } -login_style` ,
52- `Accounts_OAuth_Custom-${ name } -key_field` ,
53- `Accounts_OAuth_Custom-${ name } -username_field` ,
54- `Accounts_OAuth_Custom-${ name } -email_field` ,
55- `Accounts_OAuth_Custom-${ name } -name_field` ,
56- `Accounts_OAuth_Custom-${ name } -avatar_field` ,
57- `Accounts_OAuth_Custom-${ name } -roles_claim` ,
58- `Accounts_OAuth_Custom-${ name } -merge_roles` ,
59- `Accounts_OAuth_Custom-${ name } -roles_to_sync` ,
60- `Accounts_OAuth_Custom-${ name } -merge_users` ,
61- `Accounts_OAuth_Custom-${ name } -show_button` ,
62- `Accounts_OAuth_Custom-${ name } -groups_claim` ,
63- `Accounts_OAuth_Custom-${ name } -channels_admin` ,
64- `Accounts_OAuth_Custom-${ name } -map_channels` ,
65- `Accounts_OAuth_Custom-${ name } -groups_channel_map` ,
66- `Accounts_OAuth_Custom-${ name } -merge_users_distinct_services` ,
67- ] ;
68-
69- const promises = settingsIds . map ( ( id ) => Settings . removeById ( id ) ) ;
70-
71- ( await Promise . all ( promises ) ) . forEach ( ( value , index ) => {
72- if ( value ?. deletedCount ) {
73- void notifyOnSettingChangedById ( settingsIds [ index ] , 'removed' ) ;
74- }
75- } ) ;
80+ await removeOAuthServiceMethod ( userId , name ) ;
7681 } ,
7782} ) ;
0 commit comments