This repository was archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Erik Vattekar <[email protected]>
- Loading branch information
Showing
8 changed files
with
283 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,5 +41,9 @@ yarn-error.log* | |
spec-v1.0.yaml | ||
data.sql | ||
|
||
# local graphql | ||
.graphqlconfig | ||
schema.graphql | ||
|
||
# asdf | ||
.tool-versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import {Table, TableBody, TableCell, TableHead, TableRow} from '@mui/material' | ||
import * as React from 'react' | ||
import {useState} from 'react' | ||
import {Delete, Error, Success} from '@navikt/ds-icons' | ||
import {navGronn, navRod} from '../../../styles/constants' | ||
import humanizeDate from '../../../lib/humanizeDate' | ||
import {isAfter, parseISO} from 'date-fns' | ||
import {useRemoveRequesterMutation, useRevokeAccessMutation} from '../../../lib/schema/graphql' | ||
import {Alert} from '@navikt/ds-react' | ||
import {Accessibility} from "@mui/icons-material"; | ||
|
||
interface AccessEntry { | ||
subject: string, | ||
access?: access, | ||
} | ||
|
||
const productAccess = (access: access[]): AccessEntry[] => { | ||
// Valid access entries are unrevoked and either eternal or expires in the future | ||
const valid = (a: access) => !a.revoked && (!a.expires || isAfter(parseISO(a.expires), Date.now())) | ||
return access.filter(valid).map(a => { | ||
return { | ||
access: a, | ||
subject: a.subject.split(":")[1], | ||
}; | ||
}) | ||
} | ||
|
||
interface access { | ||
id: string; | ||
subject: string; | ||
granter: string; | ||
expires?: any; | ||
created: any; | ||
revoked?: any; | ||
} | ||
|
||
interface request { | ||
|
||
} | ||
|
||
interface AccessListProps { | ||
id: string, | ||
access: access[], | ||
requests: request[] | ||
} | ||
|
||
const UserAccessList = ({ id, access, requests}: AccessListProps) => { | ||
const [revokeAccess] = useRevokeAccessMutation() | ||
const removeAccess = async (id: string, a: AccessEntry) => { | ||
if (a.access) { | ||
try { | ||
await revokeAccess({ | ||
variables: { id: a.access.id }, | ||
refetchQueries: ['DataproductAccess'], | ||
}, | ||
) | ||
} catch (e: any) { | ||
setFormError(e.message) | ||
} | ||
} | ||
|
||
} | ||
|
||
const [formError, setFormError] = useState('') | ||
const accesses = productAccess(access) | ||
|
||
return ( | ||
<div> | ||
{formError && <Alert variant={'error'}>{formError}</Alert>} | ||
<Table sx={{ minWidth: 650 }} aria-label='simple table'> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell align='left'>Bruker / gruppe</TableCell> | ||
{accesses.length != 0 && <TableCell align='left'>Har tilgang til</TableCell>} | ||
<TableCell align='center'>Din søknad</TableCell> | ||
<TableCell align='center'>Fjern tilgang</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{accesses.map((a, i) => <TableRow key={i}> | ||
<TableCell>{a.subject}</TableCell> | ||
{accesses.length != 0 && <TableCell align='left'>{a.access ? <>{a.access.expires ? humanizeDate(a.access.expires) : 'evig'}</> : | ||
<Error style={{ color: navRod }}/>} | ||
</TableCell>} | ||
<TableCell align='center'>show</TableCell> | ||
<TableCell align='center'><Delete style={{ cursor: 'pointer', color: navRod }} | ||
onClick={() => removeAccess(id, a)}/></TableCell> | ||
</TableRow>)} | ||
|
||
</TableBody> | ||
</Table> | ||
</div> | ||
) | ||
} | ||
export default UserAccessList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { gql } from 'graphql-tag' | ||
|
||
export const ACCESS_REQUESTS_FOR_OWNER = gql` | ||
query AccessRequestsForOwner { | ||
accessRequestsForOwner { | ||
id | ||
dataproductID | ||
subject | ||
subjectType | ||
polly { | ||
id | ||
externalID | ||
name | ||
url | ||
} | ||
} | ||
} | ||
` |
Oops, something went wrong.