Commit f76b98d2 by Marcus Efraimsson

dashboards: change dashboard/folder permission error messages

parent 03f8eff8
......@@ -69,8 +69,8 @@ func UpdateDashboardPermissions(c *middleware.Context, apiCmd dtos.UpdateDashboa
if okToUpdate, err := g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, cmd.Items); err != nil || !okToUpdate {
if err != nil {
if err == guardian.ErrGuardianDuplicatePermission ||
err == guardian.ErrGuardianOverrideLowerPresedence {
if err == guardian.ErrGuardianPermissionExists ||
err == guardian.ErrGuardianOverride {
return ApiError(400, err.Error(), err)
}
......
......@@ -119,7 +119,7 @@ func TestDashboardPermissionApiEndpoint(t *testing.T) {
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{
CanAdminValue: true,
CheckPermissionBeforeUpdateValue: false,
CheckPermissionBeforeUpdateError: guardian.ErrGuardianDuplicatePermission,
CheckPermissionBeforeUpdateError: guardian.ErrGuardianPermissionExists,
})
getDashboardQueryResult := m.NewDashboard("Dash")
......@@ -149,7 +149,7 @@ func TestDashboardPermissionApiEndpoint(t *testing.T) {
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{
CanAdminValue: true,
CheckPermissionBeforeUpdateValue: false,
CheckPermissionBeforeUpdateError: guardian.ErrGuardianOverrideLowerPresedence},
CheckPermissionBeforeUpdateError: guardian.ErrGuardianOverride},
)
getDashboardQueryResult := m.NewDashboard("Dash")
......
......@@ -78,8 +78,8 @@ func UpdateFolderPermissions(c *middleware.Context, apiCmd dtos.UpdateDashboardA
if okToUpdate, err := g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, cmd.Items); err != nil || !okToUpdate {
if err != nil {
if err == guardian.ErrGuardianDuplicatePermission ||
err == guardian.ErrGuardianOverrideLowerPresedence {
if err == guardian.ErrGuardianPermissionExists ||
err == guardian.ErrGuardianOverride {
return ApiError(400, err.Error(), err)
}
......
......@@ -139,7 +139,7 @@ func TestFolderPermissionApiEndpoint(t *testing.T) {
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{
CanAdminValue: true,
CheckPermissionBeforeUpdateValue: false,
CheckPermissionBeforeUpdateError: guardian.ErrGuardianDuplicatePermission,
CheckPermissionBeforeUpdateError: guardian.ErrGuardianPermissionExists,
})
mock := &fakeFolderService{
......@@ -175,7 +175,7 @@ func TestFolderPermissionApiEndpoint(t *testing.T) {
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{
CanAdminValue: true,
CheckPermissionBeforeUpdateValue: false,
CheckPermissionBeforeUpdateError: guardian.ErrGuardianOverrideLowerPresedence},
CheckPermissionBeforeUpdateError: guardian.ErrGuardianOverride},
)
mock := &fakeFolderService{
......
......@@ -10,8 +10,8 @@ import (
)
var (
ErrGuardianDuplicatePermission = errors.New("You cannot add multiple permissions for a user, team or role")
ErrGuardianOverrideLowerPresedence = errors.New("You cannot override a permission with a lower presedence permission")
ErrGuardianPermissionExists = errors.New("This permission already exists")
ErrGuardianOverride = errors.New("You can only override a permission to be higher")
)
// DashboardGuardian to be used for guard against operations without access on dashboard and acl
......@@ -133,7 +133,7 @@ func (g *dashboardGuardianImpl) CheckPermissionBeforeUpdate(permission m.Permiss
if (a.UserId <= 0 && a.TeamId <= 0 && a.UserId == p.UserId && a.TeamId == p.TeamId && a.Role == p.Role) ||
(a.UserId > 0 && a.UserId == p.UserId) ||
(a.TeamId > 0 && a.TeamId == p.TeamId) {
return false, ErrGuardianDuplicatePermission
return false, ErrGuardianPermissionExists
}
}
......@@ -154,7 +154,7 @@ func (g *dashboardGuardianImpl) CheckPermissionBeforeUpdate(permission m.Permiss
if (a.UserId <= 0 && a.TeamId <= 0 && a.UserId == existingPerm.UserId && a.TeamId == existingPerm.TeamId && *a.Role == *existingPerm.Role && a.Permission <= existingPerm.Permission) ||
(a.UserId > 0 && a.UserId == existingPerm.UserId && a.Permission <= existingPerm.Permission) ||
(a.TeamId > 0 && a.TeamId == existingPerm.TeamId && a.Permission <= existingPerm.Permission) {
return false, ErrGuardianOverrideLowerPresedence
return false, ErrGuardianOverride
}
}
}
......
......@@ -29,7 +29,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 1, UserId: 1, Permission: m.PERMISSION_ADMIN},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianDuplicatePermission)
So(err, ShouldEqual, ErrGuardianPermissionExists)
})
Convey("With duplicate team/role permissions should return error", func() {
......@@ -38,7 +38,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 1, TeamId: 1, Permission: m.PERMISSION_ADMIN},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianDuplicatePermission)
So(err, ShouldEqual, ErrGuardianPermissionExists)
})
Convey("With duplicate everyone/role permissions should return error", func() {
......@@ -47,7 +47,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 1, Permission: m.PERMISSION_ADMIN},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianDuplicatePermission)
So(err, ShouldEqual, ErrGuardianPermissionExists)
})
})
......@@ -66,7 +66,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, UserId: 1, Permission: m.PERMISSION_ADMIN},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
Convey("When trying to update dashboard permissions with edit user permission should return error", func() {
......@@ -74,7 +74,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, UserId: 1, Permission: m.PERMISSION_EDIT},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
Convey("When trying to update dashboard permissions with view user permission should return error", func() {
......@@ -82,7 +82,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, UserId: 1, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
......@@ -109,7 +109,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, UserId: 1, Permission: m.PERMISSION_EDIT},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
Convey("When trying to update dashboard permissions with view user permission should return error", func() {
......@@ -117,7 +117,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, UserId: 1, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
......@@ -152,7 +152,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, UserId: 1, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
......@@ -171,7 +171,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, TeamId: 1, Permission: m.PERMISSION_ADMIN},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
Convey("When trying to update dashboard permissions with edit team permission should return error", func() {
......@@ -179,7 +179,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, TeamId: 1, Permission: m.PERMISSION_EDIT},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
Convey("When trying to update dashboard permissions with view team permission should return error", func() {
......@@ -187,7 +187,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, TeamId: 1, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
......@@ -214,7 +214,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, TeamId: 1, Permission: m.PERMISSION_EDIT},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
Convey("When trying to update dashboard permissions with view team permission should return error", func() {
......@@ -222,7 +222,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, TeamId: 1, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
......@@ -257,7 +257,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, TeamId: 1, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
......@@ -285,7 +285,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, Role: &r, Permission: m.PERMISSION_EDIT},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
Convey("When trying to update dashboard permissions with everyone with editor role can view permission should return error", func() {
......@@ -293,7 +293,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, Role: &r, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
......@@ -329,7 +329,7 @@ func TestGuardian(t *testing.T) {
{OrgId: 1, DashboardId: 3, Role: &r, Permission: m.PERMISSION_VIEW},
}
_, err := sc.g.CheckPermissionBeforeUpdate(m.PERMISSION_ADMIN, p)
So(err, ShouldEqual, ErrGuardianOverrideLowerPresedence)
So(err, ShouldEqual, ErrGuardianOverride)
})
})
})
......
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