[WIP] Don't wait for downloading user data when opening the app
This commit is contained in:
parent
cbd0c46e37
commit
c1d6674d04
|
@ -5,6 +5,8 @@ import config from 'travis/config/environment';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
routing: Ember.inject.service('-routing'),
|
routing: Ember.inject.service('-routing'),
|
||||||
|
permissions: Ember.inject.service(),
|
||||||
|
|
||||||
tagName: 'li',
|
tagName: 'li',
|
||||||
classNameBindings: ['build.last_build.state'],
|
classNameBindings: ['build.last_build.state'],
|
||||||
classNames: ['branch-row', 'row-li'],
|
classNames: ['branch-row', 'row-li'],
|
||||||
|
@ -54,18 +56,8 @@ export default Ember.Component.extend({
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
canTrigger: function() {
|
canTrigger: function() {
|
||||||
var permissions;
|
return this.get('permissions').hasPermission(this.get('build.repository'));
|
||||||
if (!this.get('auth.signedIn')) {
|
}.property('permissions.all', 'build.repository'),
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
permissions = this.get('auth.currentUser.permissions');
|
|
||||||
if (permissions.contains(parseInt(this.get('build.repository.id')))) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.property(),
|
|
||||||
|
|
||||||
triggerBuild: function() {
|
triggerBuild: function() {
|
||||||
var apiEndpoint, options, repoId;
|
var apiEndpoint, options, repoId;
|
||||||
|
|
|
@ -4,6 +4,8 @@ import config from 'travis/config/environment';
|
||||||
import { hasAdminPermission, hasPushPermission } from 'travis/utils/permission';
|
import { hasAdminPermission, hasPushPermission } from 'travis/utils/permission';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
|
permissions: Ember.inject.service(),
|
||||||
|
|
||||||
tagName: 'li',
|
tagName: 'li',
|
||||||
classNameBindings: ['repo.default_branch.last_build.state'],
|
classNameBindings: ['repo.default_branch.last_build.state'],
|
||||||
classNames: ['rows', 'rows--dashboard'],
|
classNames: ['rows', 'rows--dashboard'],
|
||||||
|
@ -16,13 +18,13 @@ export default Ember.Component.extend({
|
||||||
return githubCommitUrl(this.get('repo.slug'), this.get('repo.default_branch.last_build.commit.sha'));
|
return githubCommitUrl(this.get('repo.slug'), this.get('repo.default_branch.last_build.commit.sha'));
|
||||||
}.property('repo'),
|
}.property('repo'),
|
||||||
|
|
||||||
displayMenuTofu: function() {
|
displayMenuTofu: Ember.computed('permissions.all', 'repo', function() {
|
||||||
return hasPushPermission(this.get('currentUser'), this.get('repo.id'));
|
return this.get('permissions').hasPushPermission(this.get('repo'));
|
||||||
},
|
}),
|
||||||
|
|
||||||
displayActivateLink: function() {
|
displayActivateLink: Ember.computed('permissions.all', 'repo', function() {
|
||||||
return hasAdminPermission(this.get('currentUser'), this.get('repo.id'));
|
return this.get('permissions').hasAdminPermission(this.get('repo'));
|
||||||
},
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
tiggerBuild(branch) {
|
tiggerBuild(branch) {
|
||||||
|
|
|
@ -60,6 +60,8 @@ Object.defineProperty(Log.Limit.prototype, 'limited', {
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
popup: Ember.inject.service(),
|
popup: Ember.inject.service(),
|
||||||
|
permissions: Ember.inject.service(),
|
||||||
|
|
||||||
classNameBindings: ['logIsVisible:is-open'],
|
classNameBindings: ['logIsVisible:is-open'],
|
||||||
logIsVisible: false,
|
logIsVisible: false,
|
||||||
currentUserBinding: 'auth.currentUser',
|
currentUserBinding: 'auth.currentUser',
|
||||||
|
@ -190,11 +192,8 @@ export default Ember.Component.extend({
|
||||||
}.property('job.log.id', 'job.log.token'),
|
}.property('job.log.id', 'job.log.token'),
|
||||||
|
|
||||||
hasPermission: function() {
|
hasPermission: function() {
|
||||||
var permissions;
|
return this.get('permissions').hasPermission(this.get('job.repo'));
|
||||||
if (permissions = this.get('currentUser.permissions')) {
|
}.property('permissions.all', 'job.repo'),
|
||||||
return permissions.contains(parseInt(this.get('job.repo.id')));
|
|
||||||
}
|
|
||||||
}.property('currentUser.permissions.length', 'job.repo.id'),
|
|
||||||
|
|
||||||
canRemoveLog: function() {
|
canRemoveLog: function() {
|
||||||
var job;
|
var job;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import config from 'travis/config/environment';
|
import config from 'travis/config/environment';
|
||||||
import { hasPermission, hasPushPermission } from 'travis/utils/permission';
|
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
popup: Ember.inject.service(),
|
popup: Ember.inject.service(),
|
||||||
|
permissions: Ember.inject.service(),
|
||||||
|
|
||||||
classNames: ['option-button'],
|
classNames: ['option-button'],
|
||||||
classNameBindings: ['isOpen:display'],
|
classNameBindings: ['isOpen:display'],
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
|
@ -24,15 +25,15 @@ export default Ember.Component.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
displaySettingsLink: function() {
|
displaySettingsLink: function() {
|
||||||
return hasPushPermission(this.get('currentUser'), this.get('repo.id'));
|
return this.get('permissions').hasPushPermission(this.get('repo'));
|
||||||
}.property('currentUser.pushPermissions', 'repo.id'),
|
}.property('permissions.all', 'repo'),
|
||||||
|
|
||||||
displayCachesLink: function() {
|
displayCachesLink: function() {
|
||||||
return hasPushPermission(this.get('currentUser'), this.get('repo.id')) && config.endpoints.caches;
|
return this.get('permissions').hasPushPermission(this.get('repo')) && config.endpoints.caches;
|
||||||
}.property('currentUser.pushPermissions', 'repo.id'),
|
}.property('permissions.all', 'repo'),
|
||||||
|
|
||||||
displayStatusImages: function() {
|
displayStatusImages: function() {
|
||||||
return hasPermission(this.get('currentUser'), this.get('repo.id'));
|
return this.get('permissions').hasPermission(this.get('repo'));
|
||||||
}.property('currentUser.permissions', 'repo.id')
|
}.property('permissions.all', 'repo'),
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
29
app/services/permissions.js
Normal file
29
app/services/permissions.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import Ember from 'ember';
|
||||||
|
import { hasPermission, hasPushPermission, hasAdminPermission } from 'travis/utils/permission';
|
||||||
|
|
||||||
|
export default Ember.Service.extend({
|
||||||
|
auth: Ember.inject.service(),
|
||||||
|
|
||||||
|
currentUser: Ember.computed.alias('auth.currentUser'),
|
||||||
|
// This is computed property that can be used to allow any properties that
|
||||||
|
// use permissions service to add dependencies easier. So instead of depending
|
||||||
|
// on each of these things separately, we can depend on all
|
||||||
|
all: Ember.computed('currentUser.permissions', 'currentUser.permissions.[]',
|
||||||
|
'currentUser.pushPermissions', 'currentUser.pushPermissions.[]',
|
||||||
|
'currentUser.adminPermissions', 'currentUser.adminPermissions.[]',
|
||||||
|
function() {
|
||||||
|
return;
|
||||||
|
}),
|
||||||
|
|
||||||
|
hasPermission(repo) {
|
||||||
|
return hasPermission(this.get('currentUser'), repo);
|
||||||
|
},
|
||||||
|
|
||||||
|
hasPushPermission(repo) {
|
||||||
|
return hasPushPermission(this.get('currentUser'), repo);
|
||||||
|
},
|
||||||
|
|
||||||
|
hasAdminPermission(repo) {
|
||||||
|
return hasAdminPermission(this.get('currentUser'), repo);
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,31 +1,22 @@
|
||||||
|
|
||||||
var hasPermission = function(user, repoId) {
|
var hasPermission = function(user, repo) {
|
||||||
var id = parseInt(repoId);
|
let id = isNaN(repo) ? repo.get('id') : parseInt(repo);
|
||||||
var permissions;
|
if(user) {
|
||||||
if (user) {
|
return user.get('permissions').contains(id);
|
||||||
if (permissions = user.get('permissions')) {
|
|
||||||
return permissions.contains(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var hasPushPermission = function(user, repoId) {
|
var hasPushPermission = function(user, repo) {
|
||||||
var id = parseInt(repoId);
|
let id = isNaN(repo) ? repo.get('id') : parseInt(repo);
|
||||||
var permissions;
|
if(user) {
|
||||||
if (user) {
|
return user.get('pushPermissions').contains(id);
|
||||||
if (permissions = user.get('pushPermissions')) {
|
|
||||||
return permissions.contains(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var hasAdminPermission = function(user, repoId) {
|
var hasAdminPermission = function(user, repo) {
|
||||||
var id = parseInt(repoId);
|
let id = isNaN(repo) ? repo.get('id') : parseInt(repo);
|
||||||
var permissions;
|
if(user) {
|
||||||
if (user) {
|
return user.get('adminPermissions').contains(id);
|
||||||
if (permissions = user.get('adminPermissions')) {
|
|
||||||
return permissions.contains(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
12
tests/unit/services/permissions-test.js
Normal file
12
tests/unit/services/permissions-test.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { moduleFor, test } from 'ember-qunit';
|
||||||
|
|
||||||
|
moduleFor('service:permissions', 'Unit | Service | permissions', {
|
||||||
|
// Specify the other units that are required for this test.
|
||||||
|
// needs: ['service:foo']
|
||||||
|
});
|
||||||
|
|
||||||
|
// Replace this with your real tests.
|
||||||
|
test('it exists', function(assert) {
|
||||||
|
let service = this.subject();
|
||||||
|
assert.ok(service);
|
||||||
|
});
|
|
@ -6,21 +6,51 @@ module('Unit | Utility | permission');
|
||||||
|
|
||||||
test('it checks permissions', function(assert) {
|
test('it checks permissions', function(assert) {
|
||||||
let user = Ember.Object.create({permissions: [1]});
|
let user = Ember.Object.create({permissions: [1]});
|
||||||
|
|
||||||
assert.ok(hasPermission(user, 1));
|
assert.ok(hasPermission(user, 1));
|
||||||
assert.ok(!hasPermission(user, 2));
|
assert.ok(!hasPermission(user, 2));
|
||||||
assert.ok(!hasPermission(null, 1));
|
assert.ok(!hasPermission(null, 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('it checks permissions if a repo object is given', function(assert) {
|
||||||
|
let repo1 = Ember.Object.create({ id: 1 }),
|
||||||
|
repo2 = Ember.Object.create({ id: 2 }),
|
||||||
|
user = Ember.Object.create({permissions: [1]});
|
||||||
|
|
||||||
|
assert.ok(hasPermission(user, repo1));
|
||||||
|
assert.ok(!hasPermission(user, repo2));
|
||||||
|
});
|
||||||
|
|
||||||
test('it checks push permissions', function(assert) {
|
test('it checks push permissions', function(assert) {
|
||||||
let user = Ember.Object.create({pushPermissions: [1]});
|
let user = Ember.Object.create({pushPermissions: [1]});
|
||||||
|
|
||||||
assert.ok(hasPushPermission(user, 1));
|
assert.ok(hasPushPermission(user, 1));
|
||||||
assert.ok(!hasPushPermission(user, 2));
|
assert.ok(!hasPushPermission(user, 2));
|
||||||
assert.ok(!hasPushPermission(null, 1));
|
assert.ok(!hasPushPermission(null, 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('it checks push permissions if a repo object is given', function(assert) {
|
||||||
|
let repo1 = Ember.Object.create({ id: 1 }),
|
||||||
|
repo2 = Ember.Object.create({ id: 2 }),
|
||||||
|
user = Ember.Object.create({pushPermissions: [1]});
|
||||||
|
|
||||||
|
assert.ok(hasPushPermission(user, repo1));
|
||||||
|
assert.ok(!hasPushPermission(user, repo2));
|
||||||
|
});
|
||||||
|
|
||||||
test('it checks admin permissions', function(assert) {
|
test('it checks admin permissions', function(assert) {
|
||||||
let user = Ember.Object.create({adminPermissions: [1]});
|
let user = Ember.Object.create({adminPermissions: [1]});
|
||||||
|
|
||||||
assert.ok(hasAdminPermission(user, 1));
|
assert.ok(hasAdminPermission(user, 1));
|
||||||
assert.ok(!hasAdminPermission(user, 2));
|
assert.ok(!hasAdminPermission(user, 2));
|
||||||
assert.ok(!hasAdminPermission(null, 1));
|
assert.ok(!hasAdminPermission(null, 1));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('it checks admin permissions if a repo object is given', function(assert) {
|
||||||
|
let repo1 = Ember.Object.create({ id: 1 }),
|
||||||
|
repo2 = Ember.Object.create({ id: 2 }),
|
||||||
|
user = Ember.Object.create({adminPermissions: [1]});
|
||||||
|
|
||||||
|
assert.ok(hasAdminPermission(user, repo1));
|
||||||
|
assert.ok(!hasAdminPermission(user, repo2));
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user