Commit 52c154a2 by Arve Knudsen Committed by GitHub

Backend: Rename variables for style conformance (#29097)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
parent 94840b3a
......@@ -56,14 +56,14 @@ func UpdateDashboardPermissions(c *models.ReqContext, apiCmd dtos.UpdateDashboar
}
cmd := models.UpdateDashboardAclCommand{}
cmd.DashboardId = dashID
cmd.DashboardID = dashID
for _, item := range apiCmd.Items {
cmd.Items = append(cmd.Items, &models.DashboardAcl{
OrgId: c.OrgId,
DashboardId: dashID,
UserId: item.UserId,
TeamId: item.TeamId,
OrgID: c.OrgId,
DashboardID: dashID,
UserID: item.UserID,
TeamID: item.TeamID,
Role: item.Role,
Permission: item.Permission,
Created: time.Now(),
......
......@@ -31,7 +31,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -69,7 +69,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -121,7 +121,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -154,7 +154,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -188,7 +188,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......
......@@ -7,8 +7,8 @@ type UpdateDashboardAclCommand struct {
}
type DashboardAclUpdateItem struct {
UserId int64 `json:"userId"`
TeamId int64 `json:"teamId"`
UserID int64 `json:"userId"`
TeamID int64 `json:"teamId"`
Role *models.RoleType `json:"role,omitempty"`
Permission models.PermissionType `json:"permission"`
}
......@@ -67,14 +67,14 @@ func UpdateFolderPermissions(c *models.ReqContext, apiCmd dtos.UpdateDashboardAc
}
cmd := models.UpdateDashboardAclCommand{}
cmd.DashboardId = folder.Id
cmd.DashboardID = folder.Id
for _, item := range apiCmd.Items {
cmd.Items = append(cmd.Items, &models.DashboardAcl{
OrgId: c.OrgId,
DashboardId: folder.Id,
UserId: item.UserId,
TeamId: item.TeamId,
OrgID: c.OrgId,
DashboardID: folder.Id,
UserID: item.UserID,
TeamID: item.TeamID,
Role: item.Role,
Permission: item.Permission,
Created: time.Now(),
......
......@@ -33,7 +33,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -70,7 +70,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -122,7 +122,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -162,7 +162,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......@@ -198,7 +198,7 @@ func TestFolderPermissionAPIEndpoint(t *testing.T) {
cmd := dtos.UpdateDashboardAclCommand{
Items: []dtos.DashboardAclUpdateItem{
{UserId: 1000, Permission: models.PERMISSION_ADMIN},
{UserID: 1000, Permission: models.PERMISSION_ADMIN},
},
}
......
......@@ -12,9 +12,9 @@ type FakeGrafanaComClient struct {
ListAllPluginsFunc func(repoUrl string) (models.PluginRepo, error)
}
func (client *FakeGrafanaComClient) GetPlugin(pluginId, repoUrl string) (models.Plugin, error) {
func (client *FakeGrafanaComClient) GetPlugin(pluginID, repoUrl string) (models.Plugin, error) {
if client.GetPluginFunc != nil {
return client.GetPluginFunc(pluginId, repoUrl)
return client.GetPluginFunc(pluginID, repoUrl)
}
return models.Plugin{}, nil
......@@ -28,9 +28,9 @@ func (client *FakeGrafanaComClient) DownloadFile(pluginName string, tmpFile *os.
return nil
}
func (client *FakeGrafanaComClient) ListAllPlugins(repoUrl string) (models.PluginRepo, error) {
func (client *FakeGrafanaComClient) ListAllPlugins(repoURL string) (models.PluginRepo, error) {
if client.ListAllPluginsFunc != nil {
return client.ListAllPluginsFunc(repoUrl)
return client.ListAllPluginsFunc(repoURL)
}
return models.PluginRepo{}, nil
}
......@@ -132,11 +132,11 @@ func InstallPlugin(pluginName, version string, c utils.CommandLine, client utils
res, _ := services.ReadPlugin(pluginFolder, pluginName)
for _, v := range res.Dependencies.Plugins {
if err := InstallPlugin(v.Id, "", c, client); err != nil {
return errutil.Wrapf(err, "failed to install plugin '%s'", v.Id)
if err := InstallPlugin(v.ID, "", c, client); err != nil {
return errutil.Wrapf(err, "failed to install plugin '%s'", v.ID)
}
logger.Infof("Installed dependency: %v ✔\n", v.Id)
logger.Infof("Installed dependency: %v ✔\n", v.ID)
}
return err
......
......@@ -99,12 +99,12 @@ func TestInstallPluginCommand(t *testing.T) {
GetPluginFunc: func(pluginId, repoUrl string) (models.Plugin, error) {
require.Equal(t, "test-plugin-panel", pluginId)
plugin := models.Plugin{
Id: "test-plugin-panel",
ID: "test-plugin-panel",
Category: "",
Versions: []models.Version{
{
Commit: "commit",
Url: "url",
URL: "url",
Version: "1.0.0",
Arch: map[string]models.ArchMeta{
fmt.Sprintf("%s-%s", runtime.GOOS, runtime.GOARCH): {
......@@ -237,7 +237,7 @@ type versionArg struct {
func makePluginWithVersions(versions ...versionArg) *models.Plugin {
plugin := &models.Plugin{
Id: "",
ID: "",
Category: "",
Versions: []models.Version{},
}
......@@ -246,7 +246,7 @@ func makePluginWithVersions(versions ...versionArg) *models.Plugin {
ver := models.Version{
Version: version.Version,
Commit: fmt.Sprintf("commit_%s", version.Version),
Url: fmt.Sprintf("url_%s", version.Version),
URL: fmt.Sprintf("url_%s", version.Version),
}
if version.Arch != nil {
ver.Arch = map[string]models.ArchMeta{}
......
......@@ -18,7 +18,7 @@ func (cmd Command) listRemoteCommand(c utils.CommandLine) error {
if len(plugin.Versions) > 0 {
ver := latestSupportedVersion(&plugin)
if ver != nil {
logger.Infof("id: %v version: %s\n", plugin.Id, ver.Version)
logger.Infof("id: %v version: %s\n", plugin.ID, ver.Version)
}
}
}
......
......@@ -47,7 +47,7 @@ func (cmd Command) lsCommand(c utils.CommandLine) error {
}
for _, plugin := range plugins {
logger.Infof("%s %s %s\n", plugin.Id, color.YellowString("@"), plugin.Info.Version)
logger.Infof("%s %s %s\n", plugin.ID, color.YellowString("@"), plugin.Info.Version)
}
return nil
......
......@@ -37,7 +37,7 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
for _, localPlugin := range localPlugins {
for _, p := range remotePlugins.Plugins {
remotePlugin := p
if localPlugin.Id != remotePlugin.Id {
if localPlugin.ID != remotePlugin.ID {
continue
}
if shouldUpgrade(localPlugin.Info.Version, &remotePlugin) {
......@@ -47,14 +47,14 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
}
for _, p := range pluginsToUpgrade {
logger.Infof("Updating %v \n", p.Id)
logger.Infof("Updating %v \n", p.ID)
err := services.RemoveInstalledPlugin(pluginsDir, p.Id)
err := services.RemoveInstalledPlugin(pluginsDir, p.ID)
if err != nil {
return err
}
err = InstallPlugin(p.Id, "", c, cmd.Client)
err = InstallPlugin(p.ID, "", c, cmd.Client)
if err != nil {
return err
}
......
......@@ -5,7 +5,7 @@ import (
)
type InstalledPlugin struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
......@@ -24,14 +24,14 @@ type PluginInfo struct {
}
type Plugin struct {
Id string `json:"id"`
ID string `json:"id"`
Category string `json:"category"`
Versions []Version `json:"versions"`
}
type Version struct {
Commit string `json:"commit"`
Url string `json:"url"`
URL string `json:"url"`
Version string `json:"version"`
// os-arch to md5 checksum to check when downloading the file
Arch map[string]ArchMeta `json:"arch"`
......
......@@ -84,7 +84,7 @@ func ReadPlugin(pluginDir, pluginName string) (models.InstalledPlugin, error) {
res.Info.Version = "0.0.0"
}
if res.Id == "" {
if res.ID == "" {
return models.InstalledPlugin{}, errors.New("could not find plugin " + pluginName + " in " + pluginDir)
}
......
......@@ -23,19 +23,19 @@ import (
type FileLogWriter struct {
mw *MuxWriter
Format log15.Format
Filename string
Maxlines int
maxlines_curlines int
Format log15.Format
Filename string
Maxlines int
maxlinesCurlines int
// Rotate at size
Maxsize int
maxsize_cursize int
Maxsize int
maxsizeCursize int
// Rotate daily
Daily bool
Maxdays int64
daily_opendate int
Daily bool
Maxdays int64
dailyOpendate int
Rotate bool
startLock sync.Mutex
......@@ -105,16 +105,16 @@ func (w *FileLogWriter) StartLogger() error {
func (w *FileLogWriter) docheck(size int) {
w.startLock.Lock()
defer w.startLock.Unlock()
if w.Rotate && ((w.Maxlines > 0 && w.maxlines_curlines >= w.Maxlines) ||
(w.Maxsize > 0 && w.maxsize_cursize >= w.Maxsize) ||
(w.Daily && time.Now().Day() != w.daily_opendate)) {
if w.Rotate && ((w.Maxlines > 0 && w.maxlinesCurlines >= w.Maxlines) ||
(w.Maxsize > 0 && w.maxsizeCursize >= w.Maxsize) ||
(w.Daily && time.Now().Day() != w.dailyOpendate)) {
if err := w.DoRotate(); err != nil {
fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err)
return
}
}
w.maxlines_curlines++
w.maxsize_cursize += size
w.maxlinesCurlines++
w.maxsizeCursize += size
}
func (w *FileLogWriter) createLogFile() (*os.File, error) {
......@@ -152,16 +152,16 @@ func (w *FileLogWriter) initFd() error {
if err != nil {
return fmt.Errorf("get stat: %s", err)
}
w.maxsize_cursize = int(finfo.Size())
w.daily_opendate = time.Now().Day()
w.maxsizeCursize = int(finfo.Size())
w.dailyOpendate = time.Now().Day()
if finfo.Size() > 0 {
count, err := w.lineCounter()
if err != nil {
return err
}
w.maxlines_curlines = count
w.maxlinesCurlines = count
} else {
w.maxlines_curlines = 0
w.maxlinesCurlines = 0
}
return nil
}
......
......@@ -32,7 +32,7 @@ func TestLogFile(t *testing.T) {
err := fileLogWrite.Init()
require.NoError(t, err)
assert.Zero(t, fileLogWrite.maxlines_curlines)
assert.Zero(t, fileLogWrite.maxlinesCurlines)
t.Run("adding lines", func(t *testing.T) {
err := fileLogWrite.WriteLine("test1\n")
......@@ -42,6 +42,6 @@ func TestLogFile(t *testing.T) {
err = fileLogWrite.WriteLine("test3\n")
require.NoError(t, err)
assert.Equal(t, 3, fileLogWrite.maxlines_curlines)
assert.Equal(t, 3, fileLogWrite.maxlinesCurlines)
})
}
......@@ -27,7 +27,6 @@ func (im *InternalMetricsService) readSettings() error {
func (im *InternalMetricsService) parseGraphiteSettings() error {
graphiteSection, err := im.Cfg.Raw.GetSection("metrics.graphite")
if err != nil {
return nil
}
......
package serverlock
type serverLock struct {
// nolint:stylecheck
Id int64
OperationUid string
OperationUID string `xorm:"operation_uid"`
LastExecution int64
Version int64
}
......@@ -98,7 +98,7 @@ func (sl *ServerLockService) getOrCreate(ctx context.Context, actionName string)
}
lockRow := &serverLock{
OperationUid: actionName,
OperationUID: actionName,
LastExecution: 0,
}
......
......@@ -36,7 +36,7 @@ func TestServerLock(t *testing.T) {
for i := 0; i < 3; i++ {
latest, err = sl.getOrCreate(context.Background(), operationUID)
require.NoError(t, err)
assert.Equal(t, operationUID, first.OperationUid)
assert.Equal(t, operationUID, first.OperationUID)
assert.Equal(t, int64(1), first.Id)
}
......
......@@ -32,12 +32,13 @@ var (
// Dashboard ACL model
type DashboardAcl struct {
// nolint:stylecheck
Id int64
OrgId int64
DashboardId int64
OrgID int64 `xorm:"org_id"`
DashboardID int64 `xorm:"dashboard_id"`
UserId int64
TeamId int64
UserID int64 `xorm:"user_id"`
TeamID int64 `xorm:"team_id"`
Role *RoleType // pointer to be nullable
Permission PermissionType
......@@ -98,7 +99,7 @@ func (dto *DashboardAclInfoDTO) IsDuplicateOf(other *DashboardAclInfoDTO) bool {
//
type UpdateDashboardAclCommand struct {
DashboardId int64
DashboardID int64
Items []*DashboardAcl
}
......@@ -106,7 +107,7 @@ type UpdateDashboardAclCommand struct {
// QUERIES
//
type GetDashboardAclInfoListQuery struct {
DashboardId int64
OrgId int64
DashboardID int64
OrgID int64
Result []*DashboardAclInfoDTO
}
......@@ -7,15 +7,15 @@ import (
"github.com/grafana/grafana/pkg/models"
)
func MakeUserAdmin(bus bus.Bus, orgId int64, userId int64, dashboardId int64, setViewAndEditPermissions bool) error {
func MakeUserAdmin(bus bus.Bus, orgID int64, userID int64, dashboardID int64, setViewAndEditPermissions bool) error {
rtEditor := models.ROLE_EDITOR
rtViewer := models.ROLE_VIEWER
items := []*models.DashboardAcl{
{
OrgId: orgId,
DashboardId: dashboardId,
UserId: userId,
OrgID: orgID,
DashboardID: dashboardID,
UserID: userID,
Permission: models.PERMISSION_ADMIN,
Created: time.Now(),
Updated: time.Now(),
......@@ -25,16 +25,16 @@ func MakeUserAdmin(bus bus.Bus, orgId int64, userId int64, dashboardId int64, se
if setViewAndEditPermissions {
items = append(items,
&models.DashboardAcl{
OrgId: orgId,
DashboardId: dashboardId,
OrgID: orgID,
DashboardID: dashboardID,
Role: &rtEditor,
Permission: models.PERMISSION_EDIT,
Created: time.Now(),
Updated: time.Now(),
},
&models.DashboardAcl{
OrgId: orgId,
DashboardId: dashboardId,
OrgID: orgID,
DashboardID: dashboardID,
Role: &rtViewer,
Permission: models.PERMISSION_VIEW,
Created: time.Now(),
......@@ -44,7 +44,7 @@ func MakeUserAdmin(bus bus.Bus, orgId int64, userId int64, dashboardId int64, se
}
aclCmd := &models.UpdateDashboardAclCommand{
DashboardId: dashboardId,
DashboardID: dashboardID,
Items: items,
}
......
......@@ -147,7 +147,7 @@ func (g *dashboardGuardianImpl) CheckPermissionBeforeUpdate(permission models.Pe
// validate that duplicate permissions don't exists
for _, p := range updatePermissions {
aclItem := &models.DashboardAclInfoDTO{DashboardId: p.DashboardId, UserId: p.UserId, TeamId: p.TeamId, Role: p.Role, Permission: p.Permission}
aclItem := &models.DashboardAclInfoDTO{DashboardId: p.DashboardID, UserId: p.UserID, TeamId: p.TeamID, Role: p.Role, Permission: p.Permission}
if aclItem.IsDuplicateOf(everyoneWithAdminRole) {
return false, ErrGuardianPermissionExists
}
......@@ -192,7 +192,7 @@ func (g *dashboardGuardianImpl) GetAcl() ([]*models.DashboardAclInfoDTO, error)
return g.acl, nil
}
query := models.GetDashboardAclInfoListQuery{DashboardId: g.dashId, OrgId: g.orgId}
query := models.GetDashboardAclInfoListQuery{DashboardID: g.dashId, OrgID: g.orgId}
if err := bus.Dispatch(&query); err != nil {
return nil, err
}
......
......@@ -73,11 +73,11 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext, per
bus.ClearBusHandlers()
bus.AddHandler("test", func(query *models.GetDashboardAclInfoListQuery) error {
if query.OrgId != sc.givenUser.OrgId {
sc.reportFailure("Invalid organization id for GetDashboardAclInfoListQuery", sc.givenUser.OrgId, query.OrgId)
if query.OrgID != sc.givenUser.OrgId {
sc.reportFailure("Invalid organization id for GetDashboardAclInfoListQuery", sc.givenUser.OrgId, query.OrgID)
}
if query.DashboardId != sc.givenDashboardID {
sc.reportFailure("Invalid dashboard id for GetDashboardAclInfoListQuery", sc.givenDashboardID, query.DashboardId)
if query.DashboardID != sc.givenDashboardID {
sc.reportFailure("Invalid dashboard id for GetDashboardAclInfoListQuery", sc.givenDashboardID, query.DashboardID)
}
query.Result = permissions
......@@ -230,14 +230,14 @@ func (sc *scenarioContext) reportFailure(desc string, expected interface{}, actu
if p.Role != nil {
r = string(*p.Role)
}
buf.WriteString(fmt.Sprintf("\n Update permission (%d): dashboardId=%d, userId=%d, teamId=%d, role=%v, permission=%s", i, p.DashboardId, p.UserId, p.TeamId, r, p.Permission.String()))
buf.WriteString(fmt.Sprintf("\n Update permission (%d): dashboardId=%d, userId=%d, teamId=%d, role=%v, permission=%s", i, p.DashboardID, p.UserID, p.TeamID, r, p.Permission.String()))
}
sc.t.Fatalf(buf.String())
}
func newCustomUserPermission(dashboardID int64, userID int64, permission models.PermissionType) *models.DashboardAcl {
return &models.DashboardAcl{OrgId: orgID, DashboardId: dashboardID, UserId: userID, Permission: permission}
return &models.DashboardAcl{OrgID: orgID, DashboardID: dashboardID, UserID: userID, Permission: permission}
}
func newDefaultUserPermission(dashboardID int64, permission models.PermissionType) *models.DashboardAcl {
......@@ -245,7 +245,7 @@ func newDefaultUserPermission(dashboardID int64, permission models.PermissionTyp
}
func newCustomTeamPermission(dashboardID int64, teamID int64, permission models.PermissionType) *models.DashboardAcl {
return &models.DashboardAcl{OrgId: orgID, DashboardId: dashboardID, TeamId: teamID, Permission: permission}
return &models.DashboardAcl{OrgID: orgID, DashboardID: dashboardID, TeamID: teamID, Permission: permission}
}
func newDefaultTeamPermission(dashboardID int64, permission models.PermissionType) *models.DashboardAcl {
......@@ -253,23 +253,23 @@ func newDefaultTeamPermission(dashboardID int64, permission models.PermissionTyp
}
func newAdminRolePermission(dashboardID int64, permission models.PermissionType) *models.DashboardAcl {
return &models.DashboardAcl{OrgId: orgID, DashboardId: dashboardID, Role: &adminRole, Permission: permission}
return &models.DashboardAcl{OrgID: orgID, DashboardID: dashboardID, Role: &adminRole, Permission: permission}
}
func newEditorRolePermission(dashboardID int64, permission models.PermissionType) *models.DashboardAcl {
return &models.DashboardAcl{OrgId: orgID, DashboardId: dashboardID, Role: &editorRole, Permission: permission}
return &models.DashboardAcl{OrgID: orgID, DashboardID: dashboardID, Role: &editorRole, Permission: permission}
}
func newViewerRolePermission(dashboardID int64, permission models.PermissionType) *models.DashboardAcl {
return &models.DashboardAcl{OrgId: orgID, DashboardId: dashboardID, Role: &viewerRole, Permission: permission}
return &models.DashboardAcl{OrgID: orgID, DashboardID: dashboardID, Role: &viewerRole, Permission: permission}
}
func toDto(acl *models.DashboardAcl) *models.DashboardAclInfoDTO {
return &models.DashboardAclInfoDTO{
OrgId: acl.OrgId,
DashboardId: acl.DashboardId,
UserId: acl.UserId,
TeamId: acl.TeamId,
OrgId: acl.OrgID,
DashboardId: acl.DashboardID,
UserId: acl.UserID,
TeamId: acl.TeamID,
Role: acl.Role,
Permission: acl.Permission,
PermissionName: acl.Permission.String(),
......
......@@ -13,17 +13,17 @@ func init() {
func UpdateDashboardAcl(cmd *models.UpdateDashboardAclCommand) error {
return inTransaction(func(sess *DBSession) error {
// delete existing items
_, err := sess.Exec("DELETE FROM dashboard_acl WHERE dashboard_id=?", cmd.DashboardId)
_, err := sess.Exec("DELETE FROM dashboard_acl WHERE dashboard_id=?", cmd.DashboardID)
if err != nil {
return err
}
for _, item := range cmd.Items {
if item.UserId == 0 && item.TeamId == 0 && (item.Role == nil || !item.Role.IsValid()) {
if item.UserID == 0 && item.TeamID == 0 && (item.Role == nil || !item.Role.IsValid()) {
return models.ErrDashboardAclInfoMissing
}
if item.DashboardId == 0 {
if item.DashboardID == 0 {
return models.ErrDashboardPermissionDashboardEmpty
}
......@@ -35,7 +35,7 @@ func UpdateDashboardAcl(cmd *models.UpdateDashboardAclCommand) error {
// Update dashboard HasAcl flag
dashboard := models.Dashboard{HasAcl: true}
_, err = sess.Cols("has_acl").Where("id=?", cmd.DashboardId).Update(&dashboard)
_, err = sess.Cols("has_acl").Where("id=?", cmd.DashboardID).Update(&dashboard)
return err
})
}
......@@ -50,7 +50,7 @@ func GetDashboardAclInfoList(query *models.GetDashboardAclInfoListQuery) error {
falseStr := dialect.BooleanStr(false)
if query.DashboardId == 0 {
if query.DashboardID == 0 {
sql := `SELECT
da.id,
da.org_id,
......@@ -114,7 +114,7 @@ func GetDashboardAclInfoList(query *models.GetDashboardAclInfoListQuery) error {
`
query.Result = make([]*models.DashboardAclInfoDTO, 0)
err = x.SQL(rawSQL, query.OrgId, query.DashboardId).Find(&query.Result)
err = x.SQL(rawSQL, query.OrgID, query.DashboardID).Find(&query.Result)
}
for _, p := range query.Result {
......
......@@ -19,8 +19,8 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("When adding dashboard permission with userId and teamId set to 0", func() {
err := testHelperUpdateDashboardAcl(savedFolder.Id, models.DashboardAcl{
OrgId: 1,
DashboardId: savedFolder.Id,
OrgID: 1,
DashboardID: savedFolder.Id,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldEqual, models.ErrDashboardAclInfoMissing)
......@@ -28,7 +28,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Given dashboard folder with default permissions", func() {
Convey("When reading folder acl should include default acl", func() {
query := models.GetDashboardAclInfoListQuery{DashboardId: savedFolder.Id, OrgId: 1}
query := models.GetDashboardAclInfoListQuery{DashboardID: savedFolder.Id, OrgID: 1}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
......@@ -44,7 +44,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
})
Convey("When reading dashboard acl should include acl for parent folder", func() {
query := models.GetDashboardAclInfoListQuery{DashboardId: childDash.Id, OrgId: 1}
query := models.GetDashboardAclInfoListQuery{DashboardID: childDash.Id, OrgID: 1}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
......@@ -62,13 +62,13 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Given dashboard folder with removed default permissions", func() {
err := UpdateDashboardAcl(&models.UpdateDashboardAclCommand{
DashboardId: savedFolder.Id,
DashboardID: savedFolder.Id,
Items: []*models.DashboardAcl{},
})
So(err, ShouldBeNil)
Convey("When reading dashboard acl should return no acl items", func() {
query := models.GetDashboardAclInfoListQuery{DashboardId: childDash.Id, OrgId: 1}
query := models.GetDashboardAclInfoListQuery{DashboardID: childDash.Id, OrgID: 1}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
......@@ -79,15 +79,15 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Given dashboard folder permission", func() {
err := testHelperUpdateDashboardAcl(savedFolder.Id, models.DashboardAcl{
OrgId: 1,
UserId: currentUser.Id,
DashboardId: savedFolder.Id,
OrgID: 1,
UserID: currentUser.Id,
DashboardID: savedFolder.Id,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
Convey("When reading dashboard acl should include acl for parent folder", func() {
query := models.GetDashboardAclInfoListQuery{DashboardId: childDash.Id, OrgId: 1}
query := models.GetDashboardAclInfoListQuery{DashboardID: childDash.Id, OrgID: 1}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
......@@ -98,15 +98,15 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Given child dashboard permission", func() {
err := testHelperUpdateDashboardAcl(childDash.Id, models.DashboardAcl{
OrgId: 1,
UserId: currentUser.Id,
DashboardId: childDash.Id,
OrgID: 1,
UserID: currentUser.Id,
DashboardID: childDash.Id,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
Convey("When reading dashboard acl should include acl for parent folder and child", func() {
query := models.GetDashboardAclInfoListQuery{OrgId: 1, DashboardId: childDash.Id}
query := models.GetDashboardAclInfoListQuery{OrgID: 1, DashboardID: childDash.Id}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
......@@ -122,15 +122,15 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Given child dashboard permission in folder with no permissions", func() {
err := testHelperUpdateDashboardAcl(childDash.Id, models.DashboardAcl{
OrgId: 1,
UserId: currentUser.Id,
DashboardId: childDash.Id,
OrgID: 1,
UserID: currentUser.Id,
DashboardID: childDash.Id,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
Convey("When reading dashboard acl should include default acl for parent folder and the child acl", func() {
query := models.GetDashboardAclInfoListQuery{OrgId: 1, DashboardId: childDash.Id}
query := models.GetDashboardAclInfoListQuery{OrgID: 1, DashboardID: childDash.Id}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
......@@ -150,14 +150,14 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Should be able to add dashboard permission", func() {
err := testHelperUpdateDashboardAcl(savedFolder.Id, models.DashboardAcl{
OrgId: 1,
UserId: currentUser.Id,
DashboardId: savedFolder.Id,
OrgID: 1,
UserID: currentUser.Id,
DashboardID: savedFolder.Id,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
q1 := &models.GetDashboardAclInfoListQuery{DashboardId: savedFolder.Id, OrgId: 1}
q1 := &models.GetDashboardAclInfoListQuery{DashboardID: savedFolder.Id, OrgID: 1}
err = GetDashboardAclInfoList(q1)
So(err, ShouldBeNil)
......@@ -172,7 +172,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
err := testHelperUpdateDashboardAcl(savedFolder.Id)
So(err, ShouldBeNil)
q3 := &models.GetDashboardAclInfoListQuery{DashboardId: savedFolder.Id, OrgId: 1}
q3 := &models.GetDashboardAclInfoListQuery{DashboardID: savedFolder.Id, OrgID: 1}
err = GetDashboardAclInfoList(q3)
So(err, ShouldBeNil)
So(len(q3.Result), ShouldEqual, 0)
......@@ -186,14 +186,14 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Should be able to add a user permission for a team", func() {
err := testHelperUpdateDashboardAcl(savedFolder.Id, models.DashboardAcl{
OrgId: 1,
TeamId: group1.Result.Id,
DashboardId: savedFolder.Id,
OrgID: 1,
TeamID: group1.Result.Id,
DashboardID: savedFolder.Id,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
q1 := &models.GetDashboardAclInfoListQuery{DashboardId: savedFolder.Id, OrgId: 1}
q1 := &models.GetDashboardAclInfoListQuery{DashboardID: savedFolder.Id, OrgID: 1}
err = GetDashboardAclInfoList(q1)
So(err, ShouldBeNil)
So(q1.Result[0].DashboardId, ShouldEqual, savedFolder.Id)
......@@ -203,14 +203,14 @@ func TestDashboardAclDataAccess(t *testing.T) {
Convey("Should be able to update an existing permission for a team", func() {
err := testHelperUpdateDashboardAcl(savedFolder.Id, models.DashboardAcl{
OrgId: 1,
TeamId: group1.Result.Id,
DashboardId: savedFolder.Id,
OrgID: 1,
TeamID: group1.Result.Id,
DashboardID: savedFolder.Id,
Permission: models.PERMISSION_ADMIN,
})
So(err, ShouldBeNil)
q3 := &models.GetDashboardAclInfoListQuery{DashboardId: savedFolder.Id, OrgId: 1}
q3 := &models.GetDashboardAclInfoListQuery{DashboardID: savedFolder.Id, OrgID: 1}
err = GetDashboardAclInfoList(q3)
So(err, ShouldBeNil)
So(len(q3.Result), ShouldEqual, 1)
......@@ -225,7 +225,7 @@ func TestDashboardAclDataAccess(t *testing.T) {
var rootFolderId int64 = 0
Convey("When reading dashboard acl should return default permissions", func() {
query := models.GetDashboardAclInfoListQuery{DashboardId: rootFolderId, OrgId: 1}
query := models.GetDashboardAclInfoListQuery{DashboardID: rootFolderId, OrgID: 1}
err := GetDashboardAclInfoList(&query)
So(err, ShouldBeNil)
......
......@@ -41,9 +41,9 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("and acl is set for dashboard folder", func() {
var otherUser int64 = 999
err := testHelperUpdateDashboardAcl(folder.Id, models.DashboardAcl{
DashboardId: folder.Id,
OrgId: 1,
UserId: otherUser,
DashboardID: folder.Id,
OrgID: 1,
UserID: otherUser,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......@@ -62,7 +62,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("when the user is given permission", func() {
err := testHelperUpdateDashboardAcl(folder.Id, models.DashboardAcl{
DashboardId: folder.Id, OrgId: 1, UserId: currentUser.Id, Permission: models.PERMISSION_EDIT,
DashboardID: folder.Id, OrgID: 1, UserID: currentUser.Id, Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......@@ -105,7 +105,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
err := testHelperUpdateDashboardAcl(folder.Id)
So(err, ShouldBeNil)
err = testHelperUpdateDashboardAcl(childDash.Id, models.DashboardAcl{
DashboardId: folder.Id, OrgId: 1, UserId: otherUser, Permission: models.PERMISSION_EDIT,
DashboardID: folder.Id, OrgID: 1, UserID: otherUser, Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......@@ -120,7 +120,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
})
Convey("when the user is given permission to child", func() {
err := testHelperUpdateDashboardAcl(childDash.Id, models.DashboardAcl{DashboardId: childDash.Id, OrgId: 1, UserId: currentUser.Id, Permission: models.PERMISSION_EDIT})
err := testHelperUpdateDashboardAcl(childDash.Id, models.DashboardAcl{DashboardID: childDash.Id, OrgID: 1, UserID: currentUser.Id, Permission: models.PERMISSION_EDIT})
So(err, ShouldBeNil)
Convey("should be able to search for child dashboard but not folder", func() {
......@@ -181,7 +181,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("and acl is set for one dashboard folder", func() {
var otherUser int64 = 999
err := testHelperUpdateDashboardAcl(folder1.Id, models.DashboardAcl{
DashboardId: folder1.Id, OrgId: 1, UserId: otherUser, Permission: models.PERMISSION_EDIT,
DashboardID: folder1.Id, OrgID: 1, UserID: otherUser, Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......@@ -221,7 +221,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("and a dashboard with an acl is moved to the folder without an acl", func() {
err := testHelperUpdateDashboardAcl(childDash1.Id, models.DashboardAcl{
DashboardId: childDash1.Id, OrgId: 1, UserId: otherUser, Permission: models.PERMISSION_EDIT,
DashboardID: childDash1.Id, OrgID: 1, UserID: otherUser, Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......@@ -344,7 +344,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("Should have write access to one dashboard folder if default role changed to view for one folder", func() {
err := testHelperUpdateDashboardAcl(folder1.Id, models.DashboardAcl{
DashboardId: folder1.Id, OrgId: 1, UserId: editorUser.Id, Permission: models.PERMISSION_VIEW,
DashboardID: folder1.Id, OrgID: 1, UserID: editorUser.Id, Permission: models.PERMISSION_VIEW,
})
So(err, ShouldBeNil)
......@@ -408,7 +408,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("Should be able to get one dashboard folder if default role changed to edit for one folder", func() {
err := testHelperUpdateDashboardAcl(folder1.Id, models.DashboardAcl{
DashboardId: folder1.Id, OrgId: 1, UserId: viewerUser.Id, Permission: models.PERMISSION_EDIT,
DashboardID: folder1.Id, OrgID: 1, UserID: viewerUser.Id, Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......@@ -439,7 +439,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("and admin permission is given for user with org role viewer in one dashboard folder", func() {
err := testHelperUpdateDashboardAcl(folder1.Id, models.DashboardAcl{
DashboardId: folder1.Id, OrgId: 1, UserId: viewerUser.Id, Permission: models.PERMISSION_ADMIN,
DashboardID: folder1.Id, OrgID: 1, UserID: viewerUser.Id, Permission: models.PERMISSION_ADMIN,
})
So(err, ShouldBeNil)
......@@ -455,7 +455,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
Convey("and edit permission is given for user with org role viewer in one dashboard folder", func() {
err := testHelperUpdateDashboardAcl(folder1.Id, models.DashboardAcl{
DashboardId: folder1.Id, OrgId: 1, UserId: viewerUser.Id, Permission: models.PERMISSION_EDIT,
DashboardID: folder1.Id, OrgID: 1, UserID: viewerUser.Id, Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......
......@@ -287,10 +287,10 @@ func TestAccountDataAccess(t *testing.T) {
dash1 := insertTestDashboard(t, "1 test dash", ac1.OrgId, 0, false, "prod", "webapp")
dash2 := insertTestDashboard(t, "2 test dash", ac3.OrgId, 0, false, "prod", "webapp")
err = testHelperUpdateDashboardAcl(dash1.Id, models.DashboardAcl{DashboardId: dash1.Id, OrgId: ac1.OrgId, UserId: ac3.Id, Permission: models.PERMISSION_EDIT})
err = testHelperUpdateDashboardAcl(dash1.Id, models.DashboardAcl{DashboardID: dash1.Id, OrgID: ac1.OrgId, UserID: ac3.Id, Permission: models.PERMISSION_EDIT})
So(err, ShouldBeNil)
err = testHelperUpdateDashboardAcl(dash2.Id, models.DashboardAcl{DashboardId: dash2.Id, OrgId: ac3.OrgId, UserId: ac3.Id, Permission: models.PERMISSION_EDIT})
err = testHelperUpdateDashboardAcl(dash2.Id, models.DashboardAcl{DashboardID: dash2.Id, OrgID: ac3.OrgId, UserID: ac3.Id, Permission: models.PERMISSION_EDIT})
So(err, ShouldBeNil)
Convey("When org user is deleted", func() {
......@@ -299,7 +299,7 @@ func TestAccountDataAccess(t *testing.T) {
So(err, ShouldBeNil)
Convey("Should remove dependent permissions for deleted org user", func() {
permQuery := &models.GetDashboardAclInfoListQuery{DashboardId: 1, OrgId: ac1.OrgId}
permQuery := &models.GetDashboardAclInfoListQuery{DashboardID: 1, OrgID: ac1.OrgId}
err = GetDashboardAclInfoList(permQuery)
So(err, ShouldBeNil)
......@@ -307,7 +307,7 @@ func TestAccountDataAccess(t *testing.T) {
})
Convey("Should not remove dashboard permissions for same user in another org", func() {
permQuery := &models.GetDashboardAclInfoListQuery{DashboardId: 2, OrgId: ac3.OrgId}
permQuery := &models.GetDashboardAclInfoListQuery{DashboardID: 2, OrgID: ac3.OrgId}
err = GetDashboardAclInfoList(permQuery)
So(err, ShouldBeNil)
......@@ -323,7 +323,7 @@ func TestAccountDataAccess(t *testing.T) {
}
func testHelperUpdateDashboardAcl(dashboardId int64, items ...models.DashboardAcl) error {
cmd := models.UpdateDashboardAclCommand{DashboardId: dashboardId}
cmd := models.UpdateDashboardAclCommand{DashboardID: dashboardId}
for _, i := range items {
item := i
item.Created = time.Now()
......
......@@ -260,11 +260,11 @@ func createDummyDashboard(dashboardProps DashboardProps) (*models.Dashboard, err
func createDummyAcl(dashboardPermission *DashboardPermission, search Search, dashboardId int64) (int64, error) {
acl := &models.DashboardAcl{
OrgId: 1,
OrgID: 1,
Created: time.Now(),
Updated: time.Now(),
Permission: dashboardPermission.Permission,
DashboardId: dashboardId,
DashboardID: dashboardId,
}
var user *models.User
......@@ -275,7 +275,7 @@ func createDummyAcl(dashboardPermission *DashboardPermission, search Search, das
return 0, err
}
acl.UserId = user.Id
acl.UserID = user.Id
}
if dashboardPermission.Team {
......@@ -299,7 +299,7 @@ func createDummyAcl(dashboardPermission *DashboardPermission, search Search, das
}
}
acl.TeamId = team.Id
acl.TeamID = team.Id
}
if len(string(dashboardPermission.Role)) > 0 {
......@@ -307,7 +307,7 @@ func createDummyAcl(dashboardPermission *DashboardPermission, search Search, das
}
updateAclCmd := &models.UpdateDashboardAclCommand{
DashboardId: dashboardId,
DashboardID: dashboardId,
Items: []*models.DashboardAcl{acl},
}
err = UpdateDashboardAcl(updateAclCmd)
......
......@@ -242,7 +242,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
So(err, ShouldBeNil)
err = AddTeamMember(&models.AddTeamMemberCommand{OrgId: testOrgId, TeamId: groupId, UserId: userIds[2]})
So(err, ShouldBeNil)
err = testHelperUpdateDashboardAcl(1, models.DashboardAcl{DashboardId: 1, OrgId: testOrgId, Permission: models.PERMISSION_EDIT, TeamId: groupId})
err = testHelperUpdateDashboardAcl(1, models.DashboardAcl{DashboardID: 1, OrgID: testOrgId, Permission: models.PERMISSION_EDIT, TeamID: groupId})
So(err, ShouldBeNil)
err = DeleteTeam(&models.DeleteTeamCommand{OrgId: testOrgId, Id: groupId})
So(err, ShouldBeNil)
......@@ -251,7 +251,7 @@ func TestTeamCommandsAndQueries(t *testing.T) {
err = GetTeamById(query)
So(err, ShouldEqual, models.ErrTeamNotFound)
permQuery := &models.GetDashboardAclInfoListQuery{DashboardId: 1, OrgId: testOrgId}
permQuery := &models.GetDashboardAclInfoListQuery{DashboardID: 1, OrgID: testOrgId}
err = GetDashboardAclInfoList(permQuery)
So(err, ShouldBeNil)
......
......@@ -287,7 +287,7 @@ func TestUserDataAccess(t *testing.T) {
So(err, ShouldBeNil)
err = testHelperUpdateDashboardAcl(1, models.DashboardAcl{
DashboardId: 1, OrgId: users[0].OrgId, UserId: users[1].Id,
DashboardID: 1, OrgID: users[0].OrgId, UserID: users[1].Id,
Permission: models.PERMISSION_EDIT,
})
So(err, ShouldBeNil)
......@@ -308,7 +308,7 @@ func TestUserDataAccess(t *testing.T) {
So(len(query.Result), ShouldEqual, 1)
permQuery := &models.GetDashboardAclInfoListQuery{DashboardId: 1, OrgId: users[0].OrgId}
permQuery := &models.GetDashboardAclInfoListQuery{DashboardID: 1, OrgID: users[0].OrgId}
err = GetDashboardAclInfoList(permQuery)
So(err, ShouldBeNil)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment