This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
admin_actions.jsx
402 lines (352 loc) · 12.7 KB
/
admin_actions.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as AdminActions from 'mattermost-redux/actions/admin';
import * as UserActions from 'mattermost-redux/actions/users';
import * as TeamActions from 'mattermost-redux/actions/teams';
import {Client4} from 'mattermost-redux/client';
import {bindClientFunc} from 'mattermost-redux/actions/helpers';
import {trackEvent} from 'actions/diagnostics_actions.jsx';
import {emitUserLoggedOutEvent} from 'actions/global_actions.jsx';
import {getOnNavigationConfirmed} from 'selectors/views/admin';
import store from 'stores/redux_store.jsx';
import {ActionTypes} from 'utils/constants';
const dispatch = store.dispatch;
const getState = store.getState;
export async function reloadConfig(success, error) {
const {data, error: err} = await dispatch(AdminActions.reloadConfig());
if (data && success) {
dispatch(AdminActions.getConfig());
dispatch(AdminActions.getEnvironmentConfig());
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function adminResetMfa(userId, success, error) {
const {data, error: err} = await UserActions.updateUserMfa(userId, false)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function getClusterStatus(success, error) {
const {data, error: err} = await AdminActions.getClusterStatus()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function ldapTest(success, error) {
const {data, error: err} = await AdminActions.testLdap()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function invalidateAllCaches(success, error) {
const {data, error: err} = await AdminActions.invalidateCaches()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function recycleDatabaseConnection(success, error) {
const {data, error: err} = await AdminActions.recycleDatabase()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function adminResetEmail(user, success, error) {
const {data, error: err} = await UserActions.patchUser(user)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function samlCertificateStatus(success, error) {
const {data, error: err} = await AdminActions.getSamlCertificateStatus()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function getOAuthAppInfo(clientId) {
return bindClientFunc({
clientFunc: Client4.getOAuthAppInfo,
params: [clientId],
});
}
export function allowOAuth2({responseType, clientId, redirectUri, state, scope}) {
return bindClientFunc({
clientFunc: Client4.authorizeOAuthApp,
params: [responseType, clientId, redirectUri, state, scope],
});
}
export async function emailToLdap(loginId, password, token, ldapId, ldapPassword, success, error) {
const {data, error: err} = await UserActions.switchEmailToLdap(loginId, password, ldapId, ldapPassword, token)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function emailToOAuth(loginId, password, token, newType, success, error) {
const {data, error: err} = await UserActions.switchEmailToOAuth(newType, loginId, password, token)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function oauthToEmail(currentService, email, password, success, error) {
const {data, error: err} = await UserActions.switchOAuthToEmail(currentService, email, password)(dispatch, getState);
if (data) {
if (data.follow_link) {
emitUserLoggedOutEvent(data.follow_link);
}
if (success) {
success(data);
}
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function uploadBrandImage(brandImage, success, error) {
const {data, error: err} = await AdminActions.uploadBrandImage(brandImage)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function deleteBrandImage(success, error) {
const {data, error: err} = await AdminActions.deleteBrandImage()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function uploadPublicSamlCertificate(file, success, error) {
const {data, error: err} = await AdminActions.uploadPublicSamlCertificate(file)(dispatch, getState);
if (data && success) {
success('saml-public.crt');
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function uploadPrivateSamlCertificate(file, success, error) {
const {data, error: err} = await AdminActions.uploadPrivateSamlCertificate(file)(dispatch, getState);
if (data && success) {
success('saml-private.key');
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function uploadIdpSamlCertificate(file, success, error) {
const {data, error: err} = await AdminActions.uploadIdpSamlCertificate(file)(dispatch, getState);
if (data && success) {
success('saml-idp.crt');
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function removePublicSamlCertificate(success, error) {
const {data, error: err} = await AdminActions.removePublicSamlCertificate()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function removePrivateSamlCertificate(success, error) {
const {data, error: err} = await AdminActions.removePrivateSamlCertificate()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function removeIdpSamlCertificate(success, error) {
const {data, error: err} = await AdminActions.removeIdpSamlCertificate()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function getStandardAnalytics(teamId) {
await AdminActions.getStandardAnalytics(teamId)(dispatch, getState);
}
export async function getAdvancedAnalytics(teamId) {
await AdminActions.getAdvancedAnalytics(teamId)(dispatch, getState);
}
export async function getBotPostsPerDayAnalytics(teamId) {
await AdminActions.getBotPostsPerDayAnalytics(teamId)(dispatch, getState);
}
export async function getPostsPerDayAnalytics(teamId) {
await AdminActions.getPostsPerDayAnalytics(teamId)(dispatch, getState);
}
export async function getUsersPerDayAnalytics(teamId) {
await AdminActions.getUsersPerDayAnalytics(teamId)(dispatch, getState);
}
export async function elasticsearchTest(config, success, error) {
const {data, error: err} = await AdminActions.testElasticsearch(config)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function testS3Connection(success, error) {
const {data, error: err} = await AdminActions.testS3Connection()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function elasticsearchPurgeIndexes(success, error) {
const {data, error: err} = await AdminActions.purgeElasticsearchIndexes()(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function blevePurgeIndexes(success, error) {
const purgeBleveIndexes = bindClientFunc({
clientFunc: Client4.purgeBleveIndexes,
params: [],
});
const {data, error: err} = await dispatch(purgeBleveIndexes);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function setNavigationBlocked(blocked) {
return {
type: ActionTypes.SET_NAVIGATION_BLOCKED,
blocked,
};
}
export function deferNavigation(onNavigationConfirmed) {
return {
type: ActionTypes.DEFER_NAVIGATION,
onNavigationConfirmed,
};
}
export function cancelNavigation() {
return {
type: ActionTypes.CANCEL_NAVIGATION,
};
}
export function confirmNavigation() {
// have to rename these because of lint no-shadow
return (thunkDispatch, thunkGetState) => {
const callback = getOnNavigationConfirmed(thunkGetState());
if (callback) {
callback();
}
thunkDispatch({
type: ActionTypes.CONFIRM_NAVIGATION,
});
};
}
export async function invalidateAllEmailInvites(success, error) {
const {data, error: err} = await dispatch(TeamActions.invalidateAllEmailInvites());
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function testSmtp(success, error) {
const {data, error: err} = await dispatch(AdminActions.testEmail());
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function registerAdminConsolePlugin(pluginId, reducer) {
return (storeDispatch) => {
storeDispatch({
type: ActionTypes.RECEIVED_ADMIN_CONSOLE_REDUCER,
data: {
pluginId,
reducer,
},
});
};
}
export function unregisterAdminConsolePlugin(pluginId) {
return (storeDispatch) => {
storeDispatch({
type: ActionTypes.REMOVED_ADMIN_CONSOLE_REDUCER,
data: {
pluginId,
},
});
};
}
export async function testSiteURL(success, error, siteURL) {
const {data, error: err} = await dispatch(AdminActions.testSiteURL(siteURL));
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function registerAdminConsoleCustomSetting(pluginId, key, component, {showTitle}) {
return (storeDispatch) => {
storeDispatch({
type: ActionTypes.RECEIVED_ADMIN_CONSOLE_CUSTOM_COMPONENT,
data: {
pluginId,
key,
component,
options: {showTitle},
},
});
};
}
export async function getSamlMetadataFromIdp(success, error, samlMetadataURL) {
const {data, error: err} = await dispatch(AdminActions.getSamlMetadataFromIdp(samlMetadataURL));
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export async function setSamlIdpCertificateFromMetadata(success, error, certData) {
const {data, error: err} = await AdminActions.setSamlIdpCertificateFromMetadata(certData)(dispatch, getState);
if (data && success) {
success('saml-idp.crt');
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function requestTrialLicense(users, termsAccepted, receiveEmailsAccepted, page) {
return async () => {
try {
trackEvent('api', 'api_request_trial_license', {from_page: page});
const response = await Client4.doFetch(`${Client4.getBaseRoute()}/trial-license`, {
method: 'POST', body: JSON.stringify({users, terms_accepted: termsAccepted, receive_emails_accepted: receiveEmailsAccepted}),
});
return {data: response};
} catch (e) {
return {error: e.message};
}
};
}