-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
2,000 additions
and
1,086 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,18 +1,26 @@ | ||
import { setContext } from '@apollo/client/link/context'; | ||
import { pickBy } from 'lodash'; | ||
import { RefObject } from 'react'; | ||
import { GqlSensitiveOperations } from '../../operationsList'; | ||
import { Impersonation } from '../ImpersonationContext'; | ||
|
||
export const createImpersonationLink = ( | ||
ref?: RefObject<Impersonation | undefined> | ||
) => | ||
setContext((req, prev) => ({ | ||
...prev, | ||
headers: { | ||
...prev.headers, | ||
...pickBy({ | ||
'x-cord-impersonate-user': ref?.current?.user, | ||
'x-cord-impersonate-roles': ref?.current?.roles?.join(','), | ||
}), | ||
}, | ||
})); | ||
setContext((req, prev) => { | ||
const isSensitiveOp = req.operationName | ||
? GqlSensitiveOperations.has(req.operationName) | ||
: false; | ||
const impersonation = | ||
ref?.current && !isSensitiveOp ? ref.current : undefined; | ||
return { | ||
...prev, | ||
headers: { | ||
...prev.headers, | ||
...pickBy({ | ||
'x-cord-impersonate-user': impersonation?.user, | ||
'x-cord-impersonate-role': impersonation?.roles?.join(','), | ||
}), | ||
}, | ||
}; | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,49 @@ | ||
import { plugin as basePlugin } from '@graphql-codegen/named-operations-object'; | ||
import type { PluginFunction } from '@graphql-codegen/plugin-helpers'; | ||
import { concatAST, FieldNode, visit } from 'graphql'; | ||
|
||
export const plugin: PluginFunction = async (...args) => { | ||
const result = await basePlugin(...args); | ||
return result ? result + ' as const' : result; | ||
let result = await basePlugin(...args); | ||
result = result ? result + ' as const;' : result; | ||
|
||
const [schema, documents] = args; | ||
|
||
const queries = Object.values(schema.getQueryType()?.getFields() ?? {}); | ||
const mutations = Object.values(schema.getMutationType()?.getFields() ?? {}); | ||
const sensitiveQueries = new Set( | ||
[...queries, ...mutations] | ||
.filter( | ||
(f) => f.description && /^\s*@sensitive-secrets$/m.test(f.description) | ||
) | ||
.map((f) => f.name) | ||
); | ||
const sensitiveOperationsNames = new Set(); | ||
const allAst = concatAST(documents.flatMap((v) => v.document ?? [])); | ||
visit(allAst, { | ||
OperationDefinition: (node) => { | ||
if ( | ||
!node.name || | ||
(node.operation !== 'query' && node.operation !== 'mutation') | ||
) { | ||
return; | ||
} | ||
const fields = node.selectionSet.selections | ||
.filter((s): s is FieldNode => s.kind === 'Field') | ||
.map((s) => s.name.value); | ||
for (const field of fields) { | ||
if (sensitiveQueries.has(field)) { | ||
sensitiveOperationsNames.add(node.name.value); | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
result += ` | ||
export const GqlSensitiveOperations: ReadonlySet<string> = new Set([ | ||
${[...sensitiveOperationsNames].map((n) => ` '${n}'`).join(',\n')} | ||
]); | ||
`; | ||
|
||
return result; | ||
}; |
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
5 changes: 5 additions & 0 deletions
5
src/components/ProgressReportBreadcrumb/ProgressReportBreadcrumb.graphql
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,5 @@ | ||
fragment ProgressReportBreadcrumb on ProgressReport { | ||
id | ||
start | ||
end | ||
} |
17 changes: 17 additions & 0 deletions
17
src/components/ProgressReportBreadcrumb/ProgressReportBreadcrumb.tsx
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,17 @@ | ||
import { Skeleton } from '@mui/material'; | ||
import { Nullable } from '~/common'; | ||
import { Breadcrumb } from '../Breadcrumb'; | ||
import { ReportLabel } from '../PeriodicReports/ReportLabel'; | ||
import { ProgressReportBreadcrumbFragment } from './ProgressReportBreadcrumb.graphql'; | ||
|
||
interface ProgressReportBreadcrumbProps { | ||
data?: Nullable<ProgressReportBreadcrumbFragment>; | ||
} | ||
|
||
export const ProgressReportBreadcrumb = ({ | ||
data, | ||
}: ProgressReportBreadcrumbProps) => ( | ||
<Breadcrumb to={data ? `/progress-reports/${data.id}` : undefined}> | ||
{!data ? <Skeleton width={200} /> : <ReportLabel report={data} />} | ||
</Breadcrumb> | ||
); |
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 @@ | ||
export * from './ProgressReportBreadcrumb'; |
24 changes: 24 additions & 0 deletions
24
src/components/ProgressReportListBreadcrumb/ProgressReportListBreadcrumb.tsx
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,24 @@ | ||
import { Skeleton } from '@mui/material'; | ||
import { IdFragment } from '~/common'; | ||
import { Breadcrumb, BreadcrumbProps } from '../Breadcrumb'; | ||
import { idForUrl } from '../Changeset'; | ||
|
||
interface ProgressReportListBreadcrumbProps extends BreadcrumbProps { | ||
engagement?: IdFragment; | ||
} | ||
|
||
export const ProgressReportListBreadcrumb = ({ | ||
engagement, | ||
...rest | ||
}: ProgressReportListBreadcrumbProps) => ( | ||
<Breadcrumb | ||
to={ | ||
engagement | ||
? `/engagements/${idForUrl(engagement)}/reports/progress` | ||
: undefined | ||
} | ||
{...rest} | ||
> | ||
{engagement ? 'Quarterly Reports' : <Skeleton width={200} />} | ||
</Breadcrumb> | ||
); |
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 @@ | ||
export * from './ProgressReportListBreadcrumb'; |
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
Oops, something went wrong.