Move remaining client functions in components to actions (#5171)

Этот коммит содержится в:
Carlos Tadeu Panato Junior
2017-01-27 11:39:13 +01:00
коммит произвёл George Goldberg
родитель 49c677f6b4
Коммит d72547433a
32 изменённых файлов: 708 добавлений и 141 удалений

404
webapp/actions/admin_actions.jsx Обычный файл
Просмотреть файл

@@ -0,0 +1,404 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import Client from 'client/web_client.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import {browserHistory} from 'react-router/es6';
export function revokeSession(altId, success, error) {
Client.revokeSession(altId,
() => {
AsyncClient.getSessions();
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function saveConfig(config, success, error) {
Client.saveConfig(
config,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function reloadConfig(success, error) {
Client.reloadConfig(
() => {
AsyncClient.getConfig();
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function adminResetMfa(userId, success, error) {
Client.adminResetMfa(
userId,
() => {
AsyncClient.getUser(userId);
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function getClusterStatus(success, error) {
Client.getClusterStatus(
(data) => {
if (success) {
success(data);
}
},
(err) => {
AsyncClient.dispatchError(err, 'getClusterStatus');
if (error) {
error(err);
}
}
);
}
export function saveComplianceReports(job, success, error) {
Client.saveComplianceReports(
job,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function testEmail(config, success, error) {
Client.testEmail(
config,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function ldapTest(success, error) {
Client.ldapTest(
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function invalidateAllCaches(success, error) {
Client.invalidateAllCaches(
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function recycleDatabaseConnection(success, error) {
Client.recycleDatabaseConnection(
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function adminResetPassword(userId, password, success, error) {
Client.adminResetPassword(
userId,
password,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function samlCertificateStatus(success, error) {
Client.samlCertificateStatus(
(data) => {
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function ldapSyncNow(success, error) {
Client.ldapSyncNow(
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function getOAuthAppInfo(clientId, success, error) {
Client.getOAuthAppInfo(
clientId,
(data) => {
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function allowOAuth2(params, success, error) {
const responseType = params.response_type;
const clientId = params.client_id;
const redirectUri = params.redirect_uri;
const state = params.state;
const scope = params.scope;
Client.allowOAuth2(responseType, clientId, redirectUri, state, scope,
(data) => {
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function emailToLdap(loginId, password, token, ldapId, ldapPassword, success, error) {
Client.emailToLdap(
loginId,
password,
token,
ldapId,
ldapPassword,
(data) => {
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function emailToOAuth(loginId, password, token, newType, success, error) {
Client.emailToOAuth(
loginId,
password,
token,
newType,
(data) => {
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function oauthToEmail(email, password, success, error) {
Client.oauthToEmail(
email,
password,
(data) => {
if (data.follow_link) {
browserHistory.push(data.follow_link);
}
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function regenerateOAuthAppSecret(oauthAppId, success, error) {
Client.regenerateOAuthAppSecret(
oauthAppId,
(data) => {
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function uploadBrandImage(brandImage, success, error) {
Client.uploadBrandImage(
brandImage,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function uploadLicenseFile(file, success, error) {
Client.uploadLicenseFile(
file,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function removeLicenseFile(success, error) {
Client.removeLicenseFile(
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function uploadCertificateFile(certificateFile, success, error) {
Client.uploadCertificateFile(
certificateFile,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function removeCertificateFile(certificateId, success, error) {
Client.removeCertificateFile(
certificateId,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}

Просмотреть файл

@@ -417,3 +417,30 @@ export function deletePost(channelId, post, success, error) {
}
);
}
export function performSearch(terms, isMentionSearch, success, error) {
Client.search(
terms,
isMentionSearch,
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH,
results: data,
is_mention_search: isMentionSearch
});
loadProfilesForPosts(data.posts);
if (success) {
success(data);
}
},
(err) => {
AsyncClient.dispatchError(err, 'search');
if (error) {
error(err);
}
}
);
}

Просмотреть файл

@@ -60,7 +60,10 @@ export function removeUserFromTeam(teamId, userId, success, error) {
userId,
() => {
TeamStore.removeMemberInTeam(teamId, userId);
UserStore.removeProfileFromTeam(teamId, userId);
UserStore.emitInTeamChange();
AsyncClient.getUser(userId);
AsyncClient.getTeamStats(teamId);
if (success) {
success();

Просмотреть файл

@@ -4,10 +4,12 @@
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import {getChannelMembersForUserIds} from 'actions/channel_actions.jsx';
import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx';
@@ -17,7 +19,6 @@ import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
import {ActionTypes, Preferences} from 'utils/constants.jsx';
import {browserHistory} from 'react-router/es6';
export function switchFromLdapToEmail(email, password, token, ldapPassword, onSuccess, onError) {
@@ -512,6 +513,25 @@ export function activateMfa(code, success, error) {
);
}
export function deactivateMfa(success, error) {
Client.updateMfa(
'',
false,
() => {
AsyncClient.getMe();
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function checkMfa(loginId, success, error) {
if (global.window.mm_config.EnableMultifactorAuthentication !== 'true') {
success(false);
@@ -616,3 +636,138 @@ export function resendVerification(email, success, error) {
}
);
}
export function loginById(userId, password, mfaToken, hash, success, error) {
Client.loginById(
userId,
password,
mfaToken,
hash,
() => {
if (hash > 0) {
BrowserStore.setGlobalItem(hash, JSON.stringify({usedBefore: true}));
}
GlobalActions.emitInitialLoad(
() => {
const query = this.props.location.query;
if (query.redirect_to) {
browserHistory.push(query.redirect_to);
} else {
GlobalActions.redirectUserToDefaultTeam();
}
}
);
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function createUserWithInvite(user, data, emailHash, inviteId, success, error) {
Client.createUserWithInvite(
user,
data,
emailHash,
inviteId,
(response) => {
if (success) {
success(response);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function webLogin(loginId, password, token, success, error) {
Client.webLogin(
loginId,
password,
token,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function webLoginByLdap(loginId, password, token, success, error) {
Client.webLoginByLdap(
loginId,
password,
token,
(data) => {
if (success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
}
}
);
}
export function getAuthorizedApps(success, error) {
Client.getAuthorizedApps(
(authorizedApps) => {
if (success) {
success(authorizedApps);
}
},
(err) => {
if (error) {
error(err);
}
});
}
export function deauthorizeOAuthApp(appId, success, error) {
Client.deauthorizeOAuthApp(
appId,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
});
}
export function uploadProfileImage(userPicture, success, error) {
Client.uploadProfileImage(
userPicture,
() => {
AsyncClient.getMe();
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
}
}
);
}

Просмотреть файл

@@ -4,6 +4,8 @@
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import {WebrtcActionTypes} from 'utils/constants.jsx';
import Client from 'client/web_client.jsx';
export function initWebrtc(userId, isCalling) {
AppDispatcher.handleServerAction({
type: WebrtcActionTypes.INITIALIZE,
@@ -18,3 +20,17 @@ export function handle(message) {
message
});
}
export function webrtcToken(success, error) {
Client.webrtcToken(
(data) => {
if (success) {
success(data);
}
},
() => {
if (error) {
error();
}
});
}