mirror of
https://github.com/wassname/talk.git
synced 2026-08-14 12:50:17 +08:00
have function params in the correct order
This commit is contained in:
@@ -6,7 +6,7 @@ import {toggleModal as toggleShortcutModal} from '../actions/moderation';
|
||||
import {fetchConfig} from '../actions/config';
|
||||
import {FullLoading} from '../components/FullLoading';
|
||||
import AdminLogin from '../components/AdminLogin';
|
||||
import roleUtils from 'coral-framework/utils/roles';
|
||||
import {can} from 'coral-framework/utils/roles';
|
||||
|
||||
class LayoutContainer extends Component {
|
||||
componentWillMount () {
|
||||
@@ -36,7 +36,7 @@ class LayoutContainer extends Component {
|
||||
recaptchaPublic={TALK_RECAPTCHA_PUBLIC}
|
||||
errorMessage={loginError} />;
|
||||
}
|
||||
if (roleUtils.canAccessAdmin(user) && loggedIn) {
|
||||
if (can(user, 'ACCESS_ADMIN') && loggedIn) {
|
||||
return <Layout handleLogout={handleLogout} toggleShortcutModal={toggleShortcutModal} {...this.props} />;
|
||||
} else if (loggedIn) {
|
||||
return <p>you do not have permission to see this page.</p>;
|
||||
|
||||
@@ -1,30 +1,29 @@
|
||||
import intersection from 'lodash/intersection';
|
||||
|
||||
const basicRoles = {
|
||||
hasStaffTag: ['ADMIN', 'MODERATOR', 'STAFF']
|
||||
HAS_STAFF_TAG: ['ADMIN', 'MODERATOR', 'STAFF']
|
||||
};
|
||||
|
||||
const queryRoles = {
|
||||
canAccessConfig: ['ADMIN', 'MODERATOR'],
|
||||
canAccessAdmin: ['ADMIN', 'MODERATOR'],
|
||||
canViewUserEmails: ['ADMIN']
|
||||
UPDATE_CONFIG: ['ADMIN', 'MODERATOR'],
|
||||
ACCESS_ADMIN: ['ADMIN', 'MODERATOR'],
|
||||
VIEW_USER_EMAILS: ['ADMIN']
|
||||
};
|
||||
|
||||
const mutationRoles = {
|
||||
canChangeRoles: ['ADMIN'],
|
||||
canModerateComments: ['ADMIN', 'MODERATOR']
|
||||
CHANGE_ROLES: ['ADMIN'],
|
||||
MODERATE_COMMENTS: ['ADMIN', 'MODERATOR']
|
||||
};
|
||||
|
||||
const roles = {...basicRoles, ...queryRoles, ...mutationRoles};
|
||||
|
||||
export const can = (user, perms) => {
|
||||
for (let perm in perms) {
|
||||
export const can = (user, ...perms) => {
|
||||
return perms.every(perm => {
|
||||
const role = roles[perm];
|
||||
if (typeof role === 'undefined') {
|
||||
continue;
|
||||
throw new Error(`${perm} is not a valid role`);
|
||||
}
|
||||
let grant = intersection(role, user.roles).length > 0;
|
||||
return grant;
|
||||
}
|
||||
return false;
|
||||
|
||||
return intersection(role, user.roles).length > 0;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user