Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Fix user quota percentage (cs3org#3344)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 authored and vascoguita committed Oct 28, 2022
1 parent 34aaa2d commit 4f113d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/fix-quota-percentage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Fix quota percentage

https://github.com/cs3org/reva/pull/3344
23 changes: 12 additions & 11 deletions internal/http/services/owncloud/ocs/handlers/cloud/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,21 @@ func (h *Handler) GetUsers(w http.ResponseWriter, r *http.Request) {
return
}

getHomeRes, err := gc.GetHome(ctx, &provider.GetHomeRequest{})
if err != nil {
sublog.Error().Err(err).Msg("error calling GetHome")
w.WriteHeader(http.StatusInternalServerError)
return
}
if getHomeRes.Status.Code != rpc.Code_CODE_OK {
ocdav.HandleErrorStatus(sublog, w, getHomeRes.Status)
return
}
var total, used uint64 = 2, 1
var relative float32
// lightweight and federated accounts don't have access to their storage space
if u.Id.Type != userpb.UserType_USER_TYPE_LIGHTWEIGHT && u.Id.Type != userpb.UserType_USER_TYPE_FEDERATED {
getHomeRes, err := gc.GetHome(ctx, &provider.GetHomeRequest{})
if err != nil {
sublog.Error().Err(err).Msg("error calling GetHome")
w.WriteHeader(http.StatusInternalServerError)
return
}
if getHomeRes.Status.Code != rpc.Code_CODE_OK {
ocdav.HandleErrorStatus(sublog, w, getHomeRes.Status)
return
}

getQuotaRes, err := gc.GetQuota(ctx, &gateway.GetQuotaRequest{Ref: &provider.Reference{Path: getHomeRes.Path}})
if err != nil {
sublog.Error().Err(err).Msg("error calling GetQuota")
Expand All @@ -131,7 +132,7 @@ func (h *Handler) GetUsers(w http.ResponseWriter, r *http.Request) {
}
total = getQuotaRes.TotalBytes
used = getQuotaRes.UsedBytes
relative = float32(float64(used) / float64(total))
relative = float32(float64(used)/float64(total)) * 100
}

response.WriteOCSSuccess(w, r, &Users{
Expand Down

0 comments on commit 4f113d3

Please sign in to comment.