summaryrefslogtreecommitdiff
path: root/internal/api/client/admin/domainblockget.go
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-07-05 13:23:03 +0200
committerLibravatar GitHub <noreply@github.com>2021-07-05 13:23:03 +0200
commitd389e7b150df6ecd215c7b661b294ea153ad0103 (patch)
tree8739e3103cb5130875d903cc7fc72fd9db3b8434 /internal/api/client/admin/domainblockget.go
parentFix 404 contact (#74) (diff)
downloadgotosocial-d389e7b150df6ecd215c7b661b294ea153ad0103.tar.xz
Domain block (#76)
* start work on admin domain blocking * move stuff around + further work on domain blocks * move + restructure processor * prep work for deleting account * tidy * go fmt * formatting * domain blocking more work * check domain blocks way earlier on * progress on delete account * delete more stuff when an account is gone * and more... * domain blocky block block * get individual domain block, delete a block
Diffstat (limited to 'internal/api/client/admin/domainblockget.go')
-rw-r--r--internal/api/client/admin/domainblockget.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/internal/api/client/admin/domainblockget.go b/internal/api/client/admin/domainblockget.go
new file mode 100644
index 000000000..009794f8a
--- /dev/null
+++ b/internal/api/client/admin/domainblockget.go
@@ -0,0 +1,60 @@
+package admin
+
+import (
+ "net/http"
+ "strconv"
+
+ "github.com/gin-gonic/gin"
+ "github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/oauth"
+)
+
+// DomainBlockGETHandler returns one existing domain block, identified by its id.
+func (m *Module) DomainBlockGETHandler(c *gin.Context) {
+ l := m.log.WithFields(logrus.Fields{
+ "func": "DomainBlockGETHandler",
+ "request_uri": c.Request.RequestURI,
+ "user_agent": c.Request.UserAgent(),
+ "origin_ip": c.ClientIP(),
+ })
+
+ // make sure we're authed with an admin account
+ authed, err := oauth.Authed(c, true, true, true, true)
+ if err != nil {
+ l.Debugf("couldn't auth: %s", err)
+ c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
+ return
+ }
+ if !authed.User.Admin {
+ l.Debugf("user %s not an admin", authed.User.ID)
+ c.JSON(http.StatusForbidden, gin.H{"error": "not an admin"})
+ return
+ }
+
+ domainBlockID := c.Param(IDKey)
+ if domainBlockID == "" {
+ c.JSON(http.StatusBadRequest, gin.H{"error": "no domain block id provided"})
+ return
+ }
+
+ export := false
+ exportString := c.Query(ExportQueryKey)
+ if exportString != "" {
+ i, err := strconv.ParseBool(exportString)
+ if err != nil {
+ l.Debugf("error parsing export string: %s", err)
+ c.JSON(http.StatusBadRequest, gin.H{"error": "couldn't parse export query param"})
+ return
+ }
+ export = i
+ }
+
+ domainBlock, err := m.processor.AdminDomainBlockGet(authed, domainBlockID, export)
+ if err != nil {
+ l.Debugf("error getting domain block: %s", err)
+ c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ return
+ }
+
+ c.JSON(http.StatusOK, domainBlock)
+}