|
@@ -2,6 +2,7 @@ package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
@@ -98,8 +99,9 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error {
|
|
|
return inTransaction(func(sess *DBSession) error {
|
|
return inTransaction(func(sess *DBSession) error {
|
|
|
//Check if quota is already defined in the DB
|
|
//Check if quota is already defined in the DB
|
|
|
quota := m.Quota{
|
|
quota := m.Quota{
|
|
|
- Target: cmd.Target,
|
|
|
|
|
- OrgId: cmd.OrgId,
|
|
|
|
|
|
|
+ Target: cmd.Target,
|
|
|
|
|
+ OrgId: cmd.OrgId,
|
|
|
|
|
+ Updated: time.Now(),
|
|
|
}
|
|
}
|
|
|
has, err := sess.Get("a)
|
|
has, err := sess.Get("a)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -107,6 +109,7 @@ func UpdateOrgQuota(cmd *m.UpdateOrgQuotaCmd) error {
|
|
|
}
|
|
}
|
|
|
quota.Limit = cmd.Limit
|
|
quota.Limit = cmd.Limit
|
|
|
if has == false {
|
|
if has == false {
|
|
|
|
|
+ quota.Created = time.Now()
|
|
|
//No quota in the DB for this target, so create a new one.
|
|
//No quota in the DB for this target, so create a new one.
|
|
|
if _, err := sess.Insert("a); err != nil {
|
|
if _, err := sess.Insert("a); err != nil {
|
|
|
return err
|
|
return err
|
|
@@ -198,8 +201,9 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error {
|
|
|
return inTransaction(func(sess *DBSession) error {
|
|
return inTransaction(func(sess *DBSession) error {
|
|
|
//Check if quota is already defined in the DB
|
|
//Check if quota is already defined in the DB
|
|
|
quota := m.Quota{
|
|
quota := m.Quota{
|
|
|
- Target: cmd.Target,
|
|
|
|
|
- UserId: cmd.UserId,
|
|
|
|
|
|
|
+ Target: cmd.Target,
|
|
|
|
|
+ UserId: cmd.UserId,
|
|
|
|
|
+ Updated: time.Now(),
|
|
|
}
|
|
}
|
|
|
has, err := sess.Get("a)
|
|
has, err := sess.Get("a)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -207,6 +211,7 @@ func UpdateUserQuota(cmd *m.UpdateUserQuotaCmd) error {
|
|
|
}
|
|
}
|
|
|
quota.Limit = cmd.Limit
|
|
quota.Limit = cmd.Limit
|
|
|
if has == false {
|
|
if has == false {
|
|
|
|
|
+ quota.Created = time.Now()
|
|
|
//No quota in the DB for this target, so create a new one.
|
|
//No quota in the DB for this target, so create a new one.
|
|
|
if _, err := sess.Insert("a); err != nil {
|
|
if _, err := sess.Insert("a); err != nil {
|
|
|
return err
|
|
return err
|