From f82d40fdb2632f11d414f7c931a7757f8e4bad36 Mon Sep 17 00:00:00 2001 From: Chris Brame Date: Sun, 19 Sep 2021 00:03:32 -0400 Subject: [PATCH] chore(settings): added Server pane --- src/client/components/Nav/Sidebar/index.jsx | 11 +- .../Settings/Mailer/mailerCheck.jsx | 2 +- .../containers/Settings/Server/index.jsx | 117 ++++++++++++++++++ .../containers/Settings/SettingsContainer.jsx | 14 ++- src/controllers/backuprestore.js | 2 +- src/controllers/settings.js | 6 + src/permissions/index.js | 2 +- src/routes/index.js | 7 ++ 8 files changed, 150 insertions(+), 11 deletions(-) create mode 100644 src/client/containers/Settings/Server/index.jsx diff --git a/src/client/components/Nav/Sidebar/index.jsx b/src/client/components/Nav/Sidebar/index.jsx index 883404919..79aefb932 100644 --- a/src/client/components/Nav/Sidebar/index.jsx +++ b/src/client/components/Nav/Sidebar/index.jsx @@ -302,6 +302,12 @@ class Sidebar extends React.Component { href='/settings/backup' active={activeSubItem === 'settings-backup'} /> + ({ sessionUser: state.shared.sessionUser }) -export default connect( - mapStateToProps, - { updateNavChange } -)(Sidebar) +export default connect(mapStateToProps, { updateNavChange })(Sidebar) diff --git a/src/client/containers/Settings/Mailer/mailerCheck.jsx b/src/client/containers/Settings/Mailer/mailerCheck.jsx index cb655b950..12ec9df16 100644 --- a/src/client/containers/Settings/Mailer/mailerCheck.jsx +++ b/src/client/containers/Settings/Mailer/mailerCheck.jsx @@ -289,7 +289,7 @@ class Mailer_MailerCheck extends React.Component {
this.onCheckboxChanged(e, 'mailerCheckSelfSign')} disabled={!this.getSetting('mailerCheckEnabled')} diff --git a/src/client/containers/Settings/Server/index.jsx b/src/client/containers/Settings/Server/index.jsx new file mode 100644 index 000000000..c1375854d --- /dev/null +++ b/src/client/containers/Settings/Server/index.jsx @@ -0,0 +1,117 @@ +/* + * . .o8 oooo + * .o8 "888 `888 + * .o888oo oooo d8b oooo oooo .oooo888 .ooooo. .oooo.o 888 oooo + * 888 `888""8P `888 `888 d88' `888 d88' `88b d88( "8 888 .8P' + * 888 888 888 888 888 888 888ooo888 `"Y88b. 888888. + * 888 . 888 888 888 888 888 888 .o o. )88b 888 `88b. + * "888" d888b `V88V"V8P' `Y8bod88P" `Y8bod8P' 8""888P' o888o o888o + * ======================================================================== + * Author: Chris Brame + * Updated: 9/18/21 11:41 AM + * Copyright (c) 2014-2021. All rights reserved. + */ + +import React from 'react' +import PropTypes from 'prop-types' +import { connect } from 'react-redux' +import { updateSetting, updateMultipleSettings } from 'actions/settings' + +import Button from 'components/Button' +import SettingItem from 'components/Settings/SettingItem' +import EnableSwitch from 'components/Settings/EnableSwitch' + +import helpers from 'lib/helpers' +import axios from 'axios' +import Log from '../../../logger' + +class ServerSettingsController extends React.Component { + constructor (props) { + super(props) + + this.state = { + restarting: false + } + + this.restartServer = this.restartServer.bind(this) + } + + componentDidMount () { + // helpers.UI.inputs() + } + + componentDidUpdate () { + // helpers.UI.reRenderInputs() + } + + // static getDerivedStateFromProps (nextProps, state) { + // if (nextProps.settings) { + // let stateObj = { ...state } + // if (!state.tpsUsername) + // stateObj.tpsUsername = nextProps.settings.getIn(['settings', 'tpsUsername', 'value']) || '' + // if (!state.tpsApiKey) stateObj.tpsApiKey = nextProps.settings.getIn(['settings', 'tpsApiKey', 'value']) || '' + // + // return stateObj + // } + // + // return null + // } + + restartServer () { + this.setState({ restarting: true }) + + axios + .get('/api/v1/admin/restart') + .catch(error => { + helpers.hideLoader() + Log.error(error.response) + Log.error('Unable to restart server. Server must run under PM2 and Account must have admin rights.') + helpers.UI.showSnackbar('Unable to restart server. Are you an Administrator?', true) + }) + .then(() => { + this.setState({ restarting: false }) + }) + } + + getSetting (stateName) { + return this.props.settings.getIn(['settings', stateName, 'value']) + ? this.props.settings.getIn(['settings', stateName, 'value']) + : '' + } + + render () { + const { active } = this.props + return ( +
+ + } + /> +
+ ) + } +} + +ServerSettingsController.propTypes = { + active: PropTypes.bool.isRequired, + updateSetting: PropTypes.func.isRequired, + updateMultipleSettings: PropTypes.func.isRequired, + settings: PropTypes.object.isRequired +} + +const mapStateToProps = state => ({ + settings: state.settings.settings +}) + +export default connect(mapStateToProps, { updateSetting, updateMultipleSettings })(ServerSettingsController) diff --git a/src/client/containers/Settings/SettingsContainer.jsx b/src/client/containers/Settings/SettingsContainer.jsx index 0899d6cb6..9418410a6 100644 --- a/src/client/containers/Settings/SettingsContainer.jsx +++ b/src/client/containers/Settings/SettingsContainer.jsx @@ -28,6 +28,7 @@ import MailerSettingsContainer from './Mailer' import ElasticsearchSettingsContainer from './Elasticsearch' import TPSSettingsContainer from './TPS' import BackupRestoreSettingsContainer from './BackupRestore' +import ServerSettingsController from './Server' import LegalSettingsContainer from 'containers/Settings/Legal' import helpers from 'lib/helpers' @@ -137,6 +138,13 @@ class SettingsContainer extends React.Component { this.onMenuItemClick(e, 'backup') }} /> + { + this.onMenuItemClick(e, 'server') + }} + /> +
@@ -180,7 +189,4 @@ const mapStateToProps = state => ({ sidebar: state.sidebar }) -export default connect( - mapStateToProps, - { fetchSettings } -)(SettingsContainer) +export default connect(mapStateToProps, { fetchSettings })(SettingsContainer) diff --git a/src/controllers/backuprestore.js b/src/controllers/backuprestore.js index 0fd729131..2c49e1dfa 100644 --- a/src/controllers/backuprestore.js +++ b/src/controllers/backuprestore.js @@ -167,7 +167,7 @@ backupRestore.restoreBackup = function (req, res) { cache.fork.send({ name: 'cache:refresh:force' }) } - require('../permissions').flustRoles(function () {}) + require('../permissions').flushRoles(function () {}) result = { success: true } } else { diff --git a/src/controllers/settings.js b/src/controllers/settings.js index 8ded2ba92..1b31371d6 100644 --- a/src/controllers/settings.js +++ b/src/controllers/settings.js @@ -140,6 +140,12 @@ settingsController.backupSettings = function (req, res) { renderView(res, content) } +settingsController.serverSettings = function (req, res) { + var content = initViewContent('server', req) + + renderView(res, content) +} + settingsController.legal = function (req, res) { if (!checkPerms(req, 'settings:legal')) return res.redirect('/settings') diff --git a/src/permissions/index.js b/src/permissions/index.js index f9b9591f8..d67176c3b 100644 --- a/src/permissions/index.js +++ b/src/permissions/index.js @@ -179,7 +179,7 @@ function buildGrants (obj) { module.exports = { register: register, - flustRoles: register, + flushRoles: register, canThis: canThis, hasHierarchyEnabled: hasHierarchyEnabled, parseRoleHierarchy: parseRoleHierarchy, diff --git a/src/routes/index.js b/src/routes/index.js index a63c50d0f..f72d2ea39 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -317,6 +317,13 @@ function mainRoutes (router, middleware, controllers) { middleware.loadCommonData, controllers.settings.backupSettings ) + router.get( + '/settings/server', + middleware.redirectToLogin, + middleware.isAdmin, + middleware.loadCommonData, + controllers.settings.serverSettings + ) router.get('/settings/legal', middleware.redirectToLogin, middleware.loadCommonData, controllers.settings.legal) router.get('/settings/logs', middleware.redirectToLogin, middleware.loadCommonData, controllers.settings.logs)