Skip to content

Commit

Permalink
Combine permisssions in the ui on token overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Palakp41 committed Feb 14, 2019
1 parent 9867f5d commit 7b663a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

### UI Improvements
1. [11764](https://github.com/influxdata/influxdb/pull/11764): Move the download telegraf config button to view config overlay
1. [11879](https://github.com/influxdata/influxdb/pull/11879): Combine permissions for user by type

## v2.0.0-alpha.2 [2019-02-07]

Expand Down
46 changes: 21 additions & 25 deletions ui/src/me/components/account/ViewTokenOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export default class ViewTokenOverlay extends PureComponent<Props> {
const {description, permissions} = this.props.auth
const {onNotify} = this.props

const permissionsByType = {}
for (const key of permissions) {
if (permissionsByType[key.resource.type]) {
permissionsByType[key.resource.type].push(key.action)
} else {
permissionsByType[key.resource.type] = [key.action]
}
}

return (
<OverlayContainer>
<OverlayHeading title={description} onDismiss={this.handleDismiss} />
Expand All @@ -39,20 +48,20 @@ export default class ViewTokenOverlay extends PureComponent<Props> {
mode={PermissionsWidgetMode.Read}
heightPixels={500}
>
{permissions.map((p, i) => {
{Object.keys(permissionsByType).map((type, permission) => {
return (
<PermissionsWidget.Section
key={i}
id={this.id(p)}
title={this.title(p)}
key={permission}
id={type}
title={this.title(type)}
mode={PermissionsWidgetMode.Read}
>
{actions.map((a, i) => (
<PermissionsWidget.Item
key={i}
id={this.itemID(p, a)}
id={this.itemID(type, a)}
label={a}
selected={this.selected(p, a)}
selected={this.selected(permissionsByType[type][i], a)}
/>
))}
</PermissionsWidget.Section>
Expand All @@ -65,38 +74,25 @@ export default class ViewTokenOverlay extends PureComponent<Props> {
}

private selected = (
permission: Permission,
permission: string,
action: Permission.ActionEnum
): PermissionsWidgetSelection => {
if (permission.action === action) {
if (permission === action) {
return PermissionsWidgetSelection.Selected
}

return PermissionsWidgetSelection.Unselected
}

private itemID = (
permission: Permission,
permission: string,
action: Permission.ActionEnum
): string => {
return `${permission.resource.type}-${action}-${permission.resource.id ||
'*'}-${permission.resource.orgID || '*'}`
}

private id = (permission: Permission): string => {
return permission.resource.type
return `${permission}-${action}-${permission || '*'}-${permission || '*'}`
}

private title = (permission: Permission): string => {
const org = permission.resource.org || '*'
const name = permission.resource.name || '*'
const type = permission.resource.type

if (permission.resource.name || permission.resource.org) {
return `${org}:${type}:${name}`
}

return `${permission.resource.type}:*`
private title = (permission: string): string => {
return `${permission}:*`
}

private handleDismiss = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ exports[`Account rendering renders! 1`] = `
className="permissions-widget--section-list"
>
<PermissionsWidgetItem
id="orgs-read-*-*"
id="orgs-read-orgs-orgs"
key=".$0"
label="read"
mode="read"
Expand All @@ -339,21 +339,21 @@ exports[`Account rendering renders! 1`] = `
</li>
</PermissionsWidgetItem>
<PermissionsWidgetItem
id="orgs-write-*-*"
id="orgs-write-orgs-orgs"
key=".$1"
label="write"
mode="read"
selected="selected"
selected="unselected"
>
<li
className="permissions-widget--item selected"
className="permissions-widget--item unselected"
onClick={[Function]}
>
<div
className="permissions-widget--icon"
>
<span
className="icon checkmark"
className="icon remove"
/>
</div>
<label
Expand Down Expand Up @@ -388,7 +388,7 @@ exports[`Account rendering renders! 1`] = `
className="permissions-widget--section-list"
>
<PermissionsWidgetItem
id="buckets-read-*-*"
id="buckets-read-buckets-buckets"
key=".$0"
label="read"
mode="read"
Expand All @@ -413,21 +413,21 @@ exports[`Account rendering renders! 1`] = `
</li>
</PermissionsWidgetItem>
<PermissionsWidgetItem
id="buckets-write-*-*"
id="buckets-write-buckets-buckets"
key=".$1"
label="write"
mode="read"
selected="selected"
selected="unselected"
>
<li
className="permissions-widget--item selected"
className="permissions-widget--item unselected"
onClick={[Function]}
>
<div
className="permissions-widget--icon"
>
<span
className="icon checkmark"
className="icon remove"
/>
</div>
<label
Expand Down

0 comments on commit 7b663a1

Please sign in to comment.