mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 18:52:05 +03:00
Merge pull request #5445 from cobbspur/canHelper
Hide Nav Settings based on permissions
This commit is contained in:
commit
e7398b0694
17
core/client/app/helpers/gh-user-can.js
Normal file
17
core/client/app/helpers/gh-user-can.js
Normal file
@ -0,0 +1,17 @@
|
||||
import Ember from 'ember';
|
||||
// Handlebars Helper {{gh-user-can}}
|
||||
// Usage: call helper as with first parameter of session.user and second parameter the minimum role
|
||||
// e.g - {{#if (gh-user-can session.user 'admin')}} 'block content' {{/if}}
|
||||
// @param1 session.user
|
||||
// @param2 'admin' or 'editor'
|
||||
|
||||
export function ghUserCan(params) {
|
||||
if (params[1] === 'admin') {
|
||||
return !!(params[0].get('isOwner') || params[0].get('isAdmin'));
|
||||
} else if (params[1] === 'editor') {
|
||||
return !!(params[0].get('isOwner') || params[0].get('isAdmin') || params[0].get('isEditor'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export default Ember.HTMLBars.makeBoundHelper(ghUserCan);
|
@ -27,6 +27,7 @@
|
||||
<li>{{#link-to "settings.users" classNames="gh-nav-main-users"}}<i class="icon-team"></i>Team{{/link-to}}</li>
|
||||
{{!<li><a href="#"><i class="icon-idea"></i>Ideas</a></li>}}
|
||||
</ul>
|
||||
{{#if (gh-user-can session.user 'admin')}}
|
||||
<ul class="gh-nav-list gh-nav-settings">
|
||||
<li class="gh-nav-list-h">Settings</li>
|
||||
<li>{{#link-to "settings.general" classNames="gh-nav-settings-general"}}<i class="icon-settings"></i>General{{/link-to}}</li>
|
||||
@ -36,6 +37,7 @@
|
||||
<li>{{#link-to "settings.code-injection" classNames="gh-nav-settings-code-injection"}}<i class="icon-code"></i>Code Injection{{/link-to}}</li>
|
||||
<li>{{#link-to "settings.labs" classNames="gh-nav-settings-labs"}}<i class="icon-apps"></i>Labs{{/link-to}}</li>
|
||||
</ul>
|
||||
{{/if}}
|
||||
</section>
|
||||
<footer class="gh-nav-footer">
|
||||
{{gh-menu-toggle desktopAction="toggleAutoNav" mobileAction="closeMobileMenu"}}
|
||||
|
97
core/client/tests/unit/helpers/gh-user-can-test.js
Normal file
97
core/client/tests/unit/helpers/gh-user-can-test.js
Normal file
@ -0,0 +1,97 @@
|
||||
import {
|
||||
describeModule,
|
||||
it
|
||||
} from 'ember-mocha';
|
||||
import {
|
||||
ghUserCan
|
||||
} from 'ghost/helpers/gh-user-can';
|
||||
|
||||
describe ('GhUserCanHelper', function () {
|
||||
// Mock up roles and test for truthy
|
||||
describe ('Owner role', function () {
|
||||
var user = {get: function (role) {
|
||||
if (role === 'isOwner') {
|
||||
return true;
|
||||
} else if (role === 'isAdmin') {
|
||||
return false;
|
||||
} else if (role === 'isEditor') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
it(' - can be Admin', function () {
|
||||
var result = ghUserCan([user, 'admin']);
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
it(' - can be Editor', function () {
|
||||
var result = ghUserCan([user, 'editor']);
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe ('Administrator role', function () {
|
||||
var user = {
|
||||
get: function (role) {
|
||||
if (role === 'isOwner') {
|
||||
return false;
|
||||
} else if (role === 'isAdmin') {
|
||||
return true;
|
||||
} else if (role === 'isEditor') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
it(' - can be Admin', function () {
|
||||
var result = ghUserCan([user, 'admin']);
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
it(' - can be Editor', function () {
|
||||
var result = ghUserCan([user, 'editor']);
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe ('Editor role', function () {
|
||||
var user = {
|
||||
get: function (role) {
|
||||
if (role === 'isOwner') {
|
||||
return false;
|
||||
} else if (role === 'isAdmin') {
|
||||
return false;
|
||||
} else if (role === 'isEditor') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
it(' - cannot be Admin', function () {
|
||||
var result = ghUserCan([user, 'admin']);
|
||||
expect(result).to.equal(false);
|
||||
});
|
||||
it(' - can be Editor', function () {
|
||||
var result = ghUserCan([user, 'editor']);
|
||||
expect(result).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe ('Author role', function () {
|
||||
var user = {
|
||||
get: function (role) {
|
||||
if (role === 'isOwner') {
|
||||
return false;
|
||||
} else if (role === 'isAdmin') {
|
||||
return false;
|
||||
} else if (role === 'isEditor') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
it(' - cannot be Admin', function () {
|
||||
var result = ghUserCan([user, 'admin']);
|
||||
expect(result).to.equal(false);
|
||||
});
|
||||
it(' - cannot be Editor', function () {
|
||||
var result = ghUserCan([user, 'editor']);
|
||||
expect(result).to.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user