-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
3 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |