From 301543616b5376585a7caff097499421acdf1806 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:09:58 +0100 Subject: [feature] Add domain permission drafts and excludes (#3547) * [feature] Add domain permission drafts and excludes * fix typescript complaining * lint * make filenames more consistent * test own domain excluded --- web/source/settings/components/error.tsx | 6 +- .../settings/components/username-lozenge.tsx | 179 +++++++++++++ web/source/settings/components/username.tsx | 90 ------- web/source/settings/lib/navigation/menu.tsx | 19 +- .../lib/query/admin/domain-permissions/drafts.ts | 173 ++++++++++++ .../lib/query/admin/domain-permissions/excludes.ts | 124 +++++++++ .../lib/query/admin/domain-permissions/get.ts | 6 + .../lib/query/admin/domain-permissions/import.ts | 4 +- web/source/settings/lib/query/gts-api.ts | 2 + web/source/settings/lib/types/domain-permission.ts | 141 +++++++++- web/source/settings/lib/util/formvalidators.ts | 48 ++++ web/source/settings/lib/util/index.ts | 13 + web/source/settings/style.css | 95 ++++++- .../views/admin/actions/keys/expireremote.tsx | 25 +- .../views/admin/http-header-permissions/detail.tsx | 70 ++--- .../admin/http-header-permissions/overview.tsx | 5 +- .../views/moderation/accounts/pending/index.tsx | 4 +- .../views/moderation/accounts/search/index.tsx | 29 +- .../views/moderation/domain-permissions/detail.tsx | 118 ++++----- .../domain-permissions/drafts/common.tsx | 43 +++ .../domain-permissions/drafts/detail.tsx | 210 +++++++++++++++ .../moderation/domain-permissions/drafts/index.tsx | 293 +++++++++++++++++++++ .../moderation/domain-permissions/drafts/new.tsx | 119 +++++++++ .../domain-permissions/excludes/common.tsx | 54 ++++ .../domain-permissions/excludes/detail.tsx | 119 +++++++++ .../domain-permissions/excludes/index.tsx | 235 +++++++++++++++++ .../moderation/domain-permissions/excludes/new.tsx | 90 +++++++ .../moderation/domain-permissions/overview.tsx | 5 +- web/source/settings/views/moderation/menu.tsx | 34 +++ .../settings/views/moderation/reports/detail.tsx | 8 +- .../settings/views/moderation/reports/search.tsx | 6 +- web/source/settings/views/moderation/router.tsx | 12 + 32 files changed, 2086 insertions(+), 293 deletions(-) create mode 100644 web/source/settings/components/username-lozenge.tsx delete mode 100644 web/source/settings/components/username.tsx create mode 100644 web/source/settings/lib/query/admin/domain-permissions/drafts.ts create mode 100644 web/source/settings/lib/query/admin/domain-permissions/excludes.ts create mode 100644 web/source/settings/lib/util/formvalidators.ts create mode 100644 web/source/settings/views/moderation/domain-permissions/drafts/common.tsx create mode 100644 web/source/settings/views/moderation/domain-permissions/drafts/detail.tsx create mode 100644 web/source/settings/views/moderation/domain-permissions/drafts/index.tsx create mode 100644 web/source/settings/views/moderation/domain-permissions/drafts/new.tsx create mode 100644 web/source/settings/views/moderation/domain-permissions/excludes/common.tsx create mode 100644 web/source/settings/views/moderation/domain-permissions/excludes/detail.tsx create mode 100644 web/source/settings/views/moderation/domain-permissions/excludes/index.tsx create mode 100644 web/source/settings/views/moderation/domain-permissions/excludes/new.tsx (limited to 'web/source') diff --git a/web/source/settings/components/error.tsx b/web/source/settings/components/error.tsx index 977cf06c8..3ca5eb416 100644 --- a/web/source/settings/components/error.tsx +++ b/web/source/settings/components/error.tsx @@ -107,7 +107,11 @@ function Error({ error, reset }: ErrorProps) { { reset && { + e.preventDefault(); + e.stopPropagation(); + reset(); + }} role="button" tabIndex={0} > diff --git a/web/source/settings/components/username-lozenge.tsx b/web/source/settings/components/username-lozenge.tsx new file mode 100644 index 000000000..9f955cf22 --- /dev/null +++ b/web/source/settings/components/username-lozenge.tsx @@ -0,0 +1,179 @@ +/* + 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, { useEffect } from "react"; +import { useLocation } from "wouter"; +import { AdminAccount } from "../lib/types/account"; +import { useLazyGetAccountQuery } from "../lib/query/admin"; +import Loading from "./loading"; +import { Error as ErrorC } from "./error"; + +interface UsernameLozengeProps { + /** + * Either an account ID (for fetching) or an account. + */ + account?: string | AdminAccount; + /** + * Make the lozenge clickable and link to this location. + */ + linkTo?: string; + /** + * Location to set as backLocation after linking to linkTo. + */ + backLocation?: string; + /** + * Additional classnames to add to the lozenge. + */ + classNames?: string[]; +} + +export default function UsernameLozenge({ account, linkTo, backLocation, classNames }: UsernameLozengeProps) { + if (account === undefined) { + return <>[unknown]; + } else if (typeof account === "string") { + return ( + + ); + } else { + return ( + + ); + } + +} + +interface FetchUsernameLozengeProps { + accountID: string; + linkTo?: string; + backLocation?: string; + classNames?: string[]; +} + +function FetchUsernameLozenge({ accountID, linkTo, backLocation, classNames }: FetchUsernameLozengeProps) { + const [ trigger, result ] = useLazyGetAccountQuery(); + + // Call to get the account + // using the provided ID. + useEffect(() => { + trigger(accountID, true); + }, [trigger, accountID]); + + const { + data: account, + isLoading, + isFetching, + isError, + error, + } = result; + + // Wait for the account + // model to be returned. + if (isError) { + return ; + } else if (isLoading || isFetching || account === undefined) { + return ; + } + + return ( + + ); +} + +interface ReadyUsernameLozengeProps { + account: AdminAccount; + linkTo?: string; + backLocation?: string; + classNames?: string[]; +} + +function ReadyUsernameLozenge({ account, linkTo, backLocation, classNames }: ReadyUsernameLozengeProps) { + const [ _location, setLocation ] = useLocation(); + + let className = "username-lozenge"; + let isLocal = account.domain == null; + + if (account.suspended) { + className += " suspended"; + } + + if (isLocal) { + className += " local"; + } + + if (classNames) { + className = [ className, classNames ].flat().join(" "); + } + + let icon = isLocal + ? { fa: "fa-home", info: "Local user" } + : { fa: "fa-external-link-square", info: "Remote user" }; + + const content = ( + <> +