admin_console.jsx 29.5 KB
Newer Older
1 2
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
3

4 5
import 'bootstrap';

6
import PropTypes from 'prop-types';
7
import React from 'react';
8
import {Route, Switch, Redirect} from 'react-router-dom';
9

10
import AnnouncementBar from 'components/announcement_bar';
11
import SystemNotice from 'components/system_notice';
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import {reloadIfServerVersionChanged} from 'actions/global_actions.jsx';
import ClientVersionsSettings from 'components/admin_console/client_versions_settings.jsx';
import ClusterSettings from 'components/admin_console/cluster_settings.jsx';
import CustomBrandSettings from 'components/admin_console/custom_brand_settings.jsx';
import CustomEmojiSettings from 'components/admin_console/custom_emoji_settings.jsx';
import DataRetentionSettings from 'components/admin_console/data_retention_settings.jsx';
import DatabaseSettings from 'components/admin_console/database_settings.jsx';
import ElasticsearchSettings from 'components/admin_console/elasticsearch_settings.jsx';
import EmailSettings from 'components/admin_console/email_settings.jsx';
import GitLabSettings from 'components/admin_console/gitlab_settings.jsx';
import MessageExportSettings from 'components/admin_console/message_export_settings';
import OAuthSettings from 'components/admin_console/oauth_settings.jsx';
import PasswordSettings from 'components/admin_console/password_settings.jsx';
import PluginManagement from 'components/admin_console/plugin_management';
import CustomPluginSettings from 'components/admin_console/custom_plugin_settings';
27 28
import CustomIntegrationSettings from 'components/admin_console/custom_integrations_settings';
import UsersAndTeamsSettings from 'components/admin_console/users_and_teams_settings';
29

30
import SchemaAdminSettings from 'components/admin_console/schema_admin_settings';
31 32 33
import PushSettings from 'components/admin_console/push_settings.jsx';
import SamlSettings from 'components/admin_console/saml_settings.jsx';
import SessionSettings from 'components/admin_console/session_settings.jsx';
34
import DiscardChangesModal from 'components/discard_changes_modal.jsx';
35

36
import AdminSidebar from './admin_sidebar';
37
import AdminDefinition from './admin_definition';
38

39 40 41 42 43 44 45 46
const SCRoute = ({component: Component, extraProps, ...rest}) => ( //eslint-disable-line react/prop-types
    <Route
        {...rest}
        render={(props) => (
            <Component
                {...extraProps}
                {...props}
            />
47
        )}
48 49 50
    />
);

51
export default class AdminConsole extends React.Component {
52
    static propTypes = {
53

54 55 56 57 58
        /*
         * Object representing the config file
         */
        config: PropTypes.object.isRequired,

59 60 61 62 63
        /*
         * Object containing config fields that have been set through environment variables
         */
        environmentConfig: PropTypes.object,

64 65 66 67 68
        /*
         * Object representing the license
         */
        license: PropTypes.object.isRequired,

69
        /*
70
         * Object from react-router
71
         */
72 73 74
        match: PropTypes.shape({
            url: PropTypes.string.isRequired,
        }).isRequired,
75

76 77 78 79 80 81
        /*
         * String whether to show prompt to navigate away
         * from unsaved changes
         */
        showNavigationPrompt: PropTypes.bool.isRequired,

82 83
        isCurrentUserSystemAdmin: PropTypes.bool.isRequired,

84
        actions: PropTypes.shape({
85

86 87 88
            /*
             * Function to get the config file
             */
89 90
            getConfig: PropTypes.func.isRequired,

91 92 93 94 95
            /*
             * Function to get the environment config
             */
            getEnvironmentConfig: PropTypes.func.isRequired,

96 97 98 99 100 101 102 103 104 105 106 107 108
            /*
             * Function to block navigation when there are unsaved changes
             */
            setNavigationBlocked: PropTypes.func.isRequired,

            /*
             * Function to confirm navigation
             */
            confirmNavigation: PropTypes.func.isRequired,

            /*
             * Function to cancel navigation away from unsaved changes
             */
109 110
            cancelNavigation: PropTypes.func.isRequired,
        }).isRequired,
111 112
    }

113
    UNSAFE_componentWillMount() { // eslint-disable-line camelcase
114
        this.props.actions.getConfig();
115
        this.props.actions.getEnvironmentConfig();
116
        reloadIfServerVersionChanged();
117 118 119
    }

