gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

domain-blocklist.go (2438B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package web
     19 
     20 import (
     21 	"fmt"
     22 	"net/http"
     23 
     24 	"github.com/gin-gonic/gin"
     25 	apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
     26 	"github.com/superseriousbusiness/gotosocial/internal/config"
     27 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     28 	"github.com/superseriousbusiness/gotosocial/internal/oauth"
     29 )
     30 
     31 const (
     32 	domainBlockListPath = aboutPath + "/suspended"
     33 )
     34 
     35 func (m *Module) domainBlockListGETHandler(c *gin.Context) {
     36 	authed, err := oauth.Authed(c, false, false, false, false)
     37 	if err != nil {
     38 		apiutil.WebErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
     39 		return
     40 	}
     41 
     42 	if !config.GetInstanceExposeSuspendedWeb() && (authed.Account == nil || authed.User == nil) {
     43 		err := fmt.Errorf("this instance does not expose the list of suspended domains publicly")
     44 		apiutil.WebErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
     45 		return
     46 	}
     47 
     48 	instance, err := m.processor.InstanceGetV1(c.Request.Context())
     49 	if err != nil {
     50 		apiutil.WebErrorHandler(c, gtserror.NewErrorInternalError(err), m.processor.InstanceGetV1)
     51 		return
     52 	}
     53 
     54 	domainBlocks, errWithCode := m.processor.InstancePeersGet(c.Request.Context(), true, false, false)
     55 	if errWithCode != nil {
     56 		apiutil.WebErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
     57 		return
     58 	}
     59 
     60 	c.HTML(http.StatusOK, "domain-blocklist.tmpl", gin.H{
     61 		"instance":  instance,
     62 		"ogMeta":    ogBase(instance),
     63 		"blocklist": domainBlocks,
     64 		"stylesheets": []string{
     65 			assetsPathPrefix + "/Fork-Awesome/css/fork-awesome.min.css",
     66 		},
     67 		"javascript": []string{distPathPrefix + "/frontend.js"},
     68 	})
     69 }