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

* RBAC: Add IsInherited property

* PermissionList: Display inherited indicator
This commit is contained in:
Karl Persson 2022-08-23 11:34:19 +02:00 committed by GitHub
parent eb4266a85e
commit cc78486535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 2 deletions

View File

@ -235,6 +235,7 @@ type ResourcePermission struct {
Team string
BuiltInRole string
IsManaged bool
IsInherited bool
Created time.Time
Updated time.Time
}

View File

@ -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,
})
}
}

View File

@ -44,7 +44,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 *store) SetUserResourcePermission(
@ -482,6 +482,7 @@ func flatPermissionsToResourcePermission(scope string, permissions []flatResourc
Created: first.Created,
Updated: first.Updated,
IsManaged: first.IsManaged(scope),
IsInherited: first.IsInherited(scope),
}
}

View File

@ -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%' }} />

View File

@ -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>
)}

View File

@ -2,6 +2,7 @@ export type ResourcePermission = {
id: number;
resourceId: string;
isManaged: boolean;
isInherited: boolean;
userId?: number;
userLogin?: string;
userAvatarUrl?: string;