Add activate button on 'not-active' repo page
This commit is contained in:
parent
ef583a7d54
commit
115bfb6ea6
|
@ -1,3 +1,46 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
|
import config from 'travis/config/environment';
|
||||||
|
|
||||||
export default Ember.Component.extend();
|
export default Ember.Component.extend({
|
||||||
|
flashes: Ember.inject.service(),
|
||||||
|
|
||||||
|
canActivate: function() {
|
||||||
|
let user = this.get('user');
|
||||||
|
if(user) {
|
||||||
|
let permissions = user.get('pushPermissions'),
|
||||||
|
repoId = parseInt(this.get('repo.id'));
|
||||||
|
|
||||||
|
return permissions.contains(repoId);
|
||||||
|
}
|
||||||
|
}.property('user.pushPermissions.[]', 'repo'),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
activate: function() {
|
||||||
|
let apiEndpoint = config.apiEndpoint,
|
||||||
|
repoId = this.get('repo.id');
|
||||||
|
|
||||||
|
this.set('isActivating', true);
|
||||||
|
$.ajax(apiEndpoint + '/v3/repo/' + repoId + '/enable', {
|
||||||
|
headers: {
|
||||||
|
Authorization: 'token ' + this.get('auth').token()
|
||||||
|
},
|
||||||
|
method: 'POST'
|
||||||
|
}).then((response) => {
|
||||||
|
if(response.active) {
|
||||||
|
let pusher = this.get('pusher'),
|
||||||
|
repoId = this.get('repo.id');
|
||||||
|
|
||||||
|
pusher.subscribe('repo-' + repoId);
|
||||||
|
|
||||||
|
this.get('repo').set('active', true);
|
||||||
|
|
||||||
|
this.get('flashes').add('success', 'Repository has been successfully activated.');
|
||||||
|
}
|
||||||
|
this.set('isActivating', false);
|
||||||
|
}, () => {
|
||||||
|
this.set('isActivating', false);
|
||||||
|
this.get('flashes').add('error', 'There was an error while trying to activate the repository.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -11,6 +11,7 @@ initialize = function(data) {
|
||||||
instantiate: false
|
instantiate: false
|
||||||
});
|
});
|
||||||
application.inject('route', 'pusher', 'pusher:main');
|
application.inject('route', 'pusher', 'pusher:main');
|
||||||
|
application.inject('component', 'pusher', 'pusher:main');
|
||||||
return application.pusher.store = data.container.lookup('service:store');
|
return application.pusher.store = data.container.lookup('service:store');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,8 @@ import Config from 'travis/config/environment';
|
||||||
export default TravisRoute.extend({
|
export default TravisRoute.extend({
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
return this.controllerFor('repo').activate('current');
|
this.controllerFor('repo').activate('current');
|
||||||
|
controller.set('repo', model);
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
|
|
|
@ -48,5 +48,9 @@ export default Ember.Service.extend({
|
||||||
|
|
||||||
close(msg) {
|
close(msg) {
|
||||||
return this.get('flashes').removeObject(msg);
|
return this.get('flashes').removeObject(msg);
|
||||||
|
},
|
||||||
|
|
||||||
|
add(type, message) {
|
||||||
|
this.loadFlashes([ { [type]: message } ]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -63,7 +63,14 @@
|
||||||
<h2 class="page-title">This is not an active repository</h2>
|
<h2 class="page-title">This is not an active repository</h2>
|
||||||
<p class="page-notice">Want to start testing this project on Travis CI?</p>
|
<p class="page-notice">Want to start testing this project on Travis CI?</p>
|
||||||
<a href="http://docs.travis-ci.com/user/getting-started/" class="button button--green">Read the Docs on Getting Started</a>
|
<a href="http://docs.travis-ci.com/user/getting-started/" class="button button--green">Read the Docs on Getting Started</a>
|
||||||
{{#if user.pushPermissions.length}}
|
|
||||||
<p>If this repository is already in active use, <br> make sure it’s activated on {{#link-to "account" repo.owner}}your profile{{/link-to}}.</p>
|
{{#if canActivate}}
|
||||||
|
<p>You can activate the repository on {{#link-to "account" repo.owner}}your profile{{/link-to}},<br/>
|
||||||
|
or by clicking the button below:</p>
|
||||||
|
|
||||||
|
<button {{action 'activate'}} class="button button--green">Activate</button>
|
||||||
|
{{#if isActivating}}
|
||||||
|
{{loading-indicator}}
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{{not-active user=currentUser repo=repo}}
|
{{not-active user=auth.currentUser repo=repo}}
|
||||||
|
|
40
tests/unit/components/not-active-test.js
Normal file
40
tests/unit/components/not-active-test.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { moduleForComponent, test } from 'ember-qunit';
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
moduleForComponent('not-active', 'Unit | Component | not active', {
|
||||||
|
// Specify the other units that are required for this test
|
||||||
|
// needs: ['component:foo', 'helper:bar'],
|
||||||
|
unit: true
|
||||||
|
});
|
||||||
|
|
||||||
|
test('canActivate returns true if a user has access to a repo', function(assert) {
|
||||||
|
let component = this.subject();
|
||||||
|
|
||||||
|
let user = Ember.Object.create({ pushPermissions: [1] });
|
||||||
|
let repo = Ember.Object.create({ id: 1 });
|
||||||
|
|
||||||
|
component.set('user', user);
|
||||||
|
component.set('repo', repo);
|
||||||
|
|
||||||
|
//this.render();
|
||||||
|
//assert.equal(this.$().text().trim(), '');
|
||||||
|
assert.ok(component.get('canActivate'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("canActivate returns false if user doesn't exist", function(assert) {
|
||||||
|
let component = this.subject();
|
||||||
|
|
||||||
|
assert.ok(!component.get('canActivate'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("canActivate returns false if user doesn't push access to the repo", function(assert) {
|
||||||
|
let component = this.subject();
|
||||||
|
|
||||||
|
let user = Ember.Object.create({ pushPermissions: [2] });
|
||||||
|
let repo = Ember.Object.create({ id: 1 });
|
||||||
|
|
||||||
|
component.set('user', user);
|
||||||
|
component.set('repo', repo);
|
||||||
|
|
||||||
|
assert.ok(!component.get('canActivate'));
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user