    render() {
120 121 122 123 124 125
        const {
            license,
            config,
            environmentConfig,
            showNavigationPrompt,
        } = this.props;
126 127
        const {setNavigationBlocked, cancelNavigation, confirmNavigation} = this.props.actions;

128 129 130 131 132 133
        if (!this.props.isCurrentUserSystemAdmin) {
            return (
                <Redirect to='/'/>
            );
        }

134
        if (Object.keys(config).length === 0) {
135 136
            return <div/>;
        }
137 138
        if (config && Object.keys(config).length === 0 && config.constructor === 'Object') {
            return (
139
                <div className='admin-console__wrapper'>
140
                    <AnnouncementBar/>
141 142 143
                    <div className='admin-console'/>
                </div>
            );
144 145
        }

146 147 148 149 150 151 152 153
        const discardChangesModal = (
            <DiscardChangesModal
                show={showNavigationPrompt}
                onConfirm={confirmNavigation}
                onCancel={cancelNavigation}
            />
        );

154
        // not every page in the system console will need the license and config, but the vast majority will
155 156 157 158 159 160 161
        const extraProps = {
            license,
            config,
            environmentConfig,
            setNavigationBlocked,
        };

162
        return (
163
            <div className='admin-console__wrapper'>
164
                <AnnouncementBar/>
165
                <SystemNotice/>
Asaad Mahmood's avatar
Asaad Mahmood committed
166
                <AdminSidebar/>
167
                <div className='admin-console'>
168 169 170
                    <Switch>
                        <SCRoute
                            path={`${this.props.match.url}/system_analytics`}
171 172 173 174 175
                            component={SchemaAdminSettings}
                            extraProps={{
                                ...extraProps,
                                schema: AdminDefinition.reporting.system_analytics.schema,
                            }}
176 177 178 179 180 181 182
                        />
                        <Route
                            path={`${this.props.match.url}/general`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/configuration`}
183 184 185 186 187
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.general.configuration.schema,
                                        }}
188 189 190
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/localization`}
191 192 193 194 195
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.general.localization.schema,
                                        }}
196 197 198
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/users_and_teams`}
199 200
                                        component={UsersAndTeamsSettings}
                                        extraProps={extraProps}
201 202 203
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/privacy`}
204 205 206 207 208
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.general.privacy.schema,
                                        }}
209 210 211
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/compliance`}
212 213 214 215 216
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.general.compliance.schema,
                                        }}
217 218 219
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/logging`}
220 221 222 223 224
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.general.logging.schema,
                                        }}
225 226 227
                                    />
                                    <Redirect to={`${props.match.url}/configuration`}/>
                                </Switch>
228
                            )}
229
                        />
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
                        <Route
                            path={`${this.props.match.url}/permissions`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/schemes`}
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.permissions.schemes.schema,
                                        }}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/system-scheme`}
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.permissions.systemScheme.schema,
                                        }}
                                    />
                                </Switch>
                        )}
                        />
253 254 255 256 257 258
                        <Route
                            path={`${this.props.match.url}/authentication`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/authentication_email`}
259 260 261 262 263
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.authentication.email.schema,
                                        }}
264 265 266 267 268 269 270 271 272 273 274 275 276
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/gitlab`}
                                        component={GitLabSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/oauth`}
                                        component={OAuthSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/ldap`}
277 278 279 280 281
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.authentication.ldap.schema,
                                        }}
282 283 284 285 286 287 288 289
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/saml`}
                                        component={SamlSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/mfa`}
290 291 292 293 294
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.authentication.mfa.schema,
                                        }}
295 296 297
                                    />
                                    <Redirect to={`${props.match.url}/authentication_email`}/>
                                </Switch>
298
                            )}
299 300 301 302 303 304 305
                        />
                        <Route
                            path={`${this.props.match.url}/security`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/sign_up`}
306 307 308 309 310
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.security.signup.schema,
                                        }}
311 312 313 314 315 316 317 318
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/password`}
                                        component={PasswordSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/public_links`}
319 320 321 322 323
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.security.public_links.schema,
                                        }}
324 325 326 327 328 329 330 331
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/sessions`}
                                        component={SessionSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/connections`}
332 333 334 335 336
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.security.connections.schema,
                                        }}
337 338 339 340 341 342 343 344
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/client_versions`}
                                        component={ClientVersionsSettings}
                                        extraProps={extraProps}
                                    />
                                    <Redirect to={`${props.match.url}/sign_up`}/>
                                </Switch>
345
                            )}
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
                        />
                        <Route
                            path={`${this.props.match.url}/notifications`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/notifications_email`}
                                        component={EmailSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/push`}
                                        component={PushSettings}
                                        extraProps={extraProps}
                                    />
                                    <Redirect to={`${props.match.url}/notifications_email`}/>
                                </Switch>
363
                            )}
364 365 366 367 368 369 370
                        />
                        <Route
                            path={`${this.props.match.url}/integrations`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/custom`}
371 372
                                        component={CustomIntegrationSettings}
                                        extraProps={extraProps}
373 374
                                    />
                                    <SCRoute
375 376 377 378 379 380
                                        path={`${props.match.url}/webrtc`}
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.integrations.webrtc.schema,
                                        }}
381 382
                                    />
                                    <SCRoute
383 384 385 386 387 388
                                        path={`${props.match.url}/external`}
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.integrations.external.schema,
                                        }}
389 390 391
                                    />
                                    <Redirect to={`${props.match.url}/custom`}/>
                                </Switch>
392
                            )}
393 394 395 396 397 398 399
                        />
                        <Route
                            path={`${this.props.match.url}/plugins`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/configuration`}
400 401 402 403 404
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.plugins.configuration.schema,
                                        }}
