mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 14:22:25 -05:00 
			
		
		
		
	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
This commit is contained in:
		
					parent
					
						
							
								cf19aaf0df
							
						
					
				
			
			
				commit
				
					
						d389e7b150
					
				
			
		
					 100 changed files with 3447 additions and 1419 deletions
				
			
		
							
								
								
									
										70
									
								
								internal/api/client/admin/domainblockcreate.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								internal/api/client/admin/domainblockcreate.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue