From 79f1456017c2754bd14713f8751325dd2eb7d590 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Wed, 12 Oct 2022 12:38:17 -0800 Subject: [PATCH] expose demo status to API --- backend/app/api/routes.go | 2 +- backend/app/api/v1/controller.go | 14 ++++++++------ backend/app/api/v1/v1_ctrl_user.go | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/app/api/routes.go b/backend/app/api/routes.go index 5fc8c40..9befd36 100644 --- a/backend/app/api/routes.go +++ b/backend/app/api/routes.go @@ -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, diff --git a/backend/app/api/v1/controller.go b/backend/app/api/v1/controller.go index 5fa7460..f33ebfa 100644 --- a/backend/app/api/v1/controller.go +++ b/backend/app/api/v1/controller.go @@ -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 + svc *services.AllServices + maxUploadSize int64 + 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, }) } } diff --git a/backend/app/api/v1/v1_ctrl_user.go b/backend/app/api/v1/v1_ctrl_user.go index 765f54d..bb5f617 100644 --- a/backend/app/api/v1/v1_ctrl_user.go +++ b/backend/app/api/v1/v1_ctrl_user.go @@ -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 }