mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 04:40:05 -06:00
Merge pull request #2628 from owncloud/quota-stages
[Enhancement] Report quota states
This commit is contained in:
5
changelog/unreleased/report-quota-states.md
Normal file
5
changelog/unreleased/report-quota-states.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Enhancement: Report quota states
|
||||
|
||||
When listing the available spaces via the GraphAPI we now return quota states to make it easier for the clients to add visual indicators.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/2628
|
||||
2
go.mod
2
go.mod
@@ -20,7 +20,7 @@ require (
|
||||
github.com/blevesearch/bleve/v2 v2.1.0
|
||||
github.com/coreos/go-oidc/v3 v3.0.0
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11
|
||||
github.com/cs3org/reva v1.14.1-0.20211014164014-5866f5e0f31b
|
||||
github.com/cs3org/reva v1.14.1-0.20211015081146-2e9bc0c7714a
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/glauth/glauth v1.1.3-0.20210729125545-b9aecdfcac31
|
||||
github.com/go-chi/chi/v5 v5.0.4
|
||||
|
||||
4
go.sum
4
go.sum
@@ -291,8 +291,8 @@ github.com/crewjam/saml v0.4.5/go.mod h1:qCJQpUtZte9R1ZjUBcW8qtCNlinbO363ooNl02S
|
||||
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11 h1:cc/8fdzWdr/wAZOXb29J8bnXjo1poCMCLwhlFBlvhfI=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20211007101428-6d142794ec11/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
|
||||
github.com/cs3org/reva v1.14.1-0.20211014164014-5866f5e0f31b h1:IT6h3/gt83pge8hHRdb8FpIMkyrrgeEM1VF9I0RP/kA=
|
||||
github.com/cs3org/reva v1.14.1-0.20211014164014-5866f5e0f31b/go.mod h1:uENdZEtDFmTRt6+d4+Ro4P5XnNL+9I6gwftHEBJzHQw=
|
||||
github.com/cs3org/reva v1.14.1-0.20211015081146-2e9bc0c7714a h1:xauop9DkHYtOA3qLGmohOi0rt6WqN8+1BCWu5i/4cL4=
|
||||
github.com/cs3org/reva v1.14.1-0.20211015081146-2e9bc0c7714a/go.mod h1:uENdZEtDFmTRt6+d4+Ro4P5XnNL+9I6gwftHEBJzHQw=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
|
||||
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
|
||||
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
|
||||
|
||||
@@ -452,10 +452,27 @@ func (g Graph) getDriveQuota(ctx context.Context, space *storageprovider.Storage
|
||||
Total: &total,
|
||||
Used: &used,
|
||||
}
|
||||
state := calculateQuotaState(total, used)
|
||||
qta.State = &state
|
||||
|
||||
return qta, nil
|
||||
}
|
||||
|
||||
func calculateQuotaState(total int64, used int64) (state string) {
|
||||
percent := (float64(used) / float64(total)) * 100
|
||||
|
||||
switch {
|
||||
case percent <= float64(75):
|
||||
return "normal"
|
||||
case percent <= float64(90):
|
||||
return "nearing"
|
||||
case percent <= float64(99):
|
||||
return "critical"
|
||||
default:
|
||||
return "exceeded"
|
||||
}
|
||||
}
|
||||
|
||||
func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota {
|
||||
switch {
|
||||
case quota != nil && quota.Total != nil:
|
||||
@@ -471,5 +488,4 @@ func getQuota(quota *msgraph.Quota, defaultQuota string) *provider.Quota {
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user