From 453833cd11293517839ab6d479f3611359fd67e0 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 --- core/client/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 core/client/app/helpers/gh-user-can.js create mode 100644 core/client/tests/unit/helpers/gh-user-can-test.js diff --git a/core/client/app/helpers/gh-user-can.js b/core/client/app/helpers/gh-user-can.js new file mode 100644 index 0000000000..501a166154 --- /dev/null +++ b/core/client/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/core/client/app/templates/components/gh-nav-menu.hbs b/core/client/app/templates/components/gh-nav-menu.hbs index 3fc4add648..298bad9f2f 100644 --- a/core/client/app/templates/components/gh-nav-menu.hbs +++ b/core/client/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}}