From 493adb29999417bcfdd9845d2ba861144af2487c Mon Sep 17 00:00:00 2001 From: cobbspur Date: Wed, 17 Jun 2015 10:22:21 +0100 Subject: [PATCH] Hide Nav Settings based on permissions closes #5403 - adds gh-user-can helper to group user by minimum permissions - hide Nav settings menu for users below admin level --- ghost/admin/app/helpers/gh-user-can.js | 17 ++++ .../app/templates/components/gh-nav-menu.hbs | 20 ++-- .../tests/unit/helpers/gh-user-can-test.js | 97 +++++++++++++++++++ 3 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 ghost/admin/app/helpers/gh-user-can.js create mode 100644 ghost/admin/tests/unit/helpers/gh-user-can-test.js diff --git a/ghost/admin/app/helpers/gh-user-can.js b/ghost/admin/app/helpers/gh-user-can.js new file mode 100644 index 0000000000..501a166154 --- /dev/null +++ b/ghost/admin/app/helpers/gh-user-can.js @@ -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); diff --git a/ghost/admin/app/templates/components/gh-nav-menu.hbs b/ghost/admin/app/templates/components/gh-nav-menu.hbs index 3fc4add648..298bad9f2f 100644 --- a/ghost/admin/app/templates/components/gh-nav-menu.hbs +++ b/ghost/admin/app/templates/components/gh-nav-menu.hbs @@ -27,15 +27,17 @@
  • {{#link-to "settings.users" classNames="gh-nav-main-users"}}Team{{/link-to}}
  • {{!
  • Ideas
  • }} - + {{#if (gh-user-can session.user 'admin')}} + + {{/if}}