mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Fix bug what updating org quota doesn't work
3c330c8e4c/pkg/services/sqlstore/quota.go (L106)
In the real use case, `has` that is described by the above code is always `false` because it includes `Updated` in a query.
So this commit fixes this issue.
This commit is contained in:
@@ -99,14 +99,14 @@ 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,
|
Target: cmd.Target,
|
||||||
OrgId: cmd.OrgId,
|
OrgId: cmd.OrgId,
|
||||||
Updated: time.Now(),
|
|
||||||
}
|
}
|
||||||
has, err := sess.Get("a)
|
has, err := sess.Get("a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
quota.Updated = time.Now()
|
||||||
quota.Limit = cmd.Limit
|
quota.Limit = cmd.Limit
|
||||||
if !has {
|
if !has {
|
||||||
quota.Created = time.Now()
|
quota.Created = time.Now()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package sqlstore
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
m "github.com/grafana/grafana/pkg/models"
|
m "github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
@@ -168,5 +169,36 @@ func TestQuotaCommandsAndQueries(t *testing.T) {
|
|||||||
So(query.Result.Limit, ShouldEqual, 5)
|
So(query.Result.Limit, ShouldEqual, 5)
|
||||||
So(query.Result.Used, ShouldEqual, 1)
|
So(query.Result.Used, ShouldEqual, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Should org quota updating is successful even if it called multiple time", func() {
|
||||||
|
orgCmd := m.UpdateOrgQuotaCmd{
|
||||||
|
OrgId: orgId,
|
||||||
|
Target: "org_user",
|
||||||
|
Limit: 5,
|
||||||
|
}
|
||||||
|
err := UpdateOrgQuota(&orgCmd)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
query := m.GetOrgQuotaByTargetQuery{OrgId: orgId, Target: "org_user", Default: 1}
|
||||||
|
err = GetOrgQuotaByTarget(&query)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(query.Result.Limit, ShouldEqual, 5)
|
||||||
|
|
||||||
|
// XXX: resolution of `Updated` column is 1sec, so this makes delay
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
orgCmd = m.UpdateOrgQuotaCmd{
|
||||||
|
OrgId: orgId,
|
||||||
|
Target: "org_user",
|
||||||
|
Limit: 10,
|
||||||
|
}
|
||||||
|
err = UpdateOrgQuota(&orgCmd)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
query = m.GetOrgQuotaByTargetQuery{OrgId: orgId, Target: "org_user", Default: 1}
|
||||||
|
err = GetOrgQuotaByTarget(&query)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(query.Result.Limit, ShouldEqual, 10)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user