summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-09-04 15:55:17 +0200
committerLibravatar GitHub <noreply@github.com>2023-09-04 14:55:17 +0100
commit3ed1ca68e52527f74103e1a57ae48ae533508c3a (patch)
treed6113d71d6f88a3d99bbd2215ead6ca1d4fa6153 /internal/api
parent[chore]: Bump golang.org/x/image from 0.11.0 to 0.12.0 (#2178) (diff)
downloadgotosocial-3ed1ca68e52527f74103e1a57ae48ae533508c3a.tar.xz
[feature] Store admin actions in the db, prevent conflicting actions (#2167)
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/client/admin/accountaction.go11
-rw-r--r--internal/api/client/admin/domainblockcreate.go7
-rw-r--r--internal/api/client/admin/domainblockdelete.go7
-rw-r--r--internal/api/model/admin.go13
4 files changed, 28 insertions, 10 deletions
diff --git a/internal/api/client/admin/accountaction.go b/internal/api/client/admin/accountaction.go
index 484f5bbc4..91186ae73 100644
--- a/internal/api/client/admin/accountaction.go
+++ b/internal/api/client/admin/accountaction.go
@@ -79,6 +79,11 @@ import (
// description: not found
// '406':
// description: not acceptable
+// '409':
+// description: >-
+// Conflict: There is already an admin action running that conflicts with this action.
+// Check the error message in the response body for more information. This is a temporary
+// error; it should be possible to process this action if you try again in a bit.
// '500':
// description: internal server error
func (m *Module) AccountActionPOSTHandler(c *gin.Context) {
@@ -94,7 +99,7 @@ func (m *Module) AccountActionPOSTHandler(c *gin.Context) {
return
}
- form := &apimodel.AdminAccountActionRequest{}
+ form := &apimodel.AdminActionRequest{}
if err := c.ShouldBind(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return
@@ -112,9 +117,9 @@ func (m *Module) AccountActionPOSTHandler(c *gin.Context) {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return
}
- form.TargetAccountID = targetAcctID
+ form.TargetID = targetAcctID
- if errWithCode := m.processor.Admin().AccountAction(c.Request.Context(), authed.Account, form); errWithCode != nil {
+ if _, errWithCode := m.processor.Admin().AccountAction(c.Request.Context(), authed.Account, form); errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
diff --git a/internal/api/client/admin/domainblockcreate.go b/internal/api/client/admin/domainblockcreate.go
index 148fad7c9..5cf9ea279 100644
--- a/internal/api/client/admin/domainblockcreate.go
+++ b/internal/api/client/admin/domainblockcreate.go
@@ -119,6 +119,11 @@ import (
// description: not found
// '406':
// description: not acceptable
+// '409':
+// description: >-
+// Conflict: There is already an admin action running that conflicts with this action.
+// Check the error message in the response body for more information. This is a temporary
+// error; it should be possible to process this action if you try again in a bit.
// '500':
// description: internal server error
func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) {
@@ -159,7 +164,7 @@ func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) {
if !importing {
// Single domain block creation.
- domainBlock, errWithCode := m.processor.Admin().DomainBlockCreate(
+ domainBlock, _, errWithCode := m.processor.Admin().DomainBlockCreate(
c.Request.Context(),
authed.Account,
form.Domain,
diff --git a/internal/api/client/admin/domainblockdelete.go b/internal/api/client/admin/domainblockdelete.go
index 90624addc..9318bad87 100644
--- a/internal/api/client/admin/domainblockdelete.go
+++ b/internal/api/client/admin/domainblockdelete.go
@@ -66,6 +66,11 @@ import (
// description: not found
// '406':
// description: not acceptable
+// '409':
+// description: >-
+// Conflict: There is already an admin action running that conflicts with this action.
+// Check the error message in the response body for more information. This is a temporary
+// error; it should be possible to process this action if you try again in a bit.
// '500':
// description: internal server error
func (m *Module) DomainBlockDELETEHandler(c *gin.Context) {
@@ -93,7 +98,7 @@ func (m *Module) DomainBlockDELETEHandler(c *gin.Context) {
return
}
- domainBlock, errWithCode := m.processor.Admin().DomainBlockDelete(c.Request.Context(), authed.Account, domainBlockID)
+ domainBlock, _, errWithCode := m.processor.Admin().DomainBlockDelete(c.Request.Context(), authed.Account, domainBlockID)
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
diff --git a/internal/api/model/admin.go b/internal/api/model/admin.go
index 860cb8926..6be3e9cbd 100644
--- a/internal/api/model/admin.go
+++ b/internal/api/model/admin.go
@@ -163,16 +163,19 @@ type AdminEmoji struct {
URI string `json:"uri"`
}
-// AdminAccountActionRequest models the admin view of an account's details.
+// AdminActionRequest models a request
+// for an admin action to be performed.
//
// swagger:ignore
-type AdminAccountActionRequest struct {
- // Type of the account action. One of disable, silence, suspend.
+type AdminActionRequest struct {
+ // Category of the target entity.
+ Category string `form:"-" json:"-" xml:"-"`
+ // Type of admin action to take. One of disable, silence, suspend.
Type string `form:"type" json:"type" xml:"type"`
// Text describing why an action was taken.
Text string `form:"text" json:"text" xml:"text"`
- // ID of the account to be acted on.
- TargetAccountID string `form:"-" json:"-" xml:"-"`
+ // ID of the target entity.
+ TargetID string `form:"-" json:"-" xml:"-"`
}
// MediaCleanupRequest models admin media cleanup parameters