From fabed476f7c492f5b344fd2996357986f6532fdc Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Fri, 15 Oct 2021 11:13:57 +0200 Subject: [PATCH] calculate quota stage --- changelog/unreleased/report-quota-states.md | 5 +++++ graph/pkg/service/v0/drives.go | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/report-quota-states.md diff --git a/changelog/unreleased/report-quota-states.md b/changelog/unreleased/report-quota-states.md new file mode 100644 index 000000000..4cc6f6097 --- /dev/null +++ b/changelog/unreleased/report-quota-states.md @@ -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 diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index a40288a8f..3507d68e6 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -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 } - }