From efd7069fe4d39284deb3ded3db1726b9d8ddb5f9 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Wed, 15 Feb 2023 08:58:38 -0900 Subject: [PATCH] feat: hide registration button when disabled (#287) * add allow registration to API Summary * code gen * use env for troubleshooting * disable registration toggle based on backend --- Taskfile.yml | 1 + backend/app/api/handlers/v1/controller.go | 24 ++++++++++++----------- backend/app/api/static/docs/docs.go | 3 +++ backend/app/api/static/docs/swagger.json | 3 +++ backend/app/api/static/docs/swagger.yaml | 2 ++ frontend/lib/api/types/data-contracts.ts | 1 + frontend/pages/index.vue | 7 ++++--- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 816077a..a16daa5 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -2,6 +2,7 @@ version: "3" env: HBOX_STORAGE_SQLITE_URL: .data/homebox.db?_fk=1 + HBOX_OPTIONS_ALLOW_REGISTRATION: true UNSAFE_DISABLE_PASSWORD_PROJECTION: "yes_i_am_sure" tasks: setup: diff --git a/backend/app/api/handlers/v1/controller.go b/backend/app/api/handlers/v1/controller.go index 4f7a73e..f5790c8 100644 --- a/backend/app/api/handlers/v1/controller.go +++ b/backend/app/api/handlers/v1/controller.go @@ -44,12 +44,13 @@ type ( } ApiSummary struct { - Healthy bool `json:"health"` - Versions []string `json:"versions"` - Title string `json:"title"` - Message string `json:"message"` - Build Build `json:"build"` - Demo bool `json:"demo"` + Healthy bool `json:"health"` + Versions []string `json:"versions"` + Title string `json:"title"` + Message string `json:"message"` + Build Build `json:"build"` + Demo bool `json:"demo"` + AllowRegistration bool `json:"allowRegistration"` } ) @@ -82,11 +83,12 @@ func NewControllerV1(svc *services.AllServices, repos *repo.AllRepos, options .. func (ctrl *V1Controller) HandleBase(ready ReadyFunc, build Build) server.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) error { return server.Respond(w, http.StatusOK, ApiSummary{ - Healthy: ready(), - Title: "Go API Template", - Message: "Welcome to the Go API Template Application!", - Build: build, - Demo: ctrl.isDemo, + Healthy: ready(), + Title: "Go API Template", + Message: "Welcome to the Go API Template Application!", + Build: build, + Demo: ctrl.isDemo, + AllowRegistration: ctrl.allowRegistration, }) } } diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 3f7c37d..e24f140 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -2425,6 +2425,9 @@ const docTemplate = `{ "v1.ApiSummary": { "type": "object", "properties": { + "allowRegistration": { + "type": "boolean" + }, "build": { "$ref": "#/definitions/v1.Build" }, diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 3c81456..6319ff9 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -2417,6 +2417,9 @@ "v1.ApiSummary": { "type": "object", "properties": { + "allowRegistration": { + "type": "boolean" + }, "build": { "$ref": "#/definitions/v1.Build" }, diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index 4d7db79..301dd3d 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -564,6 +564,8 @@ definitions: type: object v1.ApiSummary: properties: + allowRegistration: + type: boolean build: $ref: '#/definitions/v1.Build' demo: diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index 9ed4a8d..a4a0d90 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -335,6 +335,7 @@ export interface ActionAmountResult { } export interface ApiSummary { + allowRegistration: boolean; build: Build; demo: boolean; health: boolean; diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index 423ec7d..a7846e2 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -101,7 +101,6 @@ toast.success("Logged in successfully"); - // @ts-expect-error - expires is either a date or a string, need to figure out store typing authStore.$patch({ token: data.token, expires: data.expiresAt, @@ -214,11 +213,13 @@
+

Registration Disabled