From 637f188ebec71fe4b0b80bbab4592d4c269d7d93 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:46:06 +0200 Subject: [feature] Allow import/export/creation of domain allows via admin panel (#2264) * it's happening! * aaa * fix silly whoopsie * it's working pa! it's working ma! * model report parameters * shuffle some more stuff around * getting there * oo hoo * finish tidying up for now * aaa * fix use form submit errors * peepee poo poo * aaaaa * ffff * they see me typin', they hatin' * boop * aaa * oooo * typing typing tappa tappa * almost done typing * weee * alright * push it push it real good doo doo doo doo doo doo * thingy no worky * almost done * mutation modifers not quite right * hmm * it works * view blocks + allows nicely * it works! * typia install * the old linterino * linter plz --- .../settings/admin/domain-permissions/overview.tsx | 198 +++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 web/source/settings/admin/domain-permissions/overview.tsx (limited to 'web/source/settings/admin/domain-permissions/overview.tsx') diff --git a/web/source/settings/admin/domain-permissions/overview.tsx b/web/source/settings/admin/domain-permissions/overview.tsx new file mode 100644 index 000000000..a37ec9184 --- /dev/null +++ b/web/source/settings/admin/domain-permissions/overview.tsx @@ -0,0 +1,198 @@ +/* + GoToSocial + Copyright (C) GoToSocial Authors admin@gotosocial.org + SPDX-License-Identifier: AGPL-3.0-or-later + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import React from "react"; + +import { useMemo } from "react"; +import { Link, useLocation } from "wouter"; +import { matchSorter } from "match-sorter"; + +import { useTextInput } from "../../lib/form"; + +import { TextInput } from "../../components/form/inputs"; + +import Loading from "../../components/loading"; +import { useDomainAllowsQuery, useDomainBlocksQuery } from "../../lib/query/admin/domain-permissions/get"; +import type { MappedDomainPerms, PermType } from "../../lib/types/domain-permission"; +import { NoArg } from "../../lib/types/query"; + +export interface DomainPermissionsOverviewProps { + // Params injected by + // the wouter router. + permType: PermType; + baseUrl: string, +} + +export default function DomainPermissionsOverview({ permType, baseUrl }: DomainPermissionsOverviewProps) { + if (permType !== "block" && permType !== "allow") { + throw "unrecognized perm type " + permType; + } + + // Uppercase first letter of given permType. + const permTypeUpper = useMemo(() => { + return permType.charAt(0).toUpperCase() + permType.slice(1); + }, [permType]); + + // Fetch / wait for desired perms to load. + const { data: blocks, isLoading: isLoadingBlocks } = useDomainBlocksQuery(NoArg, { skip: permType !== "block" }); + const { data: allows, isLoading: isLoadingAllows } = useDomainAllowsQuery(NoArg, { skip: permType !== "allow" }); + + let data: MappedDomainPerms | undefined; + let isLoading: boolean; + + if (permType == "block") { + data = blocks; + isLoading = isLoadingBlocks; + } else { + data = allows; + isLoading = isLoadingAllows; + } + + if (isLoading || data === undefined) { + return ; + } + + return ( +
+

Domain {permTypeUpper}s

+ { permType == "block" ? : } + + + Or use the bulk import/export interface + +
+ ); +} + +interface DomainPermsListProps { + data: MappedDomainPerms; + baseUrl: string; + permType: PermType; + permTypeUpper: string; +} + +function DomainPermsList({ data, baseUrl, permType, permTypeUpper }: DomainPermsListProps) { + // Format perms into a list. + const perms = useMemo(() => { + return Object.values(data); + }, [data]); + + const [_location, setLocation] = useLocation(); + const filterField = useTextInput("filter"); + + function filterFormSubmit(e) { + e.preventDefault(); + setLocation(`${baseUrl}/${filter}`); + } + + const filter = filterField.value ?? ""; + const filteredPerms = useMemo(() => { + return matchSorter(perms, filter, { keys: ["domain"] }); + }, [perms, filter]); + const filtered = perms.length - filteredPerms.length; + + const filterInfo = ( + + {perms.length} {permType}ed domain{perms.length != 1 ? "s" : ""} {filtered > 0 && `(${filtered} filtered by search)`} + + ); + + const entries = filteredPerms.map((entry) => { + return ( + + + {entry.domain} + {new Date(entry.created_at ?? "").toLocaleString()} + + + ); + }); + + return ( +
+
+ + + {permTypeUpper} {filter} + + +
+ {filterInfo} +
+
+ {entries} +
+
+
+
+ ); +} + +function BlockHelperText() { + return ( +

+ Blocking a domain blocks interaction between your instance, and all current and future accounts on + instance(s) running on the blocked domain. Stored content will be removed, and no more data is sent to + the remote server. This extends to all subdomains as well, so blocking 'example.com' also blocks 'social.example.com'. +
+ + Learn more about domain blocks (opens in a new tab) + +
+

+ ); +} + +function AllowHelperText() { + return ( +

+ Allowing a domain explicitly allows instance(s) running on that domain to interact with your instance. + If you're running in allowlist mode, this is how you "allow" instances through. + If you're running in blocklist mode (the default federation mode), you can use explicit domain allows + to override domain blocks. In blocklist mode, explicitly allowed instances will be able to interact with + your instance regardless of any domain blocks in place. This extends to all subdomains as well, so allowing + 'example.com' also allows 'social.example.com'. This is useful when you're importing a block list but + there are some domains on the list you don't want to block: just create an explicit allow for those domains + before importing the list. +
+ + Learn more about federation modes (opens in a new tab) + +

+ ); +} -- cgit v1.2.3