summaryrefslogtreecommitdiff
path: root/web/source/settings/lib
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-04-04 18:29:22 +0200
committerLibravatar GitHub <noreply@github.com>2025-04-04 18:29:22 +0200
commitb1844323314dd1f0832f1fcdb765a7f67ca01dbc (patch)
treee568a5941a6155e9ca55f3e4194b3256ad2fe352 /web/source/settings/lib
parent[chore] bump ncruces/go-sqlite3 to v0.25.0 (#3966) (diff)
downloadgotosocial-b1844323314dd1f0832f1fcdb765a7f67ca01dbc.tar.xz
[feature] Allow editing domain blocks/allows, fix comment import (#3967)
* start implementing editing of existing domain permissions * [feature] Allow editing domain blocks/allows, fix comment import * [bugfix] Use "comment" via /api/v1/instance * fix the stuff
Diffstat (limited to 'web/source/settings/lib')
-rw-r--r--web/source/settings/lib/query/admin/domain-permissions/import.ts38
-rw-r--r--web/source/settings/lib/query/admin/domain-permissions/update.ts43
-rw-r--r--web/source/settings/lib/types/domain-permission.ts8
3 files changed, 56 insertions, 33 deletions
diff --git a/web/source/settings/lib/query/admin/domain-permissions/import.ts b/web/source/settings/lib/query/admin/domain-permissions/import.ts
index cbcf44964..a83448a1f 100644
--- a/web/source/settings/lib/query/admin/domain-permissions/import.ts
+++ b/web/source/settings/lib/query/admin/domain-permissions/import.ts
@@ -40,39 +40,19 @@ function importEntriesProcessor(formData: ImportDomainPermsParams): (_entry: Dom
// Override each obfuscate entry if necessary.
if (formData.obfuscate !== undefined) {
- const obfuscateEntry = (entry: DomainPerm) => {
+ processingFuncs.push((entry: DomainPerm) => {
entry.obfuscate = formData.obfuscate;
- };
- processingFuncs.push(obfuscateEntry);
+ });
}
- // Check whether we need to append or replace
- // private_comment and public_comment.
+ // Check whether we need to replace
+ // private_comment and/or public_comment.
["private_comment","public_comment"].forEach((commentType) => {
- let text = formData.commentType?.trim();
- if (!text) {
- return;
- }
-
- switch(formData[`${commentType}_behavior`]) {
- case "append":
- const appendComment = (entry: DomainPerm) => {
- if (entry.commentType == undefined) {
- entry.commentType = text;
- } else {
- entry.commentType = [entry.commentType, text].join("\n");
- }
- };
-
- processingFuncs.push(appendComment);
- break;
- case "replace":
- const replaceComment = (entry: DomainPerm) => {
- entry.commentType = text;
- };
-
- processingFuncs.push(replaceComment);
- break;
+ if (formData[`replace_${commentType}`]) {
+ const text = formData[commentType]?.trim();
+ processingFuncs.push((entry: DomainPerm) => {
+ entry[commentType] = text;
+ });
}
});
diff --git a/web/source/settings/lib/query/admin/domain-permissions/update.ts b/web/source/settings/lib/query/admin/domain-permissions/update.ts
index a6b4b2039..396c30d6e 100644
--- a/web/source/settings/lib/query/admin/domain-permissions/update.ts
+++ b/web/source/settings/lib/query/admin/domain-permissions/update.ts
@@ -22,6 +22,7 @@ import { gtsApi } from "../../gts-api";
import {
replaceCacheOnMutation,
removeFromCacheOnMutation,
+ updateCacheOnMutation,
} from "../../query-modifiers";
import { listToKeyedObject } from "../../transforms";
import type {
@@ -55,6 +56,36 @@ const extended = gtsApi.injectEndpoints({
...replaceCacheOnMutation("domainAllows")
}),
+ updateDomainBlock: build.mutation<DomainPerm, any>({
+ query: ({ id, ...formData}) => ({
+ method: "PUT",
+ url: `/api/v1/admin/domain_blocks/${id}`,
+ asForm: true,
+ body: formData,
+ discardEmpty: false
+ }),
+ ...updateCacheOnMutation("domainBlocks", {
+ key: (_draft, newData) => {
+ return newData.domain;
+ }
+ })
+ }),
+
+ updateDomainAllow: build.mutation<DomainPerm, any>({
+ query: ({ id, ...formData}) => ({
+ method: "PUT",
+ url: `/api/v1/admin/domain_allows/${id}`,
+ asForm: true,
+ body: formData,
+ discardEmpty: false
+ }),
+ ...updateCacheOnMutation("domainAllows", {
+ key: (_draft, newData) => {
+ return newData.domain;
+ }
+ })
+ }),
+
removeDomainBlock: build.mutation<DomainPerm, string>({
query: (id) => ({
method: "DELETE",
@@ -92,6 +123,16 @@ const useAddDomainBlockMutation = extended.useAddDomainBlockMutation;
const useAddDomainAllowMutation = extended.useAddDomainAllowMutation;
/**
+ * Update a single domain permission (block) by PUTing to `/api/v1/admin/domain_blocks/{id}`.
+ */
+const useUpdateDomainBlockMutation = extended.useUpdateDomainBlockMutation;
+
+/**
+ * Update a single domain permission (allow) by PUTing to `/api/v1/admin/domain_allows/{id}`.
+ */
+const useUpdateDomainAllowMutation = extended.useUpdateDomainAllowMutation;
+
+/**
* Remove a single domain permission (block) by DELETEing to `/api/v1/admin/domain_blocks/{id}`.
*/
const useRemoveDomainBlockMutation = extended.useRemoveDomainBlockMutation;
@@ -104,6 +145,8 @@ const useRemoveDomainAllowMutation = extended.useRemoveDomainAllowMutation;
export {
useAddDomainBlockMutation,
useAddDomainAllowMutation,
+ useUpdateDomainBlockMutation,
+ useUpdateDomainAllowMutation,
useRemoveDomainBlockMutation,
useRemoveDomainAllowMutation
};
diff --git a/web/source/settings/lib/types/domain-permission.ts b/web/source/settings/lib/types/domain-permission.ts
index c4560d79b..27c4b56c9 100644
--- a/web/source/settings/lib/types/domain-permission.ts
+++ b/web/source/settings/lib/types/domain-permission.ts
@@ -46,8 +46,8 @@ export interface DomainPerm {
valid?: boolean;
checked?: boolean;
commentType?: string;
- private_comment_behavior?: "append" | "replace";
- public_comment_behavior?: "append" | "replace";
+ replace_private_comment?: boolean;
+ replace_public_comment?: boolean;
}
/**
@@ -65,8 +65,8 @@ const domainPermStripOnImport: Set<keyof DomainPerm> = new Set([
"valid",
"checked",
"commentType",
- "private_comment_behavior",
- "public_comment_behavior",
+ "replace_private_comment",
+ "replace_public_comment",
]);
/**