Skip to content

Commit

Permalink
Change node policy with repo policy
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Jul 1, 2024
1 parent b343ad4 commit 030f9fd
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 99 deletions.
7 changes: 5 additions & 2 deletions http-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
SuccessResponse,
CodeLocation,
Range,
SeedingPolicy,
DefaultSeedingPolicy,
} from "./lib/shared.js";
import type { Comment, Embed, Reaction } from "./lib/project/comment.js";
Expand Down Expand Up @@ -50,6 +51,7 @@ import { Fetcher } from "./lib/fetcher.js";
import {
nodeConfigSchema,
scopeSchema,
seedingPolicySchema,
successResponseSchema,
} from "./lib/shared.js";

Expand Down Expand Up @@ -85,6 +87,7 @@ export type {
Remote,
Review,
Revision,
SeedingPolicy,
TreeStats,
Tree,
Verdict,
Expand Down Expand Up @@ -211,14 +214,14 @@ export class HttpdClient {
public async getPoliciesById(
id: string,
options?: RequestOptions,
): Promise<NodePolicies["policy"][]> {
): Promise<SeedingPolicy> {
return this.#fetcher.fetchOk(
{
method: "GET",
path: `node/policies/repos/${id}`,
options,
},
array(nodePoliciesSchema.shape.policy),
seedingPolicySchema,
);
}

Expand Down
12 changes: 12 additions & 0 deletions http-client/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ export const successResponseSchema = object({

export const scopeSchema = union([literal("followed"), literal("all")]);

export const seedingPolicySchema = union([
object({
policy: literal("block"),
}),
object({
policy: literal("allow"),
scope: scopeSchema,
}),
]);

export type SeedingPolicy = z.infer<typeof seedingPolicySchema>;

const defaultSeedingPolicySchema = union([
object({
default: literal("block"),
Expand Down
20 changes: 11 additions & 9 deletions src/components/ScopePolicyExplainer.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script lang="ts">
import type { DefaultSeedingPolicy } from "@http-client";
import type { DefaultSeedingPolicy, SeedingPolicy } from "@http-client";
import { capitalize } from "lodash";
export let seedingPolicy: DefaultSeedingPolicy;
export let seedingPolicy: DefaultSeedingPolicy | SeedingPolicy;
$: [policy, scope] = Object.values(seedingPolicy);
</script>

<style>
Expand All @@ -15,28 +17,28 @@
}
</style>

{#if seedingPolicy.default === "allow"}
{#if policy === "allow"}
<div class="section">
Scope:
<span class="txt-bold">{capitalize(seedingPolicy.scope)}</span>
<span class="txt-bold">{capitalize(scope)}</span>
</div>
<div class="txt-missing">
{#if seedingPolicy.scope === "all"}
{#if scope === "all"}
All changes in seeded repositories, made by any peer, will be synced.
{:else if seedingPolicy.scope === "followed"}
{:else if scope === "followed"}
Only changes made by explicitly followed peers will be synced.
{/if}
</div>
{/if}

<div class="section">
Policy:
<span class="txt-bold">{capitalize(seedingPolicy.default)}</span>
<span class="txt-bold">{capitalize(policy)}</span>
</div>
<div class="txt-missing">
{#if seedingPolicy.default === "allow"}
{#if policy === "allow"}
All discovered repositories will get seeded.
{:else if seedingPolicy.default === "block"}
{:else if policy === "block"}
Only repositories marked as such will get seeded.
{/if}
</div>
13 changes: 8 additions & 5 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { BaseUrl, DefaultSeedingPolicy } from "@http-client";
import type {
BaseUrl,
DefaultSeedingPolicy,
SeedingPolicy,
} from "@http-client";

import md5 from "md5";
import bs58 from "bs58";
Expand All @@ -14,11 +18,10 @@ export function formatLocationHash(hash: string | null): number | null {
}

export function formatShortSeedingPolicy(
policy: DefaultSeedingPolicy | undefined,
seedingPolicy: DefaultSeedingPolicy | SeedingPolicy,
): "permissive" | "restrictive" {
return policy?.default === "allow" && policy?.scope === "all"
? "permissive"
: "restrictive";
const [policy, scope] = Object.values(seedingPolicy);
return policy === "allow" && scope === "all" ? "permissive" : "restrictive";
}

// Removes the first and last character which are always `/`.
Expand Down
4 changes: 3 additions & 1 deletion src/views/nodes/View.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
export let seedingPolicy: DefaultSeedingPolicy | undefined = undefined;
export let agent: string;
$: shortScope = formatShortSeedingPolicy(seedingPolicy);
$: shortScope = seedingPolicy
? formatShortSeedingPolicy(seedingPolicy)
: undefined;
$: hostname = isLocal(baseUrl.hostname) ? "Local Node" : baseUrl.hostname;
$: session =
$httpdStore.state === "authenticated" && isLocal(api.baseUrl.hostname)
Expand Down
6 changes: 3 additions & 3 deletions src/views/projects/Commit.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import type { BaseUrl, Commit, Node, Project } from "@http-client";
import type { BaseUrl, Commit, Project, SeedingPolicy } from "@http-client";
import Button from "@app/components/Button.svelte";
import Changeset from "@app/views/projects/Changeset.svelte";
Expand All @@ -12,7 +12,7 @@
import Id from "@app/components/Id.svelte";
export let baseUrl: BaseUrl;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let commit: Commit;
export let project: Project;
Expand Down Expand Up @@ -45,7 +45,7 @@
}
</style>

<Layout {node} {baseUrl} {project}>
<Layout {seedingPolicy} {baseUrl} {project}>
<div class="commit">
<div class="header">
<div style="display:flex; flex-direction: column; gap: 0.5rem;">
Expand Down
6 changes: 3 additions & 3 deletions src/views/projects/History.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
CommitHeader,
Project,
Remote,
Node,
Tree,
SeedingPolicy,
} from "@http-client";
import type { ProjectRoute } from "./router";
Expand All @@ -24,7 +24,7 @@
import ProjectNameHeader from "./Source/ProjectNameHeader.svelte";
export let baseUrl: BaseUrl;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let commit: string;
export let commitHeaders: CommitHeader[];
export let peer: string | undefined;
Expand Down Expand Up @@ -90,7 +90,7 @@
}
</style>

<Layout {node} {baseUrl} {project} activeTab="source">
<Layout {seedingPolicy} {baseUrl} {project} activeTab="source">
<ProjectNameHeader {project} {baseUrl} {seeding} slot="header" />

<div style:margin="1rem" slot="subheader">
Expand Down
11 changes: 8 additions & 3 deletions src/views/projects/Issue.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Issue,
IssueState,
Project,
Node,
SeedingPolicy,
} from "@http-client";
import type { Session } from "@app/lib/httpd";
Expand Down Expand Up @@ -49,7 +49,7 @@
import ThreadComponent from "@app/components/Thread.svelte";
export let baseUrl: BaseUrl;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let issue: Issue;
export let project: Project;
export let rawPath: (commit?: string) => string;
Expand Down Expand Up @@ -484,7 +484,12 @@
}
</style>

<Layout {node} {baseUrl} {project} activeTab="issues" stylePaddingBottom="0">
<Layout
{seedingPolicy}
{baseUrl}
{project}
activeTab="issues"
stylePaddingBottom="0">
<div class="issue">
<div class="main">
<CobHeader>
Expand Down
12 changes: 9 additions & 3 deletions src/views/projects/Issue/New.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts">
import type { BaseUrl, Embed, Node, Project, Reaction } from "@http-client";
import type {
BaseUrl,
Embed,
Project,
Reaction,
SeedingPolicy,
} from "@http-client";
import * as modal from "@app/lib/modal";
import * as router from "@app/lib/router";
Expand All @@ -17,7 +23,7 @@
import TextInput from "@app/components/TextInput.svelte";
export let baseUrl: BaseUrl;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let project: Project;
export let rawPath: (commit?: string) => string;
Expand Down Expand Up @@ -100,7 +106,7 @@
}
</style>

<Layout {node} {baseUrl} {project} activeTab="issues">
<Layout {seedingPolicy} {baseUrl} {project} activeTab="issues">
{#if session}
{@const session_ = session}
<div class="form">
Expand Down
12 changes: 9 additions & 3 deletions src/views/projects/Issues.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts">
import type { BaseUrl, Issue, IssueState, Node, Project } from "@http-client";
import type {
BaseUrl,
Issue,
IssueState,
Project,
SeedingPolicy,
} from "@http-client";
import capitalize from "lodash/capitalize";
import { HttpdClient } from "@http-client";
Expand All @@ -24,7 +30,7 @@
import Share from "./Share.svelte";
export let baseUrl: BaseUrl;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let issues: Issue[];
export let project: Project;
export let state: IssueState["status"];
Expand Down Expand Up @@ -106,7 +112,7 @@
}
</style>

<Layout {node} {baseUrl} {project} activeTab="issues">
<Layout {seedingPolicy} {baseUrl} {project} activeTab="issues">
<div slot="header" style:display="flex" style:padding="1rem">
<Popover
popoverPadding="0"
Expand Down
8 changes: 4 additions & 4 deletions src/views/projects/Layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import type { ActiveTab } from "./Header.svelte";
import type { BaseUrl, Node, Project } from "@http-client";
import type { BaseUrl, Project, SeedingPolicy } from "@http-client";
import AppHeader from "@app/App/Header.svelte";
Expand All @@ -11,7 +11,7 @@
import Sidebar from "@app/views/projects/Sidebar.svelte";
export let activeTab: ActiveTab | undefined = undefined;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let baseUrl: BaseUrl;
export let project: Project;
export let stylePaddingBottom: string = "2.5rem";
Expand Down Expand Up @@ -66,11 +66,11 @@
</div>

<div class="sidebar global-hide-on-medium-desktop-down">
<Sidebar {node} {activeTab} {baseUrl} {project} />
<Sidebar {seedingPolicy} {activeTab} {baseUrl} {project} />
</div>

<div class="sidebar global-hide-on-mobile-down global-hide-on-desktop-up">
<Sidebar {node} {activeTab} {baseUrl} {project} collapsedOnly />
<Sidebar {seedingPolicy} {activeTab} {baseUrl} {project} collapsedOnly />
</div>

<div class="content" style:padding-bottom={stylePaddingBottom}>
Expand Down
11 changes: 8 additions & 3 deletions src/views/projects/Patch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PatchState,
Revision,
Diff,
Node,
SeedingPolicy,
} from "@http-client";
interface Thread {
Expand Down Expand Up @@ -92,7 +92,7 @@
import TextInput from "@app/components/TextInput.svelte";
export let baseUrl: BaseUrl;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let patch: Patch;
export let stats: Diff["stats"];
export let rawPath: (commit?: string) => string;
Expand Down Expand Up @@ -708,7 +708,12 @@
}
</style>

<Layout {node} {baseUrl} {project} activeTab="patches" stylePaddingBottom="0">
<Layout
{seedingPolicy}
{baseUrl}
{project}
activeTab="patches"
stylePaddingBottom="0">
<div class="patch">
<div class="main">
<CobHeader>
Expand Down
12 changes: 9 additions & 3 deletions src/views/projects/Patches.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts">
import type { BaseUrl, Node, Patch, PatchState, Project } from "@http-client";
import type {
BaseUrl,
Patch,
PatchState,
Project,
SeedingPolicy,
} from "@http-client";
import { HttpdClient } from "@http-client";
import capitalize from "lodash/capitalize";
Expand All @@ -25,7 +31,7 @@
import Command from "@app/components/Command.svelte";
export let baseUrl: BaseUrl;
export let node: Node;
export let seedingPolicy: SeedingPolicy;
export let patches: Patch[];
export let project: Project;
export let state: PatchState["status"];
Expand Down Expand Up @@ -121,7 +127,7 @@
}
</style>

<Layout {node} {baseUrl} {project} activeTab="patches">
<Layout {seedingPolicy} {baseUrl} {project} activeTab="patches">
<div slot="header" style:display="flex" style:padding="1rem">
<Popover
popoverPadding="0"
Expand Down
Loading

0 comments on commit 030f9fd

Please sign in to comment.