405 406 407 408 409 410 411 412 413 414 415 416 417
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/management`}
                                        component={PluginManagement}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/custom/:plugin_id`}
                                        component={CustomPluginSettings}
                                        extraProps={extraProps}
                                    />
                                    <Redirect to={`${props.match.url}/configuration`}/>
                                </Switch>
418
                            )}
419 420 421 422 423 424 425
                        />
                        <Route
                            path={`${this.props.match.url}/files`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/storage`}
426 427 428 429 430
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.files.storage.schema,
                                        }}
431 432 433
                                    />
                                    <Redirect to={`${props.match.url}/storage`}/>
                                </Switch>
434
                            )}
435 436 437 438 439 440 441 442 443 444
                        />
                        <Route
                            path={`${this.props.match.url}/customization`}
                            render={(props) => (
                                <Switch>
                                    <SCRoute
                                        path={`${props.match.url}/custom_brand`}
                                        component={CustomBrandSettings}
                                        extraProps={extraProps}
                                    />
445 446 447 448 449 450 451 452
                                    <SCRoute
                                        path={`${props.match.url}/announcement`}
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.customization.announcement.schema,
                                        }}
                                    />
453 454 455 456 457 458 459
                                    <SCRoute
                                        path={`${props.match.url}/emoji`}
                                        component={CustomEmojiSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/link_previews`}
460 461 462 463 464
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.customization.link_previews.schema,
                                        }}
465 466 467
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/legal_and_support`}
468 469 470 471 472
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.customization.legal_and_support.schema,
                                        }}
473 474 475
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/native_app_links`}
476 477 478 479 480
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.customization.native_app_links.schema,
                                        }}
481 482 483
                                    />
                                    <Redirect to={`${props.match.url}/custom_brand`}/>
                                </Switch>
484
                            )}
485 486
                        />
                        <Route
487
                            path={`${this.props.match.url}/compliance`}
488 489 490
                            render={(props) => (
                                <Switch>
                                    <SCRoute
491 492
                                        path={`${props.match.url}/data_retention`}
                                        component={DataRetentionSettings}
493 494 495
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
496 497
                                        path={`${props.match.url}/message_export`}
                                        component={MessageExportSettings}
498 499
                                        extraProps={extraProps}
                                    />
500 501
                                    <Redirect to={`${props.match.url}/data_retention`}/>
                                </Switch>
502
                            )}
503 504 505 506 507
                        />
                        <Route
                            path={`${this.props.match.url}/advanced`}
                            render={(props) => (
                                <Switch>
508
                                    <SCRoute
509
                                        path={`${props.match.url}/rate`}
510 511 512 513 514
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.advanced.rate.schema,
                                        }}
515 516
                                    />
                                    <SCRoute
517 518
                                        path={`${props.match.url}/database`}
                                        component={DatabaseSettings}
519 520 521 522 523 524 525 526 527
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/elasticsearch`}
                                        component={ElasticsearchSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/developer`}
528 529 530 531 532
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.advanced.developer.schema,
                                        }}
533 534 535 536 537 538 539 540
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/cluster`}
                                        component={ClusterSettings}
                                        extraProps={extraProps}
                                    />
                                    <SCRoute
                                        path={`${props.match.url}/metrics`}
541 542 543 544 545
                                        component={SchemaAdminSettings}
                                        extraProps={{
                                            ...extraProps,
                                            schema: AdminDefinition.settings.advanced.metrics.schema,
                                        }}
546 547 548
                                    />
                                    <Redirect to={`${props.match.url}/rate`}/>
                                </Switch>
549
                            )}
550 551 552
                        />
                        <SCRoute
                            path={`${this.props.match.url}/users`}
553 554 555 556 557
                            component={SchemaAdminSettings}
                            extraProps={{
                                ...extraProps,
                                schema: AdminDefinition.reporting.system_users.schema,
                            }}
558 559 560
                        />
                        <SCRoute
                            path={`${this.props.match.url}/team_analytics`}
561 562 563 564 565
                            component={SchemaAdminSettings}
                            extraProps={{
                                ...extraProps,
                                schema: AdminDefinition.reporting.team_analytics.schema,
                            }}
566 567 568
                        />
                        <SCRoute
                            path={`${this.props.match.url}/license`}
569 570 571 572 573
                            component={SchemaAdminSettings}
                            extraProps={{
                                ...extraProps,
                                schema: AdminDefinition.other.license.schema,
                            }}
574 575 576
                        />
                        <SCRoute
                            path={`${this.props.match.url}/audits`}
577 578 579 580 581
                            component={SchemaAdminSettings}
                            extraProps={{
                                ...extraProps,
                                schema: AdminDefinition.other.audits.schema,
                            }}
582 583 584
                        />
                        <SCRoute
                            path={`${this.props.match.url}/logs`}
585 586 587 588 589
                            component={SchemaAdminSettings}
                            extraProps={{
                                ...extraProps,
                                schema: AdminDefinition.reporting.server_logs.schema,
                            }}
590 591 592
                        />
                        <Redirect to={`${this.props.match.url}/system_analytics`}/>
                    </Switch>
593
                </div>
594
                {discardChangesModal}
595 596 597 598
            </div>
        );
    }
}