-
Notifications
You must be signed in to change notification settings - Fork 650
Replace rebuild docs button with dedicated confirmation page #11508
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
Open
Turbo87
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
Turbo87:wip/docs-rebuild-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Controller from '@ember/controller'; | ||
import { service } from '@ember/service'; | ||
|
||
import { keepLatestTask } from 'ember-concurrency'; | ||
|
||
export default class RebuildDocsController extends Controller { | ||
@service notifications; | ||
@service router; | ||
|
||
rebuildTask = keepLatestTask(async () => { | ||
let { version } = this.model; | ||
try { | ||
await version.rebuildDocs(); | ||
this.notifications.success('Docs rebuild task was enqueued successfully!'); | ||
this.router.transitionTo('crate.versions', version.crate.name); | ||
} catch (error) { | ||
let reason = error?.errors?.[0]?.detail ?? 'Failed to enqueue docs rebuild task.'; | ||
let msg = `Error: ${reason}`; | ||
this.notifications.error(msg); | ||
} | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { service } from '@ember/service'; | ||
|
||
import AuthenticatedRoute from '../-authenticated-route'; | ||
|
||
export default class RebuildDocsRoute extends AuthenticatedRoute { | ||
@service router; | ||
@service session; | ||
@service store; | ||
|
||
async model(params) { | ||
// Get the crate from parent route | ||
let crate = this.modelFor('crate'); | ||
|
||
// Load the specific version | ||
let version = await this.store.queryRecord('version', { | ||
name: crate.id, | ||
num: params.version_num, | ||
}); | ||
|
||
return { crate, version }; | ||
} | ||
|
||
async afterModel(model, transition) { | ||
let user = this.session.currentUser; | ||
let owners = await model.crate.owner_user; | ||
let isOwner = owners.some(owner => owner.id === user.id); | ||
if (!isOwner) { | ||
this.router.replaceWith('catch-all', { | ||
transition, | ||
title: 'This page is only accessible by crate owners', | ||
}); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.content { | ||
max-width: 600px; | ||
margin: var(--space-xl) auto; | ||
|
||
h1 { | ||
margin-top: 0; | ||
} | ||
} | ||
|
||
.crate-info { | ||
background-color: var(--orange-50); | ||
border-radius: 8px; | ||
padding: var(--space-m); | ||
margin: var(--space-m) 0; | ||
border: 1px solid var(--orange-200); | ||
|
||
h2 { | ||
margin: 0 0 var(--space-s); | ||
} | ||
} | ||
|
||
.info-row { | ||
margin-top: var(--space-xs); | ||
} | ||
|
||
.description { | ||
margin: var(--space-m) 0; | ||
} | ||
|
||
.actions { | ||
margin-top: var(--space-m); | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: var(--space-s); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{{page-title 'Rebuild Documentation'}} | ||
|
||
<div local-class="content"> | ||
<h1 data-test-title>Rebuild Documentation</h1> | ||
|
||
<div local-class="crate-info"> | ||
<h2>Crate Information</h2> | ||
<div local-class="info-row"> | ||
<strong>Crate:</strong> <span data-test-crate-name>{{@model.crate.name}}</span> | ||
</div> | ||
<div local-class="info-row"> | ||
<strong>Version:</strong> <span data-test-version-num>{{@model.version.num}}</span> | ||
</div> | ||
</div> | ||
|
||
<div local-class="description"> | ||
<p> | ||
This will trigger a rebuild of the documentation for | ||
<a href="https://docs.rs/{{@model.crate.name}}/{{@model.version.num}}" target="_blank" rel="noopener noreferrer"> | ||
<strong>{{@model.crate.name}} {{@model.version.num}}</strong> | ||
</a> | ||
on docs.rs. | ||
</p> | ||
<p> | ||
The rebuild process may take several minutes to complete. You can monitor the build progress at the <a href="https://docs.rs/releases/queue" target="_blank" rel="noopener noreferrer">docs.rs build queue</a>. | ||
</p> | ||
</div> | ||
|
||
<div local-class="actions"> | ||
<button | ||
type="button" | ||
class="button button--yellow" | ||
disabled={{this.rebuildTask.isRunning}} | ||
data-test-confirm-rebuild-button | ||
{{on "click" (perform this.rebuildTask)}} | ||
> | ||
{{#if this.rebuildTask.isRunning}} | ||
Requesting Rebuild... | ||
{{else}} | ||
Confirm Rebuild | ||
{{/if}} | ||
</button> | ||
<LinkTo @route="crate.versions" @model={{@model.crate.name}} class="button button--tan" data-test-cancel-button> | ||
Cancel | ||
</LinkTo> | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { expect, test } from '@/e2e/helper'; | ||
|
||
test.describe('Acceptance | rebuild docs page', { tag: '@acceptance' }, () => { | ||
test('navigates to rebuild docs confirmation page', async ({ page, msw }) => { | ||
let user = msw.db.user.create(); | ||
await msw.authenticateAs(user); | ||
|
||
let crate = msw.db.crate.create({ name: 'nanomsg' }); | ||
msw.db.crateOwnership.create({ crate, user }); | ||
|
||
msw.db.version.create({ crate, num: '0.1.0', created_at: '2017-01-01' }); | ||
msw.db.version.create({ crate, num: '0.2.0', created_at: '2018-01-01' }); | ||
msw.db.version.create({ crate, num: '0.3.0', created_at: '2019-01-01', rust_version: '1.69' }); | ||
msw.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await page.goto('/crates/nanomsg/versions'); | ||
await expect(page).toHaveURL('/crates/nanomsg/versions'); | ||
|
||
await expect(page.locator('[data-test-version]')).toHaveCount(4); | ||
let versions = await page.locator('[data-test-version]').evaluateAll(el => el.map(it => it.dataset.testVersion)); | ||
expect(versions).toEqual(['0.2.1', '0.3.0', '0.2.0', '0.1.0']); | ||
|
||
let v021 = page.locator('[data-test-version="0.2.1"]'); | ||
await v021.locator('[data-test-actions-toggle]').click(); | ||
await v021.getByRole('link', { name: 'Rebuild Docs' }).click(); | ||
|
||
await expect(page).toHaveURL('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
await expect(page.locator('[data-test-title]')).toHaveText('Rebuild Documentation'); | ||
}); | ||
|
||
test('rebuild docs confirmation page shows crate info and allows confirmation', async ({ page, msw }) => { | ||
let user = msw.db.user.create(); | ||
await msw.authenticateAs(user); | ||
|
||
let crate = msw.db.crate.create({ name: 'nanomsg' }); | ||
msw.db.crateOwnership.create({ crate, user }); | ||
|
||
msw.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await page.goto('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
await expect(page).toHaveURL('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
|
||
await expect(page.locator('[data-test-title]')).toHaveText('Rebuild Documentation'); | ||
await expect(page.locator('[data-test-crate-name]')).toHaveText('nanomsg'); | ||
await expect(page.locator('[data-test-version-num]')).toHaveText('0.2.1'); | ||
|
||
await page.getByRole('button', { name: 'Confirm Rebuild' }).click(); | ||
|
||
let message = 'Docs rebuild task was enqueued successfully!'; | ||
await expect(page.locator('[data-test-notification-message="success"]')).toHaveText(message); | ||
await expect(page).toHaveURL('/crates/nanomsg/versions'); | ||
}); | ||
|
||
test('rebuild docs confirmation page redirects non-owners to error page', async ({ page, msw }) => { | ||
let user = msw.db.user.create(); | ||
await msw.authenticateAs(user); | ||
|
||
let crate = msw.db.crate.create({ name: 'nanomsg' }); | ||
msw.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await page.goto('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
|
||
// Non-owners should be redirected to the catch-all error page | ||
await expect(page.getByText('This page is only accessible by crate owners')).toBeVisible(); | ||
}); | ||
|
||
test('rebuild docs confirmation page shows authentication error for unauthenticated users', async ({ page, msw }) => { | ||
let crate = msw.db.crate.create({ name: 'nanomsg' }); | ||
msw.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await page.goto('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
|
||
// Unauthenticated users should see authentication error | ||
await expect(page).toHaveURL('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
await expect(page.locator('[data-test-title]')).toHaveText('This page requires authentication'); | ||
await expect(page.locator('[data-test-login]')).toBeVisible(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { click, currentURL, findAll } from '@ember/test-helpers'; | ||
import { module, test } from 'qunit'; | ||
|
||
import { setupApplicationTest } from 'crates-io/tests/helpers'; | ||
|
||
import { visit } from '../helpers/visit-ignoring-abort'; | ||
|
||
module('Acceptance | rebuild docs page', function (hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('navigates to rebuild docs confirmation page', async function (assert) { | ||
let user = this.db.user.create(); | ||
this.authenticateAs(user); | ||
|
||
let crate = this.db.crate.create({ name: 'nanomsg' }); | ||
this.db.crateOwnership.create({ crate, user }); | ||
|
||
this.db.version.create({ crate, num: '0.1.0', created_at: '2017-01-01' }); | ||
this.db.version.create({ crate, num: '0.2.0', created_at: '2018-01-01' }); | ||
this.db.version.create({ crate, num: '0.3.0', created_at: '2019-01-01', rust_version: '1.69' }); | ||
this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await visit('/crates/nanomsg/versions'); | ||
assert.strictEqual(currentURL(), '/crates/nanomsg/versions'); | ||
|
||
let versions = findAll('[data-test-version]').map(it => it.dataset.testVersion); | ||
assert.deepEqual(versions, ['0.2.1', '0.3.0', '0.2.0', '0.1.0']); | ||
|
||
await click('[data-test-version="0.2.1"] [data-test-actions-toggle]'); | ||
await click('[data-test-version="0.2.1"] [data-test-id="btn-rebuild-docs"]'); | ||
|
||
assert.strictEqual(currentURL(), '/crates/nanomsg/0.2.1/rebuild-docs'); | ||
assert.dom('[data-test-title]').hasText('Rebuild Documentation'); | ||
}); | ||
|
||
test('rebuild docs confirmation page shows crate info and allows confirmation', async function (assert) { | ||
let user = this.db.user.create(); | ||
this.authenticateAs(user); | ||
|
||
let crate = this.db.crate.create({ name: 'nanomsg' }); | ||
this.db.crateOwnership.create({ crate, user }); | ||
|
||
this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await visit('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
assert.strictEqual(currentURL(), '/crates/nanomsg/0.2.1/rebuild-docs'); | ||
|
||
assert.dom('[data-test-title]').hasText('Rebuild Documentation'); | ||
assert.dom('[data-test-crate-name]').hasText('nanomsg'); | ||
assert.dom('[data-test-version-num]').hasText('0.2.1'); | ||
|
||
await click('[data-test-confirm-rebuild-button]'); | ||
|
||
let message = 'Docs rebuild task was enqueued successfully!'; | ||
assert.dom('[data-test-notification-message="success"]').hasText(message); | ||
assert.strictEqual(currentURL(), '/crates/nanomsg/versions'); | ||
}); | ||
|
||
test('rebuilds docs confirmation page redirects non-owners to error page', async function (assert) { | ||
let user = this.db.user.create(); | ||
this.authenticateAs(user); | ||
|
||
let crate = this.db.crate.create({ name: 'nanomsg' }); | ||
this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await visit('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
assert.dom('[data-test-title]').hasText('This page is only accessible by crate owners'); | ||
assert.dom('[data-test-go-back]').exists(); | ||
}); | ||
|
||
test('rebuild docs confirmation page shows authentication error for unauthenticated users', async function (assert) { | ||
let crate = this.db.crate.create({ name: 'nanomsg' }); | ||
this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); | ||
|
||
await visit('/crates/nanomsg/0.2.1/rebuild-docs'); | ||
|
||
// Unauthenticated users should see authentication error | ||
assert.strictEqual(currentURL(), '/crates/nanomsg/0.2.1/rebuild-docs'); | ||
assert.dom('[data-test-title]').hasText('This page requires authentication'); | ||
assert.dom('[data-test-login]').exists(); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we instead show the message on the page instead of redirecting the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned in the DMs, this is how the rest of crates.io behaves and I don't see a reason why we should do it differently for this route. note that the URL will stay the same and the user will see a "This page is only accessible by crate owners" message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If URL is the same, then all good for me. 👍