Skip to content

Commit cb560e8

Browse files
committed
crate/settings: Add warning banner when trustpub_only blocks publishing
Shows a warning alert above the trusted publishing section when `trustpub_only` is enabled but no trusted publisher configs exist. The warning text: "Trusted publishing is required but no publishers are configured. Publishing to this crate is currently blocked."
1 parent b6075e9 commit cb560e8

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

app/controllers/crate/settings/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ export default class CrateSettingsController extends Controller {
2020
*/
2121
trustpubOnlyCheckboxWasVisible = false;
2222

23+
get #hasConfigs() {
24+
return this.githubConfigs?.length > 0 || this.gitlabConfigs?.length > 0;
25+
}
26+
2327
get showTrustpubOnlyCheckbox() {
24-
let hasConfigs = this.githubConfigs?.length > 0 || this.gitlabConfigs?.length > 0;
25-
return hasConfigs || this.crate?.trustpub_only || this.trustpubOnlyCheckboxWasVisible;
28+
return this.#hasConfigs || this.crate?.trustpub_only || this.trustpubOnlyCheckboxWasVisible;
29+
}
30+
31+
get showTrustpubOnlyWarning() {
32+
return this.crate?.trustpub_only && !this.#hasConfigs;
2633
}
2734

2835
@action showAddOwnerForm() {

app/templates/crate/settings/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@
114114
}
115115
}
116116

117+
.trustpub-only-warning {
118+
margin-bottom: var(--space-s);
119+
}
120+
117121
.trustpub-only-checkbox {
118122
border-top: 1px solid light-dark(hsla(51, 90%, 42%, 0.25), #232321);
119123
}

app/templates/crate/settings/index.gjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import pageTitle from 'ember-page-title/helpers/page-title';
88
import not from 'ember-truth-helpers/helpers/not';
99
import or from 'ember-truth-helpers/helpers/or';
1010

11+
import Alert from 'crates-io/components/alert';
1112
import CrateHeader from 'crates-io/components/crate-header';
1213
import Tooltip from 'crates-io/components/tooltip';
1314
import TrustpubOnlyCheckbox from 'crates-io/components/trustpub-only-checkbox';
@@ -117,6 +118,12 @@ import UserAvatar from 'crates-io/components/user-avatar';
117118
</div>
118119
</div>
119120

121+
{{#if @controller.showTrustpubOnlyWarning}}
122+
<Alert @variant='warning' class='trustpub-only-warning' data-test-trustpub-only-warning>
123+
Trusted publishing is required but no publishers are configured. Publishing to this crate is currently blocked.
124+
</Alert>
125+
{{/if}}
126+
120127
<div class='trustpub'>
121128
<table data-test-trusted-publishing>
122129
<thead>

tests/routes/crate/settings-test.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,86 @@ module('Route | crate.settings', hooks => {
277277
});
278278
});
279279

280+
module('trustpub_only warning banner', function () {
281+
test('hidden when flag is false', async function (assert) {
282+
const { crate, user } = prepare(this);
283+
this.authenticateAs(user);
284+
285+
await visit(`/crates/${crate.name}/settings`);
286+
287+
assert.dom('[data-test-trustpub-only-warning]').doesNotExist();
288+
});
289+
290+
test('hidden when flag is true and configs exist', async function (assert) {
291+
const { crate, user } = prepare(this);
292+
this.db.crate.update({ where: { id: { equals: crate.id } }, data: { trustpubOnly: true } });
293+
this.authenticateAs(user);
294+
295+
this.db.trustpubGithubConfig.create({
296+
crate,
297+
repository_owner: 'rust-lang',
298+
repository_name: 'crates.io',
299+
workflow_filename: 'ci.yml',
300+
});
301+
302+
await visit(`/crates/${crate.name}/settings`);
303+
304+
assert.dom('[data-test-trustpub-only-warning]').doesNotExist();
305+
});
306+
307+
test('shown when flag is true but no configs exist', async function (assert) {
308+
const { crate, user } = prepare(this);
309+
this.db.crate.update({ where: { id: { equals: crate.id } }, data: { trustpubOnly: true } });
310+
this.authenticateAs(user);
311+
312+
await visit(`/crates/${crate.name}/settings`);
313+
314+
assert.dom('[data-test-trustpub-only-warning]').exists();
315+
assert
316+
.dom('[data-test-trustpub-only-warning]')
317+
.hasText(
318+
'Trusted publishing is required but no publishers are configured. Publishing to this crate is currently blocked.',
319+
);
320+
});
321+
322+
test('disappears when checkbox is unchecked', async function (assert) {
323+
const { crate, user } = prepare(this);
324+
this.db.crate.update({ where: { id: { equals: crate.id } }, data: { trustpubOnly: true } });
325+
this.authenticateAs(user);
326+
327+
await visit(`/crates/${crate.name}/settings`);
328+
329+
assert.dom('[data-test-trustpub-only-warning]').exists();
330+
331+
await click('[data-test-trustpub-only-checkbox] [data-test-checkbox]');
332+
333+
assert.dom('[data-test-trustpub-only-warning]').doesNotExist();
334+
});
335+
336+
test('appears when checkbox is checked with no configs', async function (assert) {
337+
const { crate, user } = prepare(this);
338+
this.db.crate.update({ where: { id: { equals: crate.id } }, data: { trustpubOnly: true } });
339+
this.authenticateAs(user);
340+
341+
this.db.trustpubGithubConfig.create({
342+
crate,
343+
repository_owner: 'rust-lang',
344+
repository_name: 'crates.io',
345+
workflow_filename: 'ci.yml',
346+
});
347+
348+
await visit(`/crates/${crate.name}/settings`);
349+
350+
assert.dom('[data-test-trustpub-only-warning]').doesNotExist();
351+
352+
// Remove the config
353+
await click('[data-test-github-config="1"] [data-test-remove-config-button]');
354+
355+
// Warning should now appear
356+
assert.dom('[data-test-trustpub-only-warning]').exists();
357+
});
358+
});
359+
280360
module('trustpub_only checkbox', function () {
281361
test('hidden when no configs and flag is false', async function (assert) {
282362
const { crate, user } = prepare(this);

0 commit comments

Comments
 (0)