put permissions into a mixin
This commit is contained in:
parent
3618488151
commit
2220334265
|
@ -1,7 +1,8 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import config from 'travis/config/environment';
|
import config from 'travis/config/environment';
|
||||||
|
import Permissions from 'travis/mixins/permissions';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend(Permissions, {
|
||||||
popup: Ember.inject.service(),
|
popup: Ember.inject.service(),
|
||||||
classNames: ['option-button'],
|
classNames: ['option-button'],
|
||||||
classNameBindings: ['isOpen:display'],
|
classNameBindings: ['isOpen:display'],
|
||||||
|
@ -22,37 +23,16 @@ export default Ember.Component.extend({
|
||||||
return this.toggleProperty('isOpen');
|
return this.toggleProperty('isOpen');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
hasPermission: function() {
|
|
||||||
var permissions;
|
|
||||||
if (permissions = this.get('currentUser.permissions')) {
|
|
||||||
return permissions.contains(parseInt(this.get('repo.id')));
|
|
||||||
}
|
|
||||||
}.property('currentUser.permissions.length', 'repo.id'),
|
|
||||||
|
|
||||||
hasPushPermission: function() {
|
|
||||||
var permissions;
|
|
||||||
if (permissions = this.get('currentUser.pushPermissions')) {
|
|
||||||
return permissions.contains(parseInt(this.get('repo.id')));
|
|
||||||
}
|
|
||||||
}.property('currentUser.pushPermissions.length', 'repo.id'),
|
|
||||||
|
|
||||||
hasAdminPermission: function() {
|
|
||||||
var permissions;
|
|
||||||
if (permissions = this.get('currentUser.adminPermissions')) {
|
|
||||||
return permissions.contains(parseInt(this.get('repo.id')));
|
|
||||||
}
|
|
||||||
}.property('currentUser.adminPermissions.length', 'repo.id'),
|
|
||||||
|
|
||||||
displaySettingsLink: function() {
|
displaySettingsLink: function() {
|
||||||
return this.get('hasPushPermission');
|
return this.hasPushPermission(this.get('currentUser'), this.get('repo.id'));
|
||||||
}.property('hasPushPermission'),
|
}.property('currentUser.pushPermissions', 'repo.id'),
|
||||||
|
|
||||||
displayCachesLink: function() {
|
displayCachesLink: function() {
|
||||||
return this.get('hasPushPermission') && config.endpoints.caches;
|
return this.hasPushPermission(this.get('currentUser'), this.get('repo.id')) && config.endpoints.caches;
|
||||||
}.property('hasPushPermission'),
|
}.property('currentUser.pushPermissions', 'repo.id'),
|
||||||
|
|
||||||
displayStatusImages: function() {
|
displayStatusImages: function() {
|
||||||
return this.get('hasPermission');
|
return this.hasPermission(this.get('currentUser'), this.get('repo.id'));
|
||||||
}.property('hasPermission')
|
}.property('currentUser.permissions', 'repo.id')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
26
app/mixins/permissions.js
Normal file
26
app/mixins/permissions.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
export default Ember.Mixin.create({
|
||||||
|
|
||||||
|
hasPermission: function(currentUser, repoId) {
|
||||||
|
var id = parseInt(repoId);
|
||||||
|
var permissions;
|
||||||
|
if (permissions = this.get('currentUser.permissions')) {
|
||||||
|
return permissions.contains(id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hasPushPermission: function(currentUser, repoId) {
|
||||||
|
var id = parseInt(repoId);
|
||||||
|
var permissions;
|
||||||
|
if (permissions = this.get('currentUser.pushPermissions')) {
|
||||||
|
return permissions.contains(id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
hasAdminPermission: function(currentUser, repoId) {
|
||||||
|
var id = parseInt(repoId);
|
||||||
|
var permissions;
|
||||||
|
if (permissions = this.get('currentUser.adminPermissions')) {
|
||||||
|
return permissions.contains(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
12
tests/unit/mixins/permissions-test.js
Normal file
12
tests/unit/mixins/permissions-test.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import PermissionsMixin from 'travis/mixins/permissions';
|
||||||
|
import { module, test } from 'qunit';
|
||||||
|
|
||||||
|
module('Unit | Mixin | permissions');
|
||||||
|
|
||||||
|
// Replace this with your real tests.
|
||||||
|
test('it works', function(assert) {
|
||||||
|
let PermissionsObject = Ember.Object.extend(PermissionsMixin);
|
||||||
|
let subject = PermissionsObject.create();
|
||||||
|
assert.ok(subject);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user