add quota middleware to enforce quotas. issue #321

Conflicts:
	pkg/api/api.go
This commit is contained in:
woodsaj
2015-09-11 01:03:47 +08:00
parent 9023171940
commit 0688050552
4 changed files with 41 additions and 2 deletions
+12
View File
@@ -1,6 +1,7 @@
package models
import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/setting"
"time"
)
@@ -61,3 +62,14 @@ type UpdateQuotaCmd struct {
Limit int64 `json:"limit"`
OrgId int64 `json:"-"`
}
func QuotaReached(org_id int64, target QuotaTarget) (bool, error) {
query := GetQuotaByTargetQuery{OrgId: org_id, Target: target}
if err := bus.Dispatch(&query); err != nil {
return true, err
}
if query.Result.Used >= query.Result.Limit {
return true, nil
}
return false, nil
}