Add config to disable registration
This commit is contained in:
30
internal/apitest/get_appinfo_test.go
Normal file
30
internal/apitest/get_appinfo_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package apitest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/dto"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetAppInfo_Ok(t *testing.T) {
|
||||
router := testutils.TestSetup()
|
||||
|
||||
req, _ := http.NewRequest("GET", "/ws/appinfo", nil)
|
||||
w := httptest.NewRecorder()
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
var appInfo dto.AppInfo
|
||||
|
||||
err := json.Unmarshal(w.Body.Bytes(), &appInfo)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
assert.Equal(t, false, appInfo.RegistrationDisabled)
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package dto
|
||||
|
||||
type AppInfo struct {
|
||||
RegistrationDisabled bool `json:"registrationDisabled"`
|
||||
}
|
||||
|
||||
type BookGet struct {
|
||||
Title string `json:"title" binding:"required,max=300"`
|
||||
Author string `json:"author" binding:"max=100"`
|
||||
|
||||
@@ -17,6 +17,11 @@ func Auth() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
//do not check appinfo
|
||||
if strings.HasPrefix(c.FullPath(), "/ws/appinfo") {
|
||||
return
|
||||
}
|
||||
|
||||
//do not check static files
|
||||
if strings.HasPrefix(c.FullPath(), "/static/bookcover/") {
|
||||
return
|
||||
|
||||
12
internal/routes/appinfo.go
Normal file
12
internal/routes/appinfo.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/dto"
|
||||
)
|
||||
|
||||
func GetAppInfo(ac appcontext.AppContext) {
|
||||
ac.C.JSON(http.StatusOK, dto.AppInfo{RegistrationDisabled: ac.Config.DisableRegistration})
|
||||
}
|
||||
@@ -30,6 +30,10 @@ func Setup(config *config.Config) *gin.Engine {
|
||||
ws := r.Group("/ws")
|
||||
ws.Use(middleware.Auth())
|
||||
|
||||
ws.GET("/appinfo", func(c *gin.Context) {
|
||||
routes.GetAppInfo(appcontext.AppContext{C: c, Db: db, I18n: bundle, Config: config})
|
||||
})
|
||||
|
||||
ws.GET("/mybooks/read", func(c *gin.Context) {
|
||||
routes.GetMyBooksReadHandler(appcontext.AppContext{C: c, Db: db, I18n: bundle, Config: config})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user