diff --git a/app/controllers/crate/owners.js b/app/controllers/crate/owners.js
index 049d6a5ea25..24363239c3a 100644
--- a/app/controllers/crate/owners.js
+++ b/app/controllers/crate/owners.js
@@ -31,14 +31,20 @@ export default Controller.extend({
}
},
- async removeOwner(user) {
+ async removeOwner(owner) {
this.set('removed', false);
-
try {
- await this.crate.removeOwner(user.get('login'));
- this.set('removed', `User ${user.get('login')} removed as crate owner`);
-
- this.get('crate.owner_user').removeObject(user);
+ await this.crate.removeOwner(owner.get('login'));
+ switch (owner.kind) {
+ case 'user':
+ this.set('removed', `User ${owner.get('login')} removed as crate owner`);
+ this.get('crate.owner_user').removeObject(owner);
+ break;
+ case 'team':
+ this.set('removed', `Team ${owner.get('display_name')} removed as crate owner`);
+ this.get('crate.owner_team').removeObject(owner);
+ break;
+ }
} catch (error) {
if (error.errors) {
this.set('removed', `Error removing owner: ${error.errors[0].detail}`);
diff --git a/app/models/team.js b/app/models/team.js
index d98748e54e4..e0278de189d 100644
--- a/app/models/team.js
+++ b/app/models/team.js
@@ -14,4 +14,8 @@ export default Model.extend({
let login_split = login.split(':');
return login_split[1];
}),
+ display_name: computed('name', 'org_name', function() {
+ let { name, org_name } = this.getProperties('name', 'org_name');
+ return `${org_name}/${name}`;
+ }),
});
diff --git a/app/templates/crate/owners.hbs b/app/templates/crate/owners.hbs
index f8d1b8ce7a6..effbe3f88cc 100644
--- a/app/templates/crate/owners.hbs
+++ b/app/templates/crate/owners.hbs
@@ -44,8 +44,32 @@
{{/if}}
+ {{#each this.crate.owner_team as |team|}}
+
+
+
+
+
+
+
+
+ {{team.display_name}}
+
+
+
+ {{#if team.email}}
+ {{team.email}}
+ {{else}}
+
+ {{/if}}
+
+
+
+
+
+ {{/each}}
{{#each this.crate.owner_user as |user|}}
-
+
diff --git a/mirage/route-handlers/crates.js b/mirage/route-handlers/crates.js
index 45472b63c46..375674c12ca 100644
--- a/mirage/route-handlers/crates.js
+++ b/mirage/route-handlers/crates.js
@@ -181,9 +181,9 @@ export function register(server) {
const body = JSON.parse(request.requestBody);
const [ownerId] = body.owners;
- const user = schema.users.findBy({ login: ownerId });
+ const owner = schema.users.findBy({ login: ownerId }) || schema.teams.findBy({ login: ownerId });
- if (!user) {
+ if (!owner) {
return notFound();
}
diff --git a/tests/acceptance/crate-test.js b/tests/acceptance/crate-test.js
index 26f0d928408..14c4aa7d3e7 100644
--- a/tests/acceptance/crate-test.js
+++ b/tests/acceptance/crate-test.js
@@ -255,7 +255,9 @@ module('Acceptance | crate page', function(hooks) {
await visit('/crates/nanomsg/owners');
- assert.dom('.owners .row').exists({ count: 2 });
+ assert.dom('.owners .row').exists({ count: 4 });
+ assert.dom('a[href="/teams/github:org:thehydroimpulse"]').exists();
+ assert.dom('a[href="/teams/github:org:blabaere"]').exists();
assert.dom('a[href="/users/thehydroimpulse"]').exists();
assert.dom('a[href="/users/blabaere"]').exists();
});
@@ -268,7 +270,7 @@ module('Acceptance | crate page', function(hooks) {
assert.dom('.error').exists();
assert.dom('.error').hasText('Please enter a username');
- assert.dom('.owners .row').exists({ count: 2 });
+ assert.dom('.owners .row').exists({ count: 4 });
});
test('attempting to add non-existent owner', async function(assert) {
@@ -280,7 +282,7 @@ module('Acceptance | crate page', function(hooks) {
assert.dom('.error').exists();
assert.dom('.error').hasText('Error sending invite: Not Found');
- assert.dom('.owners .row').exists({ count: 2 });
+ assert.dom('.owners .row').exists({ count: 4 });
});
test('add a new owner', async function(assert) {
@@ -292,16 +294,26 @@ module('Acceptance | crate page', function(hooks) {
assert.dom('.invited').exists();
assert.dom('.invited').hasText('An invite has been sent to iain8');
- assert.dom('.owners .row').exists({ count: 2 });
+ assert.dom('.owners .row').exists({ count: 4 });
});
- test('remove a crate owner', async function(assert) {
+ test('remove a crate owner when owner is a user', async function(assert) {
this.server.loadFixtures();
await visit('/crates/nanomsg/owners');
- await click('.owners .row:first-child .remove-owner');
+ await click('[data-test-owner-user="thehydroimpulse"] .remove-owner');
- assert.dom('.removed').exists();
- assert.dom('.owners .row').exists({ count: 1 });
+ assert.dom('.removed').hasText('User thehydroimpulse removed as crate owner');
+ assert.dom('[data-test-owner-user]').exists({ count: 1 });
+ });
+
+ test('remove a crate owner when owner is a team', async function(assert) {
+ this.server.loadFixtures();
+
+ await visit('/crates/nanomsg/owners');
+ await click('[data-test-owner-team="github:org:thehydroimpulse"] .remove-owner');
+
+ assert.dom('.removed').hasText('Team org/thehydroimpulseteam removed as crate owner');
+ assert.dom('[data-test-owner-team]').exists({ count: 1 });
});
});