add quota middleware to enforce quotas. issue #321
Conflicts: pkg/api/api.go
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user