mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 00:30:27 +00:00
expose demo status to API
This commit is contained in:
parent
64f7ff2e2f
commit
79f1456017
3 changed files with 10 additions and 8 deletions
|
@ -44,7 +44,7 @@ func (a *app) newRouter(repos *repo.AllRepos) *chi.Mux {
|
|||
v1Base := v1.BaseUrlFunc(prefix)
|
||||
v1Ctrl := v1.NewControllerV1(a.services,
|
||||
v1.WithMaxUploadSize(a.conf.Web.MaxUploadSize),
|
||||
v1.WithDisablePasswordChange(a.conf.Demo), // Disable Password Change in Demo Mode
|
||||
v1.WithDemoStatus(a.conf.Demo), // Disable Password Change in Demo Mode
|
||||
)
|
||||
r.Get(v1Base("/status"), v1Ctrl.HandleBase(func() bool { return true }, v1.Build{
|
||||
Version: Version,
|
||||
|
|
|
@ -13,16 +13,16 @@ func WithMaxUploadSize(maxUploadSize int64) func(*V1Controller) {
|
|||
}
|
||||
}
|
||||
|
||||
func WithDisablePasswordChange(disablePasswordChange bool) func(*V1Controller) {
|
||||
func WithDemoStatus(demoStatus bool) func(*V1Controller) {
|
||||
return func(ctrl *V1Controller) {
|
||||
ctrl.disablePasswordChange = disablePasswordChange
|
||||
ctrl.isDemo = demoStatus
|
||||
}
|
||||
}
|
||||
|
||||
type V1Controller struct {
|
||||
svc *services.AllServices
|
||||
maxUploadSize int64
|
||||
disablePasswordChange bool
|
||||
isDemo bool
|
||||
}
|
||||
|
||||
type (
|
||||
|
@ -37,7 +37,8 @@ type (
|
|||
Versions []string `json:"versions"`
|
||||
Title string `json:"title"`
|
||||
Message string `json:"message"`
|
||||
Build Build
|
||||
Build Build `json:"build"`
|
||||
Demo bool `json:"demo"`
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -73,6 +74,7 @@ func (ctrl *V1Controller) HandleBase(ready ReadyFunc, build Build) http.HandlerF
|
|||
Title: "Go API Template",
|
||||
Message: "Welcome to the Go API Template Application!",
|
||||
Build: build,
|
||||
Demo: ctrl.isDemo,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ type (
|
|||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleUserSelfChangePassword() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if ctrl.disablePasswordChange {
|
||||
if ctrl.isDemo {
|
||||
server.RespondError(w, http.StatusForbidden, nil)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue