Merge pull request #13645 from influxdata/fix/permissions-buckets-token
Fix permissions on view token overlaypull/13656/head
commit
5b814fd664
|
@ -25,6 +25,10 @@ import {
|
||||||
Task as TaskApi,
|
Task as TaskApi,
|
||||||
Organization,
|
Organization,
|
||||||
Variable,
|
Variable,
|
||||||
|
Authorization,
|
||||||
|
AuthorizationUpdateRequest,
|
||||||
|
Permission,
|
||||||
|
PermissionResource,
|
||||||
} from '@influxdata/influx'
|
} from '@influxdata/influx'
|
||||||
|
|
||||||
export const links: Links = {
|
export const links: Links = {
|
||||||
|
@ -679,3 +683,237 @@ export const scraperTargets = [
|
||||||
url: 'http://localhost:9999/metrics',
|
url: 'http://localhost:9999/metrics',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
export const auth: Authorization = {
|
||||||
|
id: '03c03a8a64728000',
|
||||||
|
token:
|
||||||
|
'RcW2uWiD-vfxujKyJCirK8un3lJsWPfiA6ulmWY_SlSITUal7Z180OwExiKKfrO98X8W6qGrd5hSGdag-hEpWw==',
|
||||||
|
status: AuthorizationUpdateRequest.StatusEnum.Active,
|
||||||
|
description: 'My token',
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
userID: '039edab303789000',
|
||||||
|
user: 'adminuser',
|
||||||
|
permissions: [
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Orgs,
|
||||||
|
id: '039edab314789000',
|
||||||
|
name: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Authorizations,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Authorizations,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Buckets,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Buckets,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Dashboards,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Dashboards,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Sources,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Sources,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Tasks,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Tasks,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Telegrafs,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Telegrafs,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Users,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Users,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Variables,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Variables,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Scrapers,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Scrapers,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Secrets,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Secrets,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Labels,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Labels,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Views,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Views,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Read,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Documents,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: Permission.ActionEnum.Write,
|
||||||
|
resource: {
|
||||||
|
type: PermissionResource.TypeEnum.Documents,
|
||||||
|
orgID: '039edab314789000',
|
||||||
|
org: 'a',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
links: {
|
||||||
|
self: '/api/v2/authorizations/03c03a8a64728000',
|
||||||
|
user: '/api/v2/users/039edab303789000',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import {shallow} from 'enzyme'
|
||||||
import ViewTokenOverlay from 'src/authorizations/components/ViewTokenOverlay'
|
import ViewTokenOverlay from 'src/authorizations/components/ViewTokenOverlay'
|
||||||
|
|
||||||
// Fixtures
|
// Fixtures
|
||||||
import {authorization as auth} from 'src/authorizations/apis/__mocks__/data'
|
import {auth} from 'mocks/dummyData'
|
||||||
|
import {permissions} from 'src/utils/permissions'
|
||||||
|
|
||||||
const setup = (override?) => {
|
const setup = (override?) => {
|
||||||
const props = {
|
const props = {
|
||||||
|
@ -14,18 +15,41 @@ const setup = (override?) => {
|
||||||
...override,
|
...override,
|
||||||
}
|
}
|
||||||
|
|
||||||
const wrapper = shallow(<ViewTokenOverlay {...props} />)
|
return shallow(<ViewTokenOverlay {...props} />)
|
||||||
|
|
||||||
return {wrapper}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Account', () => {
|
describe('Account', () => {
|
||||||
describe('rendering', () => {
|
describe('rendering', () => {
|
||||||
it('renders!', () => {
|
it('renders!', () => {
|
||||||
const {wrapper} = setup()
|
const wrapper = setup()
|
||||||
|
|
||||||
expect(wrapper.exists()).toBe(true)
|
expect(wrapper.exists()).toBe(true)
|
||||||
expect(wrapper).toMatchSnapshot()
|
expect(wrapper).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('if there is all access tokens', () => {
|
||||||
|
it('renders permissions correctly', () => {
|
||||||
|
const actual = permissions(auth.permissions)
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
'orgs-a': ['read'],
|
||||||
|
authorizations: ['read', 'write'],
|
||||||
|
buckets: ['read', 'write'],
|
||||||
|
dashboards: ['read', 'write'],
|
||||||
|
sources: ['read', 'write'],
|
||||||
|
tasks: ['read', 'write'],
|
||||||
|
telegrafs: ['read', 'write'],
|
||||||
|
users: ['read', 'write'],
|
||||||
|
variables: ['read', 'write'],
|
||||||
|
scrapers: ['read', 'write'],
|
||||||
|
secrets: ['read', 'write'],
|
||||||
|
labels: ['read', 'write'],
|
||||||
|
views: ['read', 'write'],
|
||||||
|
documents: ['read', 'write'],
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -62,16 +62,18 @@ export default class ViewTokenOverlay extends PureComponent<Props> {
|
||||||
const p = this.props.auth.permissions.reduce((acc, {action, resource}) => {
|
const p = this.props.auth.permissions.reduce((acc, {action, resource}) => {
|
||||||
const {type} = resource
|
const {type} = resource
|
||||||
const name = get(resource, 'name', '')
|
const name = get(resource, 'name', '')
|
||||||
|
let key = `${type}`
|
||||||
let key = `${type}-${name}`
|
|
||||||
let actions = get(resource, key, [])
|
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
|
key = `${type}-${name}`
|
||||||
|
}
|
||||||
|
|
||||||
|
let actions = get(acc, key, [])
|
||||||
|
|
||||||
|
if (name && actions) {
|
||||||
return {...acc, [key]: [...actions, action]}
|
return {...acc, [key]: [...actions, action]}
|
||||||
}
|
}
|
||||||
|
|
||||||
actions = get(resource, type, [])
|
actions = get(acc, key || resource.type, [])
|
||||||
|
|
||||||
return {...acc, [type]: [...actions, action]}
|
return {...acc, [type]: [...actions, action]}
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,11 @@ exports[`Account rendering renders! 1`] = `
|
||||||
>
|
>
|
||||||
<OverlayHeading
|
<OverlayHeading
|
||||||
onDismiss={[Function]}
|
onDismiss={[Function]}
|
||||||
title="im a token"
|
title="My token"
|
||||||
/>
|
/>
|
||||||
<OverlayBody>
|
<OverlayBody>
|
||||||
<CodeSnippet
|
<CodeSnippet
|
||||||
copyText="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
|
copyText="RcW2uWiD-vfxujKyJCirK8un3lJsWPfiA6ulmWY_SlSITUal7Z180OwExiKKfrO98X8W6qGrd5hSGdag-hEpWw=="
|
||||||
label="Code Snippet"
|
label="Code Snippet"
|
||||||
/>
|
/>
|
||||||
<PermissionsWidget
|
<PermissionsWidget
|
||||||
|
@ -18,14 +18,33 @@ exports[`Account rendering renders! 1`] = `
|
||||||
mode="read"
|
mode="read"
|
||||||
>
|
>
|
||||||
<PermissionsWidgetSection
|
<PermissionsWidgetSection
|
||||||
id="orgs"
|
id="orgs-a"
|
||||||
key="orgs"
|
key="orgs-a"
|
||||||
mode="read"
|
mode="read"
|
||||||
title="orgs"
|
title="orgs-a"
|
||||||
>
|
>
|
||||||
<PermissionsWidgetItem
|
<PermissionsWidgetItem
|
||||||
id="orgs-write-orgs-orgs"
|
id="orgs-a-read-orgs-a-orgs-a"
|
||||||
key="0"
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="authorizations"
|
||||||
|
key="authorizations"
|
||||||
|
mode="read"
|
||||||
|
title="authorizations"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="authorizations-read-authorizations-authorizations"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="authorizations-write-authorizations-authorizations"
|
||||||
|
key="1"
|
||||||
label="write"
|
label="write"
|
||||||
selected="selected"
|
selected="selected"
|
||||||
/>
|
/>
|
||||||
|
@ -37,8 +56,223 @@ exports[`Account rendering renders! 1`] = `
|
||||||
title="buckets"
|
title="buckets"
|
||||||
>
|
>
|
||||||
<PermissionsWidgetItem
|
<PermissionsWidgetItem
|
||||||
id="buckets-write-buckets-buckets"
|
id="buckets-read-buckets-buckets"
|
||||||
key="0"
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="buckets-write-buckets-buckets"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="dashboards"
|
||||||
|
key="dashboards"
|
||||||
|
mode="read"
|
||||||
|
title="dashboards"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="dashboards-read-dashboards-dashboards"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="dashboards-write-dashboards-dashboards"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="sources"
|
||||||
|
key="sources"
|
||||||
|
mode="read"
|
||||||
|
title="sources"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="sources-read-sources-sources"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="sources-write-sources-sources"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="tasks"
|
||||||
|
key="tasks"
|
||||||
|
mode="read"
|
||||||
|
title="tasks"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="tasks-read-tasks-tasks"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="tasks-write-tasks-tasks"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="telegrafs"
|
||||||
|
key="telegrafs"
|
||||||
|
mode="read"
|
||||||
|
title="telegrafs"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="telegrafs-read-telegrafs-telegrafs"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="telegrafs-write-telegrafs-telegrafs"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="users"
|
||||||
|
key="users"
|
||||||
|
mode="read"
|
||||||
|
title="users"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="users-read-users-users"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="users-write-users-users"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="variables"
|
||||||
|
key="variables"
|
||||||
|
mode="read"
|
||||||
|
title="variables"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="variables-read-variables-variables"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="variables-write-variables-variables"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="scrapers"
|
||||||
|
key="scrapers"
|
||||||
|
mode="read"
|
||||||
|
title="scrapers"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="scrapers-read-scrapers-scrapers"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="scrapers-write-scrapers-scrapers"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="secrets"
|
||||||
|
key="secrets"
|
||||||
|
mode="read"
|
||||||
|
title="secrets"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="secrets-read-secrets-secrets"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="secrets-write-secrets-secrets"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="labels"
|
||||||
|
key="labels"
|
||||||
|
mode="read"
|
||||||
|
title="labels"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="labels-read-labels-labels"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="labels-write-labels-labels"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="views"
|
||||||
|
key="views"
|
||||||
|
mode="read"
|
||||||
|
title="views"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="views-read-views-views"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="views-write-views-views"
|
||||||
|
key="1"
|
||||||
|
label="write"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
</PermissionsWidgetSection>
|
||||||
|
<PermissionsWidgetSection
|
||||||
|
id="documents"
|
||||||
|
key="documents"
|
||||||
|
mode="read"
|
||||||
|
title="documents"
|
||||||
|
>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="documents-read-documents-documents"
|
||||||
|
key="0"
|
||||||
|
label="read"
|
||||||
|
selected="selected"
|
||||||
|
/>
|
||||||
|
<PermissionsWidgetItem
|
||||||
|
id="documents-write-documents-documents"
|
||||||
|
key="1"
|
||||||
label="write"
|
label="write"
|
||||||
selected="selected"
|
selected="selected"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import {Permission} from '@influxdata/influx'
|
||||||
|
import {get} from 'lodash'
|
||||||
|
|
||||||
|
export const permissions = (
|
||||||
|
permissions: Permission[]
|
||||||
|
): {[x: string]: Permission.ActionEnum[]} => {
|
||||||
|
const p = permissions.reduce((acc, {action, resource}) => {
|
||||||
|
const {type} = resource
|
||||||
|
const name = get(resource, 'name', '')
|
||||||
|
let key = `${type}`
|
||||||
|
if (name) {
|
||||||
|
key = `${type}-${name}`
|
||||||
|
}
|
||||||
|
|
||||||
|
let actions = get(acc, key, [])
|
||||||
|
|
||||||
|
if (name && actions) {
|
||||||
|
return {...acc, [key]: [...actions, action]}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions = get(acc, key || resource.type, [])
|
||||||
|
return {...acc, [type]: [...actions, action]}
|
||||||
|
}, {})
|
||||||
|
return p
|
||||||
|
}
|
Loading…
Reference in New Issue