check for push permission in ssh key settings
This commit is contained in:
parent
ac6c73a340
commit
691e02d08f
|
@ -42,12 +42,31 @@ Route = TravisRoute.extend
|
||||||
response.active
|
response.active
|
||||||
);
|
);
|
||||||
|
|
||||||
|
hasPushAccess: ->
|
||||||
|
repoId = parseInt @modelFor('repo').get('id')
|
||||||
|
pushAccess = true
|
||||||
|
|
||||||
|
Ajax.get '/users/permissions', (data) =>
|
||||||
|
|
||||||
|
admin = data.admin.filter (item) ->
|
||||||
|
return item == repoId
|
||||||
|
push = data.push.filter (item) ->
|
||||||
|
return item == repoId
|
||||||
|
pull = data.pull.filter (item) ->
|
||||||
|
return item == repoId
|
||||||
|
|
||||||
|
if Ember.isEmpty admin && Ember.isEmpty push && !Ember.isEmpty pull
|
||||||
|
pushAccess = false
|
||||||
|
|
||||||
|
pushAccess
|
||||||
|
|
||||||
model: () ->
|
model: () ->
|
||||||
return Ember.RSVP.hash({
|
return Ember.RSVP.hash({
|
||||||
settings: @modelFor('repo').fetchSettings(),
|
settings: @modelFor('repo').fetchSettings(),
|
||||||
envVars: this.fetchEnvVars(),
|
envVars: this.fetchEnvVars(),
|
||||||
sshKey: this.fetchSshKey(),
|
sshKey: this.fetchSshKey(),
|
||||||
customSshKey: this.fetchCustomSshKey(),
|
customSshKey: this.fetchCustomSshKey(),
|
||||||
|
hasPushAccess: this.hasPushAccess(),
|
||||||
repositoryActive: this.fetchRepositoryActiveFlag()
|
repositoryActive: this.fetchRepositoryActiveFlag()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,19 @@
|
||||||
{{#if isDeleting}}
|
{{#if isDeleting}}
|
||||||
{{loading-indicator}}
|
{{loading-indicator}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
{{#if pushAccess}}
|
||||||
<div class="tooltip">
|
<div class="tooltip">
|
||||||
<a href="#" title="" {{action "delete"}}>
|
<a href="#" title="" {{action "delete"}}>
|
||||||
<span class="icon-delete"></span>
|
<span class="icon-delete"></span>
|
||||||
</a>
|
</a>
|
||||||
<div class="tooltip-bubble">Delete</div>
|
<div class="tooltip-bubble">Delete</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="tooltip--height">
|
||||||
|
<span class="icon-delete-disabled"></span>
|
||||||
|
<div class="tooltip-bubble">You can't<br>delete keys</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
@ -30,11 +30,18 @@
|
||||||
<h2 class="small-title">SSH Key</h2>
|
<h2 class="small-title">SSH Key</h2>
|
||||||
|
|
||||||
{{#if model.customSshKey}}
|
{{#if model.customSshKey}}
|
||||||
{{ssh-key key=model.customSshKey sshKeyDeleted="sshKeyDeleted"}}
|
{{ssh-key key=model.customSshKey sshKeyDeleted="sshKeyDeleted" pushAccess=model.hasPushAccess}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{ssh-key key=model.sshKey}}
|
{{ssh-key key=model.sshKey}}
|
||||||
|
|
||||||
|
{{#if model.hasPushAccess}}
|
||||||
{{add-ssh-key repo=repo sshKeyAdded="sshKeyAdded"}}
|
{{add-ssh-key repo=repo sshKeyAdded="sshKeyAdded"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#unless model.hasPushAccess}}
|
||||||
|
<p>You don't have sufficient permissons to add or remove ssh keys on this repository.</p>
|
||||||
|
{{/unless}}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -41,7 +41,7 @@ test('it renders the custom ssh key if custom key is set', function(assert) {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('it deletes a custom key', function(assert) {
|
test('it deletes a custom key if permissions are right', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var store = this.container.lookup('store:main');
|
var store = this.container.lookup('store:main');
|
||||||
|
@ -52,7 +52,7 @@ test('it deletes a custom key', function(assert) {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.set('key', key);
|
this.set('key', key);
|
||||||
this.render(hbs`{{ssh-key key=key sshKeyDeleted="sshKeyDeleted"}}`);
|
this.render(hbs`{{ssh-key key=key sshKeyDeleted="sshKeyDeleted" pushAccess=true}}`);
|
||||||
this.on('sshKeyDeleted', function() {});
|
this.on('sshKeyDeleted', function() {});
|
||||||
|
|
||||||
this.$('.ssh-key-action a').click();
|
this.$('.ssh-key-action a').click();
|
||||||
|
@ -60,3 +60,20 @@ test('it deletes a custom key', function(assert) {
|
||||||
assert.ok(key.get('isDeleted'), 'key should be deleted');
|
assert.ok(key.get('isDeleted'), 'key should be deleted');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('it does not delete the custom key if permissions are insufficient', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
|
||||||
|
var store = this.container.lookup('store:main');
|
||||||
|
|
||||||
|
var key;
|
||||||
|
Ember.run(function() {
|
||||||
|
key = store.push('sshKey', {description: 'fookey', fingerprint: 'somethingthing', id: 1});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.set('key', key);
|
||||||
|
this.render(hbs`{{ssh-key key=key sshKeyDeleted="sshKeyDeleted" pushAccess=false}}`);
|
||||||
|
|
||||||
|
assert.ok(Ember.isEmpty(this.$('.ssh-key-action').find('a')), 'delete link should not be displayed');
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user