Skip to content

Commit

Permalink
chore(settings): added Server pane
Browse files Browse the repository at this point in the history
  • Loading branch information
polonel committed Sep 19, 2021
1 parent 2425d7e commit f82d40f
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/client/components/Nav/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ class Sidebar extends React.Component {
href='/settings/backup'
active={activeSubItem === 'settings-backup'}
/>
<SubmenuItem
text='Server'
icon='dns'
href='/settings/server'
active={activeSubItem === 'settings-server'}
/>
<SubmenuItem
text='Legal'
icon='gavel'
Expand Down Expand Up @@ -342,7 +348,4 @@ const mapStateToProps = state => ({
sessionUser: state.shared.sessionUser
})

export default connect(
mapStateToProps,
{ updateNavChange }
)(Sidebar)
export default connect(mapStateToProps, { updateNavChange })(Sidebar)
2 changes: 1 addition & 1 deletion src/client/containers/Settings/Mailer/mailerCheck.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Mailer_MailerCheck extends React.Component {
<div className='uk-float-right'>
<EnableSwitch
label={'Enable'}
stateName={'mailerCheckCreateAccount'}
stateName={'mailerCheckSelfSign'}
checked={this.state.mailerCheckSelfSign}
onChange={e => this.onCheckboxChanged(e, 'mailerCheckSelfSign')}
disabled={!this.getSetting('mailerCheckEnabled')}
Expand Down
117 changes: 117 additions & 0 deletions src/client/containers/Settings/Server/index.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className={active ? 'active' : 'hide'}>
<SettingItem
title={'Restart Server'}
subtitle={'Restart the Trudesk Instance. '}
component={
<Button
text={'Restart'}
flat={false}
waves={true}
style={'danger'}
extraClass={'right mt-8 mr-5'}
onClick={this.restartServer}
disabled={this.state.restarting}
/>
}
/>
</div>
)
}
}

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)
14 changes: 10 additions & 4 deletions src/client/containers/Settings/SettingsContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -137,6 +138,13 @@ class SettingsContainer extends React.Component {
this.onMenuItemClick(e, 'backup')
}}
/>
<MenuItem
title='Server'
active={this.state.activeCategory === 'settings-server'}
onClick={e => {
this.onMenuItemClick(e, 'server')
}}
/>
<MenuItem
title='Legal'
active={this.state.activeCategory === 'settings-legal'}
Expand All @@ -162,6 +170,7 @@ class SettingsContainer extends React.Component {
<ElasticsearchSettingsContainer active={this.state.activeCategory === 'settings-elasticsearch'} />
<TPSSettingsContainer active={this.state.activeCategory === 'settings-tps'} />
<BackupRestoreSettingsContainer active={this.state.activeCategory === 'settings-backup'} />
<ServerSettingsController active={this.state.activeCategory === 'settings-server'} />
<LegalSettingsContainer active={this.state.activeCategory === 'settings-legal'} />
</div>
</div>
Expand All @@ -180,7 +189,4 @@ const mapStateToProps = state => ({
sidebar: state.sidebar
})

export default connect(
mapStateToProps,
{ fetchSettings }
)(SettingsContainer)
export default connect(mapStateToProps, { fetchSettings })(SettingsContainer)
2 changes: 1 addition & 1 deletion src/controllers/backuprestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion src/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function buildGrants (obj) {

module.exports = {
register: register,
flustRoles: register,
flushRoles: register,
canThis: canThis,
hasHierarchyEnabled: hasHierarchyEnabled,
parseRoleHierarchy: parseRoleHierarchy,
Expand Down
7 changes: 7 additions & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f82d40f

Please sign in to comment.