1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 15:49:44 +02:00

Ensure non-negative space summary counts

Sometimes users direct manipulate database and so space level counts don't match.

We ensure that counts don't go negative.
This commit is contained in:
Harvey Kandola 2019-02-28 12:42:42 +00:00
parent c108d0eb30
commit 4b7d4cf872

View file

@ -429,6 +429,14 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
return
}
// Cater for negative counts caused by user database manipulation.
if sp.CountCategory < 0 {
sp.CountCategory = 0
}
if sp.CountContent < 0 {
sp.CountContent = 0
}
ctx.Transaction, err = h.Runtime.Db.Beginx()
if err != nil {
response.WriteServerError(w, method, err)
@ -461,6 +469,16 @@ func (h *Handler) GetViewable(w http.ResponseWriter, r *http.Request) {
h.Runtime.Log.Error(method, err)
}
// Cater for negative counts caused by user database manipulation.
for i := range sp {
if sp[i].CountCategory < 0 {
sp[i].CountCategory = 0
}
if sp[i].CountContent < 0 {
sp[i].CountContent = 0
}
}
response.WriteJSON(w, sp)
}