Skip to content

Commit be0d710

Browse files
authored
fix: only show edit perflight script button if user has permissions (#6867)
1 parent fdbfb14 commit be0d710

File tree

4 files changed

+54
-29
lines changed

4 files changed

+54
-29
lines changed

.changeset/olive-ghosts-shout.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Only show the "edit preflight script" button in the laboratory when the users has permissions to
6+
edit it.

packages/services/api/src/modules/collection/module.graphql.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export const typeDefs = gql`
158158
extend type Target {
159159
viewerCanViewLaboratory: Boolean!
160160
viewerCanModifyLaboratory: Boolean!
161+
viewerCanModifyPreflightScript: Boolean!
161162
documentCollection(id: ID!): DocumentCollection
162163
documentCollections(first: Int = 100, after: String = null): DocumentCollectionConnection!
163164
documentCollectionOperation(id: ID!): DocumentCollectionOperation

packages/services/api/src/modules/collection/resolvers/Target.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const Target: Pick<
77
| 'documentCollectionOperation'
88
| 'documentCollections'
99
| 'viewerCanModifyLaboratory'
10+
| 'viewerCanModifyPreflightScript'
1011
| 'viewerCanViewLaboratory'
1112
| '__isTypeOf'
1213
> = {
@@ -38,4 +39,15 @@ export const Target: Pick<
3839
},
3940
});
4041
},
42+
viewerCanModifyPreflightScript: async (target, _arg, { session }) => {
43+
return session.canPerformAction({
44+
action: 'laboratory:modifyPreflightScript',
45+
organizationId: target.orgId,
46+
params: {
47+
organizationId: target.orgId,
48+
projectId: target.projectId,
49+
targetId: target.id,
50+
},
51+
});
52+
},
4153
};

packages/web/app/src/lib/preflight/graphiql-plugin.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const PreflightScript_TargetFragment = graphql(`
134134
id
135135
sourceCode
136136
}
137+
viewerCanModifyPreflightScript
137138
}
138139
`);
139140

@@ -424,6 +425,7 @@ export function usePreflight(args: {
424425
isEnabled,
425426
setIsEnabled,
426427
content: target?.preflightScript?.sourceCode ?? '',
428+
viewerCanModifyPreflightScript: target?.viewerCanModifyPreflightScript ?? false,
427429
environmentVariables,
428430
setEnvironmentVariables,
429431
state,
@@ -493,37 +495,41 @@ function PreflightContent() {
493495

494496
return (
495497
<>
496-
<PreflightModal
497-
// to unmount on submit/close
498-
key={String(showModal)}
499-
isOpen={showModal}
500-
toggle={toggleShowModal}
501-
execute={value =>
502-
preflight.execute(value, true).catch(err => {
503-
console.error(err);
504-
})
505-
}
506-
state={preflight.state}
507-
abortExecution={preflight.abortExecution}
508-
logs={preflight.logs}
509-
clearLogs={preflight.clearLogs}
510-
content={preflight.content}
511-
onContentChange={handleContentChange}
512-
envValue={preflight.environmentVariables}
513-
onEnvValueChange={preflight.setEnvironmentVariables}
514-
/>
498+
{preflight.viewerCanModifyPreflightScript && (
499+
<PreflightModal
500+
// to unmount on submit/close
501+
key={String(showModal)}
502+
isOpen={showModal}
503+
toggle={toggleShowModal}
504+
execute={value =>
505+
preflight.execute(value, true).catch(err => {
506+
console.error(err);
507+
})
508+
}
509+
state={preflight.state}
510+
abortExecution={preflight.abortExecution}
511+
logs={preflight.logs}
512+
clearLogs={preflight.clearLogs}
513+
content={preflight.content}
514+
onContentChange={handleContentChange}
515+
envValue={preflight.environmentVariables}
516+
onEnvValueChange={preflight.setEnvironmentVariables}
517+
/>
518+
)}
515519
<div className="graphiql-doc-explorer-title flex items-center justify-between gap-4">
516520
Preflight Script
517-
<Button
518-
variant="orangeLink"
519-
size="icon-sm"
520-
className="size-auto gap-1"
521-
onClick={toggleShowModal}
522-
data-cy="preflight-modal-button"
523-
>
524-
<Pencil1Icon className="shrink-0" />
525-
Edit
526-
</Button>
521+
{preflight.viewerCanModifyPreflightScript && (
522+
<Button
523+
variant="orangeLink"
524+
size="icon-sm"
525+
className="size-auto gap-1"
526+
onClick={toggleShowModal}
527+
data-cy="preflight-modal-button"
528+
>
529+
<Pencil1Icon className="shrink-0" />
530+
Edit
531+
</Button>
532+
)}
527533
</div>
528534
<Subtitle>
529535
Before each GraphQL request begins, this script is executed automatically - for example, to

0 commit comments

Comments
 (0)