1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

feat: allow unlimited date ranges

This commit is contained in:
Ferdinand Mütsch
2021-02-06 23:23:26 +01:00
parent 2f5973cfa3
commit 6d2697ec37
5 changed files with 7 additions and 11 deletions

View File

@ -68,7 +68,8 @@ func (h *BadgeHandler) Get(w http.ResponseWriter, r *http.Request) {
_, rangeFrom, rangeTo := utils.ResolveInterval(interval)
minStart := utils.StartOfDay(rangeTo.Add(-24 * time.Hour * time.Duration(user.ShareDataMaxDays)))
if rangeFrom.Before(minStart) {
// negative value means no limit
if rangeFrom.Before(minStart) && user.ShareDataMaxDays >= 0 {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("requested time range too broad"))
return

View File

@ -65,7 +65,7 @@ func (h *StatsHandler) Get(w http.ResponseWriter, r *http.Request) {
minStart := utils.StartOfDay(rangeTo.Add(-24 * time.Hour * time.Duration(requestedUser.ShareDataMaxDays)))
if (authorizedUser == nil || requestedUser.ID != authorizedUser.ID) &&
(requestedUser.ShareDataMaxDays == 0 || rangeFrom.Before(minStart)) {
rangeFrom.Before(minStart) && requestedUser.ShareDataMaxDays >= 0 {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("requested time range too broad"))
return

View File

@ -2,7 +2,6 @@ package routes
import (
"encoding/base64"
"errors"
"fmt"
"github.com/emvi/logbuch"
"github.com/gorilla/mux"
@ -218,11 +217,7 @@ func (h *SettingsHandler) actionUpdateSharing(w http.ResponseWriter, r *http.Req
user.ShareEditors, err = strconv.ParseBool(r.PostFormValue("share_editors"))
user.ShareOSs, err = strconv.ParseBool(r.PostFormValue("share_oss"))
user.ShareMachines, err = strconv.ParseBool(r.PostFormValue("share_machines"))
if v, e := strconv.Atoi(r.PostFormValue("max_days")); e == nil && v >= 0 {
user.ShareDataMaxDays = uint(v)
} else {
err = errors.New("")
}
user.ShareDataMaxDays, err = strconv.Atoi(r.PostFormValue("max_days"))
if err != nil {
return http.StatusBadRequest, "", "invalid input"