Move integrations over to redux and v4 (#6679)

Этот коммит содержится в:
Joram Wilander
2017-06-19 13:55:47 -04:00
коммит произвёл Christopher Speller
родитель 1594cf8af1
Коммит ef9326bcbb
21 изменённых файлов: 306 добавлений и 608 удалений

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

@@ -1,16 +1,18 @@
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import Client from 'client/web_client.jsx';
import {clientLogout} from 'actions/global_actions.jsx';
import Client from 'client/web_client.jsx';
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import * as AdminActions from 'mattermost-redux/actions/admin';
import * as UserActions from 'mattermost-redux/actions/users';
import * as IntegrationActions from 'mattermost-redux/actions/integrations';
import {Client4} from 'mattermost-redux/client';
export function saveConfig(config, success, error) {
AdminActions.updateConfig(config)(dispatch, getState).then(
@@ -157,13 +159,13 @@ export function ldapSyncNow(success, error) {
}
export function getOAuthAppInfo(clientId, success, error) {
Client.getOAuthAppInfo(
clientId,
Client4.getOAuthAppInfo(clientId).then(
(data) => {
if (success) {
success(data);
}
},
}
).catch(
(err) => {
if (error) {
error(err);
@@ -179,12 +181,13 @@ export function allowOAuth2(params, success, error) {
const state = params.state;
const scope = params.scope;
Client.allowOAuth2(responseType, clientId, redirectUri, state, scope,
Client4.authorizeOAuthApp(responseType, clientId, redirectUri, state, scope).then(
(data) => {
if (success) {
success(data);
}
},
}
).catch(
(err) => {
if (error) {
error(err);
@@ -238,16 +241,13 @@ export function oauthToEmail(currentService, email, password, success, error) {
}
export function regenerateOAuthAppSecret(oauthAppId, success, error) {
Client.regenerateOAuthAppSecret(
oauthAppId,
IntegrationActions.regenOAuthAppSecret(oauthAppId)(dispatch, getState).then(
(data) => {
if (success) {
if (data && success) {
success(data);
}
},
(err) => {
if (error) {
error(err);
} else if (data == null && error) {
const serverError = getState().requests.admin.updateOAuthApp.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);

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

@@ -1,35 +1,26 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
import {ActionTypes} from 'utils/constants.jsx';
import TeamStore from 'stores/team_store.jsx';
// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
import {getProfilesByIds} from 'mattermost-redux/actions/users';
import * as IntegrationActions from 'mattermost-redux/actions/integrations';
export function loadIncomingHooks() {
Client.listIncomingHooks(
export function loadIncomingHooks(complete) {
IntegrationActions.getIncomingHooks('', 0, 10000)(dispatch, getState).then(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_INCOMING_WEBHOOKS,
teamId: TeamStore.getCurrentId(),
incomingWebhooks: data
});
if (data) {
loadProfilesForIncomingHooks(data);
}
loadProfilesForIncomingHooks(data);
},
(err) => {
AsyncClient.dispatchError(err, 'listIncomingHooks');
if (complete) {
complete(data);
}
}
);
}
@@ -51,19 +42,16 @@ function loadProfilesForIncomingHooks(hooks) {
getProfilesByIds(list)(dispatch, getState);
}
export function loadOutgoingHooks() {
Client.listOutgoingHooks(
export function loadOutgoingHooks(complete) {
IntegrationActions.getOutgoingHooks('', '', 0, 10000)(dispatch, getState).then(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_OUTGOING_WEBHOOKS,
teamId: TeamStore.getCurrentId(),
outgoingWebhooks: data
});
if (data) {
loadProfilesForOutgoingHooks(data);
}
loadProfilesForOutgoingHooks(data);
},
(err) => {
AsyncClient.dispatchError(err, 'listOutgoingHooks');
if (complete) {
complete(data);
}
}
);
}
@@ -85,19 +73,16 @@ function loadProfilesForOutgoingHooks(hooks) {
getProfilesByIds(list)(dispatch, getState);
}
export function loadTeamCommands() {
Client.listTeamCommands(
export function loadTeamCommands(complete) {
IntegrationActions.getCustomTeamCommands(TeamStore.getCurrentId())(dispatch, getState).then(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_COMMANDS,
teamId: Client.teamId,
commands: data
});
if (data) {
loadProfilesForCommands(data);
}
loadProfilesForCommands(data);
},
(err) => {
AsyncClient.dispatchError(err, 'loadTeamCommands');
if (complete) {
complete(data);
}
}
);
}
@@ -118,3 +103,101 @@ function loadProfilesForCommands(commands) {
getProfilesByIds(list)(dispatch, getState);
}
export function addIncomingHook(hook, success, error) {
IntegrationActions.createIncomingHook(hook)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.createIncomingHook.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}
export function updateIncomingHook(hook, success, error) {
IntegrationActions.updateIncomingHook(hook)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.updateIncomingHook.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}
export function addOutgoingHook(hook, success, error) {
IntegrationActions.createOutgoingHook(hook)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.createOutgoingHook.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}
export function updateOutgoingHook(hook, success, error) {
IntegrationActions.updateOutgoingHook(hook)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.updateOutgoingHook.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}
export function deleteIncomingHook(id) {
IntegrationActions.removeIncomingHook(id)(dispatch, getState);
}
export function deleteOutgoingHook(id) {
IntegrationActions.removeOutgoingHook(id)(dispatch, getState);
}
export function regenOutgoingHookToken(id) {
IntegrationActions.regenOutgoingHookToken(id)(dispatch, getState);
}
export function addCommand(command, success, error) {
IntegrationActions.addCommand(command)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.addCommand.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}
export function editCommand(command, success, error) {
IntegrationActions.editCommand(command)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.editCommand.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}
export function deleteCommand(id) {
IntegrationActions.deleteCommand(id)(dispatch, getState);
}
export function regenCommandToken(id) {
IntegrationActions.regenCommandToken(id)(dispatch, getState);
}

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

@@ -1,60 +1,44 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import Client from 'client/web_client.jsx';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import Constants from 'utils/constants.jsx';
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
const ActionTypes = Constants.ActionTypes;
import * as IntegrationActions from 'mattermost-redux/actions/integrations';
export function listOAuthApps(userId, onSuccess, onError) {
Client.listOAuthApps(
export function listOAuthApps(complete) {
IntegrationActions.getOAuthApps(0, 10000)(dispatch, getState).then(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_OAUTHAPPS,
userId,
oauthApps: data
});
if (onSuccess) {
onSuccess(data);
if (complete) {
complete(data);
}
},
onError
}
);
}
export function deleteOAuthApp(id, userId, onSuccess, onError) {
Client.deleteOAuthApp(
id,
() => {
AppDispatcher.handleServerAction({
type: ActionTypes.REMOVED_OAUTHAPP,
userId,
id
});
if (onSuccess) {
onSuccess();
}
},
onError
);
}
export function registerOAuthApp(app, onSuccess, onError) {
Client.registerOAuthApp(
app,
export function deleteOAuthApp(id, success, error) {
IntegrationActions.deleteOAuthApp(id)(dispatch, getState).then(
(data) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_OAUTHAPP,
oauthApp: data
});
if (onSuccess) {
onSuccess(data);
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.deleteOAuthApp.error;
error({id: serverError.server_error_id, ...serverError});
}
},
onError
}
);
}
export function registerOAuthApp(app, success, error) {
IntegrationActions.addOAuthApp(app)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.integrations.addOAuthApp.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}

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

@@ -12,8 +12,6 @@ import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/s
import {getDirectChannelName, getUserIdFromChannelName} from 'utils/utils.jsx';
import Client from 'client/web_client.jsx';
import {Constants, ActionTypes, Preferences} from 'utils/constants.jsx';
import {browserHistory} from 'react-router/es6';
@@ -26,6 +24,7 @@ import * as Selectors from 'mattermost-redux/selectors/entities/users';
import {getBool} from 'mattermost-redux/selectors/entities/preferences';
import * as UserActions from 'mattermost-redux/actions/users';
import {Client4} from 'mattermost-redux/client';
import {getClientConfig, getLicenseConfig} from 'mattermost-redux/actions/general';
import {getTeamMembersByIds, getMyTeamMembers, getMyTeamUnreads} from 'mattermost-redux/actions/teams';
@@ -739,32 +738,35 @@ export function webLoginByLdap(loginId, password, token, success, error) {
}
export function getAuthorizedApps(success, error) {
Client.getAuthorizedApps(
Client4.getAuthorizedOAuthApps(getState().entities.users.currentUserId).then(
(authorizedApps) => {
if (success) {
success(authorizedApps);
}
},
}
).catch(
(err) => {
if (error) {
error(err);
}
});
}
);
}
export function deauthorizeOAuthApp(appId, success, error) {
Client.deauthorizeOAuthApp(
appId,
Client4.deauthorizeOAuthApp(appId).then(
() => {
if (success) {
success();
}
},
}
).catch(
(err) => {
if (error) {
error(err);
}
});
}
);
}
export function uploadProfileImage(userPicture, success, error) {