Dashboards: Fix bug with anon users with editor permissions creating dashboards (#113260)
This commit is contained in:
@@ -1174,12 +1174,7 @@ func (dr *DashboardServiceImpl) SetDefaultPermissionsAfterCreate(ctx context.Con
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
uid, err := user.GetInternalID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
permissions := []accesscontrol.SetResourcePermissionCommand{}
|
||||
|
||||
isNested := obj.GetFolder() != ""
|
||||
//nolint:staticcheck // not yet migrated to OpenFeature
|
||||
if dr.features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboards) && isNested {
|
||||
@@ -1187,6 +1182,10 @@ func (dr *DashboardServiceImpl) SetDefaultPermissionsAfterCreate(ctx context.Con
|
||||
return nil
|
||||
}
|
||||
if user.IsIdentityType(claims.TypeUser, claims.TypeServiceAccount) {
|
||||
uid, err := user.GetInternalID()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
permissions = append(permissions, accesscontrol.SetResourcePermissionCommand{
|
||||
UserID: uid, Permission: dashboardaccess.PERMISSION_ADMIN.String(),
|
||||
})
|
||||
|
||||
@@ -2127,6 +2127,7 @@ func TestSetDefaultPermissionsAfterCreate(t *testing.T) {
|
||||
name string
|
||||
rootFolder bool
|
||||
featureKubernetesDashboards bool
|
||||
User *user.SignedInUser
|
||||
expectedPermission []accesscontrol.SetResourcePermissionCommand
|
||||
}{
|
||||
{
|
||||
@@ -2149,6 +2150,19 @@ func TestSetDefaultPermissionsAfterCreate(t *testing.T) {
|
||||
{BuiltinRole: string(org.RoleViewer), Permission: dashboardaccess.PERMISSION_VIEW.String()},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with kubernetesDashboards feature in root folder and user is anonymous",
|
||||
rootFolder: true,
|
||||
featureKubernetesDashboards: true,
|
||||
User: &user.SignedInUser{
|
||||
IsAnonymous: true,
|
||||
UserID: 0,
|
||||
},
|
||||
expectedPermission: []accesscontrol.SetResourcePermissionCommand{
|
||||
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_EDIT.String()},
|
||||
{BuiltinRole: string(org.RoleViewer), Permission: dashboardaccess.PERMISSION_VIEW.String()},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "without kubernetesDashboards feature in subfolder",
|
||||
rootFolder: false,
|
||||
@@ -2172,6 +2186,9 @@ func TestSetDefaultPermissionsAfterCreate(t *testing.T) {
|
||||
OrgRole: "Admin",
|
||||
UserID: 1,
|
||||
}
|
||||
if tc.User != nil {
|
||||
user = tc.User
|
||||
}
|
||||
ctx := request.WithNamespace(context.Background(), "default")
|
||||
ctx = identity.WithRequester(ctx, user)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user