forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes TryGhost#3402, Closes TryGhost#3428 ------------------- ### Components - Added GhostSelectComponent to handle async select creation (h/t @rwjblue) - Added GhostRolesSelector (extends GhostSelect) for displaying user role options - Created StoreInjector for surgically inserting the store into things that normally wouldn't have them. ### Users Settings - InviteNewUserModal now uses GhostRolesSelector & defaults to Author - The role dropdown for user settings has permissions set per 3402 ### User Model - Added `role` property as an interface to getting and setting `roles` - Refactored anything that set `roles` to set `role` - isAdmin, isAuthor, isOwner and isEditor are all keyed off of `role` now ### Tests - Added functional tests for Settings.Users - updated settings.users and settings.users.user screens - fix spacing on screens ### Server Fixtures - Fixed owner fixture's roles
- Loading branch information
Showing
13 changed files
with
264 additions
and
131 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
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,13 @@ | ||
import GhostSelect from 'ghost/components/gh-select'; | ||
|
||
var RolesSelector = GhostSelect.extend({ | ||
roles: Ember.computed.alias('options'), | ||
options: Ember.computed(function () { | ||
var rolesPromise = this.store.find('role', { permissions: 'assign' }); | ||
|
||
return Ember.ArrayProxy.extend(Ember.PromiseProxyMixin) | ||
.create({promise: rolesPromise}); | ||
}) | ||
}); | ||
|
||
export default RolesSelector; |
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,69 @@ | ||
//GhostSelect is a solution to Ember.Select being evil and worthless. | ||
// (Namely, this solves problems with async data in Ember.Select) | ||
//Inspired by (that is, totally ripped off from) this JSBin | ||
//http://emberjs.jsbin.com/rwjblue/40/edit | ||
|
||
//Usage: | ||
//Extend this component and create a template for your component. | ||
//Your component must define the `options` property. | ||
//Optionally use `initialValue` to set the object | ||
// you want to have selected to start with. | ||
//Both options and initalValue are promise safe. | ||
//Set onChange in your template to be the name | ||
// of the action you want called in your | ||
//For an example, see gh-roles-selector | ||
|
||
var GhostSelect = Ember.Component.extend({ | ||
tagName: 'span', | ||
classNames: ['gh-select'], | ||
|
||
options: null, | ||
initialValue: null, | ||
|
||
resolvedOptions: null, | ||
resolvedInitialValue: null, | ||
|
||
//Convert promises to their values | ||
init: function () { | ||
var self = this; | ||
this._super.apply(this, arguments); | ||
|
||
Ember.RSVP.hash({ | ||
resolvedOptions: this.get('options'), | ||
resolvedInitialValue: this.get('initialValue') | ||
}).then(function (resolvedHash) { | ||
self.setProperties(resolvedHash); | ||
|
||
//Run after render to ensure the <option>s have rendered | ||
Ember.run.schedule('afterRender', function () { | ||
self.setInitialValue(); | ||
}); | ||
}); | ||
}, | ||
|
||
setInitialValue: function () { | ||
var initialValue = this.get('resolvedInitialValue'), | ||
options = this.get('resolvedOptions'), | ||
initialValueIndex = options.indexOf(initialValue); | ||
if (initialValueIndex > -1) { | ||
this.$('option:eq(' + initialValueIndex + ')').prop('selected', true); | ||
} | ||
}, | ||
//Called by DOM events, weee! | ||
change: function () { | ||
this._changeSelection(); | ||
}, | ||
//Send value to specified action | ||
_changeSelection: function () { | ||
var value = this._selectedValue(); | ||
Ember.set(this, 'value', value); | ||
this.sendAction('onChange', value); | ||
}, | ||
_selectedValue: function () { | ||
var selectedIndex = this.$('select')[0].selectedIndex; | ||
|
||
return this.get('options').objectAt(selectedIndex); | ||
} | ||
}); | ||
|
||
export default GhostSelect; |
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
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,10 @@ | ||
//Used to surgically insert the store into things that wouldn't normally have them. | ||
var StoreInjector = { | ||
name: 'store-injector', | ||
after: 'store', | ||
initialize: function (container, application) { | ||
application.inject('component:gh-role-selector', 'store', 'store:main'); | ||
} | ||
}; | ||
|
||
export default StoreInjector; |
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,5 @@ | ||
<select {{bind-attr id=selectId name=selectName}}> | ||
{{#each roles}} | ||
<option {{bind-attr value=id}}>{{name}}</option> | ||
{{/each}} | ||
</select> |
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
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,13 @@ | ||
var SettingsUserView = Ember.View.extend({ | ||
currentUser: Ember.computed.alias('controller.session.user'), | ||
|
||
isNotOwnProfile: Ember.computed('controller.user.id', 'currentUser.id', function () { | ||
return this.get('controller.user.id') !== this.get('currentUser.id'); | ||
}), | ||
|
||
canAssignRoles: Ember.computed.or('currentUser.isAdmin', 'currentUser.isOwner'), | ||
|
||
rolesDropdownIsVisible: Ember.computed.and('isNotOwnProfile', 'canAssignRoles') | ||
}); | ||
|
||
export default SettingsUserView; |
Oops, something went wrong.