diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-06-19 13:55:47 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-06-19 10:55:47 -0700 |
commit | ef9326bcbb461b4f3265f75a9f738e67e58b88d1 (patch) | |
tree | 1d2abc5304be4df51762985753ede12749f3bf43 /webapp/actions | |
parent | 1594cf8af102d0ffe7c62fc68004049e918a530a (diff) | |
download | chat-ef9326bcbb461b4f3265f75a9f738e67e58b88d1.tar.gz chat-ef9326bcbb461b4f3265f75a9f738e67e58b88d1.tar.bz2 chat-ef9326bcbb461b4f3265f75a9f738e67e58b88d1.zip |
Move integrations over to redux and v4 (#6679)
Diffstat (limited to 'webapp/actions')
-rw-r--r-- | webapp/actions/admin_actions.jsx | 30 | ||||
-rw-r--r-- | webapp/actions/integration_actions.jsx | 171 | ||||
-rw-r--r-- | webapp/actions/oauth_actions.jsx | 68 | ||||
-rw-r--r-- | webapp/actions/user_actions.jsx | 20 |
4 files changed, 179 insertions, 110 deletions
diff --git a/webapp/actions/admin_actions.jsx b/webapp/actions/admin_actions.jsx index 307f0c4a7..b9580c746 100644 --- a/webapp/actions/admin_actions.jsx +++ b/webapp/actions/admin_actions.jsx @@ -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}); } } ); diff --git a/webapp/actions/integration_actions.jsx b/webapp/actions/integration_actions.jsx index c1bbf3432..39dbbb2a8 100644 --- a/webapp/actions/integration_actions.jsx +++ b/webapp/actions/integration_actions.jsx @@ -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 - }); - - loadProfilesForIncomingHooks(data); - }, - (err) => { - AsyncClient.dispatchError(err, 'listIncomingHooks'); + if (data) { + loadProfilesForIncomingHooks(data); + } + + 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 - }); - - loadProfilesForOutgoingHooks(data); - }, - (err) => { - AsyncClient.dispatchError(err, 'listOutgoingHooks'); + if (data) { + loadProfilesForOutgoingHooks(data); + } + + 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 - }); - - loadProfilesForCommands(data); - }, - (err) => { - AsyncClient.dispatchError(err, 'loadTeamCommands'); + if (data) { + loadProfilesForCommands(data); + } + + 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); +} diff --git a/webapp/actions/oauth_actions.jsx b/webapp/actions/oauth_actions.jsx index d7e033604..03508efc1 100644 --- a/webapp/actions/oauth_actions.jsx +++ b/webapp/actions/oauth_actions.jsx @@ -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(); +export function deleteOAuthApp(id, success, error) { + IntegrationActions.deleteOAuthApp(id)(dispatch, getState).then( + (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, onSuccess, onError) { - Client.registerOAuthApp( - app, +export function registerOAuthApp(app, success, error) { + IntegrationActions.addOAuthApp(app)(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.addOAuthApp.error; + error({id: serverError.server_error_id, ...serverError}); } - }, - onError + } ); } diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 88325de3e..c94f6232d 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -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) { |