mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-06 19:08:07 -06:00
[feature] Allow editing domain blocks/allows, fix comment import
This commit is contained in:
parent
7d253550b3
commit
e856d09f8e
13 changed files with 320 additions and 181 deletions
|
|
@ -5823,6 +5823,53 @@ paths:
|
||||||
summary: View domain allow with the given ID.
|
summary: View domain allow with the given ID.
|
||||||
tags:
|
tags:
|
||||||
- admin
|
- admin
|
||||||
|
put:
|
||||||
|
consumes:
|
||||||
|
- multipart/form-data
|
||||||
|
operationId: domainAllowUpdate
|
||||||
|
parameters:
|
||||||
|
- description: The id of the domain allow.
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Obfuscate the name of the domain when serving it publicly. Eg., `example.org` becomes something like `ex***e.org`.
|
||||||
|
in: formData
|
||||||
|
name: obfuscate
|
||||||
|
type: boolean
|
||||||
|
- description: Public comment about this domain allow. This will be displayed alongside the domain allow if you choose to share allows.
|
||||||
|
in: formData
|
||||||
|
name: public_comment
|
||||||
|
type: string
|
||||||
|
- description: Private comment about this domain allow. Will only be shown to other admins, so this is a useful way of internally keeping track of why a certain domain ended up allowed.
|
||||||
|
in: formData
|
||||||
|
name: private_comment
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: The updated domain allow.
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domainPermission'
|
||||||
|
"400":
|
||||||
|
description: bad request
|
||||||
|
"401":
|
||||||
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden
|
||||||
|
"404":
|
||||||
|
description: not found
|
||||||
|
"406":
|
||||||
|
description: not acceptable
|
||||||
|
"500":
|
||||||
|
description: internal server error
|
||||||
|
security:
|
||||||
|
- OAuth2 Bearer:
|
||||||
|
- admin:write:domain_allows
|
||||||
|
summary: Update a single domain allow.
|
||||||
|
tags:
|
||||||
|
- admin
|
||||||
/api/v1/admin/domain_blocks:
|
/api/v1/admin/domain_blocks:
|
||||||
get:
|
get:
|
||||||
operationId: domainBlocksGet
|
operationId: domainBlocksGet
|
||||||
|
|
@ -5990,6 +6037,53 @@ paths:
|
||||||
summary: View domain block with the given ID.
|
summary: View domain block with the given ID.
|
||||||
tags:
|
tags:
|
||||||
- admin
|
- admin
|
||||||
|
put:
|
||||||
|
consumes:
|
||||||
|
- multipart/form-data
|
||||||
|
operationId: domainBlockUpdate
|
||||||
|
parameters:
|
||||||
|
- description: The id of the domain block.
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Obfuscate the name of the domain when serving it publicly. Eg., `example.org` becomes something like `ex***e.org`.
|
||||||
|
in: formData
|
||||||
|
name: obfuscate
|
||||||
|
type: boolean
|
||||||
|
- description: Public comment about this domain block. This will be displayed alongside the domain block if you choose to share blocks.
|
||||||
|
in: formData
|
||||||
|
name: public_comment
|
||||||
|
type: string
|
||||||
|
- description: Private comment about this domain block. Will only be shown to other admins, so this is a useful way of internally keeping track of why a certain domain ended up blocked.
|
||||||
|
in: formData
|
||||||
|
name: private_comment
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: The updated domain block.
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domainPermission'
|
||||||
|
"400":
|
||||||
|
description: bad request
|
||||||
|
"401":
|
||||||
|
description: unauthorized
|
||||||
|
"403":
|
||||||
|
description: forbidden
|
||||||
|
"404":
|
||||||
|
description: not found
|
||||||
|
"406":
|
||||||
|
description: not acceptable
|
||||||
|
"500":
|
||||||
|
description: internal server error
|
||||||
|
security:
|
||||||
|
- OAuth2 Bearer:
|
||||||
|
- admin:write:domain_blocks
|
||||||
|
summary: Update a single domain block.
|
||||||
|
tags:
|
||||||
|
- admin
|
||||||
/api/v1/admin/domain_keys_expire:
|
/api/v1/admin/domain_keys_expire:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ type Domain struct {
|
||||||
SilencedAt string `json:"silenced_at,omitempty"`
|
SilencedAt string `json:"silenced_at,omitempty"`
|
||||||
// If the domain is blocked, what's the publicly-stated reason for the block.
|
// If the domain is blocked, what's the publicly-stated reason for the block.
|
||||||
// example: they smell
|
// example: they smell
|
||||||
PublicComment string `form:"public_comment" json:"public_comment,omitempty"`
|
PublicComment *string `form:"public_comment" json:"public_comment,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DomainPermission represents a permission applied to one domain (explicit block/allow).
|
// DomainPermission represents a permission applied to one domain (explicit block/allow).
|
||||||
|
|
@ -48,10 +48,10 @@ type DomainPermission struct {
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
// Obfuscate the domain name when serving this domain permission entry publicly.
|
// Obfuscate the domain name when serving this domain permission entry publicly.
|
||||||
// example: false
|
// example: false
|
||||||
Obfuscate bool `json:"obfuscate,omitempty"`
|
Obfuscate *bool `json:"obfuscate,omitempty"`
|
||||||
// Private comment for this permission entry, visible to this instance's admins only.
|
// Private comment for this permission entry, visible to this instance's admins only.
|
||||||
// example: they are poopoo
|
// example: they are poopoo
|
||||||
PrivateComment string `json:"private_comment,omitempty"`
|
PrivateComment *string `json:"private_comment,omitempty"`
|
||||||
// If applicable, the ID of the subscription that caused this domain permission entry to be created.
|
// If applicable, the ID of the subscription that caused this domain permission entry to be created.
|
||||||
// example: 01FBW25TF5J67JW3HFHZCSD23K
|
// example: 01FBW25TF5J67JW3HFHZCSD23K
|
||||||
SubscriptionID string `json:"subscription_id,omitempty"`
|
SubscriptionID string `json:"subscription_id,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DomainPermissionCreate creates an instance-level permission
|
// DomainPermissionCreate creates an instance-level permission
|
||||||
|
|
@ -197,14 +198,14 @@ func (p *Processor) DomainPermissionsImport(
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
// Parse file as slice of domain blocks.
|
// Parse file as slice of domain permissions.
|
||||||
domainPerms := make([]*apimodel.DomainPermission, 0)
|
apiDomainPerms := make([]*apimodel.DomainPermission, 0)
|
||||||
if err := json.NewDecoder(file).Decode(&domainPerms); err != nil {
|
if err := json.NewDecoder(file).Decode(&apiDomainPerms); err != nil {
|
||||||
err = gtserror.Newf("error parsing attachment as domain permissions: %w", err)
|
err = gtserror.Newf("error parsing attachment as domain permissions: %w", err)
|
||||||
return nil, gtserror.NewErrorBadRequest(err, err.Error())
|
return nil, gtserror.NewErrorBadRequest(err, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
count := len(domainPerms)
|
count := len(apiDomainPerms)
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
err = gtserror.New("error importing domain permissions: 0 entries provided")
|
err = gtserror.New("error importing domain permissions: 0 entries provided")
|
||||||
return nil, gtserror.NewErrorBadRequest(err, err.Error())
|
return nil, gtserror.NewErrorBadRequest(err, err.Error())
|
||||||
|
|
@ -214,52 +215,97 @@ func (p *Processor) DomainPermissionsImport(
|
||||||
// between successes and errors so that the caller can
|
// between successes and errors so that the caller can
|
||||||
// try failed imports again if desired.
|
// try failed imports again if desired.
|
||||||
multiStatusEntries := make([]apimodel.MultiStatusEntry, 0, count)
|
multiStatusEntries := make([]apimodel.MultiStatusEntry, 0, count)
|
||||||
|
for _, apiDomainPerm := range apiDomainPerms {
|
||||||
for _, domainPerm := range domainPerms {
|
multiStatusEntries = append(
|
||||||
var (
|
multiStatusEntries,
|
||||||
domain = domainPerm.Domain.Domain
|
p.importOrUpdateDomainPerm(
|
||||||
obfuscate = domainPerm.Obfuscate
|
ctx,
|
||||||
publicComment = domainPerm.PublicComment
|
permissionType,
|
||||||
privateComment = domainPerm.PrivateComment
|
account,
|
||||||
subscriptionID = "" // No sub ID for imports.
|
apiDomainPerm,
|
||||||
errWithCode gtserror.WithCode
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
domainPerm, _, errWithCode = p.DomainPermissionCreate(
|
|
||||||
ctx,
|
|
||||||
permissionType,
|
|
||||||
account,
|
|
||||||
domain,
|
|
||||||
obfuscate,
|
|
||||||
publicComment,
|
|
||||||
privateComment,
|
|
||||||
subscriptionID,
|
|
||||||
)
|
|
||||||
|
|
||||||
var entry *apimodel.MultiStatusEntry
|
|
||||||
|
|
||||||
if errWithCode != nil {
|
|
||||||
entry = &apimodel.MultiStatusEntry{
|
|
||||||
// Use the failed domain entry as the resource value.
|
|
||||||
Resource: domain,
|
|
||||||
Message: errWithCode.Safe(),
|
|
||||||
Status: errWithCode.Code(),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
entry = &apimodel.MultiStatusEntry{
|
|
||||||
// Use successfully created API model domain block as the resource value.
|
|
||||||
Resource: domainPerm,
|
|
||||||
Message: http.StatusText(http.StatusOK),
|
|
||||||
Status: http.StatusOK,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
multiStatusEntries = append(multiStatusEntries, *entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return apimodel.NewMultiStatus(multiStatusEntries), nil
|
return apimodel.NewMultiStatus(multiStatusEntries), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Processor) importOrUpdateDomainPerm(
|
||||||
|
ctx context.Context,
|
||||||
|
permType gtsmodel.DomainPermissionType,
|
||||||
|
account *gtsmodel.Account,
|
||||||
|
apiDomainPerm *apimodel.DomainPermission,
|
||||||
|
) apimodel.MultiStatusEntry {
|
||||||
|
var (
|
||||||
|
domain = apiDomainPerm.Domain.Domain
|
||||||
|
obfuscate = apiDomainPerm.Obfuscate
|
||||||
|
publicComment = apiDomainPerm.PublicComment
|
||||||
|
privateComment = apiDomainPerm.PrivateComment
|
||||||
|
subscriptionID = "" // No sub ID for imports.
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check if this domain
|
||||||
|
// perm already exists.
|
||||||
|
var (
|
||||||
|
domainPerm gtsmodel.DomainPermission
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if permType == gtsmodel.DomainPermissionBlock {
|
||||||
|
domainPerm, err = p.state.DB.GetDomainBlock(ctx, domain)
|
||||||
|
} else {
|
||||||
|
domainPerm, err = p.state.DB.GetDomainAllow(ctx, domain)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||||
|
// Real db error.
|
||||||
|
return apimodel.MultiStatusEntry{
|
||||||
|
Resource: domain,
|
||||||
|
Message: "db error checking for existence of domain permission",
|
||||||
|
Status: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var errWithCode gtserror.WithCode
|
||||||
|
if domainPerm != nil {
|
||||||
|
// Permission already exists, update it.
|
||||||
|
apiDomainPerm, errWithCode = p.DomainPermissionUpdate(
|
||||||
|
ctx,
|
||||||
|
permType,
|
||||||
|
domainPerm.GetID(),
|
||||||
|
obfuscate,
|
||||||
|
publicComment,
|
||||||
|
privateComment,
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// Permission didn't exist yet, create it.
|
||||||
|
apiDomainPerm, _, errWithCode = p.DomainPermissionCreate(
|
||||||
|
ctx,
|
||||||
|
permType,
|
||||||
|
account,
|
||||||
|
domain,
|
||||||
|
util.PtrOrZero(obfuscate),
|
||||||
|
util.PtrOrZero(publicComment),
|
||||||
|
util.PtrOrZero(privateComment),
|
||||||
|
subscriptionID,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if errWithCode != nil {
|
||||||
|
return apimodel.MultiStatusEntry{
|
||||||
|
Resource: domain,
|
||||||
|
Message: errWithCode.Safe(),
|
||||||
|
Status: errWithCode.Code(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return apimodel.MultiStatusEntry{
|
||||||
|
Resource: apiDomainPerm,
|
||||||
|
Message: http.StatusText(http.StatusOK),
|
||||||
|
Status: http.StatusOK,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DomainPermissionsGet returns all existing domain
|
// DomainPermissionsGet returns all existing domain
|
||||||
// permissions of the requested type. If export is
|
// permissions of the requested type. If export is
|
||||||
// true, the format will be suitable for writing out
|
// true, the format will be suitable for writing out
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ func (p *Processor) InstancePeersGet(ctx context.Context, includeSuspended bool,
|
||||||
domains = append(domains, &apimodel.Domain{
|
domains = append(domains, &apimodel.Domain{
|
||||||
Domain: d,
|
Domain: d,
|
||||||
SuspendedAt: util.FormatISO8601(domainBlock.CreatedAt),
|
SuspendedAt: util.FormatISO8601(domainBlock.CreatedAt),
|
||||||
PublicComment: domainBlock.PublicComment,
|
PublicComment: &domainBlock.PublicComment,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -742,8 +742,8 @@ func permsFromJSON(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set remaining fields.
|
// Set remaining fields.
|
||||||
perm.SetPublicComment(apiPerm.PublicComment)
|
perm.SetPublicComment(util.PtrOrZero(apiPerm.PublicComment))
|
||||||
perm.SetObfuscate(&apiPerm.Obfuscate)
|
perm.SetObfuscate(util.Ptr(util.PtrOrZero(apiPerm.Obfuscate)))
|
||||||
|
|
||||||
// We're done.
|
// We're done.
|
||||||
perms = append(perms, perm)
|
perms = append(perms, perm)
|
||||||
|
|
|
||||||
|
|
@ -2182,7 +2182,7 @@ func (c *Converter) DomainPermToAPIDomainPerm(
|
||||||
domainPerm := &apimodel.DomainPermission{
|
domainPerm := &apimodel.DomainPermission{
|
||||||
Domain: apimodel.Domain{
|
Domain: apimodel.Domain{
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
PublicComment: d.GetPublicComment(),
|
PublicComment: util.Ptr(d.GetPublicComment()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2193,8 +2193,8 @@ func (c *Converter) DomainPermToAPIDomainPerm(
|
||||||
}
|
}
|
||||||
|
|
||||||
domainPerm.ID = d.GetID()
|
domainPerm.ID = d.GetID()
|
||||||
domainPerm.Obfuscate = util.PtrOrZero(d.GetObfuscate())
|
domainPerm.Obfuscate = d.GetObfuscate()
|
||||||
domainPerm.PrivateComment = d.GetPrivateComment()
|
domainPerm.PrivateComment = util.Ptr(d.GetPrivateComment())
|
||||||
domainPerm.SubscriptionID = d.GetSubscriptionID()
|
domainPerm.SubscriptionID = d.GetSubscriptionID()
|
||||||
domainPerm.CreatedBy = d.GetCreatedByAccountID()
|
domainPerm.CreatedBy = d.GetCreatedByAccountID()
|
||||||
if createdAt := d.GetCreatedAt(); !createdAt.IsZero() {
|
if createdAt := d.GetCreatedAt(); !createdAt.IsZero() {
|
||||||
|
|
|
||||||
|
|
@ -40,39 +40,19 @@ function importEntriesProcessor(formData: ImportDomainPermsParams): (_entry: Dom
|
||||||
|
|
||||||
// Override each obfuscate entry if necessary.
|
// Override each obfuscate entry if necessary.
|
||||||
if (formData.obfuscate !== undefined) {
|
if (formData.obfuscate !== undefined) {
|
||||||
const obfuscateEntry = (entry: DomainPerm) => {
|
processingFuncs.push((entry: DomainPerm) => {
|
||||||
entry.obfuscate = formData.obfuscate;
|
entry.obfuscate = formData.obfuscate;
|
||||||
};
|
});
|
||||||
processingFuncs.push(obfuscateEntry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether we need to append or replace
|
// Check whether we need to replace
|
||||||
// private_comment and public_comment.
|
// private_comment and/or public_comment.
|
||||||
["private_comment","public_comment"].forEach((commentType) => {
|
["private_comment","public_comment"].forEach((commentType) => {
|
||||||
let text = formData.commentType?.trim();
|
if (formData[`replace_${commentType}`]) {
|
||||||
if (!text) {
|
const text = formData[commentType]?.trim();
|
||||||
return;
|
processingFuncs.push((entry: DomainPerm) => {
|
||||||
}
|
entry[commentType] = text;
|
||||||
|
});
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,9 @@ const extended = gtsApi.injectEndpoints({
|
||||||
}),
|
}),
|
||||||
|
|
||||||
updateDomainBlock: build.mutation<DomainPerm, any>({
|
updateDomainBlock: build.mutation<DomainPerm, any>({
|
||||||
query: (formData) => ({
|
query: ({ id, ...formData}) => ({
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
url: `/api/v1/admin/domain_blocks/${formData.id}`,
|
url: `/api/v1/admin/domain_blocks/${id}`,
|
||||||
asForm: true,
|
asForm: true,
|
||||||
body: formData,
|
body: formData,
|
||||||
discardEmpty: false
|
discardEmpty: false
|
||||||
|
|
@ -72,9 +72,9 @@ const extended = gtsApi.injectEndpoints({
|
||||||
}),
|
}),
|
||||||
|
|
||||||
updateDomainAllow: build.mutation<DomainPerm, any>({
|
updateDomainAllow: build.mutation<DomainPerm, any>({
|
||||||
query: (formData) => ({
|
query: ({ id, ...formData}) => ({
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
url: `/api/v1/admin/domain_allows/${formData.id}`,
|
url: `/api/v1/admin/domain_allows/${id}`,
|
||||||
asForm: true,
|
asForm: true,
|
||||||
body: formData,
|
body: formData,
|
||||||
discardEmpty: false
|
discardEmpty: false
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ export interface DomainPerm {
|
||||||
valid?: boolean;
|
valid?: boolean;
|
||||||
checked?: boolean;
|
checked?: boolean;
|
||||||
commentType?: string;
|
commentType?: string;
|
||||||
private_comment_behavior?: "append" | "replace";
|
replace_private_comment?: boolean;
|
||||||
public_comment_behavior?: "append" | "replace";
|
replace_public_comment?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -65,8 +65,8 @@ const domainPermStripOnImport: Set<keyof DomainPerm> = new Set([
|
||||||
"valid",
|
"valid",
|
||||||
"checked",
|
"checked",
|
||||||
"commentType",
|
"commentType",
|
||||||
"private_comment_behavior",
|
"replace_private_comment",
|
||||||
"public_comment_behavior",
|
"replace_public_comment",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -618,6 +618,15 @@ span.form-info {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
section > div.domain-block,
|
||||||
|
section > div.domain-allow {
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
> a {
|
||||||
|
margin-top: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.domain-permissions-list {
|
.domain-permissions-list {
|
||||||
p {
|
p {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
|
@ -976,32 +985,26 @@ button.tab-button {
|
||||||
|
|
||||||
.domain-perm-import-list {
|
.domain-perm-import-list {
|
||||||
.checkbox-list-wrapper {
|
.checkbox-list-wrapper {
|
||||||
overflow-x: auto;
|
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.checkbox-list {
|
.checkbox-list {
|
||||||
|
overflow-x: auto;
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
|
align-items: center;
|
||||||
input[type="checkbox"] {
|
input[type="checkbox"] {
|
||||||
align-self: start;
|
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.entry {
|
.entry {
|
||||||
gap: 0;
|
grid-template-columns: auto max(50%, 14rem) 1fr;
|
||||||
width: 100%;
|
column-gap: 1rem;
|
||||||
grid-template-columns: auto minmax(25ch, 2fr) minmax(40ch, 1fr);
|
align-items: center;
|
||||||
grid-template-rows: auto 1fr;
|
|
||||||
|
|
||||||
input[type="checkbox"] {
|
|
||||||
margin-right: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.domain-input {
|
.domain-input {
|
||||||
margin-right: 0.5rem;
|
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr $fa-fw;
|
grid-template-columns: 1fr $fa-fw;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
|
@ -1020,13 +1023,21 @@ button.tab-button {
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
align-self: center;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
grid-column: 4;
|
|
||||||
grid-row: 1 / span 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.set-comment-checkbox {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.25rem;
|
||||||
|
|
||||||
|
padding: 0.5rem 1rem 1rem 1rem;
|
||||||
|
width: 100%;
|
||||||
|
border: 0.1rem solid var(--gray1);
|
||||||
|
border-radius: 0.1rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.import-export {
|
.import-export {
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ import { PermType } from "../../../lib/types/perm";
|
||||||
import { useCapitalize } from "../../../lib/util";
|
import { useCapitalize } from "../../../lib/util";
|
||||||
import { formDomainValidator } from "../../../lib/util/formvalidators";
|
import { formDomainValidator } from "../../../lib/util/formvalidators";
|
||||||
import UsernameLozenge from "../../../components/username-lozenge";
|
import UsernameLozenge from "../../../components/username-lozenge";
|
||||||
|
import { FormSubmitEvent } from "../../../lib/form/types";
|
||||||
|
|
||||||
export default function DomainPermView() {
|
export default function DomainPermView() {
|
||||||
const baseUrl = useBaseUrl();
|
const baseUrl = useBaseUrl();
|
||||||
|
|
@ -161,7 +162,7 @@ function DomainPermDetails({
|
||||||
<UsernameLozenge
|
<UsernameLozenge
|
||||||
account={perm.created_by}
|
account={perm.created_by}
|
||||||
linkTo={`~/settings/moderation/accounts/${perm.created_by}`}
|
linkTo={`~/settings/moderation/accounts/${perm.created_by}`}
|
||||||
backLocation={`~${baseUrl}/${location}`}
|
backLocation={`~${baseUrl}${location}`}
|
||||||
/>
|
/>
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -207,8 +208,8 @@ function CreateOrUpdateDomainPerm({
|
||||||
validator: formDomainValidator,
|
validator: formDomainValidator,
|
||||||
}),
|
}),
|
||||||
obfuscate: useBoolInput("obfuscate", { source: perm }),
|
obfuscate: useBoolInput("obfuscate", { source: perm }),
|
||||||
commentPrivate: useTextInput("private_comment", { source: perm }),
|
privateComment: useTextInput("private_comment", { source: perm }),
|
||||||
commentPublic: useTextInput("public_comment", { source: perm })
|
publicComment: useTextInput("public_comment", { source: perm })
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check which perm type we're meant to be handling
|
// Check which perm type we're meant to be handling
|
||||||
|
|
@ -248,12 +249,23 @@ function CreateOrUpdateDomainPerm({
|
||||||
// permType, and whether we're creating or updating.
|
// permType, and whether we're creating or updating.
|
||||||
const [submit, submitResult] = useFormSubmit(
|
const [submit, submitResult] = useFormSubmit(
|
||||||
form,
|
form,
|
||||||
[
|
[ createOrUpdateTrigger, createOrUpdateResult ],
|
||||||
createOrUpdateTrigger,
|
|
||||||
createOrUpdateResult,
|
|
||||||
],
|
|
||||||
{
|
{
|
||||||
changedOnly: isExistingPerm
|
changedOnly: isExistingPerm,
|
||||||
|
// If we're updating an existing perm,
|
||||||
|
// insert the perm ID into the mutation
|
||||||
|
// data before submitting. Otherwise just
|
||||||
|
// return the mutationData unmodified.
|
||||||
|
customizeMutationArgs: (mutationData) => {
|
||||||
|
if (isExistingPerm) {
|
||||||
|
return {
|
||||||
|
id: perm?.id,
|
||||||
|
...mutationData,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return mutationData;
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -261,7 +273,7 @@ function CreateOrUpdateDomainPerm({
|
||||||
const permTypeUpper = useCapitalize(permType);
|
const permTypeUpper = useCapitalize(permType);
|
||||||
|
|
||||||
const [location, setLocation] = useLocation();
|
const [location, setLocation] = useLocation();
|
||||||
function verifyUrlThenSubmit(e) {
|
function onSubmit(e: FormSubmitEvent) {
|
||||||
// Adding a new domain permissions happens on a url like
|
// Adding a new domain permissions happens on a url like
|
||||||
// "/settings/admin/domain-permissions/:permType/domain.com",
|
// "/settings/admin/domain-permissions/:permType/domain.com",
|
||||||
// but if domain input changes, that doesn't match anymore
|
// but if domain input changes, that doesn't match anymore
|
||||||
|
|
@ -277,7 +289,7 @@ function CreateOrUpdateDomainPerm({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={verifyUrlThenSubmit}>
|
<form onSubmit={onSubmit}>
|
||||||
{ !isExistingPerm &&
|
{ !isExistingPerm &&
|
||||||
<TextInput
|
<TextInput
|
||||||
field={form.domain}
|
field={form.domain}
|
||||||
|
|
@ -294,14 +306,14 @@ function CreateOrUpdateDomainPerm({
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextArea
|
<TextArea
|
||||||
field={form.commentPrivate}
|
field={form.privateComment}
|
||||||
label="Private comment"
|
label="Private comment"
|
||||||
autoCapitalize="sentences"
|
autoCapitalize="sentences"
|
||||||
rows={3}
|
rows={3}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextArea
|
<TextArea
|
||||||
field={form.commentPublic}
|
field={form.publicComment}
|
||||||
label="Public comment"
|
label="Public comment"
|
||||||
autoCapitalize="sentences"
|
autoCapitalize="sentences"
|
||||||
rows={3}
|
rows={3}
|
||||||
|
|
@ -311,21 +323,22 @@ function CreateOrUpdateDomainPerm({
|
||||||
<MutationButton
|
<MutationButton
|
||||||
label={isExistingPerm ? "Update " + permType.toString() : permTypeUpper}
|
label={isExistingPerm ? "Update " + permType.toString() : permTypeUpper}
|
||||||
result={submitResult}
|
result={submitResult}
|
||||||
showError={false}
|
disabled={
|
||||||
disabled={false}
|
isExistingPerm &&
|
||||||
|
!form.obfuscate.hasChanged() &&
|
||||||
|
!form.privateComment.hasChanged() &&
|
||||||
|
!form.publicComment.hasChanged()
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{
|
{ isExistingPerm &&
|
||||||
isExistingPerm &&
|
<button
|
||||||
<MutationButton
|
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => removeTrigger(perm.id?? "")}
|
onClick={() => removeTrigger(perm.id?? "")}
|
||||||
label={"Remove " + permType.toString()}
|
|
||||||
result={removeResult}
|
|
||||||
className="button danger"
|
className="button danger"
|
||||||
showError={false}
|
>
|
||||||
disabled={!isExistingPerm}
|
Remove {permType.toString()}
|
||||||
/>
|
</button>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export default function ImportExport() {
|
||||||
>
|
>
|
||||||
< back
|
< back
|
||||||
</span>
|
</span>
|
||||||
Confirm import of domain {form.permType.value}s:
|
Confirm {form.permType.value}s:
|
||||||
</h1>
|
</h1>
|
||||||
<ProcessImport
|
<ProcessImport
|
||||||
list={parseResult.data}
|
list={parseResult.data}
|
||||||
|
|
|
||||||
|
|
@ -24,14 +24,12 @@ import { isValidDomainPermission, hasBetterScope } from "../../../lib/util/domai
|
||||||
import {
|
import {
|
||||||
useTextInput,
|
useTextInput,
|
||||||
useBoolInput,
|
useBoolInput,
|
||||||
useRadioInput,
|
|
||||||
useCheckListInput,
|
useCheckListInput,
|
||||||
} from "../../../lib/form";
|
} from "../../../lib/form";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
TextArea,
|
TextArea,
|
||||||
RadioGroup,
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
TextInput,
|
TextInput,
|
||||||
} from "../../../components/form/inputs";
|
} from "../../../components/form/inputs";
|
||||||
|
|
@ -113,84 +111,81 @@ function ImportList({ list, data: domainPerms, permType }: ImportListProps) {
|
||||||
privateComment: useTextInput("private_comment", {
|
privateComment: useTextInput("private_comment", {
|
||||||
defaultValue: `Imported on ${new Date().toLocaleString()}`
|
defaultValue: `Imported on ${new Date().toLocaleString()}`
|
||||||
}),
|
}),
|
||||||
privateCommentBehavior: useRadioInput("private_comment_behavior", {
|
replacePrivateComment: useBoolInput("replace_private_comment", { defaultValue: false }),
|
||||||
defaultValue: "append",
|
|
||||||
options: {
|
|
||||||
append: "Append to",
|
|
||||||
replace: "Replace"
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
publicComment: useTextInput("public_comment"),
|
publicComment: useTextInput("public_comment"),
|
||||||
publicCommentBehavior: useRadioInput("public_comment_behavior", {
|
replacePublicComment: useBoolInput("replace_public_comment", { defaultValue: false }),
|
||||||
defaultValue: "append",
|
|
||||||
options: {
|
|
||||||
append: "Append to",
|
|
||||||
replace: "Replace"
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
permType: permType,
|
permType: permType,
|
||||||
};
|
};
|
||||||
|
|
||||||
const [importDomains, importResult] = useFormSubmit(form, useImportDomainPermsMutation(), { changedOnly: false });
|
const [importDomains, importResult] = useFormSubmit(
|
||||||
|
form,
|
||||||
|
useImportDomainPermsMutation(),
|
||||||
|
{ changedOnly: false },
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<form
|
||||||
<form
|
onSubmit={importDomains}
|
||||||
onSubmit={importDomains}
|
className="domain-perm-import-list"
|
||||||
className="domain-perm-import-list"
|
>
|
||||||
>
|
<span>{list.length} domain{list.length != 1 ? "s" : ""} in this list</span>
|
||||||
<span>{list.length} domain{list.length != 1 ? "s" : ""} in this list</span>
|
|
||||||
|
|
||||||
{hasComment.both &&
|
{hasComment.both &&
|
||||||
<Select field={showComment} options={
|
<Select field={showComment} options={
|
||||||
<>
|
<>
|
||||||
<option value="public_comment">Show public comments</option>
|
<option value="public_comment">Show public comments</option>
|
||||||
<option value="private_comment">Show private comments</option>
|
<option value="private_comment">Show private comments</option>
|
||||||
</>
|
</>
|
||||||
} />
|
} />
|
||||||
}
|
}
|
||||||
|
|
||||||
<div className="checkbox-list-wrapper">
|
<div className="checkbox-list-wrapper">
|
||||||
<DomainCheckList
|
<DomainCheckList
|
||||||
field={form.domains}
|
field={form.domains}
|
||||||
domainPerms={domainPerms}
|
domainPerms={domainPerms}
|
||||||
commentType={showComment.value as "public_comment" | "private_comment"}
|
commentType={showComment.value as "public_comment" | "private_comment"}
|
||||||
permType={form.permType}
|
permType={form.permType}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Checkbox
|
||||||
|
field={form.obfuscate}
|
||||||
|
label="Obfuscate domains in public lists"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="set-comment-checkbox">
|
||||||
|
<Checkbox
|
||||||
|
field={form.replacePrivateComment}
|
||||||
|
label="Set/replace private comment(s) to:"
|
||||||
|
/>
|
||||||
<TextArea
|
<TextArea
|
||||||
field={form.privateComment}
|
field={form.privateComment}
|
||||||
label="Private comment"
|
|
||||||
rows={3}
|
rows={3}
|
||||||
|
disabled={!form.replacePrivateComment.value}
|
||||||
|
placeholder="Private comment"
|
||||||
/>
|
/>
|
||||||
<RadioGroup
|
</div>
|
||||||
field={form.privateCommentBehavior}
|
|
||||||
label="imported private comment"
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
<div className="set-comment-checkbox">
|
||||||
|
<Checkbox
|
||||||
|
field={form.replacePublicComment}
|
||||||
|
label="Set/replace public comment(s) to:"
|
||||||
|
/>
|
||||||
<TextArea
|
<TextArea
|
||||||
field={form.publicComment}
|
field={form.publicComment}
|
||||||
label="Public comment"
|
|
||||||
rows={3}
|
rows={3}
|
||||||
|
disabled={!form.replacePublicComment.value}
|
||||||
|
placeholder="Public comment"
|
||||||
/>
|
/>
|
||||||
<RadioGroup
|
</div>
|
||||||
field={form.publicCommentBehavior}
|
|
||||||
label="imported public comment"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Checkbox
|
|
||||||
field={form.obfuscate}
|
|
||||||
label="Obfuscate domains in public lists"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<MutationButton
|
<MutationButton
|
||||||
label="Import"
|
label="Import"
|
||||||
disabled={false}
|
disabled={false}
|
||||||
result={importResult}
|
result={importResult}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue