-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
1 parent
cf19aaf
commit d389e7b
Showing
100 changed files
with
3,432 additions
and
1,404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package admin | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
"github.com/superseriousbusiness/gotosocial/internal/api/model" | ||
"github.com/superseriousbusiness/gotosocial/internal/oauth" | ||
) | ||
|
||
// DomainBlocksPOSTHandler deals with the creation of a new domain block. | ||
func (m *Module) DomainBlocksPOSTHandler(c *gin.Context) { | ||
l := m.log.WithFields(logrus.Fields{ | ||
"func": "DomainBlocksPOSTHandler", | ||
"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 | ||
} | ||
|
||
// extract the media create form from the request context | ||
l.Tracef("parsing request form: %+v", c.Request.Form) | ||
form := &model.DomainBlockCreateRequest{} | ||
if err := c.ShouldBind(form); err != nil { | ||
l.Debugf("error parsing form %+v: %s", c.Request.Form, err) | ||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("could not parse form: %s", err)}) | ||
return | ||
} | ||
|
||
// Give the fields on the request form a first pass to make sure the request is superficially valid. | ||
l.Tracef("validating form %+v", form) | ||
if err := validateCreateDomainBlock(form); err != nil { | ||
l.Debugf("error validating form: %s", err) | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
domainBlock, err := m.processor.AdminDomainBlockCreate(authed, form) | ||
if err != nil { | ||
l.Debugf("error creating domain block: %s", err) | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, domainBlock) | ||
} | ||
|
||
func validateCreateDomainBlock(form *model.DomainBlockCreateRequest) error { | ||
// add some more validation here later if necessary | ||
if form.Domain == "" { | ||
return errors.New("empty domain provided") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package admin | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
"github.com/superseriousbusiness/gotosocial/internal/oauth" | ||
) | ||
|
||
// DomainBlockDELETEHandler deals with the delete of an existing domain block. | ||
func (m *Module) DomainBlockDELETEHandler(c *gin.Context) { | ||
l := m.log.WithFields(logrus.Fields{ | ||
"func": "DomainBlockDELETEHandler", | ||
"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 | ||
} | ||
|
||
domainBlock, errWithCode := m.processor.AdminDomainBlockDelete(authed, domainBlockID) | ||
if errWithCode != nil { | ||
l.Debugf("error deleting domain block: %s", errWithCode.Error()) | ||
c.JSON(errWithCode.Code(), gin.H{"error": errWithCode.Safe()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, domainBlock) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package admin | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
"github.com/superseriousbusiness/gotosocial/internal/oauth" | ||
) | ||
|
||
// DomainBlocksGETHandler returns a list of all existing domain blocks. | ||
func (m *Module) DomainBlocksGETHandler(c *gin.Context) { | ||
l := m.log.WithFields(logrus.Fields{ | ||
"func": "DomainBlocksGETHandler", | ||
"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 | ||
} | ||
|
||
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 | ||
} | ||
|
||
domainBlocks, err := m.processor.AdminDomainBlocksGet(authed, export) | ||
if err != nil { | ||
l.Debugf("error getting domain blocks: %s", err) | ||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, domainBlocks) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.