mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-17 03:39:33 +01:00
fix(ui): notice buttons act once, links send no referrer, solo windows defer
- A closing notice card stays in the DOM for its 200 ms fade, and its link and "See what's new" buttons still worked there: a double click opened the notice twice. close() now makes the card inert and every button handler does nothing once it is closing. - Notice links (and the combined card's "See what's new") open with noopener,noreferrer. noopener alone still sent this instance's origin, which can be a tailnet name or a tunnel URL, as the Referer. The plain update toast is unchanged. - The https rule is checked again at the button (CodemanSecurityNotices.urlOk): a caller handing showSecurityNotice or showUpdateNotice an unchecked URL gets no link button. - A detached session window (/session/:id) is rendered without __codemanCliAvailable, so it could never select the OpenCode notice, yet it took the update toast and recorded the version, and the dashboard then showed the notice as a separate card. While any notice is pending, a solo window now shows and records nothing and leaves both to the dashboard; with none pending it shows the plain toast as before. - The wiring tests pin the page's own clock (JSDOM gives the window its own Date). On the real clock 18 of them would have failed on every push from 2027-01-01, when the fixture notice expires. New tests pin the once-only close directly (the old double-click comment claimed more than it checked), the single open, the sink check, the solo windows, the scroll cap and the light-skin ink. - CLAUDE.md now says the public .json files are served no-cache, the exception to the year-long immutable cache. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ee6b115023
commit
82c34fba99
6 files changed
+184
-21
No files matched your search
@@ -3583,5 +3583,10 @@ function planStartupNotices(state = {}) {
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.CodemanSecurityNotices = { select: selectSecurityNotices, plan: planStartupNotices };
|
||||
window.CodemanSecurityNotices = {
|
||||
select: selectSecurityNotices,
|
||||
plan: planStartupNotices,
|
||||
// The same https-only rule select() applies, for the card's link button to check again.
|
||||
urlOk: (url) => typeof url === 'string' && SECURITY_NOTICE_URL_PATTERN.test(url),
|
||||
};
|
||||
}
|
||||
+30
-10
@@ -6298,10 +6298,9 @@ Object.assign(CodemanApp.prototype, {
|
||||
main.append(this._noticeEl('div', 'security-notice-eyebrow', 'Security notice'));
|
||||
main.append(...this._noticeTextBlock(notice));
|
||||
const actions = this._noticeEl('div', 'security-notice-actions');
|
||||
actions.append(
|
||||
this._noticeLinkButton(notice, () => card.close('link')),
|
||||
this._noticeButton('security-notice-quiet', 'Dismiss', () => card.close('dismiss'))
|
||||
);
|
||||
const link = this._noticeLinkButton(notice, card, () => card.close('link'));
|
||||
if (link) actions.append(link);
|
||||
actions.append(this._noticeButton('security-notice-quiet', 'Dismiss', () => card.close('dismiss')));
|
||||
main.append(actions);
|
||||
card.el.append(this._noticeIcon('shield', 'security-notice-icon'), main, card.closeButton);
|
||||
card.mount();
|
||||
@@ -6336,10 +6335,15 @@ Object.assign(CodemanApp.prototype, {
|
||||
head.append(this._noticeIcon('shield'), this._noticeEl('span', 'security-notice-eyebrow', 'Security notice'));
|
||||
section.append(head, ...this._noticeTextBlock(notice));
|
||||
main.append(section);
|
||||
actions.append(this._noticeLinkButton(notice, () => { seen(notice.id); card.close('link'); }));
|
||||
const link = this._noticeLinkButton(notice, card, () => { seen(notice.id); card.close('link'); });
|
||||
if (link) actions.append(link);
|
||||
}
|
||||
actions.append(
|
||||
this._noticeButton('security-notice-secondary', "See what's new", () => window.open(releaseUrl, '_blank', 'noopener'))
|
||||
this._noticeButton(
|
||||
'security-notice-secondary',
|
||||
"See what's new",
|
||||
card.act(() => window.open(releaseUrl, '_blank', 'noopener,noreferrer'))
|
||||
)
|
||||
);
|
||||
main.append(actions);
|
||||
card.el.append(this._noticeIcon('update', 'security-notice-icon update-notice-icon'), main, card.closeButton);
|
||||
@@ -6347,7 +6351,12 @@ Object.assign(CodemanApp.prototype, {
|
||||
return { dismiss: () => card.close(null) };
|
||||
},
|
||||
|
||||
/** The shell both notice cards share: role=alert, the ×, mount and a once-only close. */
|
||||
/**
|
||||
* The shell both notice cards share: role=alert, the ×, mount and a once-only close.
|
||||
* A closing card stays in the DOM for its 200 ms fade, so close() also makes it inert, and
|
||||
* `act(fn)` wraps a button's handler to do nothing once the card is closing (a double click
|
||||
* on a link used to open it twice; the × and Dismiss go through close(), already once-only).
|
||||
*/
|
||||
_noticeCard(className, onUserClose) {
|
||||
const el = this._noticeEl('div', className);
|
||||
el.setAttribute('role', 'alert');
|
||||
@@ -6356,6 +6365,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
const close = (reason) => {
|
||||
if (closed) return;
|
||||
closed = true;
|
||||
el.inert = true;
|
||||
el.classList.remove('show');
|
||||
setTimeout(() => el.remove(), 200);
|
||||
if (reason && typeof onUserClose === 'function') {
|
||||
@@ -6368,7 +6378,8 @@ Object.assign(CodemanApp.prototype, {
|
||||
this._toastStack().appendChild(el);
|
||||
requestAnimationFrame(() => el.classList.add('show'));
|
||||
};
|
||||
return { el, closeButton, close, mount };
|
||||
const act = (fn) => () => { if (!closed) fn(); };
|
||||
return { el, closeButton, close, mount, act };
|
||||
},
|
||||
|
||||
/** The notice's own title (when it has one) and message: textContent, never translated. */
|
||||
@@ -6379,11 +6390,20 @@ Object.assign(CodemanApp.prototype, {
|
||||
return parts;
|
||||
},
|
||||
|
||||
_noticeLinkButton(notice, after) {
|
||||
/**
|
||||
* The notice's link as the primary button, or null when the link is not https.
|
||||
* selectSecurityNotices() already drops such a notice; the URL is checked again here, at the
|
||||
* sink, because showSecurityNotice/showUpdateNotice take any object. Opened with noopener
|
||||
* AND noreferrer: noopener alone still sends this instance's origin (a tailnet name, a tunnel
|
||||
* URL) to the linked site as the Referer.
|
||||
*/
|
||||
_noticeLinkButton(notice, card, after) {
|
||||
const url = notice.url;
|
||||
if (!window.CodemanSecurityNotices?.urlOk?.(url)) return null;
|
||||
return this._noticeButton(
|
||||
'security-notice-primary',
|
||||
notice.label,
|
||||
() => { window.open(notice.url, '_blank', 'noopener'); after(); },
|
||||
card.act(() => { window.open(url, '_blank', 'noopener,noreferrer'); after(); }),
|
||||
true
|
||||
);
|
||||
},
|
||||
|
||||
@@ -386,6 +386,14 @@ Object.assign(CodemanApp.prototype, {
|
||||
* fresh install or a reload on the same version (showSecurityNotice). With no notice
|
||||
* selected the update toast is the plain one it always was. Storage blocked shows neither:
|
||||
* nothing could remember a close.
|
||||
*
|
||||
* ⚠️ A detached session window (/session/:id) is rendered without __codemanCliAvailable, so
|
||||
* it can never select a notice naming a CLI. Were it to take the update toast anyway, it
|
||||
* would record the version and the dashboard would later show that notice as a separate
|
||||
* card, not inside the update toast. So while any notice is pending (_loadSecurityNotices
|
||||
* counts every CLI the file names as installed there), a solo window shows and records
|
||||
* nothing and leaves both to the dashboard; with none pending it shows the plain update
|
||||
* toast as it always did.
|
||||
*/
|
||||
async checkWhatsNew(runningVersion) {
|
||||
if (this._whatsNewChecked) return;
|
||||
@@ -398,6 +406,7 @@ Object.assign(CodemanApp.prototype, {
|
||||
seen && seen !== runningVersion ? this._fetchWhatsNewNotes() : null,
|
||||
this._loadSecurityNotices(),
|
||||
]);
|
||||
if (this.isSoloWindow && notices.length) return;
|
||||
const plan = window.CodemanSecurityNotices.plan({ seenVersion: seen, runningVersion, notes, notices });
|
||||
if (plan.recordVersion) remember();
|
||||
if (plan.update) {
|
||||
@@ -443,7 +452,9 @@ Object.assign(CodemanApp.prototype, {
|
||||
* CodemanSecurityNotices.select() in constants.js: dates, the seen list, and for a notice
|
||||
* naming a CLI, `window.__codemanCliAvailable[cli] === true` only (unknown means not
|
||||
* installed). [] on any failure, and when storage is blocked (a close could not be
|
||||
* remembered, so the card would return on every load).
|
||||
* remembered, so the card would return on every load). In a solo window every CLI the file
|
||||
* names counts as installed: there the answer only decides whether to leave the release to
|
||||
* the dashboard (see checkWhatsNew), and is never shown.
|
||||
*/
|
||||
async _loadSecurityNotices() {
|
||||
let seen;
|
||||
@@ -452,8 +463,12 @@ Object.assign(CodemanApp.prototype, {
|
||||
const res = await fetch(CodemanBase.url('/security-notices.json'), { cache: 'no-cache' });
|
||||
if (!res.ok) return [];
|
||||
const data = await res.json();
|
||||
const list = Array.isArray(data?.notices) ? data.notices : [];
|
||||
const available = this.isSoloWindow
|
||||
? Object.fromEntries(list.filter((entry) => typeof entry?.cli === 'string').map((entry) => [entry.cli, true]))
|
||||
: window.__codemanCliAvailable;
|
||||
return window.CodemanSecurityNotices.select(data?.notices, {
|
||||
available: window.__codemanCliAvailable,
|
||||
available,
|
||||
seen,
|
||||
now: Date.now(),
|
||||
lang: window.CodemanI18n?.language || window.__codemanLanguage,
|
||||
|
||||
Reference in new issue
Block a user