Skip to content

Commit

Permalink
feat(ui): show which roles user has access to for a given destination (
Browse files Browse the repository at this point in the history
  • Loading branch information
jmorganca committed Jul 6, 2022
1 parent 6fe7bb4 commit 40c5224
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion ui/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
},
"plugins": ["jest"],
"globals": {
"Promise": true
"Promise": true,
"Set": true
},
"env": {
"jest/globals": true
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/grants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export function sortByPrivilege(a, b) {
if (a === 'cluster-admin') {
if (a?.privilege === 'cluster-admin') {
return -1
}

if (b === 'cluster-admin') {
if (b?.privilege === 'cluster-admin') {
return 1
}

Expand Down
17 changes: 14 additions & 3 deletions ui/pages/destinations/[[...slug]].js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ function Details({ destination, onDelete }) {
parent(resource) ? `/api/grants?resource=${parent(resource)}` : null
)

const connectable = grants?.find(
const showConnect = grants?.find(
g => g.user === auth?.id || usergroups.some(ug => ug.id === g.group)
)

const usergrants = [...(grants || []), ...(inherited || [])]?.filter(
g => g.user === auth?.id || usergroups.some(ug => ug.id === g.group)
)
const userroles = [
...new Set(usergrants?.sort(sortByPrivilege)?.map(ug => ug.privilege)),
]

const empty =
grants?.length === 0 && (parent(resource) ? inherited?.length === 0 : true)

Expand Down Expand Up @@ -157,12 +165,12 @@ function Details({ destination, onDelete }) {
</div>
</section>
)}
{connectable && (
{showConnect && (
<section>
<h3 className='border-b border-gray-800 py-4 text-3xs uppercase text-gray-400'>
Connect
</h3>
<p className='my-4 text-2xs'>
<p className='my-4 text-2xs leading-normal'>
Connect to this {destination?.kind || 'resource'} via the{' '}
<a
target='_blank'
Expand All @@ -172,6 +180,9 @@ function Details({ destination, onDelete }) {
>
Infra CLI
</a>
. You have{' '}
<span className='font-semibold'>{userroles.join(', ')}</span>{' '}
access.
</p>
<pre className='overflow-auto rounded-md bg-gray-900 px-4 py-3 text-2xs leading-normal text-gray-300'>
infra login {window.location.host}
Expand Down

0 comments on commit 40c5224

Please sign in to comment.