Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 0e696c4

Browse files
committed
grant mutation requires a NewGrant model as input
1 parent 00e9f05 commit 0e696c4

File tree

4 files changed

+62
-39
lines changed

4 files changed

+62
-39
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ yarn-error.log*
4040
# Schema from backend
4141
spec-v1.0.yaml
4242
data.sql
43+
44+
# asdf
45+
.tool-versions

components/dataproducts/access/newAccessForm.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
SubjectType,
44
useAddRequesterMutation,
55
useGrantAccessMutation,
6+
NewGrant,
7+
PollyInput,
68
} from '../../../lib/schema/graphql'
79
import * as React from 'react'
810
import {Dispatch, SetStateAction, useState} from 'react'
@@ -50,6 +52,7 @@ const NewAccessForm = ({ open, setOpen, id, pii }: NewAccessFormProps) => {
5052
subject: '',
5153
accessType: '',
5254
expires: '',
55+
polly: null,
5356
}
5457
const { formState, handleSubmit, control, watch, register, reset } =
5558
useForm({
@@ -66,7 +69,7 @@ const NewAccessForm = ({ open, setOpen, id, pii }: NewAccessFormProps) => {
6669
const [addRequester] = useAddRequesterMutation()
6770
const [grantAccess] = useGrantAccessMutation()
6871

69-
const onSubmit = async (requestData: { subjectType: string, subject: string, accessType: string, expires: any }) => {
72+
const onSubmit = async (requestData: { subjectType: string, subject: string, accessType: string, expires: any, polly: PollyInput }) => {
7073
requestData.expires = date
7174
const accessSubject = requestData.subjectType === 'all-users' ? '[email protected]' : subject
7275

@@ -100,14 +103,19 @@ const NewAccessForm = ({ open, setOpen, id, pii }: NewAccessFormProps) => {
100103
}
101104

102105
try {
103-
const variables: GrantAccessMutationVariables = {
106+
const newGrant: NewGrant = {
104107
subjectType: toSubjectType(requestData.subjectType),
105108
subject: accessSubject,
106109
dataproductID: id,
110+
polly: null,
111+
}
112+
113+
const variables: GrantAccessMutationVariables = {
114+
input: newGrant,
107115
}
108116

109117
if (requestData.accessType === 'until') {
110-
variables.expires = date
118+
variables.input.expires = date
111119
}
112120

113121
await grantAccess({

lib/queries/access/grantAccess.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
import { gql } from 'graphql-tag'
22

33
export const GRANT_ACCESS = gql`
4-
mutation GrantAccess(
5-
$dataproductID: ID!
6-
$subject: String!
7-
$subjectType: SubjectType!
8-
$expires: Time
9-
) {
10-
grantAccessToDataproduct(
11-
dataproductID: $dataproductID
12-
subject: $subject
13-
subjectType: $subjectType
14-
expires: $expires
15-
) {
4+
mutation GrantAccess($input: NewGrant!) {
5+
grantAccessToDataproduct(input: $input) {
166
id
177
}
188
}

lib/schema/graphql.ts

+46-24
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export type Access = {
3535
granter: Scalars['String']
3636
/** id for the access entry */
3737
id: Scalars['ID']
38+
/** polly is the documentation for the access grant */
39+
polly?: Maybe<PollyResult>
3840
/** revoked is timestamp for when access was revoked */
3941
revoked?: Maybe<Scalars['Time']>
4042
/** subject to grant access */
@@ -264,10 +266,7 @@ export type MutationDummyArgs = {
264266
}
265267

266268
export type MutationGrantAccessToDataproductArgs = {
267-
dataproductID: Scalars['ID']
268-
expires?: Maybe<Scalars['Time']>
269-
subject?: Maybe<Scalars['String']>
270-
subjectType?: Maybe<SubjectType>
269+
input: NewGrant
271270
}
272271

273272
export type MutationMapDataproductArgs = {
@@ -332,6 +331,20 @@ export type NewDataproduct = {
332331
teamkatalogenURL?: Maybe<Scalars['String']>
333332
}
334333

334+
/** NewGrant contains metadata on a dataproduct grant */
335+
export type NewGrant = {
336+
/** id of dataproduct. */
337+
dataproductID: Scalars['ID']
338+
/** expires is a timestamp for when the access expires. */
339+
expires?: Maybe<Scalars['Time']>
340+
/** polly is the process policy attached to this grant */
341+
polly?: Maybe<PollyInput>
342+
/** subject to be granted access. */
343+
subject?: Maybe<Scalars['String']>
344+
/** subjectType is the type of entity which should be granted access (user, group or service account). */
345+
subjectType?: Maybe<SubjectType>
346+
}
347+
335348
export type NewStory = {
336349
/** group is the owner group for the story. */
337350
group: Scalars['String']
@@ -354,6 +367,25 @@ export type Owner = {
354367
teamkatalogenURL?: Maybe<Scalars['String']>
355368
}
356369

370+
export type PollyInput = {
371+
/** id from polly */
372+
id: Scalars['String']
373+
/** name from polly */
374+
name: Scalars['String']
375+
/** url from polly */
376+
url: Scalars['String']
377+
}
378+
379+
export type PollyResult = {
380+
__typename?: 'PollyResult'
381+
/** id from polly */
382+
id: Scalars['String']
383+
/** name from polly */
384+
name: Scalars['String']
385+
/** url from polly */
386+
url: Scalars['String']
387+
}
388+
357389
export type Query = {
358390
__typename?: 'Query'
359391
/** dataproduct returns the given dataproduct. */
@@ -376,6 +408,8 @@ export type Query = {
376408
groupStats: Array<GroupStats>
377409
/** Keywords returns all keywords, with an optional filter */
378410
keywords: Array<Keyword>
411+
/** searches polly for process purposes matching query input */
412+
polly: Array<PollyResult>
379413
/** search through existing dataproducts. */
380414
search: Array<SearchResultRow>
381415
/** stories returns all either draft or published stories depending on the draft boolean. */
@@ -426,6 +460,10 @@ export type QueryKeywordsArgs = {
426460
prefix?: Maybe<Scalars['String']>
427461
}
428462

463+
export type QueryPollyArgs = {
464+
q: Scalars['String']
465+
}
466+
429467
export type QuerySearchArgs = {
430468
options?: Maybe<SearchOptions>
431469
q?: Maybe<SearchQuery>
@@ -696,10 +734,7 @@ export type DataproductAccessQuery = {
696734
}
697735

698736
export type GrantAccessMutationVariables = Exact<{
699-
dataproductID: Scalars['ID']
700-
subject: Scalars['String']
701-
subjectType: SubjectType
702-
expires?: Maybe<Scalars['Time']>
737+
input: NewGrant
703738
}>
704739

705740
export type GrantAccessMutation = {
@@ -1279,18 +1314,8 @@ export type DataproductAccessQueryResult = Apollo.QueryResult<
12791314
DataproductAccessQueryVariables
12801315
>
12811316
export const GrantAccessDocument = gql`
1282-
mutation GrantAccess(
1283-
$dataproductID: ID!
1284-
$subject: String!
1285-
$subjectType: SubjectType!
1286-
$expires: Time
1287-
) {
1288-
grantAccessToDataproduct(
1289-
dataproductID: $dataproductID
1290-
subject: $subject
1291-
subjectType: $subjectType
1292-
expires: $expires
1293-
) {
1317+
mutation GrantAccess($input: NewGrant!) {
1318+
grantAccessToDataproduct(input: $input) {
12941319
id
12951320
}
12961321
}
@@ -1313,10 +1338,7 @@ export type GrantAccessMutationFn = Apollo.MutationFunction<
13131338
* @example
13141339
* const [grantAccessMutation, { data, loading, error }] = useGrantAccessMutation({
13151340
* variables: {
1316-
* dataproductID: // value for 'dataproductID'
1317-
* subject: // value for 'subject'
1318-
* subjectType: // value for 'subjectType'
1319-
* expires: // value for 'expires'
1341+
* input: // value for 'input'
13201342
* },
13211343
* });
13221344
*/

0 commit comments

Comments
 (0)