From d72547433af3ec5829ce0de4f4e1cfd440be7142 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Fri, 27 Jan 2017 11:39:13 +0100 Subject: Move remaining client functions in components to actions (#5171) --- webapp/actions/admin_actions.jsx | 404 +++++++++++++++++++++ webapp/actions/post_actions.jsx | 27 ++ webapp/actions/team_actions.jsx | 3 + webapp/actions/user_actions.jsx | 157 +++++++- webapp/actions/webrtc_actions.jsx | 16 + webapp/components/activity_log_modal.jsx | 9 +- webapp/components/admin_console/admin_settings.jsx | 5 +- .../admin_console/admin_team_members_dropdown.jsx | 18 +- .../admin_console/brand_image_setting.jsx | 3 +- .../admin_console/cluster_table_container.jsx | 10 +- .../admin_console/compliance_reports.jsx | 3 +- .../admin_console/email_connection_test.jsx | 5 +- .../components/admin_console/ldap_test_button.jsx | 5 +- .../components/admin_console/license_settings.jsx | 8 +- webapp/components/admin_console/purge_caches.jsx | 6 +- webapp/components/admin_console/recycle_db.jsx | 5 +- webapp/components/admin_console/reload_config.jsx | 8 +- .../admin_console/reset_password_modal.jsx | 5 +- webapp/components/admin_console/saml_settings.jsx | 9 +- .../components/admin_console/sync_now_button.jsx | 5 +- webapp/components/authorize.jsx | 7 +- .../components/claim/components/email_to_ldap.jsx | 4 +- .../components/claim/components/email_to_oauth.jsx | 4 +- .../components/claim/components/oauth_to_email.jsx | 12 +- .../components/installed_oauth_app.jsx | 4 +- webapp/components/login/login_controller.jsx | 31 +- webapp/components/search_bar.jsx | 20 +- .../components/signup/components/signup_email.jsx | 26 +- .../components/signup/components/signup_ldap.jsx | 4 +- .../user_settings/user_settings_general.jsx | 6 +- .../user_settings/user_settings_security.jsx | 18 +- webapp/components/webrtc/webrtc_controller.jsx | 2 +- 32 files changed, 708 insertions(+), 141 deletions(-) create mode 100644 webapp/actions/admin_actions.jsx diff --git a/webapp/actions/admin_actions.jsx b/webapp/actions/admin_actions.jsx new file mode 100644 index 000000000..73b73c130 --- /dev/null +++ b/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); + } + } + ); +} diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx index 3f660b94d..61f193b66 100644 --- a/webapp/actions/post_actions.jsx +++ b/webapp/actions/post_actions.jsx @@ -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); + } + } + ); +} diff --git a/webapp/actions/team_actions.jsx b/webapp/actions/team_actions.jsx index 941ea880d..e23fe1e5d 100644 --- a/webapp/actions/team_actions.jsx +++ b/webapp/actions/team_actions.jsx @@ -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(); diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 09148c3f2..73a84a7c6 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -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); + } + } + ); +} diff --git a/webapp/actions/webrtc_actions.jsx b/webapp/actions/webrtc_actions.jsx index 444eee241..b096e1c33 100644 --- a/webapp/actions/webrtc_actions.jsx +++ b/webapp/actions/webrtc_actions.jsx @@ -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(); + } + }); +} diff --git a/webapp/components/activity_log_modal.jsx b/webapp/components/activity_log_modal.jsx index 0789d8efc..cd369f742 100644 --- a/webapp/components/activity_log_modal.jsx +++ b/webapp/components/activity_log_modal.jsx @@ -5,7 +5,6 @@ import LoadingScreen from './loading_screen.jsx'; import UserStore from 'stores/user_store.jsx'; -import Client from 'client/web_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -14,6 +13,8 @@ import React from 'react'; import {Modal} from 'react-bootstrap'; import {FormattedMessage, FormattedTime, FormattedDate} from 'react-intl'; +import {revokeSession} from 'actions/admin_actions.jsx'; + export default class ActivityLogModal extends React.Component { constructor(props) { super(props); @@ -46,10 +47,8 @@ export default class ActivityLogModal extends React.Component { setTimeout(() => { modalContent.removeClass('animation--highlight'); }, 1500); - Client.revokeSession(altId, - () => { - AsyncClient.getSessions(); - }, + revokeSession(altId, + null, (err) => { const state = this.getStateFromStores(); state.serverError = err; diff --git a/webapp/components/admin_console/admin_settings.jsx b/webapp/components/admin_console/admin_settings.jsx index 9975a3975..b9883d7d8 100644 --- a/webapp/components/admin_console/admin_settings.jsx +++ b/webapp/components/admin_console/admin_settings.jsx @@ -4,11 +4,12 @@ import React from 'react'; import * as AsyncClient from 'utils/async_client.jsx'; -import Client from 'client/web_client.jsx'; import FormError from 'components/form_error.jsx'; import SaveButton from 'components/admin_console/save_button.jsx'; +import {saveConfig} from 'actions/admin_actions.jsx'; + export default class AdminSettings extends React.Component { static get propTypes() { return { @@ -53,7 +54,7 @@ export default class AdminSettings extends React.Component { let config = JSON.parse(JSON.stringify(this.props.config)); config = this.getConfigFromState(config); - Client.saveConfig( + saveConfig( config, () => { AsyncClient.getConfig((savedConfig) => { diff --git a/webapp/components/admin_console/admin_team_members_dropdown.jsx b/webapp/components/admin_console/admin_team_members_dropdown.jsx index ee9e53f6c..01e94db16 100644 --- a/webapp/components/admin_console/admin_team_members_dropdown.jsx +++ b/webapp/components/admin_console/admin_team_members_dropdown.jsx @@ -6,12 +6,10 @@ import ConfirmModal from '../confirm_modal.jsx'; import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; -import Client from 'client/web_client.jsx'; import Constants from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import {updateUserRoles, updateActive} from 'actions/user_actions.jsx'; -import {updateTeamMemberRoles} from 'actions/team_actions.jsx'; +import {updateTeamMemberRoles, removeUserFromTeam, adminResetMfa} from 'actions/team_actions.jsx'; import {FormattedMessage} from 'react-intl'; @@ -75,14 +73,10 @@ export default class AdminTeamMembersDropdown extends React.Component { } handleRemoveFromTeam() { - Client.removeUserFromTeam( + removeUserFromTeam( this.props.teamMember.team_id, this.props.user.id, - () => { - AsyncClient.getTeamStats(this.props.teamMember.team_id); - UserStore.removeProfileFromTeam(this.props.teamMember.team_id, this.props.user.id); - UserStore.emitInTeamChange(); - }, + null, (err) => { this.setState({serverError: err.message}); } @@ -150,10 +144,8 @@ export default class AdminTeamMembersDropdown extends React.Component { handleResetMfa(e) { e.preventDefault(); - Client.adminResetMfa(this.props.user.id, - () => { - AsyncClient.getUser(this.props.user.id); - }, + adminResetMfa(this.props.user.id, + null, (err) => { this.setState({serverError: err.message}); } diff --git a/webapp/components/admin_console/brand_image_setting.jsx b/webapp/components/admin_console/brand_image_setting.jsx index 653073200..b58c0159c 100644 --- a/webapp/components/admin_console/brand_image_setting.jsx +++ b/webapp/components/admin_console/brand_image_setting.jsx @@ -7,6 +7,7 @@ import ReactDOM from 'react-dom'; import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; +import {uploadBrandImage} from 'actions/admin_actions.jsx'; import FormError from 'components/form_error.jsx'; import {FormattedHTMLMessage, FormattedMessage} from 'react-intl'; @@ -81,7 +82,7 @@ export default class BrandImageSetting extends React.Component { error: '' }); - Client.uploadBrandImage( + uploadBrandImage( this.state.brandImage, () => { $(ReactDOM.findDOMNode(this.refs.upload)).button('complete'); diff --git a/webapp/components/admin_console/cluster_table_container.jsx b/webapp/components/admin_console/cluster_table_container.jsx index aad5753b7..8dba80cce 100644 --- a/webapp/components/admin_console/cluster_table_container.jsx +++ b/webapp/components/admin_console/cluster_table_container.jsx @@ -4,8 +4,8 @@ import React from 'react'; import ClusterTable from './cluster_table.jsx'; import LoadingScreen from '../loading_screen.jsx'; -import Client from 'client/web_client.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; + +import {getClusterStatus} from 'actions/admin_actions.jsx'; export default class ClusterTableContainer extends React.Component { constructor(props) { @@ -19,15 +19,13 @@ export default class ClusterTableContainer extends React.Component { } load() { - Client.getClusterStatus( + getClusterStatus( (data) => { this.setState({ clusterInfos: data }); }, - (err) => { - AsyncClient.dispatchError(err, 'getClusterStatus'); - } + null ); } diff --git a/webapp/components/admin_console/compliance_reports.jsx b/webapp/components/admin_console/compliance_reports.jsx index aac09c0de..7274e6774 100644 --- a/webapp/components/admin_console/compliance_reports.jsx +++ b/webapp/components/admin_console/compliance_reports.jsx @@ -9,6 +9,7 @@ import UserStore from '../../stores/user_store.jsx'; import Client from 'client/web_client.jsx'; import * as AsyncClient from '../../utils/async_client.jsx'; +import {saveComplianceReports} from 'actions/admin_actions.jsx'; import {FormattedMessage, FormattedDate, FormattedTime} from 'react-intl'; @@ -72,7 +73,7 @@ export default class ComplianceReports extends React.Component { job.start_at = Date.parse(ReactDOM.findDOMNode(this.refs.from).value); job.end_at = Date.parse(ReactDOM.findDOMNode(this.refs.to).value); - Client.saveComplianceReports( + saveComplianceReports( job, () => { ReactDOM.findDOMNode(this.refs.emails).value = ''; diff --git a/webapp/components/admin_console/email_connection_test.jsx b/webapp/components/admin_console/email_connection_test.jsx index 8e11a0bb4..b99633eec 100644 --- a/webapp/components/admin_console/email_connection_test.jsx +++ b/webapp/components/admin_console/email_connection_test.jsx @@ -3,11 +3,12 @@ import React from 'react'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage} from 'react-intl'; +import {testEmail} from 'actions/admin_actions.jsx'; + export default class EmailConnectionTestButton extends React.Component { static get propTypes() { return { @@ -41,7 +42,7 @@ export default class EmailConnectionTestButton extends React.Component { const config = JSON.parse(JSON.stringify(this.props.config)); this.props.getConfigFromState(config); - Client.testEmail( + testEmail( config, () => { this.setState({ diff --git a/webapp/components/admin_console/ldap_test_button.jsx b/webapp/components/admin_console/ldap_test_button.jsx index e077aec5f..a564fa42a 100644 --- a/webapp/components/admin_console/ldap_test_button.jsx +++ b/webapp/components/admin_console/ldap_test_button.jsx @@ -3,11 +3,12 @@ import React from 'react'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; +import {ldapTest} from 'actions/admin_actions.jsx'; + export default class LdapTestButton extends React.Component { static get propTypes() { return { @@ -38,7 +39,7 @@ export default class LdapTestButton extends React.Component { }); const doRequest = () => { //eslint-disable-line func-style - Client.ldapTest( + ldapTest( () => { this.setState({ buisy: false, diff --git a/webapp/components/admin_console/license_settings.jsx b/webapp/components/admin_console/license_settings.jsx index d98309f80..6c14394b7 100644 --- a/webapp/components/admin_console/license_settings.jsx +++ b/webapp/components/admin_console/license_settings.jsx @@ -4,7 +4,8 @@ import $ from 'jquery'; import ReactDOM from 'react-dom'; import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; + +import {uploadLicenseFile, removeLicenseFile} from 'actions/admin_actions.jsx'; import {injectIntl, intlShape, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'react-intl'; @@ -54,7 +55,8 @@ class LicenseSettings extends React.Component { $('#upload-button').button('loading'); - Client.uploadLicenseFile(file, + uploadLicenseFile( + file, () => { Utils.clearFileInput(element[0]); $('#upload-button').button('reset'); @@ -74,7 +76,7 @@ class LicenseSettings extends React.Component { $('#remove-button').button('loading'); - Client.removeLicenseFile( + removeLicenseFile( () => { $('#remove-button').button('reset'); this.setState({fileSelected: false, fileName: null, serverError: null}); diff --git a/webapp/components/admin_console/purge_caches.jsx b/webapp/components/admin_console/purge_caches.jsx index 2d8db7bfa..9f52433d5 100644 --- a/webapp/components/admin_console/purge_caches.jsx +++ b/webapp/components/admin_console/purge_caches.jsx @@ -3,10 +3,10 @@ import React from 'react'; -import Client from 'client/web_client.jsx'; - import {FormattedMessage} from 'react-intl'; +import {invalidateAllCaches} from 'actions/admin_actions.jsx'; + export default class PurgeCachesButton extends React.Component { constructor(props) { super(props); @@ -27,7 +27,7 @@ export default class PurgeCachesButton extends React.Component { fail: null }); - Client.invalidateAllCaches( + invalidateAllCaches( () => { this.setState({ loading: false diff --git a/webapp/components/admin_console/recycle_db.jsx b/webapp/components/admin_console/recycle_db.jsx index 53e8e7436..5683f97e2 100644 --- a/webapp/components/admin_console/recycle_db.jsx +++ b/webapp/components/admin_console/recycle_db.jsx @@ -3,11 +3,12 @@ import React from 'react'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; +import {recycleDatabaseConnection} from 'actions/admin_actions.jsx'; + export default class RecycleDbButton extends React.Component { constructor(props) { super(props); @@ -28,7 +29,7 @@ export default class RecycleDbButton extends React.Component { fail: null }); - Client.recycleDatabaseConnection( + recycleDatabaseConnection( () => { this.setState({ loading: false diff --git a/webapp/components/admin_console/reload_config.jsx b/webapp/components/admin_console/reload_config.jsx index 0b50d5803..25e9463d3 100644 --- a/webapp/components/admin_console/reload_config.jsx +++ b/webapp/components/admin_console/reload_config.jsx @@ -3,13 +3,12 @@ import React from 'react'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; -import {getConfig} from 'utils/async_client.jsx'; - import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; +import {reloadConfig} from 'actions/admin_actions.jsx'; + export default class ReloadConfigButton extends React.Component { constructor(props) { super(props); @@ -30,9 +29,8 @@ export default class ReloadConfigButton extends React.Component { fail: null }); - Client.reloadConfig( + reloadConfig( () => { - getConfig(); this.setState({ loading: false }); diff --git a/webapp/components/admin_console/reset_password_modal.jsx b/webapp/components/admin_console/reset_password_modal.jsx index e3fd2bf00..757f85517 100644 --- a/webapp/components/admin_console/reset_password_modal.jsx +++ b/webapp/components/admin_console/reset_password_modal.jsx @@ -1,12 +1,13 @@ // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {Modal} from 'react-bootstrap'; import {injectIntl, intlShape, FormattedMessage} from 'react-intl'; +import {adminResetPassword} from 'actions/admin_actions.jsx'; + import React from 'react'; class ResetPasswordModal extends React.Component { @@ -32,7 +33,7 @@ class ResetPasswordModal extends React.Component { } this.setState({serverError: null}); - Client.adminResetPassword( + adminResetPassword( this.props.user.id, password, () => { diff --git a/webapp/components/admin_console/saml_settings.jsx b/webapp/components/admin_console/saml_settings.jsx index ad7a82553..7b9ed38b8 100644 --- a/webapp/components/admin_console/saml_settings.jsx +++ b/webapp/components/admin_console/saml_settings.jsx @@ -12,9 +12,10 @@ import RemoveFileSetting from './remove_file_setting.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; import SettingsGroup from './settings_group.jsx'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; +import {samlCertificateStatus, uploadCertificateFile, removeCertificateFile} from 'actions/admin_actions.jsx'; + export default class SamlSettings extends AdminSettings { constructor(props) { super(props); @@ -73,7 +74,7 @@ export default class SamlSettings extends AdminSettings { } componentWillMount() { - Client.samlCertificateStatus( + samlCertificateStatus( (data) => { const files = {}; if (!data.IdpCertificateFile) { @@ -93,7 +94,7 @@ export default class SamlSettings extends AdminSettings { } uploadCertificate(id, file, callback) { - Client.uploadCertificateFile( + uploadCertificateFile( file, () => { const fileName = file.name; @@ -112,7 +113,7 @@ export default class SamlSettings extends AdminSettings { } removeCertificate(id, callback) { - Client.removeCertificateFile( + removeCertificateFile( this.state[id], () => { this.handleChange(id, ''); diff --git a/webapp/components/admin_console/sync_now_button.jsx b/webapp/components/admin_console/sync_now_button.jsx index 95d126291..f1197b216 100644 --- a/webapp/components/admin_console/sync_now_button.jsx +++ b/webapp/components/admin_console/sync_now_button.jsx @@ -3,11 +3,12 @@ import React from 'react'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; +import {ldapSyncNow} from 'actions/admin_actions.jsx'; + export default class SyncNowButton extends React.Component { static get propTypes() { return { @@ -33,7 +34,7 @@ export default class SyncNowButton extends React.Component { fail: null }); - Client.ldapSyncNow( + ldapSyncNow( () => { this.setState({ buisy: false diff --git a/webapp/components/authorize.jsx b/webapp/components/authorize.jsx index 684bae589..f3f5770de 100644 --- a/webapp/components/authorize.jsx +++ b/webapp/components/authorize.jsx @@ -1,7 +1,6 @@ // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import Client from 'client/web_client.jsx'; import FormError from 'components/form_error.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; @@ -9,6 +8,8 @@ import React from 'react'; import icon50 from 'images/icon50x50.png'; +import {getOAuthAppInfo, allowOAuth2} from 'actions/admin_actions.jsx'; + export default class Authorize extends React.Component { static get propTypes() { return { @@ -27,7 +28,7 @@ export default class Authorize extends React.Component { } componentWillMount() { - Client.getOAuthAppInfo( + getOAuthAppInfo( this.props.location.query.client_id, (app) => { this.setState({app}); @@ -46,7 +47,7 @@ export default class Authorize extends React.Component { handleAllow() { const params = this.props.location.query; - Client.allowOAuth2(params.response_type, params.client_id, params.redirect_uri, params.state, params.scope, + allowOAuth2(params, (data) => { if (data.redirect) { window.location.href = data.redirect; diff --git a/webapp/components/claim/components/email_to_ldap.jsx b/webapp/components/claim/components/email_to_ldap.jsx index 890512803..7d062a957 100644 --- a/webapp/components/claim/components/email_to_ldap.jsx +++ b/webapp/components/claim/components/email_to_ldap.jsx @@ -4,9 +4,9 @@ import LoginMfa from 'components/login/components/login_mfa.jsx'; import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; import {checkMfa} from 'actions/user_actions.jsx'; +import {emailToLdap} from 'actions/admin_actions.jsx'; import React from 'react'; import {FormattedMessage} from 'react-intl'; @@ -79,7 +79,7 @@ export default class EmailToLDAP extends React.Component { } submit(loginId, password, token, ldapId, ldapPassword) { - Client.emailToLdap( + emailToLdap( loginId, password, token, diff --git a/webapp/components/claim/components/email_to_oauth.jsx b/webapp/components/claim/components/email_to_oauth.jsx index 3cede15a3..bc5a7bdaa 100644 --- a/webapp/components/claim/components/email_to_oauth.jsx +++ b/webapp/components/claim/components/email_to_oauth.jsx @@ -4,10 +4,10 @@ import LoginMfa from 'components/login/components/login_mfa.jsx'; import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; import Constants from 'utils/constants.jsx'; import {checkMfa} from 'actions/user_actions.jsx'; +import {emailToOAuth} from 'actions/admin_actions.jsx'; import React from 'react'; import ReactDOM from 'react-dom'; @@ -55,7 +55,7 @@ export default class EmailToOAuth extends React.Component { } submit(loginId, password, token) { - Client.emailToOAuth( + emailToOAuth( loginId, password, token, diff --git a/webapp/components/claim/components/oauth_to_email.jsx b/webapp/components/claim/components/oauth_to_email.jsx index ed604583d..ffba1c331 100644 --- a/webapp/components/claim/components/oauth_to_email.jsx +++ b/webapp/components/claim/components/oauth_to_email.jsx @@ -2,13 +2,13 @@ // See License.txt for license information. import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; import Constants from 'utils/constants.jsx'; import React from 'react'; import ReactDOM from 'react-dom'; import {FormattedMessage} from 'react-intl'; -import {browserHistory} from 'react-router/es6'; + +import {oauthToEmail} from 'actions/admin_actions.jsx'; export default class OAuthToEmail extends React.Component { constructor(props) { @@ -48,14 +48,10 @@ export default class OAuthToEmail extends React.Component { state.error = null; this.setState(state); - Client.oauthToEmail( + oauthToEmail( this.props.email, password, - (data) => { - if (data.follow_link) { - browserHistory.push(data.follow_link); - } - }, + null, (err) => { this.setState({error: err.message}); } diff --git a/webapp/components/integrations/components/installed_oauth_app.jsx b/webapp/components/integrations/components/installed_oauth_app.jsx index 15a79ed4c..a6dea65bf 100644 --- a/webapp/components/integrations/components/installed_oauth_app.jsx +++ b/webapp/components/integrations/components/installed_oauth_app.jsx @@ -5,10 +5,10 @@ import React from 'react'; import FormError from 'components/form_error.jsx'; -import Client from 'client/web_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; +import {regenerateOAuthAppSecret} from 'actions/admin_actions.jsx'; const FAKE_SECRET = '***************'; @@ -49,7 +49,7 @@ export default class InstalledOAuthApp extends React.Component { handleRegenerate(e) { e.preventDefault(); - Client.regenerateOAuthAppSecret( + regenerateOAuthAppSecret( this.props.oauthApp.id, (data) => { this.props.oauthApp.client_secret = data.client_secret; diff --git a/webapp/components/login/login_controller.jsx b/webapp/components/login/login_controller.jsx index 3064371c3..535cdfd12 100644 --- a/webapp/components/login/login_controller.jsx +++ b/webapp/components/login/login_controller.jsx @@ -7,6 +7,7 @@ import FormError from 'components/form_error.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {addUserToTeamFromInvite} from 'actions/team_actions.jsx'; +import {checkMfa, webLogin} from 'actions/user_actions.jsx'; import BrowserStore from 'stores/browser_store.jsx'; import UserStore from 'stores/user_store.jsx'; @@ -119,29 +120,25 @@ export default class LoginController extends React.Component { return; } - if (global.window.mm_config.EnableMultifactorAuthentication === 'true') { - Client.checkMfa( - loginId, - (data) => { - if (data.mfa_required === 'true') { - this.setState({showMfa: true}); - } else { - this.submit(loginId, password, ''); - } - }, - (err) => { - this.setState({serverError: err.message}); + checkMfa( + loginId, + (data) => { + if (data && data.mfa_required === 'true') { + this.setState({showMfa: true}); + } else { + this.submit(loginId, password, ''); } - ); - } else { - this.submit(loginId, password, ''); - } + }, + (err) => { + this.setState({serverError: err.message}); + } + ); } submit(loginId, password, token) { this.setState({serverError: null, loading: true}); - Client.webLogin( + webLogin( loginId, password, token, diff --git a/webapp/components/search_bar.jsx b/webapp/components/search_bar.jsx index 77f62a708..c5fcd4697 100644 --- a/webapp/components/search_bar.jsx +++ b/webapp/components/search_bar.jsx @@ -2,8 +2,6 @@ // See License.txt for license information. import $ from 'jquery'; -import Client from 'client/web_client.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import SearchStore from 'stores/search_store.jsx'; import UserStore from 'stores/user_store.jsx'; @@ -14,7 +12,7 @@ import SearchSuggestionList from './suggestion/search_suggestion_list.jsx'; import SearchUserProvider from './suggestion/search_user_provider.jsx'; import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; -import {loadProfilesForPosts, getFlaggedPosts} from 'actions/post_actions.jsx'; +import {getFlaggedPosts, performSearch} from 'actions/post_actions.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; @@ -118,26 +116,18 @@ export default class SearchBar extends React.Component { if (terms.length) { this.setState({isSearching: true}); - Client.search( + performSearch( terms, isMentionSearch, - (data) => { + () => { this.setState({isSearching: false}); + if (Utils.isMobile() && this.search) { this.search.value = ''; } - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_SEARCH, - results: data, - is_mention_search: isMentionSearch - }); - - loadProfilesForPosts(data.posts); }, - (err) => { + () => { this.setState({isSearching: false}); - AsyncClient.dispatchError(err, 'search'); } ); } diff --git a/webapp/components/signup/components/signup_email.jsx b/webapp/components/signup/components/signup_email.jsx index e8181fd23..9ed10b94c 100644 --- a/webapp/components/signup/components/signup_email.jsx +++ b/webapp/components/signup/components/signup_email.jsx @@ -6,11 +6,9 @@ import LoadingScreen from 'components/loading_screen.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {track} from 'actions/analytics_actions.jsx'; import {getInviteInfo} from 'actions/team_actions.jsx'; - -import BrowserStore from 'stores/browser_store.jsx'; +import {loginById, createUserWithInvite} from 'actions/user_actions.jsx'; import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; import Constants from 'utils/constants.jsx'; import React from 'react'; @@ -119,26 +117,12 @@ export default class SignupEmail extends React.Component { handleSignupSuccess(user, data) { track('signup', 'signup_user_02_complete'); - Client.loginById( + loginById( data.id, user.password, '', - () => { - if (this.state.hash > 0) { - BrowserStore.setGlobalItem(this.state.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(); - } - } - ); - }, + this.state.hash, + null, (err) => { if (err.id === 'api.user.login.not_verified.app_error') { browserHistory.push('/should_verify_email?email=' + encodeURIComponent(user.email) + '&teamname=' + encodeURIComponent(this.state.teamName)); @@ -242,7 +226,7 @@ export default class SignupEmail extends React.Component { allow_marketing: true }; - Client.createUserWithInvite(user, + createUserWithInvite(user, this.state.data, this.state.hash, this.state.inviteId, diff --git a/webapp/components/signup/components/signup_ldap.jsx b/webapp/components/signup/components/signup_ldap.jsx index 3e8b39a26..4c9afc8d6 100644 --- a/webapp/components/signup/components/signup_ldap.jsx +++ b/webapp/components/signup/components/signup_ldap.jsx @@ -6,9 +6,9 @@ import FormError from 'components/form_error.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {track} from 'actions/analytics_actions.jsx'; import {addUserToTeamFromInvite} from 'actions/team_actions.jsx'; +import {webLoginByLdap} from 'actions/user_actions.jsx'; import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; import React from 'react'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; @@ -56,7 +56,7 @@ export default class SignupLdap extends React.Component { this.setState({ldapError: ''}); - Client.webLoginByLdap( + webLoginByLdap( this.state.ldapId, this.state.ldapPassword, null, diff --git a/webapp/components/user_settings/user_settings_general.jsx b/webapp/components/user_settings/user_settings_general.jsx index 06fe31a9e..d9551dccc 100644 --- a/webapp/components/user_settings/user_settings_general.jsx +++ b/webapp/components/user_settings/user_settings_general.jsx @@ -15,7 +15,7 @@ import * as AsyncClient from 'utils/async_client.jsx'; import * as Utils from 'utils/utils.jsx'; import {intlShape, injectIntl, defineMessages, FormattedMessage, FormattedHTMLMessage, FormattedDate} from 'react-intl'; -import {updateUser} from 'actions/user_actions.jsx'; +import {updateUser, uploadProfileImage} from 'actions/user_actions.jsx'; const holders = defineMessages({ usernameReserved: { @@ -241,11 +241,11 @@ class UserSettingsGeneralTab extends React.Component { this.setState({loadingPicture: true}); - Client.uploadProfileImage(picture, + uploadProfileImage( + picture, () => { this.updateSection(''); this.submitActive = false; - AsyncClient.getMe(); }, (err) => { var state = this.setupInitialState(this.props); diff --git a/webapp/components/user_settings/user_settings_security.jsx b/webapp/components/user_settings/user_settings_security.jsx index e936f5b96..210e455b7 100644 --- a/webapp/components/user_settings/user_settings_security.jsx +++ b/webapp/components/user_settings/user_settings_security.jsx @@ -9,12 +9,11 @@ import ToggleModalButton from '../toggle_modal_button.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; -import Client from 'client/web_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import * as Utils from 'utils/utils.jsx'; import Constants from 'utils/constants.jsx'; -import {updatePassword} from 'actions/user_actions.jsx'; +import {updatePassword, getAuthorizedApps, deactivateMfa, deauthorizeOAuthApp} from 'actions/user_actions.jsx'; import $ from 'jquery'; import React from 'react'; @@ -29,7 +28,7 @@ export default class SecurityTab extends React.Component { this.submitPassword = this.submitPassword.bind(this); this.setupMfa = this.setupMfa.bind(this); - this.deactivateMfa = this.deactivateMfa.bind(this); + this.removeMfa = this.removeMfa.bind(this); this.updateCurrentPassword = this.updateCurrentPassword.bind(this); this.updateNewPassword = this.updateNewPassword.bind(this); this.updateConfirmPassword = this.updateConfirmPassword.bind(this); @@ -55,7 +54,7 @@ export default class SecurityTab extends React.Component { componentDidMount() { if (global.mm_config.EnableOAuthServiceProvider === 'true') { - Client.getAuthorizedApps( + getAuthorizedApps( (authorizedApps) => { this.setState({authorizedApps, serverError: null}); //eslint-disable-line react/no-did-mount-set-state }, @@ -120,10 +119,8 @@ export default class SecurityTab extends React.Component { browserHistory.push('/mfa/setup'); } - deactivateMfa() { - Client.updateMfa( - '', - false, + removeMfa() { + deactivateMfa( () => { if (global.window.mm_license.MFA === 'true' && global.window.mm_config.EnableMultifactorAuthentication === 'true' && @@ -133,7 +130,6 @@ export default class SecurityTab extends React.Component { } this.props.updateSection(''); - AsyncClient.getMe(); this.setState(this.getDefaultState()); }, (err) => { @@ -163,7 +159,7 @@ export default class SecurityTab extends React.Component { deauthorizeApp(e) { e.preventDefault(); const appId = e.currentTarget.getAttribute('data-app'); - Client.deauthorizeOAuthApp( + deauthorizeOAuthApp( appId, () => { const authorizedApps = this.state.authorizedApps.filter((app) => { @@ -223,7 +219,7 @@ export default class SecurityTab extends React.Component { {mfaButtonText} diff --git a/webapp/components/webrtc/webrtc_controller.jsx b/webapp/components/webrtc/webrtc_controller.jsx index 03953a19a..b8d3d4db6 100644 --- a/webapp/components/webrtc/webrtc_controller.jsx +++ b/webapp/components/webrtc/webrtc_controller.jsx @@ -644,7 +644,7 @@ export default class WebrtcController extends React.Component { } onConnectCall() { - Client.webrtcToken( + WebrtcActions.webrtcToken( (info) => { const connectingMsg = (