add webmanifest for public app, make timezone configurable to fix schedule hours comparison

This commit is contained in:
Roberto Hidalgo 2023-05-30 19:06:14 -06:00
parent a34457492c
commit feb3973869
6 changed files with 65 additions and 15 deletions

View File

@ -1,4 +1,5 @@
name: Casa de alguien
timezone: America/Mexico_City
adapter:
kind: dry-run

View File

@ -12,7 +12,6 @@
<link rel="manifest" href="/static/admin-manifest.webmanifest" />
<link rel="icon" type="image/png" href="/static/icon/128.png" sizes="128x128" />
<link rel="icon" type="image/png" href="/static/icon/512.png" sizes="512" />
<link rel="apple-touch-icon" href="/static/icon/512.png">
<link rel="apple-touch-icon" sizes="152x152" href="/static/icon/152.png">
<link rel="apple-touch-icon" sizes="384x384" href="/static/icon/384.png">

View File

@ -9,7 +9,13 @@
<link rel="stylesheet" href="https://cdn.rob.mx/css/fonts.css" />
<link rel="stylesheet" href="https://cdn.rob.mx/nidito/index.css" />
<link rel="stylesheet" href="/static/index.css" />
<!-- link rel="manifest" href="/static/manifest.webmanifest" /-->
<link rel="manifest" href="/static/manifest.webmanifest" />
<link rel="icon" type="image/png" href="/static/icon/128.png" sizes="128x128" />
<link rel="icon" type="image/png" href="/static/icon/512.png" sizes="512" />
<link rel="apple-touch-icon" href="/static/icon/512.png">
<link rel="apple-touch-icon" sizes="152x152" href="/static/icon/152.png">
<link rel="apple-touch-icon" sizes="384x384" href="/static/icon/384.png">
<link rel="apple-touch-icon" sizes="192x192" href="/static/icon/192.png">
</head>
<body>
<header id="main-header">

View File

@ -52,7 +52,7 @@ type Config struct {
Adapter map[string]any `yaml:"adapter"`
HTTP *HTTPConfig `yaml:"http"`
WebPush *push.Config `yaml:"push"`
Timezone string `yaml:"timezone"`
DB string `yaml:"db"`
}
@ -146,7 +146,7 @@ func notifyAdmins(message string) {
for _, sub := range subs {
err := push.Notify(message, sub)
if err != nil {
logrus.Errorf("could not push notification to subscription %s: %s", sub.ID, err)
logrus.Errorf("could not push notification to subscription %s: %s", sub.ID(), err)
}
}
}
@ -155,14 +155,14 @@ func rex(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
var err error
u := user.FromContext(r)
defer func() {
_, sqlErr := _db.Collection("log").Insert(newAuditLog(r, err))
defer func(req *http.Request, err error) {
_, sqlErr := _db.Collection("log").Insert(newAuditLog(req, err))
if sqlErr != nil {
logrus.Errorf("could not record error log: %s", sqlErr)
}
}()
}(r, err)
err = u.IsAllowed(time.Now())
err = u.IsAllowed(time.Now().In(TZ))
if err != nil {
logrus.Errorf("Denying rex to %s: %s", u.Name, err)
http.Error(w, "Access denied", http.StatusForbidden)
@ -182,6 +182,7 @@ func rex(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
}
var _db db.Session
var TZ *time.Location = time.UTC
func Initialize(config *Config) (http.Handler, error) {
devMode := os.Getenv("ENV") == "dev"
@ -190,6 +191,14 @@ func Initialize(config *Config) (http.Handler, error) {
allowCORS(nil)(w, r, nil)
})
if config.Timezone != "" {
mtz, err := time.LoadLocation(config.Timezone)
if err != nil {
return nil, fmt.Errorf("Unknown timezone %s", config.Timezone)
}
TZ = mtz
}
db := sqlite.ConnectionURL{
Database: config.DB,
Options: map[string]string{

View File

@ -4,9 +4,44 @@
"display": "standalone",
"icons": [
{
"src": "static/icon@192.png",
"src": "static/icon/72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "static/icon/96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "static/icon/128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "static/icon/144.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "static/icon/152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "static/icon/192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "static/icon/384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "static/icon/512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"name": "Puerta Nidito",

View File

@ -126,7 +126,7 @@ func (user *User) IsAllowed(t time.Time) error {
return fmt.Errorf("usuario expirado, avísale a Roberto")
}
if user.Schedule != nil && !user.Schedule.AllowedAt(time.Now()) {
if user.Schedule != nil && !user.Schedule.AllowedAt(t) {
return fmt.Errorf("accesso denegado, intente nuevamente en otro momento")
}