Skip to content

Display teams on the crate owners page #2253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions app/controllers/crate/owners.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 4 additions & 0 deletions app/models/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}),
});
26 changes: 25 additions & 1 deletion app/templates/crate/owners.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,32 @@
{{/if}}

<div class='owners white-rows'>
{{#each this.crate.owner_team as |team|}}
<div class='crate row' data-test-owner-team={{team.login}}>
<div>
<LinkTo @route={{team.kind}} @model={{team.login}}>
<UserAvatar @user={{team}} @size="medium-small" />
</LinkTo>
</div>
<div>
<LinkTo @route={{team.kind}} @model={{team.login}}>
{{team.display_name}}
</LinkTo>
</div>
<div class='stats'>
{{#if team.email}}
{{team.email}}
{{else}}
&nbsp;
{{/if}}
</div>
<div class='stats downloads'>
<button type="button" class='remove-owner small yellow-button' {{action 'removeOwner' team}}>Remove</button>
</div>
</div>
{{/each}}
{{#each this.crate.owner_user as |user|}}
<div class='crate row'>
<div class='crate row' data-test-owner-user={{user.login}}>
<div>
<LinkTo @route={{user.kind}} @model={{user.login}}>
<UserAvatar @user={{user}} @size="medium-small" />
Expand Down
4 changes: 2 additions & 2 deletions mirage/route-handlers/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
28 changes: 20 additions & 8 deletions tests/acceptance/crate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 });
});
});