add quota middleware to enforce quotas. issue #321
Conflicts: pkg/api/api.go
This commit is contained in:
@@ -253,3 +253,16 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
|
||||
|
||||
ctx.JSON(status, resp)
|
||||
}
|
||||
|
||||
func LimitQuota(target m.QuotaTarget) macaron.Handler {
|
||||
return func(c *Context) {
|
||||
limitReached, err := m.QuotaReached(c.OrgId, target)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "failed to get quota", err)
|
||||
}
|
||||
if limitReached {
|
||||
c.JsonApiErr(403, "Quota reached", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user