Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Remove mm_config and mm_license global state from webapp, phase 2 (PR #3
Browse files Browse the repository at this point in the history
) (#865)

* MM-9635: expunge global mm_(license|config) from channel intro message component

* MM-9635: pass isLicensed to isChannelAdmin

* MM-9635: remove unused getWebsocketPort

* MM-9635: pass enableEmailBatching to getEmailInterval

* MM-9635: pass license and config to canDownloadFiles

* MM-9635: pass license and config to checkIfMFARequired
  • Loading branch information
lieut-data committed Feb 28, 2018
1 parent 78180eb commit 7036c4a
Show file tree
Hide file tree
Showing 42 changed files with 576 additions and 288 deletions.
2 changes: 1 addition & 1 deletion components/audio_video_preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ReactDOM from 'react-dom';
import Constants from 'utils/constants.jsx';
import * as Utils from 'utils/utils.jsx';

import FileInfoPreview from './file_info_preview.jsx';
import FileInfoPreview from 'components/file_info_preview';

export default class AudioVideoPreview extends React.PureComponent {
static propTypes = {
Expand Down
3 changes: 2 additions & 1 deletion components/channel_header/channel_header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class ChannelHeader extends React.Component {
rhsState: PropTypes.oneOf(
Object.values(RHSStates)
),
isLicensed: PropTypes.bool.isRequired,
enableWebrtc: PropTypes.bool.isRequired,
actions: PropTypes.shape({
leaveChannel: PropTypes.func.isRequired,
Expand Down Expand Up @@ -309,7 +310,7 @@ export default class ChannelHeader extends React.Component {
);

let channelTitle = channel.display_name;
const isChannelAdmin = Utils.isChannelAdmin(this.props.channelMember.roles);
const isChannelAdmin = Utils.isChannelAdmin(this.props.isLicensed, this.props.channelMember.roles);
const isTeamAdmin = !Utils.isEmptyObject(this.props.teamMember) && Utils.isAdmin(this.props.teamMember.roles);
const isSystemAdmin = Utils.isSystemAdmin(this.props.currentUser.roles);
const isDirect = (this.props.channel.type === Constants.DM_CHANNEL);
Expand Down
7 changes: 4 additions & 3 deletions components/channel_header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {getBool} from 'mattermost-redux/selectors/entities/preferences';
import {getMyTeamMember} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentUser, getStatusForUserId, getUser} from 'mattermost-redux/selectors/entities/users';
import {getUserIdFromChannelName, isDefault, isFavoriteChannel} from 'mattermost-redux/utils/channel_utils';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general';

import {withRouter} from 'react-router-dom';

Expand Down Expand Up @@ -40,8 +40,8 @@ function mapStateToProps(state, ownProps) {
dmUserStatus = {status: getStatusForUserId(state, dmUserId)};
}

const license = getLicense(state);
const config = getConfig(state);
const enableWebrtc = config.EnableWebrtc === 'true';

return {
channel,
Expand All @@ -54,7 +54,8 @@ function mapStateToProps(state, ownProps) {
dmUserStatus,
enableFormatting: getBool(state, Preferences.CATEGORY_ADVANCED_SETTINGS, 'formatting', true),
rhsState: getRhsState(state),
enableWebrtc,
isLicensed: license.IsLicensed === 'true',
enableWebrtc: config.EnableWebrtc === 'true',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class ChannelMembersDropdown extends React.Component {

render() {
const supportsChannelAdmin = this.props.isLicensed;
const isChannelAdmin = supportsChannelAdmin && Utils.isChannelAdmin(this.props.channelMember.roles);
const isChannelAdmin = supportsChannelAdmin && Utils.isChannelAdmin(this.props.isLicensed, this.props.channelMember.roles);

let serverError = null;
if (this.state.serverError) {
Expand Down
2 changes: 1 addition & 1 deletion components/code_preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Constants from 'utils/constants.jsx';
import * as SyntaxHighlighting from 'utils/syntax_highlighting.jsx';
import loadingGif from 'images/load.gif';

import FileInfoPreview from './file_info_preview.jsx';
import FileInfoPreview from 'components/file_info_preview';

export default class CodePreview extends React.Component {
constructor(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {getFileThumbnailUrl, getFileUrl} from 'mattermost-redux/utils/file_utils

import {FileTypes} from 'utils/constants.jsx';
import {
canDownloadFiles,
trimFilename,
} from 'utils/file_utils';
import {
Expand All @@ -16,10 +15,11 @@ import {
loadImage,
} from 'utils/utils.jsx';

import FilenameOverlay from 'components/file_attachment/filename_overlay.jsx';
import FileThumbnail from 'components/file_attachment/file_thumbnail.jsx';
import DownloadIcon from 'components/svg/download_icon';

import FilenameOverlay from './filename_overlay.jsx';
import FileThumbnail from './file_thumbnail.jsx';

export default class FileAttachment extends React.PureComponent {
static propTypes = {

Expand All @@ -42,6 +42,8 @@ export default class FileAttachment extends React.PureComponent {
* Display in compact format
*/
compactDisplay: PropTypes.bool,

canDownloadFiles: PropTypes.bool,
};

constructor(props) {
Expand Down Expand Up @@ -138,14 +140,13 @@ export default class FileAttachment extends React.PureComponent {
);
}

const canDownload = canDownloadFiles();
let filenameOverlay;
if (canDownload) {
if (this.props.canDownloadFiles) {
filenameOverlay = (
<FilenameOverlay
fileInfo={fileInfo}
compactDisplay={compactDisplay}
canDownload={canDownload}
canDownload={this.props.canDownloadFiles}
handleImageClick={this.onAttachmentClick}
iconClass={'post-image__download'}
>
Expand Down
20 changes: 20 additions & 0 deletions components/file_attachment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import {connect} from 'react-redux';
import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general';

import {canDownloadFiles} from 'utils/file_utils.jsx';

import FileAttachment from './file_attachment.jsx';

function mapStateToProps(state) {
const license = getLicense(state);
const config = getConfig(state);

return {
canDownloadFiles: canDownloadFiles(license, config),
};
}

export default connect(mapStateToProps)(FileAttachment);
4 changes: 2 additions & 2 deletions components/file_attachment_list/file_attachment_list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import React from 'react';
import Constants, {FileTypes} from 'utils/constants.jsx';
import {getFileType} from 'utils/utils';

import FileAttachment from 'components/file_attachment.jsx';
import FileAttachment from 'components/file_attachment';
import SingleImageView from 'components/single_image_view.jsx';
import ViewImageModal from 'components/view_image.jsx';
import ViewImageModal from 'components/view_image';

export default class FileAttachmentList extends React.Component {
static propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@
import PropTypes from 'prop-types';
import React from 'react';

import * as FileUtils from 'utils/file_utils';
import * as Utils from 'utils/utils.jsx';

export default class FileInfoPreview extends React.PureComponent {
static propTypes = {

/**
* Object with info about file
*/
fileInfo: PropTypes.object.isRequired,

/**
* String containing file URL
*/
fileUrl: PropTypes.string.isRequired,
canDownloadFiles: PropTypes.bool.isRequired,
};

render() {
Expand All @@ -37,7 +29,7 @@ export default class FileInfoPreview extends React.PureComponent {
const infoString = infoParts.join(', ');

let preview = null;
if (FileUtils.canDownloadFiles()) {
if (this.props.canDownloadFiles) {
preview = (
<a
className='file-details__preview'
Expand Down
20 changes: 20 additions & 0 deletions components/file_info_preview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import {connect} from 'react-redux';
import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general';

import {canDownloadFiles} from 'utils/file_utils.jsx';

import FileInfoPreview from './file_info_preview.jsx';

function mapStateToProps(state) {
const license = getLicense(state);
const config = getConfig(state);

return {
canDownloadFiles: canDownloadFiles(license, config),
};
}

export default connect(mapStateToProps)(FileInfoPreview);
20 changes: 20 additions & 0 deletions components/logged_in/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import {connect} from 'react-redux';
import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general';

import {checkIfMFARequired} from 'utils/route';

import LoggedIn from './logged_in.jsx';

function mapStateToProps(state, ownProps) {
const license = getLicense(state);
const config = getConfig(state);

return {
mfaRequired: checkIfMFARequired(license, config, ownProps.match.url),
};
}

export default connect(mapStateToProps)(LoggedIn);
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import ErrorStore from 'stores/error_store.jsx';
import * as UserAgent from 'utils/user_agent.jsx';
import * as Utils from 'utils/utils.jsx';
import LoadingScreen from 'components/loading_screen.jsx';
import {checkIfMFARequired} from 'utils/route';
import store from 'stores/redux_store.jsx';

const dispatch = store.dispatch;
Expand Down Expand Up @@ -151,7 +150,7 @@ export default class LoggedIn extends React.Component {
return <LoadingScreen/>;
}

if (this.props.location.pathname !== '/mfa/setup' && checkIfMFARequired(this.props.match.url)) {
if (this.props.location.pathname !== '/mfa/setup' && this.props.mfaRequired) {
return <Redirect to={'/mfa/setup'}/>;
}

Expand All @@ -169,4 +168,5 @@ export default class LoggedIn extends React.Component {

LoggedIn.propTypes = {
children: PropTypes.object,
mfaRequired: PropTypes.bool.isRequired,
};
9 changes: 8 additions & 1 deletion components/needs_team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import {fetchMyChannelsAndMembers, getMyChannelMembers, markChannelAsRead, viewC
import {getMyTeamUnreads} from 'mattermost-redux/actions/teams';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import {withRouter} from 'react-router-dom';
import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general';

import {checkIfMFARequired} from 'utils/route';

import NeedsTeam from './needs_team.jsx';

function mapStateToProps(state) {
function mapStateToProps(state, ownProps) {
const license = getLicense(state);
const config = getConfig(state);

return {
theme: getTheme(state),
mfaRequired: checkIfMFARequired(license, config, ownProps.match.url),
};
}

Expand Down
4 changes: 2 additions & 2 deletions components/needs_team/needs_team.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Constants from 'utils/constants.jsx';
import * as UserAgent from 'utils/user_agent.jsx';
import * as Utils from 'utils/utils.jsx';
import {loadProfilesForSidebar} from 'actions/user_actions.jsx';
import {checkIfMFARequired} from 'utils/route';
import {makeAsyncComponent} from 'components/async_load';
import loadBackstageController from 'bundle-loader?lazy!components/backstage';
import ChannelController from 'components/channel_layout/channel_controller';
Expand All @@ -42,6 +41,7 @@ export default class NeedsTeam extends React.Component {
getMyChannelMembers: PropTypes.func.isRequired,
}).isRequired,
theme: PropTypes.object.isRequired,
mfaRequired: PropTypes.bool.isRequired,
};

constructor(params) {
Expand All @@ -52,7 +52,7 @@ export default class NeedsTeam extends React.Component {

this.blurTime = new Date().getTime();

if (checkIfMFARequired(this.props.match.url)) {
if (this.props.mfaRequired) {
this.props.history.push('/mfa/setup');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion components/pdf_preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PDFJS from 'pdfjs-dist';

import loadingGif from 'images/load.gif';

import FileInfoPreview from './file_info_preview.jsx';
import FileInfoPreview from 'components/file_info_preview';

const MAX_PDF_PAGES = 5;
PDFJS.disableWorker = true;
Expand Down
Loading

0 comments on commit 7036c4a

Please sign in to comment.