mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-28 00:04:31 +02:00
Ivan - Add view restrictions for admin [skip ci]
This commit is contained in:
parent
5fca935c8d
commit
c66a73df8e
@ -6,6 +6,17 @@ import { browserHistory } from 'react-router';
|
|||||||
|
|
||||||
import ModalContainer from 'app-components/modal-container';
|
import ModalContainer from 'app-components/modal-container';
|
||||||
|
|
||||||
|
const level2Paths = [
|
||||||
|
'/admin/panel/tickets/custom-responses',
|
||||||
|
'/admin/panel/users',
|
||||||
|
'/admin/panel/articles'
|
||||||
|
];
|
||||||
|
|
||||||
|
const level3Paths = [
|
||||||
|
'/admin/panel/staff',
|
||||||
|
'/admin/panel/settings'
|
||||||
|
];
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
router: React.PropTypes.object,
|
router: React.PropTypes.object,
|
||||||
@ -66,6 +77,25 @@ class App extends React.Component {
|
|||||||
} else if(validations.loggedInStaff) {
|
} else if(validations.loggedInStaff) {
|
||||||
browserHistory.push('/admin/panel');
|
browserHistory.push('/admin/panel');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.props.session.userLevel && !this.isPathAvailableForStaff()) {
|
||||||
|
browserHistory.push('/admin/panel');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isPathAvailableForStaff() {
|
||||||
|
let pathForLevel2 = _.findIndex(level2Paths, path => _.includes(this.props.location.pathname, path)) !== -1;
|
||||||
|
let pathForLevel3 = _.findIndex(level3Paths, path => _.includes(this.props.location.pathname, path)) !== -1;
|
||||||
|
|
||||||
|
if (this.props.session.userLevel === 1) {
|
||||||
|
return !pathForLevel2 && !pathForLevel3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.props.session.userLevel === 2) {
|
||||||
|
return !pathForLevel3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import {connect} from 'react-redux';
|
||||||
|
|
||||||
import {dispatch} from 'app/store';
|
import {dispatch} from 'app/store';
|
||||||
import i18n from 'lib-app/i18n';
|
import i18n from 'lib-app/i18n';
|
||||||
@ -90,113 +91,142 @@ class AdminPanelMenu extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getRoutes() {
|
getRoutes() {
|
||||||
return [
|
return this.getItemsByFilteredByLevel([
|
||||||
{
|
{
|
||||||
groupName: i18n('DASHBOARD'),
|
groupName: i18n('DASHBOARD'),
|
||||||
path: '/admin/panel',
|
path: '/admin/panel',
|
||||||
icon: 'tachometer',
|
icon: 'tachometer',
|
||||||
items: [
|
level: 1,
|
||||||
|
items: this.getItemsByFilteredByLevel([
|
||||||
{
|
{
|
||||||
name: i18n('TICKET_STATS'),
|
name: i18n('TICKET_STATS'),
|
||||||
path: '/admin/panel/stats'
|
path: '/admin/panel/stats',
|
||||||
|
level: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('LAST_ACTIVITY'),
|
name: i18n('LAST_ACTIVITY'),
|
||||||
path: '/admin/panel/activity'
|
path: '/admin/panel/activity',
|
||||||
|
level: 1
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
groupName: i18n('TICKETS'),
|
groupName: i18n('TICKETS'),
|
||||||
path: '/admin/panel/tickets',
|
path: '/admin/panel/tickets',
|
||||||
icon: 'ticket',
|
icon: 'ticket',
|
||||||
items: [
|
level: 1,
|
||||||
|
items: this.getItemsByFilteredByLevel([
|
||||||
{
|
{
|
||||||
name: i18n('MY_TICKETS'),
|
name: i18n('MY_TICKETS'),
|
||||||
path: '/admin/panel/tickets/my-tickets'
|
path: '/admin/panel/tickets/my-tickets',
|
||||||
|
level: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('NEW_TICKETS'),
|
name: i18n('NEW_TICKETS'),
|
||||||
path: '/admin/panel/tickets/new-tickets'
|
path: '/admin/panel/tickets/new-tickets',
|
||||||
|
level: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('ALL_TICKETS'),
|
name: i18n('ALL_TICKETS'),
|
||||||
path: '/admin/panel/tickets/all-tickets'
|
path: '/admin/panel/tickets/all-tickets',
|
||||||
|
level: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('CUSTOM_RESPONSES'),
|
name: i18n('CUSTOM_RESPONSES'),
|
||||||
path: '/admin/panel/tickets/custom-responses'
|
path: '/admin/panel/tickets/custom-responses',
|
||||||
|
level: 2
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
groupName: i18n('USERS'),
|
groupName: i18n('USERS'),
|
||||||
path: '/admin/panel/users',
|
path: '/admin/panel/users',
|
||||||
icon: 'user',
|
icon: 'user',
|
||||||
items: [
|
level: 1,
|
||||||
|
items: this.getItemsByFilteredByLevel([
|
||||||
{
|
{
|
||||||
name: i18n('LIST_USERS'),
|
name: i18n('LIST_USERS'),
|
||||||
path: '/admin/panel/users/list-users'
|
path: '/admin/panel/users/list-users',
|
||||||
|
level: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('BAN_USERS'),
|
name: i18n('BAN_USERS'),
|
||||||
path: '/admin/panel/users/ban-users'
|
path: '/admin/panel/users/ban-users',
|
||||||
|
level: 1
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
groupName: i18n('ARTICLES'),
|
groupName: i18n('ARTICLES'),
|
||||||
path: '/admin/panel/articles',
|
path: '/admin/panel/articles',
|
||||||
icon: 'book',
|
icon: 'book',
|
||||||
items: [
|
level: 2,
|
||||||
|
items: this.getItemsByFilteredByLevel([
|
||||||
{
|
{
|
||||||
name: i18n('LIST_ARTICLES'),
|
name: i18n('LIST_ARTICLES'),
|
||||||
path: '/admin/panel/articles/list-articles'
|
path: '/admin/panel/articles/list-articles',
|
||||||
|
level: 2
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
groupName: i18n('STAFF'),
|
groupName: i18n('STAFF'),
|
||||||
path: '/admin/panel/staff',
|
path: '/admin/panel/staff',
|
||||||
icon: 'users',
|
icon: 'users',
|
||||||
items: [
|
level: 3,
|
||||||
|
items: this.getItemsByFilteredByLevel([
|
||||||
{
|
{
|
||||||
name: i18n('STAFF_MEMBERS'),
|
name: i18n('STAFF_MEMBERS'),
|
||||||
path: '/admin/panel/staff/staff-members'
|
path: '/admin/panel/staff/staff-members',
|
||||||
|
level: 3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('DEPARTMENTS'),
|
name: i18n('DEPARTMENTS'),
|
||||||
path: '/admin/panel/staff/departments'
|
path: '/admin/panel/staff/departments',
|
||||||
|
level: 3
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
groupName: i18n('SETTINGS'),
|
groupName: i18n('SETTINGS'),
|
||||||
path: '/admin/panel/settings',
|
path: '/admin/panel/settings',
|
||||||
icon: 'cogs',
|
icon: 'cogs',
|
||||||
items: [
|
level: 3,
|
||||||
|
items: this.getItemsByFilteredByLevel([
|
||||||
{
|
{
|
||||||
name: i18n('SYSTEM_PREFERENCES'),
|
name: i18n('SYSTEM_PREFERENCES'),
|
||||||
path: '/admin/panel/settings/system-preferences'
|
path: '/admin/panel/settings/system-preferences',
|
||||||
|
level: 3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('USER_SYSTEM'),
|
name: i18n('USER_SYSTEM'),
|
||||||
path: '/admin/panel/settings/user-system'
|
path: '/admin/panel/settings/user-system',
|
||||||
|
level: 3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('EMAIL_TEMPLATES'),
|
name: i18n('EMAIL_TEMPLATES'),
|
||||||
path: '/admin/panel/settings/email-templates'
|
path: '/admin/panel/settings/email-templates',
|
||||||
|
level: 3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: i18n('FILTERS_CUSTOM_FIELDS'),
|
name: i18n('FILTERS_CUSTOM_FIELDS'),
|
||||||
path: '/admin/panel/settings/custom-fields'
|
path: '/admin/panel/settings/custom-fields',
|
||||||
|
level: 3
|
||||||
}
|
}
|
||||||
]
|
])
|
||||||
}
|
}
|
||||||
];
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
getItemsByFilteredByLevel(items) {
|
||||||
|
return (this.props.level) ? _.filter(items, route => this.props.level >= route.level) : items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AdminPanelMenu;
|
export default connect((store) => {
|
||||||
|
return {
|
||||||
|
level: store.session.userLevel
|
||||||
|
};
|
||||||
|
})(AdminPanelMenu);
|
@ -61,6 +61,7 @@ class CheckBox extends React.Component {
|
|||||||
delete props.errored;
|
delete props.errored;
|
||||||
delete props.label;
|
delete props.label;
|
||||||
delete props.value;
|
delete props.value;
|
||||||
|
delete props.wrapInLabel;
|
||||||
|
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ $transition: background-color 0.3s ease, color 0.3s ease;
|
|||||||
}
|
}
|
||||||
|
|
||||||
&_horizontal {
|
&_horizontal {
|
||||||
text-align: center;
|
text-align: left;
|
||||||
|
|
||||||
.menu__list {
|
.menu__list {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
@ -98,6 +98,7 @@ $transition: background-color 0.3s ease, color 0.3s ease;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.menu__list-item {
|
.menu__list-item {
|
||||||
|
text-align: center;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
color: $primary-black;
|
color: $primary-black;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -11,7 +11,7 @@ module.exports = [
|
|||||||
name: 'Emilia Clarke',
|
name: 'Emilia Clarke',
|
||||||
email: 'staff@opensupports.com',
|
email: 'staff@opensupports.com',
|
||||||
profilePic: 'http://www.opensupports.com/profilepic.jpg',
|
profilePic: 'http://www.opensupports.com/profilepic.jpg',
|
||||||
level: 1,
|
level: 3,
|
||||||
staff: true,
|
staff: true,
|
||||||
departments: [
|
departments: [
|
||||||
{id: 1, name: 'Sales Support'},
|
{id: 1, name: 'Sales Support'},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user