2015-07-20 07:51:27 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2015-09-10 12:51:12 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2015-07-20 07:51:27 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func GetOrgQuotas(c *middleware.Context) Response {
|
2015-09-10 12:51:12 -05:00
|
|
|
if !setting.Quota.Enabled {
|
|
|
|
return ApiError(404, "Quotas not enabled", nil)
|
|
|
|
}
|
2015-07-20 07:51:27 -05:00
|
|
|
query := m.GetQuotasQuery{OrgId: c.ParamsInt64(":orgId")}
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
|
return ApiError(500, "Failed to get org quotas", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Json(200, query.Result)
|
|
|
|
}
|
|
|
|
|
2015-09-10 12:47:33 -05:00
|
|
|
// allow users to query the quotas of their own org.
|
|
|
|
func GetQuotas(c *middleware.Context) Response {
|
2015-09-10 12:51:12 -05:00
|
|
|
if !setting.Quota.Enabled {
|
|
|
|
return ApiError(404, "Quotas not enabled", nil)
|
|
|
|
}
|
2015-09-10 12:47:33 -05:00
|
|
|
query := m.GetQuotasQuery{OrgId: c.OrgId}
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
|
return ApiError(500, "Failed to get quotas", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Json(200, query.Result)
|
|
|
|
}
|
|
|
|
|
2015-07-20 07:51:27 -05:00
|
|
|
func UpdateOrgQuota(c *middleware.Context, cmd m.UpdateQuotaCmd) Response {
|
2015-09-10 12:51:12 -05:00
|
|
|
if !setting.Quota.Enabled {
|
|
|
|
return ApiError(404, "Quotas not enabled", nil)
|
|
|
|
}
|
2015-07-20 07:51:27 -05:00
|
|
|
cmd.OrgId = c.ParamsInt64(":orgId")
|
|
|
|
cmd.Target = m.QuotaTarget(c.Params(":target"))
|
2015-07-21 05:30:31 -05:00
|
|
|
|
|
|
|
if !cmd.Target.IsValid() {
|
|
|
|
return ApiError(404, "Invalid quota target", nil)
|
|
|
|
}
|
|
|
|
|
2015-07-20 07:51:27 -05:00
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
|
|
|
return ApiError(500, "Failed to update org quotas", err)
|
|
|
|
}
|
|
|
|
return ApiSuccess("Organization quota updated")
|
|
|
|
}
|