Skip to content

Commit

Permalink
Update docs (#1052)
Browse files Browse the repository at this point in the history
* Add catch block to apiRequest permission method.

* Update nav permissions docs.
  • Loading branch information
Hyperkid123 authored Nov 2, 2020
1 parent c886bb5 commit daae19e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ List of available permissions methods:
* `isProd` - test if current environment is production (prod-beta and prod-stable)
* `isBeta` - test if current environment is beta (ci-beta, qa-beta and prod-beta)
* `hasPermissions` - test if current user has rbac role permissions ['app:scope:permission']
* `apiRequest` - call custom API endpoint to test if the item should be displayed
* `apiRequest` - call custom API endpoint to test if the item should be displayed.

* Expects `true`/`false` response.
* `accessor` attribute can be specified. If the boolean value is in nested object. The accessor is a string path of [lodash get](https://lodash.com/docs/4.17.15#get) function.
* If the promise receives an error, the item won't be displayed.

### apiRequest example

```yml
app:
title: App title
Expand All @@ -95,13 +100,39 @@ List of available permissions methods:
- id: dynamic-sub-app
title: dynamic-sub-app
permissions:
method: apiRequest
args: # acceps all axios request config options https://github.com/axios/axios#request-config
- url: "/request/url"
foo: bar
method: apiRequest
args: # acceps all axios request config options https://github.com/axios/axios#request-config
- url: "/request/url"
foo: bar

```

### multiple permissions example

Each nav item can have multiple required permissions. If **all checks are successful** the item will display.

```yml
app:
title: App title
api:
versions:
- v1
frontend:
paths:
- /foo/bar
sub_apps:
- id: 'sub-app-one'
title: 'Sub app one'
permissions:
- method: apiRequest
args:
- url: '/foo/bar'
show: true
- method: hasPermissions
args:
- [catalog:portfolios:create]
```

## Global filter

On all insights application users expect to see global filter with predefined options and every app should integrate with it.
Expand Down
7 changes: 6 additions & 1 deletion src/js/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export const visibilityFunctions = {
url,
method: method || 'GET',
...options,
}).then((response) => (accessor ? get(response?.data || response || {}, accessor) : response?.data || response)),
})
.then((response) => (accessor ? get(response?.data || response || {}, accessor) : response?.data || response))
.catch((err) => {
console.log(err);
return false;
}),
};

export const isVisible = (limitedApps, app, visibility) => {
Expand Down

0 comments on commit daae19e

Please sign in to comment.