From 6171dcbe5109d7accbf44f19c20c9f4a0ee5e06f Mon Sep 17 00:00:00 2001
From: tobi <31960611+tsmethurst@users.noreply.github.com>
Date: Sun, 5 May 2024 13:47:22 +0200
Subject: [feature] Add HTTP header permission section to frontend (#2893)
* [feature] Add HTTP header filter section to frontend
* tweak naming a bit
---
.../query/admin/http-header-permissions/index.ts | 159 +++++++++++++++++++++
1 file changed, 159 insertions(+)
create mode 100644 web/source/settings/lib/query/admin/http-header-permissions/index.ts
(limited to 'web/source/settings/lib/query/admin/http-header-permissions/index.ts')
diff --git a/web/source/settings/lib/query/admin/http-header-permissions/index.ts b/web/source/settings/lib/query/admin/http-header-permissions/index.ts
new file mode 100644
index 000000000..342b9eb56
--- /dev/null
+++ b/web/source/settings/lib/query/admin/http-header-permissions/index.ts
@@ -0,0 +1,159 @@
+/*
+ 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 { gtsApi } from "../../gts-api";
+import { HeaderPermission } from "../../../types/http-header-permissions";
+
+const extended = gtsApi.injectEndpoints({
+ endpoints: (build) => ({
+
+ /* HTTP HEADER ALLOWS */
+
+ getHeaderAllows: build.query({
+ query: () => ({
+ url: `/api/v1/admin/header_allows`
+ }),
+ providesTags: (res) =>
+ res
+ ? [
+ ...res.map(({ id }) => ({ type: "HTTPHeaderAllows" as const, id })),
+ { type: "HTTPHeaderAllows", id: "LIST" },
+ ]
+ : [{ type: "HTTPHeaderAllows", id: "LIST" }],
+ }),
+
+ getHeaderAllow: build.query({
+ query: (id) => ({
+ url: `/api/v1/admin/header_allows/${id}`
+ }),
+ providesTags: (_res, _error, id) => [{ type: "HTTPHeaderAllows", id }],
+ }),
+
+ postHeaderAllow: build.mutation({
+ query: (formData) => ({
+ method: "POST",
+ url: `/api/v1/admin/header_allows`,
+ asForm: true,
+ body: formData,
+ discardEmpty: true
+ }),
+ invalidatesTags: [{ type: "HTTPHeaderAllows", id: "LIST" }],
+ }),
+
+ deleteHeaderAllow: build.mutation({
+ query: (id) => ({
+ method: "DELETE",
+ url: `/api/v1/admin/header_allows/${id}`
+ }),
+ invalidatesTags: (_res, _error, id) => [{ type: "HTTPHeaderAllows", id }],
+ }),
+
+ /* HTTP HEADER BLOCKS */
+
+ getHeaderBlocks: build.query({
+ query: () => ({
+ url: `/api/v1/admin/header_blocks`
+ }),
+ providesTags: (res) =>
+ res
+ ? [
+ ...res.map(({ id }) => ({ type: "HTTPHeaderBlocks" as const, id })),
+ { type: "HTTPHeaderBlocks", id: "LIST" },
+ ]
+ : [{ type: "HTTPHeaderBlocks", id: "LIST" }],
+ }),
+
+ postHeaderBlock: build.mutation({
+ query: (formData) => ({
+ method: "POST",
+ url: `/api/v1/admin/header_blocks`,
+ asForm: true,
+ body: formData,
+ discardEmpty: true
+ }),
+ invalidatesTags: [{ type: "HTTPHeaderBlocks", id: "LIST" }],
+ }),
+
+ getHeaderBlock: build.query({
+ query: (id) => ({
+ url: `/api/v1/admin/header_blocks/${id}`
+ }),
+ providesTags: (_res, _error, id) => [{ type: "HTTPHeaderBlocks", id }],
+ }),
+
+ deleteHeaderBlock: build.mutation({
+ query: (id) => ({
+ method: "DELETE",
+ url: `/api/v1/admin/header_blocks/${id}`
+ }),
+ invalidatesTags: (_res, _error, id) => [{ type: "HTTPHeaderBlocks", id }],
+ }),
+ }),
+});
+
+/**
+ * Get admin view of all HTTP header allow regexes.
+ */
+const useGetHeaderAllowsQuery = extended.useGetHeaderAllowsQuery;
+
+/**
+ * Get admin view of one HTTP header allow regex.
+ */
+const useGetHeaderAllowQuery = extended.useGetHeaderAllowQuery;
+
+/**
+ * Create a new HTTP header allow regex.
+ */
+const usePostHeaderAllowMutation = extended.usePostHeaderAllowMutation;
+
+/**
+ * Delete one HTTP header allow regex.
+ */
+const useDeleteHeaderAllowMutation = extended.useDeleteHeaderAllowMutation;
+
+/**
+ * Get admin view of all HTTP header block regexes.
+ */
+const useGetHeaderBlocksQuery = extended.useGetHeaderBlocksQuery;
+
+/**
+ * Get admin view of one HTTP header block regex.
+ */
+const useGetHeaderBlockQuery = extended.useGetHeaderBlockQuery;
+
+/**
+ * Create a new HTTP header block regex.
+ */
+const usePostHeaderBlockMutation = extended.usePostHeaderBlockMutation;
+
+/**
+ * Delete one HTTP header block regex.
+ */
+const useDeleteHeaderBlockMutation = extended.useDeleteHeaderBlockMutation;
+
+export {
+ useGetHeaderAllowsQuery,
+ useGetHeaderAllowQuery,
+ usePostHeaderAllowMutation,
+ useDeleteHeaderAllowMutation,
+ useGetHeaderBlocksQuery,
+ useGetHeaderBlockQuery,
+ usePostHeaderBlockMutation,
+ useDeleteHeaderBlockMutation,
+};
--
cgit v1.2.3