mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 09:48:10 -05:00
Cleaned up Admin
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -11,11 +11,15 @@ module.exports = function (app, passport) {
|
|||||||
// serializing, and querying the user record by ID from the database when
|
// serializing, and querying the user record by ID from the database when
|
||||||
// deserializing.
|
// deserializing.
|
||||||
passport.serializeUser((user, done) => {
|
passport.serializeUser((user, done) => {
|
||||||
|
console.log("passport.serializeUser() - Serializing the user: " + user.id);
|
||||||
done(null, user.id)
|
done(null, user.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
passport.deserializeUser((id, done) => {
|
passport.deserializeUser((id, done) => {
|
||||||
|
console.log("passport.deserializeUser() - Trying to deSerialize the user: " + id);
|
||||||
User.findById(id, (err, user) => {
|
User.findById(id, (err, user) => {
|
||||||
|
console.log("passport.deserializeUser() - Found the user: " + user);
|
||||||
|
console.log("passport.deserializeUser() - Err: " + err);
|
||||||
done(err, user)
|
done(err, user)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -140,15 +140,19 @@ function csv_import(shortName, filename, callback) {
|
|||||||
console.error("Error: csv import 2: " + err);
|
console.error("Error: csv import 2: " + err);
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
} else {
|
} else {
|
||||||
|
var response = [];
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
var row = data[i];
|
var row = data[i];
|
||||||
|
row.num = parseInt(row.num);
|
||||||
|
row.tag = row.tag.toLowerCase();
|
||||||
|
row.group = row.group.toLowerCase();
|
||||||
var newTg = new Talkgroup();
|
var newTg = new Talkgroup();
|
||||||
newTg.num = parseInt(row.num);
|
newTg.num = row.num;
|
||||||
newTg.alpha = row.alpha;
|
newTg.alpha = row.alpha;
|
||||||
newTg.mode = row.mode;
|
newTg.mode = row.mode;
|
||||||
newTg.description = row.description;
|
newTg.description = row.description;
|
||||||
newTg.tag = row.tag.toLowerCase();
|
newTg.tag = row.tag;
|
||||||
newTg.group = row.group.toLowerCase();
|
newTg.group = row.group;
|
||||||
newTg.priority = row.priority;
|
newTg.priority = row.priority;
|
||||||
newTg.shortName = shortName;
|
newTg.shortName = shortName;
|
||||||
|
|
||||||
@@ -158,8 +162,10 @@ function csv_import(shortName, filename, callback) {
|
|||||||
callback(err, null);
|
callback(err, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
response.push(row);
|
||||||
}
|
}
|
||||||
callback(null, data);
|
callback(null, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -242,7 +248,6 @@ exports.fetchTalkgroups = function(req, res, next) {
|
|||||||
res.json({ success: false, message: err });
|
res.json({ success: false, message: err });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({ success: true, talkgroups: talkgroups });
|
res.json({ success: true, talkgroups: talkgroups });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ function isAdmin(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isLoggedIn(req, res, next) {
|
function isLoggedIn(req, res, next) {
|
||||||
|
console.log(req)
|
||||||
if (req.isAuthenticated()) return next();
|
if (req.isAuthenticated()) return next();
|
||||||
res.status(401).send({
|
res.status(401).send({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -7,49 +7,48 @@ import axios from "axios";
|
|||||||
* Higher-order component (HOC) to wrap restricted pages
|
* Higher-order component (HOC) to wrap restricted pages
|
||||||
*/
|
*/
|
||||||
const restricted = (BaseComponent, store) => {
|
const restricted = (BaseComponent, store) => {
|
||||||
class Restricted extends Component {
|
class Restricted extends Component {
|
||||||
componentWillMount() {
|
componentDidMount() {
|
||||||
this.checkAuthentication(this.props);
|
this.checkAuthentication(this.props);
|
||||||
}
|
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
if (nextProps.location !== this.props.location) {
|
|
||||||
this.checkAuthentication(nextProps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkAuthentication(params) {
|
|
||||||
const authenticated = store.getState().user.authenticated;
|
|
||||||
if (!authenticated) {
|
|
||||||
axios
|
|
||||||
.get(process.env.REACT_APP_ACCOUNT_SERVER + "/authenticated", {withCredentials: true})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.success) {
|
|
||||||
const user = response.data.user
|
|
||||||
store.dispatch({
|
|
||||||
type: types.LOGIN_SUCCESS_USER,
|
|
||||||
data: user
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
|
|
||||||
/*history.replace({ pathname: '/login',
|
|
||||||
state: { nextPathname: params.location.pathname } });*/
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
if (response instanceof Error) {
|
|
||||||
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
|
|
||||||
// Something happened during logout that triggered an Error
|
|
||||||
console.log("Error", response.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return <BaseComponent {...this.props} />;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return withRouter(Restricted);
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
if (prevProps.location !== this.props.location) {
|
||||||
|
this.checkAuthentication(this.props);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAuthentication(params) {
|
||||||
|
const authenticated = store.getState().user.authenticated;
|
||||||
|
if (!authenticated) {
|
||||||
|
axios
|
||||||
|
.get(process.env.REACT_APP_ACCOUNT_SERVER + "/authenticated", { withCredentials: true })
|
||||||
|
.then(response => {
|
||||||
|
if (response.data.success) {
|
||||||
|
const user = response.data.user
|
||||||
|
store.dispatch({
|
||||||
|
type: types.LOGIN_SUCCESS_USER,
|
||||||
|
data: user
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
|
||||||
|
/*history.replace({ pathname: '/login',
|
||||||
|
state: { nextPathname: params.location.pathname } });*/
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(response => {
|
||||||
|
if (response instanceof Error) {
|
||||||
|
window.location = process.env.REACT_APP_ACCOUNT_SERVER + "/login?nextLocation=admin";
|
||||||
|
// Something happened during logout that triggered an Error
|
||||||
|
console.log("Error", response.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
return <BaseComponent {...this.props} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return withRouter(Restricted);
|
||||||
}
|
}
|
||||||
export default restricted
|
export default restricted
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import ReactDOM from "react-dom";
|
|
||||||
import {
|
import {
|
||||||
Container,
|
|
||||||
Header,
|
|
||||||
Form,
|
|
||||||
Grid,
|
Grid,
|
||||||
Modal,
|
Modal,
|
||||||
Rail,
|
Rail,
|
||||||
@@ -11,15 +7,10 @@ import {
|
|||||||
List,
|
List,
|
||||||
Input,
|
Input,
|
||||||
Button,
|
Button,
|
||||||
Message,
|
|
||||||
Icon,
|
Icon,
|
||||||
Table
|
Table
|
||||||
} from "semantic-ui-react";
|
} from "semantic-ui-react";
|
||||||
|
|
||||||
// ----------------------------------------------------
|
|
||||||
const requestMessageStyle = {
|
|
||||||
color: "red"
|
|
||||||
};
|
|
||||||
|
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
class GroupModal extends Component {
|
class GroupModal extends Component {
|
||||||
@@ -46,14 +37,17 @@ class GroupModal extends Component {
|
|||||||
this.props.talkgroupActions.fetchTalkgroups(this.props.shortName);
|
this.props.talkgroupActions.fetchTalkgroups(this.props.shortName);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (nextProps.talkgroups && nextProps.groups && nextProps.editGroupId) {
|
|
||||||
var editGroup = nextProps.groups.find(
|
// This determines if you are trying to edit a group.
|
||||||
group => group._id === nextProps.editGroupId
|
// In this case, the value of editGroupID will chane to the group being edited
|
||||||
|
if (this.props.talkgroups && this.props.groups && this.props.editGroupId && !prevProps.editGroupId) {
|
||||||
|
var editGroup = this.props.groups.find(
|
||||||
|
group => group._id === this.props.editGroupId
|
||||||
);
|
);
|
||||||
var items = [];
|
var items = [];
|
||||||
|
|
||||||
var talkgroups = nextProps.talkgroups;
|
var talkgroups = this.props.talkgroups;
|
||||||
for (var i = 0; i < editGroup.talkgroups.length; i++) {
|
for (var i = 0; i < editGroup.talkgroups.length; i++) {
|
||||||
const talkgroupId = editGroup.talkgroups[i];
|
const talkgroupId = editGroup.talkgroups[i];
|
||||||
const index = talkgroups.findIndex(tg => tg.num === talkgroupId);
|
const index = talkgroups.findIndex(tg => tg.num === talkgroupId);
|
||||||
@@ -68,19 +62,23 @@ class GroupModal extends Component {
|
|||||||
.concat(talkgroups.slice(index + 1));
|
.concat(talkgroups.slice(index + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const group = {name: editGroup.groupName, items: items}
|
// we want to remove that are part of the Group from the list on the Left
|
||||||
this.setState({group: group, talkgroups: talkgroups, groupName: editGroup.groupName});
|
const group = { name: editGroup.groupName, items: items }
|
||||||
} else {
|
this.setState({ group: group, talkgroups: talkgroups, groupName: editGroup.groupName });
|
||||||
this.setState({ talkgroups: nextProps.talkgroups })
|
} else {
|
||||||
|
// If we are not editing, make sure there is the full list on the left.
|
||||||
|
this.setState({ talkgroups: this.props.talkgroups })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// If we are done editing, clear out the modal
|
||||||
|
if (!this.props.editGroupId && (this.props.editGroupId !== prevProps.editGroupId)) {
|
||||||
if (!nextProps.editGroupId && (this.props.editGroupId != nextProps.editGroupId)) {
|
this.setState({
|
||||||
this.setState({ groupName: "", group: {
|
groupName: "", group: {
|
||||||
name: "",
|
name: "",
|
||||||
items: []
|
items: []
|
||||||
}});
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTalkgroup(event, index) {
|
removeTalkgroup(event, index) {
|
||||||
@@ -125,11 +123,7 @@ class GroupModal extends Component {
|
|||||||
handleClose = () => this.props.onClose(false);
|
handleClose = () => this.props.onClose(false);
|
||||||
handleSubmit() {
|
handleSubmit() {
|
||||||
var talkgroupNums = this.state.group.items.map(a => a.num);
|
var talkgroupNums = this.state.group.items.map(a => a.num);
|
||||||
const data = {
|
|
||||||
shortName: this.props.shortName,
|
|
||||||
groupName: this.state.groupName,
|
|
||||||
talkgroups: JSON.stringify(talkgroupNums)
|
|
||||||
};
|
|
||||||
if (this.props.editGroupId) {
|
if (this.props.editGroupId) {
|
||||||
const data = {
|
const data = {
|
||||||
_id: this.props.editGroupId,
|
_id: this.props.editGroupId,
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ function makeUserRequest(method, data, api = "/login") {
|
|||||||
method: method,
|
method: method,
|
||||||
url: api,
|
url: api,
|
||||||
data: data,
|
data: data,
|
||||||
config: {withCredentials: true}
|
withCredentials: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,9 +41,7 @@ class AddPermissionModal extends Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||||
handleChange = (e, { newRole }) => this.setState({ newRole })
|
handleChange = (e, { newRole }) => this.setState({ newRole })
|
||||||
|
|||||||
@@ -163,12 +163,15 @@ class System extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProp) {
|
componentDidReceiveProps(prevProp) {
|
||||||
if (!this.props.errors && nextProp.errors) {
|
|
||||||
this.processErrors(nextProp.errors);
|
// If we just received the error statistics for a system, for the first time, proccess them.
|
||||||
|
if (this.props.errors && !prevProp.errors) {
|
||||||
|
this.processErrors(this.prop.errors);
|
||||||
}
|
}
|
||||||
if (!this.props.statistic && nextProp.statistic) {
|
// If we just received the call statistics for a system, for the first time, proccess them.
|
||||||
this.processStatistics(nextProp.statistic);
|
if (this.props.statistic && !prevProp.statistic) {
|
||||||
|
this.processStatistics(this.prop.statistic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ class SystemForm extends Component {
|
|||||||
countryError: false,
|
countryError: false,
|
||||||
isEditing: this.props.isEditing
|
isEditing: this.props.isEditing
|
||||||
};
|
};
|
||||||
if (this.props.isEditing && this.props.system)
|
if (this.props.isEditing && this.props.system) {
|
||||||
{
|
|
||||||
this.state.name = this.props.system.name;
|
this.state.name = this.props.system.name;
|
||||||
this.state.shortName = this.props.system.shortName;
|
this.state.shortName = this.props.system.shortName;
|
||||||
this.state.description = this.props.system.description;
|
this.state.description = this.props.system.description;
|
||||||
@@ -67,18 +66,19 @@ class SystemForm extends Component {
|
|||||||
this.state.showScreenName = this.props.system.showScreenName;
|
this.state.showScreenName = this.props.system.showScreenName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If we directly to an updating url, the system fetch will come back after the constructer, so we need to catch this and update the values
|
||||||
componentWillReceiveProps(nextProps) {
|
componentDidUpdate(prevProps) {
|
||||||
if (this.props.isEditing && nextProps.system) {
|
if (this.props.isEditing && this.props.system && !prevProps.system) {
|
||||||
this.setState({
|
this.setState({
|
||||||
name: nextProps.system.name,
|
name: this.props.system.name,
|
||||||
shortName: nextProps.system.shortName,
|
shortName: this.props.system.shortName,
|
||||||
description: nextProps.system.description,
|
description: this.props.system.description,
|
||||||
systemType: nextProps.system.systemType,
|
systemType: this.props.system.systemType,
|
||||||
state: nextProps.system.state,
|
city: this.props.system.city,
|
||||||
county: nextProps.system.county,
|
state: this.props.system.state,
|
||||||
country: nextProps.system.country,
|
county: this.props.system.county,
|
||||||
showScreenName: nextProps.system.showScreenName,
|
country: this.props.system.country,
|
||||||
|
showScreenName: this.props.system.showScreenName,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ class SystemForm extends Component {
|
|||||||
|
|
||||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||||
handleCheckboxChange() {
|
handleCheckboxChange() {
|
||||||
this.setState({showScreenName: !this.state.showScreenName});
|
this.setState({ showScreenName: !this.state.showScreenName });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
@@ -266,7 +266,7 @@ class SystemForm extends Component {
|
|||||||
<Message.Content>
|
<Message.Content>
|
||||||
<Message.Header>Problems...</Message.Header>
|
<Message.Header>Problems...</Message.Header>
|
||||||
<ul>
|
<ul>
|
||||||
{this.state.checkInputMessages.map(function(listValue) {
|
{this.state.checkInputMessages.map(function (listValue) {
|
||||||
return <li key={`ListItem_${counter++}`}>{listValue}</li>;
|
return <li key={`ListItem_${counter++}`}>{listValue}</li>;
|
||||||
})}
|
})}
|
||||||
{this.props.requestMessage.length > 0 && (
|
{this.props.requestMessage.length > 0 && (
|
||||||
@@ -310,9 +310,9 @@ class SystemForm extends Component {
|
|||||||
|
|
||||||
<p>Your Screen Name: {this.props.screenName}</p>
|
<p>Your Screen Name: {this.props.screenName}</p>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
onChange={this.handleCheckboxChange}
|
onChange={this.handleCheckboxChange}
|
||||||
checked={this.state.showScreenName}
|
checked={this.state.showScreenName}
|
||||||
label="Show in System Listing" />
|
label="Show in System Listing" />
|
||||||
|
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
<Divider horizontal />
|
<Divider horizontal />
|
||||||
@@ -360,8 +360,8 @@ class SystemForm extends Component {
|
|||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Form.Group widths="equal">
|
<Form.Group widths="equal">
|
||||||
|
|
||||||
{this.state.systemType === "city" && (
|
{this.state.systemType === "city" && (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
type="text"
|
type="text"
|
||||||
name="city"
|
name="city"
|
||||||
@@ -372,9 +372,9 @@ class SystemForm extends Component {
|
|||||||
placeholder="City..."
|
placeholder="City..."
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
)}
|
)}
|
||||||
{this.state.systemType === "county" && (
|
{this.state.systemType === "county" && (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
type="text"
|
type="text"
|
||||||
name="county"
|
name="county"
|
||||||
@@ -385,9 +385,9 @@ class SystemForm extends Component {
|
|||||||
placeholder="County..."
|
placeholder="County..."
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
)}
|
)}
|
||||||
{this.state.systemType === "international" ? (
|
{this.state.systemType === "international" ? (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
type="text"
|
type="text"
|
||||||
name="country"
|
name="country"
|
||||||
@@ -397,18 +397,18 @@ class SystemForm extends Component {
|
|||||||
label="Country"
|
label="Country"
|
||||||
placeholder="Country..."
|
placeholder="Country..."
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
) : (
|
) : (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Dropdown
|
<Form.Dropdown
|
||||||
name="state"
|
name="state"
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
error={this.state.stateError}
|
error={this.state.stateError}
|
||||||
value={this.state.state}
|
value={this.state.state}
|
||||||
options={stateOptions}
|
options={stateOptions}
|
||||||
label="State"
|
label="State"
|
||||||
placeholder="Select State..."
|
placeholder="Select State..."
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ function makeUserRequest(method, data, api = "/login") {
|
|||||||
return axios({
|
return axios({
|
||||||
method: method,
|
method: method,
|
||||||
url: api,
|
url: api,
|
||||||
data: data
|
data: data,
|
||||||
|
withCredentials: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +188,7 @@ export function deleteSystem(shortName) {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(beginDeleteSystem());
|
dispatch(beginDeleteSystem());
|
||||||
|
|
||||||
return makeUserRequest("delete", null, process.env.REACT_APP_ADMIN_SERVER + "/systems/"+shortName, {withCredentials: true})
|
return makeUserRequest("delete", null, process.env.REACT_APP_ADMIN_SERVER + "/systems/"+shortName)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
dispatch(deleteSystemSuccess({shortName: shortName}));
|
dispatch(deleteSystemSuccess({shortName: shortName}));
|
||||||
|
|||||||
Reference in New Issue
Block a user