mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 18:22:26 -05:00 
			
		
		
		
	* 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
		
			
				
	
	
		
			54 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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)
 | |
| }
 |