RBAC: Display indicator if a permission is inherited (#54080) (#54380)

* RBAC: Add IsInherited property

* PermissionList: Display inherited indicator

(cherry picked from commit cc78486535)

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-08-29 05:29:37 -04:00
committed by GitHub
co-authored by Karl Persson
parent c8a313c289
commit 493c7866a2
6 changed files with 9 additions and 2 deletions
@@ -34,7 +34,7 @@ func (p *flatResourcePermission) IsManaged(scope string) bool {
}
func (p *flatResourcePermission) IsInherited(scope string) bool {
return p.Scope != scope
return !strings.HasPrefix(p.Scope, strings.Split(strings.ReplaceAll(scope, "*", ""), ":")[0])
}
func (s *AccessControlStore) SetUserResourcePermission(
@@ -472,6 +472,7 @@ func flatPermissionsToResourcePermission(scope string, permissions []flatResourc
Created: first.Created,
Updated: first.Updated,
IsManaged: first.IsManaged(scope),
IsInherited: first.IsInherited(scope),
}
}
+1
View File
@@ -234,6 +234,7 @@ type ResourcePermission struct {
Team string
BuiltInRole string
IsManaged bool
IsInherited bool
Created time.Time
Updated time.Time
}
@@ -74,6 +74,7 @@ type resourcePermissionDTO struct {
ID int64 `json:"id"`
RoleName string `json:"roleName"`
IsManaged bool `json:"isManaged"`
IsInherited bool `json:"isInherited"`
UserID int64 `json:"userId,omitempty"`
UserLogin string `json:"userLogin,omitempty"`
UserAvatarUrl string `json:"userAvatarUrl,omitempty"`
@@ -122,6 +123,7 @@ func (a *api) getPermissions(c *models.ReqContext) response.Response {
Actions: p.Actions,
Permission: permission,
IsManaged: p.IsManaged,
IsInherited: p.IsInherited,
})
}
}
@@ -24,6 +24,7 @@ export const PermissionList = ({ title, items, permissionLevels, canSet, onRemov
<tr>
<th style={{ width: '1%' }} />
<th>{title}</th>
<th style={{ width: '1%' }} />
<th>Permission</th>
<th style={{ width: '1%' }} />
<th style={{ width: '1%' }} />
@@ -16,6 +16,7 @@ export const PermissionListItem = ({ item, permissionLevels, canSet, onRemove, o
<tr>
<td style={{ width: '1%' }}>{getAvatar(item)}</td>
<td style={{ width: '90%' }}>{getDescription(item)}</td>
<td>{item.isInherited && <em className="muted no-wrap">Inherited from folder</em>}</td>
<td>
<div className="gf-form">
<Select
@@ -43,7 +44,7 @@ export const PermissionListItem = ({ item, permissionLevels, canSet, onRemove, o
aria-label={`Remove permission for ${getName(item)}`}
/>
) : (
<Tooltip content="Provisioned permission">
<Tooltip content={item.isInherited ? 'Inherited Permission' : 'Provisioned Permission'}>
<Button size="sm" icon="lock" />
</Tooltip>
)}
@@ -2,6 +2,7 @@ export type ResourcePermission = {
id: number;
resourceId: string;
isManaged: boolean;
isInherited: boolean;
userId?: number;
userLogin?: string;
userAvatarUrl?: string;