2021-07-05 12:23:03 +01:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
|
|
|
)
|
|
|
|
|
2021-08-02 18:06:44 +01:00
|
|
|
// DomainBlocksGETHandler swagger:operation GET /api/v1/admin/domain_blocks domainBlocksGet
|
2021-07-31 22:17:39 +01:00
|
|
|
//
|
|
|
|
// View all domain blocks currently in place.
|
|
|
|
//
|
|
|
|
// ---
|
|
|
|
// tags:
|
|
|
|
// - admin
|
|
|
|
//
|
|
|
|
// produces:
|
|
|
|
// - application/json
|
|
|
|
//
|
|
|
|
// parameters:
|
|
|
|
// - name: export
|
|
|
|
// type: boolean
|
|
|
|
// description: |-
|
|
|
|
// If set to true, then each entry in the returned list of domain blocks will only consist of
|
|
|
|
// the fields 'domain' and 'public_comment'. This is perfect for when you want to save and share
|
|
|
|
// a list of all the domains you have blocked on your instance, so that someone else can easily import them,
|
|
|
|
// but you don't need them to see the database IDs of your blocks, or private comments etc.
|
|
|
|
// in: query
|
|
|
|
// required: false
|
|
|
|
//
|
|
|
|
// security:
|
|
|
|
// - OAuth2 Bearer:
|
|
|
|
// - admin
|
|
|
|
//
|
|
|
|
// responses:
|
|
|
|
// '200':
|
|
|
|
// description: All domain blocks currently in place.
|
|
|
|
// schema:
|
|
|
|
// type: array
|
|
|
|
// items:
|
|
|
|
// "$ref": "#/definitions/domainBlock"
|
|
|
|
// '403':
|
|
|
|
// description: forbidden
|
|
|
|
// '400':
|
|
|
|
// description: bad request
|
|
|
|
// '404':
|
|
|
|
// description: not found
|
2021-07-05 12:23:03 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-08-25 14:34:33 +01:00
|
|
|
domainBlocks, err := m.processor.AdminDomainBlocksGet(c.Request.Context(), authed, export)
|
2021-07-05 12:23:03 +01:00
|
|
|
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)
|
|
|
|
}
|