-
Notifications
You must be signed in to change notification settings - Fork 689
Description
What needs to be done: This looks like a lot, but I tried to provide a lot of detail and examples to work from. The actual code changes shouldn't be very big.
-
If the current user is an owner of the current crate, add a link or button in the sidebar with each version that says "yank" if the version is not yanked and "unyank" if the version is yanked. (Or is there a better place to put this control? I'm open to different UIs)
- The HTML for the versions list in the sidebar is in
crates.io/app/templates/crate/version.hbs
Lines 195 to 208 in adf28ad
<h3>Versions</h3> <ul> {{#each smallSortedVersions as |version|}} <li> {{#link-to 'crate.version' version.num data-test-version-link=version.num}} {{ version.num }} {{/link-to}} <span class='date'>{{moment-format version.created_at 'll'}}</span> {{#if version.yanked}} <span class='yanked'>yanked</span> {{/if}} </li> {{/each}} </ul> - To tell if the current user is an owner, use the
isOwnerhelper like the "Manage owners" section does herecrates.io/app/templates/crate/version.hbs
Lines 167 to 173 in adf28ad
{{#if isOwner}} <p> {{#link-to 'crate.owners' crate}} Manage owners {{/link-to}} </p> {{/if}} - Because we only show the latest 5 versions in the sidebar, the new link/button should be shown on the "All versions" page as well so any version can be yanked. The "All versions" page's HTML is here https://github.com/rust-lang/crates.io/blob/adf28ad82b4ec2aa8af95c03e42f9f361296278f/app/templates/crate/versions.hbs
- The HTML for the versions list in the sidebar is in
-
The link/button should send a
DELETErequest to/api/v1/crates/[crate name]/[version num]/yankfor yanking and aPUTrequest to/api/v1/crates/[crate name]/[version num]/unyankfor unyanking.- A similar link/button is the "Remove" button for removing an owner
crates.io/app/templates/crate/owners.hbs
Line 67 in adf28ad
<button class='remove-owner small yellow-button' {{action 'removeOwner' user}}>Remove</button> - Which calls the ember
removeOwnercontroller function:crates.io/app/controllers/crate/owners.js
Lines 34 to 49 in adf28ad
async removeOwner(user) { 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); } catch (error) { if (error.errors) { this.set('removed', `Error removing owner: ${error.errors[0].detail}`); } else { this.set('removed', 'Error removing owner'); } } }, - Which calls the ember crate model
removeOwnerfunction:Lines 48 to 50 in adf28ad
removeOwner(username) { return this.store.adapterFor('crate').removeOwner(this.id, username); }, - Which calls the ember crate adapter
removeOwnerfunction:crates.io/app/adapters/crate.js
Lines 16 to 22 in adf28ad
removeOwner(id, username) { return this.ajax(this.urlForOwnerAction(id), 'DELETE', { data: { owners: [username], }, }); }, - I'm not actually sure how idiomatic Ember this example is; if this example isn't good, feel free to do whatever the normal Ember way of doing this would be.
- There should be an indication to the user that the request is being sent and then that the request has completed either successfully or with an error. You should be able to yank and unyank the same version repeatedly without reloading the full page.
- A similar link/button is the "Remove" button for removing an owner
-
The ember tests should assert that the UI behaves as expected. This commit has an example of adding an ember test for the "remove owner" functionality: f524472
-
There should be a test in the Rust code that yank and unyank can be performed by
MockCookieUsers as well asMockTokenUsers.- Implement
yankandunyankhelper methods on like they are onMockTokenUser - Duplicate this test and instead of calling
yankandunyankon theMockTokenUser, call them on theMockCookieUser. - The owners tests are good examples of using a
MockCookieUser. https://github.com/rust-lang/crates.io/blob/adf28ad82b4ec2aa8af95c03e42f9f361296278f/src/tests/owners.rs
- Implement