mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Split releases into trusted and untrusted scopes
- Upgrade radicle-artifact to 0.23 - Use radicle-artifact Filters, Trust and Scope for releases - Count only releases a user can browse: delegate + other - Count releases only for a single repo, not in repo lists - Add the scope=trusted|untrusted query - Keep allAuthors for older clients until a major release - Replace the All filter with Delegates and Others in the UI - Open lists and releases on Delegates, also when empty - Show the Others filter whenever it has content - Name the scope in the empty artifacts message - Filter by creator on older nodes, which ignore scope - Page releases on the raw response length - Warn on a release by a non-delegate - Warn on a delegate's release while it shows others' artifacts - Count only delegate attestations in a badge - Warn about browser links added by non-delegates - Say browser downloads are not checked against the CID - Move the scope and warning logic to `src/lib/releases.ts` - Test artifact scopes, scope routes, opening on Delegates and the warnings
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import type { Artifact, Author, ReleaseScope } from "@http-client";
|
||||
|
||||
export interface ArtifactView {
|
||||
shown: Artifact[];
|
||||
redactedCount: number;
|
||||
counts: Record<ReleaseScope, number>;
|
||||
showFilters: boolean;
|
||||
}
|
||||
|
||||
// Whether the artifact was redacted by a trusted party (its author or a
|
||||
// delegate), mirroring the backend's default-hidden rule.
|
||||
export function redactedByTrusted(
|
||||
artifact: Artifact,
|
||||
delegates: Set<string>,
|
||||
): boolean {
|
||||
return artifact.redactions.some(
|
||||
r => r.user.id === artifact.author.id || delegates.has(r.user.id),
|
||||
);
|
||||
}
|
||||
|
||||
// The artifacts of a release in one author scope. The endpoint returns every
|
||||
// author, so the split happens here. The scope asked for is shown even when it
|
||||
// is empty: switching to others by itself would show untrusted content unasked.
|
||||
export function artifactView(
|
||||
artifacts: Artifact[],
|
||||
delegates: Set<string>,
|
||||
scope: ReleaseScope,
|
||||
showRedacted: boolean,
|
||||
): ArtifactView {
|
||||
const byScope: Record<ReleaseScope, Artifact[]> = {
|
||||
trusted: artifacts.filter(a => delegates.has(a.author.id)),
|
||||
untrusted: artifacts.filter(a => !delegates.has(a.author.id)),
|
||||
};
|
||||
const visible = (list: Artifact[]) =>
|
||||
showRedacted ? list : list.filter(a => !redactedByTrusted(a, delegates));
|
||||
|
||||
return {
|
||||
shown: visible(byScope[scope]),
|
||||
// The hidden set within the current author scope.
|
||||
redactedCount: byScope[scope].filter(a => redactedByTrusted(a, delegates))
|
||||
.length,
|
||||
// Counts reflect what each scope would show, so an artifact hidden as
|
||||
// redacted never counts. The filter itself comes from the unfiltered sets,
|
||||
// so toggling redacted artifacts never hides it.
|
||||
counts: {
|
||||
trusted: visible(byScope.trusted).length,
|
||||
untrusted: visible(byScope.untrusted).length,
|
||||
},
|
||||
// Others is one click away whenever it holds something.
|
||||
showFilters: byScope.untrusted.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Anyone can attest their own artifact, so only delegates count.
|
||||
export function attestedBy(
|
||||
attestations: Author[],
|
||||
delegates: Set<string>,
|
||||
): number {
|
||||
return attestations.filter(a => delegates.has(a.id)).length;
|
||||
}
|
||||
|
||||
// A non-delegate's release is untrusted as a whole, as its creator chose its
|
||||
// title, tag and commit. A delegate's release is untrusted only while it
|
||||
// shows artifacts by non-delegates.
|
||||
export function releaseWarning(
|
||||
creator: string,
|
||||
delegates: Set<string>,
|
||||
artifactScope: ReleaseScope,
|
||||
): "release" | "artifacts" | undefined {
|
||||
if (!delegates.has(creator)) {
|
||||
return "release";
|
||||
}
|
||||
return artifactScope === "untrusted" ? "artifacts" : undefined;
|
||||
}
|
||||
@@ -13,6 +13,20 @@ export function defaultBranch(repo: Repo): string {
|
||||
return repo.payloads["xyz.radicle.project"].data.defaultBranch;
|
||||
}
|
||||
|
||||
// Counts the releases a user can browse: the two unredacted buckets, or the
|
||||
// single count older nodes report in place of the buckets. Undefined means the
|
||||
// node doesn't report releases at all, which is how the release API is
|
||||
// detected.
|
||||
export function visibleReleaseCount(repo: Repo): number | undefined {
|
||||
const releases = repo.payloads["xyz.radicle.project"].meta.releases;
|
||||
if (releases === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return typeof releases === "number"
|
||||
? releases
|
||||
: releases.delegate + releases.other;
|
||||
}
|
||||
|
||||
export function unqualifyBranch(refname: string): string {
|
||||
return refname.startsWith(REFS_HEADS)
|
||||
? refname.slice(REFS_HEADS.length)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import config from "@app/lib/config";
|
||||
import debounce from "lodash/debounce";
|
||||
import { routeToPath } from "@app/lib/router";
|
||||
import { toClipboard } from "@app/lib/utils";
|
||||
import { toClipboard, visibleReleaseCount } from "@app/lib/utils";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
@@ -21,6 +21,9 @@
|
||||
export let repo: Repo;
|
||||
export let repoId: string;
|
||||
|
||||
// Undefined on older nodes that don't report release counts.
|
||||
$: releaseCount = visibleReleaseCount(repo);
|
||||
|
||||
let shareIcon: "link" | "checkmark" = "link";
|
||||
|
||||
const restoreIcon = debounce(() => {
|
||||
@@ -160,9 +163,9 @@
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<!-- Only nodes that report a release count support the release API; hide the
|
||||
<!-- Only nodes that report release counts support the release API; hide the
|
||||
tab on older nodes where the field is absent. -->
|
||||
{#if repo.payloads["xyz.radicle.project"].meta.releases !== undefined}
|
||||
{#if releaseCount !== undefined}
|
||||
<Link
|
||||
route={{
|
||||
resource: "repo.releases",
|
||||
@@ -179,7 +182,7 @@
|
||||
class="counter"
|
||||
class:hover={hover && activeTab !== "releases"}
|
||||
class:selected={activeTab === "releases"}>
|
||||
{repo.payloads["xyz.radicle.project"].meta.releases}
|
||||
{releaseCount}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
<script lang="ts">
|
||||
import type { Artifact, BaseUrl, Release, Repo } from "@http-client";
|
||||
import type {
|
||||
Artifact,
|
||||
BaseUrl,
|
||||
Release,
|
||||
ReleaseScope,
|
||||
Repo,
|
||||
} from "@http-client";
|
||||
|
||||
import * as utils from "@app/lib/utils";
|
||||
import {
|
||||
artifactView,
|
||||
attestedBy,
|
||||
redactedByTrusted,
|
||||
releaseWarning,
|
||||
} from "@app/lib/releases";
|
||||
|
||||
import Badge from "@app/components/Badge.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
@@ -15,12 +27,13 @@
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import NodeId from "@app/components/NodeId.svelte";
|
||||
import Separator from "./Separator.svelte";
|
||||
import UntrustedWarning from "./Release/UntrustedWarning.svelte";
|
||||
|
||||
export let baseUrl: BaseUrl;
|
||||
export let release: Release;
|
||||
export let repo: Repo;
|
||||
export let repoId: string;
|
||||
export let allAuthors: boolean;
|
||||
export let scope: ReleaseScope | undefined = undefined;
|
||||
export let nodeId: string;
|
||||
export let nodeAvatarUrl: string | undefined;
|
||||
|
||||
@@ -33,14 +46,6 @@
|
||||
|
||||
$: delegateIds = new Set(repo.delegates.map(d => d.id));
|
||||
|
||||
// Whether the artifact was redacted by a trusted party (its author or a
|
||||
// delegate), mirroring the backend's default-hidden rule.
|
||||
function redactedByTrusted(artifact: Artifact, delegates: Set<string>) {
|
||||
return artifact.redactions.some(
|
||||
r => r.user.id === artifact.author.id || delegates.has(r.user.id),
|
||||
);
|
||||
}
|
||||
|
||||
// Label for the redacted badge. Delegate takes precedence over author,
|
||||
// since the author may also be a delegate.
|
||||
function redactedByLabel(artifact: Artifact, delegates: Set<string>): string {
|
||||
@@ -48,46 +53,26 @@
|
||||
return byDelegate ? "Redacted by delegate" : "Redacted by author";
|
||||
}
|
||||
|
||||
// Artifacts visible under the given redaction toggle.
|
||||
function visible(
|
||||
list: Artifact[],
|
||||
show: boolean,
|
||||
delegates: Set<string>,
|
||||
): Artifact[] {
|
||||
return show ? list : list.filter(a => !redactedByTrusted(a, delegates));
|
||||
}
|
||||
|
||||
$: delegateArtifacts = release.artifacts.filter(a =>
|
||||
delegateIds.has(a.author.id),
|
||||
);
|
||||
// Artifacts are scoped to delegate authors by default; the endpoint returns
|
||||
// all of them, so filtering happens client-side. With no delegate artifact
|
||||
// at all, fall back to every author.
|
||||
$: authorArtifacts =
|
||||
allAuthors || delegateArtifacts.length === 0
|
||||
? release.artifacts
|
||||
: delegateArtifacts;
|
||||
$: shownArtifacts = visible(authorArtifacts, showRedacted, delegateIds);
|
||||
// The redacted count is the hidden set within the current author scope.
|
||||
$: redactedCount = authorArtifacts.filter(a =>
|
||||
redactedByTrusted(a, delegateIds),
|
||||
).length;
|
||||
|
||||
// Segment counts reflect what each choice would actually show, so an
|
||||
// artifact hidden as redacted never counts towards a scope. They label the
|
||||
// segments only: the author scope and the filter visibility come from the
|
||||
// unfiltered sets, so toggling redacted artifacts never moves them.
|
||||
$: delegateCount = visible(
|
||||
delegateArtifacts,
|
||||
showRedacted,
|
||||
$: activeScope = scope ?? "trusted";
|
||||
$: view = artifactView(
|
||||
release.artifacts,
|
||||
delegateIds,
|
||||
).length;
|
||||
$: allCount = visible(release.artifacts, showRedacted, delegateIds).length;
|
||||
activeScope,
|
||||
showRedacted,
|
||||
);
|
||||
$: shownArtifacts = view.shown;
|
||||
$: redactedCount = view.redactedCount;
|
||||
$: delegateCount = view.counts.trusted;
|
||||
$: otherCount = view.counts.untrusted;
|
||||
$: showFilters = view.showFilters;
|
||||
|
||||
// Filter only when both scopes hold something.
|
||||
$: showFilters =
|
||||
delegateArtifacts.length > 0 &&
|
||||
delegateArtifacts.length !== release.artifacts.length;
|
||||
$: warning = releaseWarning(release.creator.id, delegateIds, activeScope);
|
||||
$: untrustedWarning =
|
||||
warning === "release"
|
||||
? "Not from a delegate. Only download if you trust the author."
|
||||
: warning === "artifacts"
|
||||
? "Not from delegates. Only download if you trust the authors."
|
||||
: undefined;
|
||||
|
||||
// Format a byte count as a human-readable size (mirrors the CLI display).
|
||||
function formatBytes(bytes: number): string {
|
||||
@@ -186,6 +171,10 @@
|
||||
.redacted-toggle {
|
||||
margin-left: auto;
|
||||
}
|
||||
.untrusted-warning {
|
||||
padding: 0.75rem 1rem;
|
||||
border-bottom: 1px solid var(--color-border-subtle);
|
||||
}
|
||||
.filter-divider {
|
||||
border-bottom: 1px solid var(--color-border-subtle);
|
||||
}
|
||||
@@ -382,7 +371,7 @@
|
||||
resource: "repo.releases",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
allAuthors,
|
||||
scope: delegateIds.has(release.creator.id) ? undefined : "untrusted",
|
||||
}}>
|
||||
Releases
|
||||
</Link>
|
||||
@@ -436,6 +425,11 @@
|
||||
</CobHeader>
|
||||
|
||||
<div class="artifacts">
|
||||
{#if untrustedWarning}
|
||||
<div class="untrusted-warning">
|
||||
<UntrustedWarning text={untrustedWarning} />
|
||||
</div>
|
||||
{/if}
|
||||
{#if showFilters || redactedCount > 0}
|
||||
<div class="filter">
|
||||
{#if showFilters}
|
||||
@@ -449,14 +443,14 @@
|
||||
}}>
|
||||
<Button
|
||||
let:hover
|
||||
variant={!allAuthors ? "gray" : "background"}>
|
||||
variant={activeScope === "trusted" ? "gray" : "background"}>
|
||||
<Icon name="badge" />
|
||||
<div class="title-counter">
|
||||
Delegates
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={!allAuthors}
|
||||
class:hover={hover && allAuthors}>
|
||||
class:selected={activeScope === "trusted"}
|
||||
class:hover={hover && activeScope !== "trusted"}>
|
||||
{delegateCount}
|
||||
</span>
|
||||
</div>
|
||||
@@ -468,19 +462,22 @@
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
release: release.id,
|
||||
allAuthors: true,
|
||||
scope: "untrusted",
|
||||
}}>
|
||||
<Button
|
||||
let:hover
|
||||
variant={allAuthors ? "gray" : "background"}>
|
||||
title="Non-delegates"
|
||||
variant={activeScope === "untrusted"
|
||||
? "gray"
|
||||
: "background"}>
|
||||
<Icon name="avatar-incognito" />
|
||||
<div class="title-counter">
|
||||
All
|
||||
Others
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={allAuthors}
|
||||
class:hover={hover && !allAuthors}>
|
||||
{allCount}
|
||||
class:selected={activeScope === "untrusted"}
|
||||
class:hover={hover && activeScope !== "untrusted"}>
|
||||
{otherCount}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
@@ -505,7 +502,11 @@
|
||||
{#if shownArtifacts.length === 0}
|
||||
<div class="empty-artifacts">
|
||||
<Icon name="attach" />
|
||||
No artifacts
|
||||
{!showFilters
|
||||
? "No artifacts"
|
||||
: activeScope === "trusted"
|
||||
? "No artifacts by delegates"
|
||||
: "No artifacts by others"}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -520,6 +521,10 @@
|
||||
{@const locationCount = artifact.locations.length}
|
||||
{@const cliOnly =
|
||||
locationCount > 0 && !artifact.locations.some(l => isWebUrl(l.url))}
|
||||
{@const attestedByDelegates = attestedBy(
|
||||
artifact.attestations,
|
||||
delegateIds,
|
||||
)}
|
||||
{@const redactions = delegatesFirst(
|
||||
artifact.redactions,
|
||||
r => r.user.id,
|
||||
@@ -534,6 +539,15 @@
|
||||
{redactedByLabel(artifact, delegateIds)}
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if attestedByDelegates > 0}
|
||||
<Badge size="tiny" variant="positive">
|
||||
<Icon name="checkmark" />
|
||||
Attested by {attestedByDelegates} delegate{attestedByDelegates ===
|
||||
1
|
||||
? ""
|
||||
: "s"}
|
||||
</Badge>
|
||||
{/if}
|
||||
<div class="artifact-actions">
|
||||
{#if size}
|
||||
<span class="size">{size}</span>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
import Popover from "@app/components/Popover.svelte";
|
||||
import Radio from "@app/components/Radio.svelte";
|
||||
import ExternalLink from "@app/components/ExternalLink.svelte";
|
||||
import UntrustedWarning from "./UntrustedWarning.svelte";
|
||||
|
||||
export let artifact: Artifact;
|
||||
export let rid: string;
|
||||
@@ -25,6 +26,8 @@
|
||||
(a, b) =>
|
||||
Number(delegateIds.has(b.user.id)) - Number(delegateIds.has(a.user.id)),
|
||||
);
|
||||
$: authorTrusted = delegateIds.has(artifact.author.id);
|
||||
$: linksByOthers = webLocations.some(l => !delegateIds.has(l.user.id));
|
||||
// Any location at all can be fetched with the CLI, web locations included.
|
||||
$: downloadable = artifact.locations.length > 0;
|
||||
$: command = `rad artifact -r ${rid} download --cid ${artifact.cid}`;
|
||||
@@ -50,6 +53,9 @@
|
||||
.warning :global(svg) {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.untrusted {
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
.locations {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -90,6 +96,12 @@
|
||||
</Button>
|
||||
|
||||
<div slot="popover" style:width="24rem" class="popover">
|
||||
{#if !authorTrusted}
|
||||
<div class="untrusted">
|
||||
<UntrustedWarning
|
||||
text="Not from a delegate. Only download if you trust the author." />
|
||||
</div>
|
||||
{/if}
|
||||
<div style:margin-bottom="1.5rem">
|
||||
<Radio ariaLabel="Toggle download method" styleGap="2px">
|
||||
<Button
|
||||
@@ -131,8 +143,14 @@
|
||||
{:else}
|
||||
<div class="warning">
|
||||
<Icon name="warning" />
|
||||
These downloads are not verified.
|
||||
These downloads are not checked against the CID.
|
||||
</div>
|
||||
{#if authorTrusted && linksByOthers}
|
||||
<div class="untrusted">
|
||||
<UntrustedWarning
|
||||
text="Links without a delegate badge are not from a delegate. Only use them if you trust who added them." />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="locations">
|
||||
{#each webLocations as location (location.url)}
|
||||
<div class="location">
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
export let delegateIds: Set<string>;
|
||||
export let release: Release;
|
||||
export let repoId: string;
|
||||
export let allAuthors: boolean = false;
|
||||
|
||||
// The COB has no title; fall back to the tag name, then the release id.
|
||||
$: title = release.title || release.tagName || release.id;
|
||||
@@ -84,7 +83,6 @@
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
release: release.id,
|
||||
allAuthors,
|
||||
}}>
|
||||
<InlineTitle fontSize="body-m-regular" content={title} />
|
||||
</Link>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<script lang="ts">
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
|
||||
export let text: string;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
color: var(--color-text-secondary);
|
||||
font: var(--txt-body-s-regular);
|
||||
}
|
||||
.icon {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
color: var(--color-feedback-warning-text);
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="banner" role="note">
|
||||
<span class="icon"><Icon name="warning" /></span>
|
||||
<span>{text}</span>
|
||||
</div>
|
||||
@@ -1,8 +1,8 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl, Release, Repo } from "@http-client";
|
||||
import type { BaseUrl, Release, ReleaseScope, Repo } from "@http-client";
|
||||
|
||||
import { HttpdClient } from "@http-client";
|
||||
import { RELEASES_PER_PAGE } from "./router";
|
||||
import { RELEASES_PER_PAGE, releasesQuery, scopeReleases } from "./router";
|
||||
import { baseUrlToString } from "@app/lib/utils";
|
||||
|
||||
import Button from "@app/components/Button.svelte";
|
||||
@@ -15,12 +15,14 @@
|
||||
import Placeholder from "@app/components/Placeholder.svelte";
|
||||
import ReleaseTeaser from "@app/views/repos/Release/ReleaseTeaser.svelte";
|
||||
import Separator from "./Separator.svelte";
|
||||
import UntrustedWarning from "@app/views/repos/Release/UntrustedWarning.svelte";
|
||||
|
||||
export let baseUrl: BaseUrl;
|
||||
export let releases: Release[];
|
||||
export let lastPageFull: boolean;
|
||||
export let repo: Repo;
|
||||
export let repoId: string;
|
||||
export let allAuthors: boolean;
|
||||
export let scope: ReleaseScope;
|
||||
export let showFilters: boolean;
|
||||
export let nodeId: string;
|
||||
export let nodeAvatarUrl: string | undefined;
|
||||
@@ -30,21 +32,19 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let error: any;
|
||||
let allReleases: Release[];
|
||||
let morePages: boolean;
|
||||
|
||||
$: {
|
||||
allReleases = releases;
|
||||
morePages = lastPageFull;
|
||||
page = 0;
|
||||
}
|
||||
|
||||
$: delegateIds = new Set(repo.delegates.map(d => d.id));
|
||||
// The delegate count isn't in repo metadata; derive it from the loaded
|
||||
// pages. It labels the segment only, and reads as "30+" while pages are
|
||||
// outstanding; whether the segments show at all is settled by the router.
|
||||
$: delegateReleaseCount = allAuthors
|
||||
? allReleases.filter(r => delegateIds.has(r.creator.id)).length
|
||||
: allReleases.length;
|
||||
|
||||
$: releaseCount = repo.payloads["xyz.radicle.project"].meta.releases;
|
||||
// Older nodes report a single count, so their segments go without counters.
|
||||
$: releasesMeta = repo.payloads["xyz.radicle.project"].meta.releases;
|
||||
$: counts = typeof releasesMeta === "object" ? releasesMeta : undefined;
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
@@ -54,12 +54,12 @@
|
||||
// doesn't leave a gap behind on retry.
|
||||
const next = page + 1;
|
||||
try {
|
||||
const response = await api.repo.getAllReleases(repo.rid, {
|
||||
allAuthors,
|
||||
page: next,
|
||||
perPage: RELEASES_PER_PAGE,
|
||||
});
|
||||
allReleases = [...allReleases, ...response];
|
||||
const response = await api.repo.getAllReleases(
|
||||
repo.rid,
|
||||
releasesQuery(scope, next),
|
||||
);
|
||||
allReleases = [...allReleases, ...scopeReleases(response, repo, scope)];
|
||||
morePages = response.length === RELEASES_PER_PAGE;
|
||||
page = next;
|
||||
} catch (e) {
|
||||
error = e;
|
||||
@@ -69,10 +69,9 @@
|
||||
}
|
||||
|
||||
// The count for the current filter isn't in repo metadata, so offer "More"
|
||||
// whenever every loaded page came back full; a short page means we've reached
|
||||
// the end.
|
||||
$: showMoreButton =
|
||||
!loading && !error && allReleases.length === (page + 1) * RELEASES_PER_PAGE;
|
||||
// while the last page came back full; a short page means we've reached the
|
||||
// end.
|
||||
$: showMoreButton = !loading && !error && morePages;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -83,6 +82,10 @@
|
||||
padding: 1rem;
|
||||
border-bottom: 1px solid var(--color-border-subtle);
|
||||
}
|
||||
.warning {
|
||||
padding: 0.75rem 1rem;
|
||||
border-bottom: 1px solid var(--color-border-subtle);
|
||||
}
|
||||
.counter {
|
||||
border-radius: var(--border-radius-sm);
|
||||
background-color: var(--color-surface-mid);
|
||||
@@ -141,16 +144,20 @@
|
||||
<div class="header">
|
||||
<Link
|
||||
route={{ resource: "repo.releases", repo: repoId, node: baseUrl }}>
|
||||
<Button let:hover variant={!allAuthors ? "gray" : "background"}>
|
||||
<Button
|
||||
let:hover
|
||||
variant={scope === "trusted" ? "gray" : "background"}>
|
||||
<Icon name="badge" />
|
||||
<div class="title-counter">
|
||||
Delegates
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={!allAuthors}
|
||||
class:hover={hover && allAuthors}>
|
||||
{delegateReleaseCount}{showMoreButton ? "+" : ""}
|
||||
</span>
|
||||
{#if counts}
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={scope === "trusted"}
|
||||
class:hover={hover && scope !== "trusted"}>
|
||||
{counts.delegate}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
@@ -159,18 +166,21 @@
|
||||
resource: "repo.releases",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
allAuthors: true,
|
||||
scope: "untrusted",
|
||||
}}>
|
||||
<Button let:hover variant={allAuthors ? "gray" : "background"}>
|
||||
<Button
|
||||
let:hover
|
||||
title="Non-delegates"
|
||||
variant={scope === "untrusted" ? "gray" : "background"}>
|
||||
<Icon name="avatar-incognito" />
|
||||
<div class="title-counter">
|
||||
All
|
||||
{#if releaseCount !== undefined}
|
||||
Others
|
||||
{#if counts}
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={allAuthors}
|
||||
class:hover={hover && !allAuthors}>
|
||||
{releaseCount}
|
||||
class:selected={scope === "untrusted"}
|
||||
class:hover={hover && scope !== "untrusted"}>
|
||||
{counts.other}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -178,6 +188,12 @@
|
||||
</Link>
|
||||
</div>
|
||||
{/if}
|
||||
{#if scope === "untrusted"}
|
||||
<div class="warning">
|
||||
<UntrustedWarning
|
||||
text="Not from delegates. Only download from authors you trust." />
|
||||
</div>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
<List items={allReleases}>
|
||||
@@ -186,7 +202,6 @@
|
||||
let:item
|
||||
{baseUrl}
|
||||
{repoId}
|
||||
{allAuthors}
|
||||
{delegateIds}
|
||||
release={item} />
|
||||
</List>
|
||||
@@ -203,9 +218,11 @@
|
||||
<div class="placeholder">
|
||||
<Placeholder
|
||||
iconName="parcel"
|
||||
caption={showFilters && !allAuthors
|
||||
? "No releases by delegates"
|
||||
: "No releases"} />
|
||||
caption={!showFilters
|
||||
? "No releases"
|
||||
: scope === "trusted"
|
||||
? "No releases by delegates"
|
||||
: "No releases by others"} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import type {
|
||||
PatchState,
|
||||
PeerRefs,
|
||||
Release,
|
||||
ReleaseScope,
|
||||
Remote,
|
||||
Repo,
|
||||
Revision,
|
||||
@@ -111,7 +112,7 @@ interface RepoReleasesRoute {
|
||||
resource: "repo.releases";
|
||||
node: BaseUrl;
|
||||
repo: string;
|
||||
allAuthors?: boolean;
|
||||
scope?: ReleaseScope;
|
||||
}
|
||||
|
||||
interface RepoReleaseRoute {
|
||||
@@ -119,7 +120,7 @@ interface RepoReleaseRoute {
|
||||
node: BaseUrl;
|
||||
repo: string;
|
||||
release: string;
|
||||
allAuthors?: boolean;
|
||||
scope?: ReleaseScope;
|
||||
}
|
||||
|
||||
interface RepoIssueRoute {
|
||||
@@ -284,7 +285,8 @@ export type RepoLoadedRoute =
|
||||
repo: Repo;
|
||||
repoId: string;
|
||||
releases: Release[];
|
||||
allAuthors: boolean;
|
||||
lastPageFull: boolean;
|
||||
scope: ReleaseScope;
|
||||
showFilters: boolean;
|
||||
nodeId: string;
|
||||
nodeAvatarUrl: string | undefined;
|
||||
@@ -297,7 +299,7 @@ export type RepoLoadedRoute =
|
||||
repo: Repo;
|
||||
repoId: string;
|
||||
release: Release;
|
||||
allAuthors: boolean;
|
||||
scope?: ReleaseScope;
|
||||
nodeId: string;
|
||||
nodeAvatarUrl: string | undefined;
|
||||
};
|
||||
@@ -504,81 +506,77 @@ function releasesNotSupported(node: BaseUrl): NotFoundRoute {
|
||||
};
|
||||
}
|
||||
|
||||
// The query for a page of releases in one author scope. Older nodes ignore
|
||||
// `scope`, so ask them for every author too when the scope is untrusted.
|
||||
export function releasesQuery(scope: ReleaseScope, page: number) {
|
||||
return {
|
||||
scope,
|
||||
allAuthors: scope === "untrusted" ? true : undefined,
|
||||
page,
|
||||
perPage: RELEASES_PER_PAGE,
|
||||
};
|
||||
}
|
||||
|
||||
// Keep only the releases in the author scope. A newer node has done this
|
||||
// already; an older one answers the untrusted scope with every author. Its pages
|
||||
// then come back short, so page on the length of the response, not of this.
|
||||
export function scopeReleases(
|
||||
releases: Release[],
|
||||
repo: Repo,
|
||||
scope: ReleaseScope,
|
||||
): Release[] {
|
||||
if (scope === "trusted") {
|
||||
return releases;
|
||||
}
|
||||
const delegateIds = new Set(repo.delegates.map(d => d.id));
|
||||
return releases.filter(r => !delegateIds.has(r.creator.id));
|
||||
}
|
||||
|
||||
async function loadReleasesView(
|
||||
route: RepoReleasesRoute,
|
||||
): Promise<RepoLoadedRoute | NotFoundRoute> {
|
||||
const api = new HttpdClient(route.node);
|
||||
const allAuthors = route.allAuthors || false;
|
||||
// Open on delegates even when they have no releases, so untrusted content
|
||||
// shows only when asked for.
|
||||
const scope = route.scope ?? "trusted";
|
||||
|
||||
// Fetch releases alongside the repo so the common path stays parallel; the
|
||||
// repo's `meta.releases` then tells us whether a failure is an unsupported
|
||||
// node or a genuine error. The delegate scope is a subset of every author,
|
||||
// so the all-authors view sizes both scopes from its own page, while the
|
||||
// delegate view has to ask for the other scope to size it.
|
||||
const [repo, releasesResult, everyAuthorPage, node] = await Promise.all([
|
||||
// node or a genuine error.
|
||||
const [repo, releasesResult, node] = await Promise.all([
|
||||
api.repo.getByRid(route.repo),
|
||||
api.repo
|
||||
.getAllReleases(route.repo, {
|
||||
allAuthors,
|
||||
page: 0,
|
||||
perPage: RELEASES_PER_PAGE,
|
||||
})
|
||||
.then(
|
||||
releases => ({ releases }),
|
||||
(error: unknown) => ({ error }),
|
||||
),
|
||||
allAuthors
|
||||
? undefined
|
||||
: api.repo
|
||||
.getAllReleases(route.repo, {
|
||||
allAuthors: true,
|
||||
page: 0,
|
||||
perPage: RELEASES_PER_PAGE,
|
||||
})
|
||||
// Only the filter rides on this, so a failure here shouldn't take
|
||||
// the page down with it.
|
||||
.catch(() => undefined),
|
||||
api.repo.getAllReleases(route.repo, releasesQuery(scope, 0)).then(
|
||||
releases => ({ releases }),
|
||||
(error: unknown) => ({ error }),
|
||||
),
|
||||
api.getNode(),
|
||||
]);
|
||||
|
||||
const releaseCount = repo.payloads["xyz.radicle.project"].meta.releases;
|
||||
if (releaseCount === undefined) {
|
||||
// Older nodes report a single count here, newer ones the buckets, and
|
||||
// either way its absence means no release API.
|
||||
const releasesMeta = repo.payloads["xyz.radicle.project"].meta.releases;
|
||||
if (releasesMeta === undefined) {
|
||||
return releasesNotSupported(route.node);
|
||||
}
|
||||
if ("error" in releasesResult) {
|
||||
throw releasesResult.error;
|
||||
}
|
||||
const page = releasesResult.releases;
|
||||
|
||||
const releases = releasesResult.releases;
|
||||
|
||||
// Offer the author filter only where the two scopes hold different releases,
|
||||
// so a repo whose releases are all by delegates carries no filter with an
|
||||
// identical list behind it, and one with none of its own still leaves a way
|
||||
// through to the others. Both sizes come from a list the endpoint returned:
|
||||
// `meta.releases` counts every release COB, including ones the endpoint
|
||||
// hides such as fully redacted releases, so it would overcount either scope.
|
||||
// A full page means the list may go on, so keep the filter rather than have
|
||||
// it appear or vanish as the user pages, and keep it too if the other scope
|
||||
// failed to load. Decided here so it stays fixed for the life of the route.
|
||||
const delegateIds = new Set(repo.delegates.map(d => d.id));
|
||||
const delegateReleaseCount = allAuthors
|
||||
? releases.filter(r => delegateIds.has(r.creator.id)).length
|
||||
: releases.length;
|
||||
const everyAuthorCount = allAuthors
|
||||
? releases.length
|
||||
: everyAuthorPage?.length;
|
||||
// Others is one click away whenever it holds releases.
|
||||
const showFilters =
|
||||
everyAuthorCount === undefined ||
|
||||
everyAuthorCount === RELEASES_PER_PAGE ||
|
||||
delegateReleaseCount !== everyAuthorCount;
|
||||
typeof releasesMeta !== "number"
|
||||
? releasesMeta.other > 0
|
||||
: scope === "untrusted" || (await legacyHasOthers(api, route.repo, repo));
|
||||
|
||||
return {
|
||||
resource: "repo.releases",
|
||||
params: {
|
||||
baseUrl: route.node,
|
||||
repoId: route.repo,
|
||||
releases,
|
||||
allAuthors,
|
||||
releases: scopeReleases(page, repo, scope),
|
||||
lastPageFull: page.length === RELEASES_PER_PAGE,
|
||||
scope,
|
||||
showFilters,
|
||||
repo,
|
||||
nodeId: node.id,
|
||||
@@ -587,11 +585,29 @@ async function loadReleasesView(
|
||||
};
|
||||
}
|
||||
|
||||
// Older nodes report a single release count without the delegate and
|
||||
// non-delegate buckets, so look for others in the first page of every author.
|
||||
// A full page means others may come later, and only the filter depends on
|
||||
// this, so a full page or a failed fetch keeps the filter. Remove this once
|
||||
// nodes without the buckets are no longer supported.
|
||||
async function legacyHasOthers(
|
||||
api: HttpdClient,
|
||||
repoId: string,
|
||||
repo: Repo,
|
||||
): Promise<boolean> {
|
||||
const everyAuthor = await api.repo
|
||||
.getAllReleases(repoId, releasesQuery("untrusted", 0))
|
||||
.catch(() => undefined);
|
||||
if (everyAuthor === undefined || everyAuthor.length === RELEASES_PER_PAGE) {
|
||||
return true;
|
||||
}
|
||||
return scopeReleases(everyAuthor, repo, "untrusted").length > 0;
|
||||
}
|
||||
|
||||
async function loadReleaseView(
|
||||
route: RepoReleaseRoute,
|
||||
): Promise<RepoLoadedRoute | NotFoundRoute> {
|
||||
const api = new HttpdClient(route.node);
|
||||
const allAuthors = route.allAuthors || false;
|
||||
|
||||
const [repo, releaseResult, node] = await Promise.all([
|
||||
api.repo.getByRid(route.repo),
|
||||
@@ -616,7 +632,7 @@ async function loadReleaseView(
|
||||
repoId: route.repo,
|
||||
repo,
|
||||
release: releaseResult.release,
|
||||
allAuthors,
|
||||
scope: route.scope,
|
||||
nodeId: node.id,
|
||||
nodeAvatarUrl: node.avatarUrl,
|
||||
},
|
||||
@@ -1153,23 +1169,25 @@ export function resolveRepoRoute(
|
||||
return resolvePatchesRoute(node, repo, segments, urlSearch);
|
||||
} else if (content === "releases") {
|
||||
const release = segments.shift();
|
||||
const allAuthors =
|
||||
new URLSearchParams(sanitizeQueryString(urlSearch)).get("allAuthors") ===
|
||||
"true";
|
||||
const scope =
|
||||
new URLSearchParams(sanitizeQueryString(urlSearch)).get("scope") ===
|
||||
"untrusted"
|
||||
? "untrusted"
|
||||
: undefined;
|
||||
if (release) {
|
||||
return {
|
||||
resource: "repo.release",
|
||||
node,
|
||||
repo,
|
||||
release,
|
||||
allAuthors,
|
||||
scope,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
resource: "repo.releases",
|
||||
node,
|
||||
repo,
|
||||
allAuthors,
|
||||
scope,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
@@ -1295,14 +1313,14 @@ export function repoRouteToPath(route: RepoRoute): string {
|
||||
return patchRouteToPath(route);
|
||||
} else if (route.resource === "repo.releases") {
|
||||
let url = [...pathSegments, "releases"].join("/");
|
||||
if (route.allAuthors) {
|
||||
url += "?allAuthors=true";
|
||||
if (route.scope === "untrusted") {
|
||||
url += "?scope=untrusted";
|
||||
}
|
||||
return url;
|
||||
} else if (route.resource === "repo.release") {
|
||||
let url = [...pathSegments, "releases", route.release].join("/");
|
||||
if (route.allAuthors) {
|
||||
url += "?allAuthors=true";
|
||||
if (route.scope === "untrusted") {
|
||||
url += "?scope=untrusted";
|
||||
}
|
||||
return url;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user