Skip to content

Commit

Permalink
fix typo, improve app environment propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Jul 8, 2024
1 parent 1395568 commit b616ae3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 30 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ APP_PEPPER?=""
API_TOKEN?=""

APP_ENVIRONMENT?=dev
REGISTERATION_ENABLED?=true
REGISTRATION_ENABLED?=true

VAPID_PUB_KEY?=""
VAPID_PRIV_KEY?=""
Expand Down Expand Up @@ -48,8 +48,8 @@ DOCKER_IMAGE_TAG?=${REGISTRY}backend:${APP_VERSION}-go${GOLANG_VERSION}
DOCKER_INTERNAL_PORT?=8080
DOCKER_NETWORK_NAME?=traefik
DOCKER_USER?=littr
DOCKER_VOLUME_DATA_NAME?="litter-data"
DOCKER_VOLUME_PIX_NAME?="litter-pix"
DOCKER_VOLUME_DATA_NAME?=litter-data
DOCKER_VOLUME_PIX_NAME?=litter-pix

# define standard colors
# https://gist.github.com/rsperl/d2dfe88a520968fbc1f49db0a29345b9
Expand Down
2 changes: 1 addition & 1 deletion api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "MIT",
"url": "https://github.com/krustowski/litter-go/blob/master/LICENSE"
},
"version": "0.35.0"
"version": "0.35.3"
},
"host": "littr.n0p.cz",
"basePath": "/api/v1",
Expand Down
32 changes: 19 additions & 13 deletions configs/backend.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
package configs

import (
"strconv"
"os"
)

const (
// Time interval after that a heartbeat event of type 'message' is to be sent to connected clients/subscribers.
HEARTBEAT_SLEEP_TIME = 20
//REGISTERATION_ENABLED = false
HEARTBEAT_SLEEP_TIME = 20
)

/*
* Registeration
* Registration
*/

var REGISTERATION_ENABLED bool = false

if os.Getenv("REGISTERATION_ENABLED") != "" {
REGISTERATION_ENABLED = os.Getenv("REGISTERATION_ENABLED")
}
var REGISTRATION_ENABLED bool = func() bool {
if os.Getenv("REGISTRATION_ENABLED") != "" {
boolVal, err := strconv.ParseBool(os.Getenv("REGISTRATION_ENABLED"))
if err != nil {
return false
}
return boolVal
}
return true
}()

/*
* App environment
*/

var APP_ENVIRONMENT string = "dev"

if os.Getenv("APP_ENVIRONMENT") != "" {
APP_ENVIRONMENT = os.Getenv("APP_ENVIRONMENT")
}
var APP_ENVIRONMENT string = func() string {
if os.Getenv("APP_ENVIRONMENT") != "" {
return os.Getenv("APP_ENVIRONMENT")
}
return "dev"
}()

/*
* BE data migrations
Expand Down
4 changes: 2 additions & 2 deletions pkg/backend/users/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func addNewUser(w http.ResponseWriter, r *http.Request) {
resp := common.Response{}
l := common.NewLogger(r, "users")

if !configs.REGISTERATION_ENABLED {
resp.Message = "registeration disallowed at the moment"
if !configs.REGISTRATION_ENABLED {
resp.Message = "registration disallowed at the moment"
resp.Code = http.StatusForbidden

l.Println(resp.Message, resp.Code)
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (c *loginContent) Render() app.UI {
),

// register button
app.If(configs.REGISTERATION_ENABLED,
app.If(configs.REGISTRATION_ENABLED,
app.Button().Class("max deep-orange7 white-text bold").Style("border-radius", "8px").TabIndex(5).OnClick(c.onClickRegister).Disabled(c.loginButtonDisabled).Body(
app.Text("register"),
),
Expand Down
9 changes: 4 additions & 5 deletions pkg/frontend/navbars.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"log"
"strconv"
"strings"
"time"

"go.savla.dev/littr/configs"
Expand Down Expand Up @@ -327,12 +326,12 @@ func (h *header) Render() app.UI {
app.Span().Body(
app.Text(headerString),
app.If(configs.APP_ENVIRONMENT == "dev",
app.Span().Class("col").Body(
app.Sup().Body(
app.Text(" (beta) "),
app.Span().Class("col").Body(
app.Sup().Body(
app.Text(" (beta) "),
),
),
),
),
),
),

Expand Down
4 changes: 2 additions & 2 deletions pkg/frontend/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ func (c *registerContent) Render() app.UI {

// register button
app.Div().Class("row").Body(
app.If(configs.REGISTERATION_ENABLED,
app.If(configs.REGISTRATION_ENABLED,
app.Button().Class("max deep-orange7 white-text bold").Style("border-radius", "8px").OnClick(c.onClickRegister).Disabled(c.registerButtonDisabled).Body(
app.Text("register"),
),
).Else(
app.Button().Class("max deep-orange7 white-text bold").Style("border-radius", "8px").OnClick(nil).Disabled(true).Body(
app.Text("registeration off"),
app.Text("registration off"),
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions pkg/frontend/settings.handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func (c *settingsContent) onClickNotifSwitch(ctx app.Context, e app.Event) {
},
}

// send the registeration to backend
// send the registration to backend
if _, ok := litterAPI("POST", "/api/v1/push/subscription", deviceSub, c.user.Nickname, 0); !ok {
toastText := "cannot reach backend!"

Expand Down Expand Up @@ -626,7 +626,7 @@ func (c *settingsContent) onClickPrivateSwitch(ctx app.Context, e app.Event) {
private := c.user.Private

ctx.Async(func() {
// send the registeration to backend
// send the registration to backend
if _, ok := litterAPI("PATCH", "/api/v1/users/"+c.user.Nickname+"/private", nil, c.user.Nickname, 0); !ok {
toastText = "cannot reach backend!"

Expand Down
2 changes: 1 addition & 1 deletion pkg/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type User struct {
// Color is the user's UI color scheme.
Color string `json:"color" default:"#000000"`

// RegisteredTime is an UNIX timestamp of the user's registeration.
// RegisteredTime is an UNIX timestamp of the user's registration.
RegisteredTime time.Time `json:"registered_time"`

// LastLoginTime is an UNIX timestamp of the last user's successful log-in.
Expand Down

0 comments on commit b616ae3

Please sign in to comment.