Fix Policy view for Project and Target (#4435)

This commit is contained in:
Kamil Kisiela 2024-04-05 16:34:37 +02:00 committed by GitHub
parent 3ad479adbd
commit bba88bdb5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 13 deletions

View file

@ -81,6 +81,7 @@ export default gql`
extend type Project {
schemaPolicy: SchemaPolicy
parentSchemaPolicy: SchemaPolicy
}
extend type Target {

View file

@ -176,6 +176,15 @@ export class SchemaPolicyProvider {
return this.storage.getSchemaPolicyForOrganization(selector.organization);
}
async getOrganizationPolicyForProject(selector: ProjectSelector) {
await this.authManager.ensureProjectAccess({
...selector,
scope: ProjectAccessScope.SETTINGS,
});
return this.storage.getSchemaPolicyForOrganization(selector.organization);
}
async getProjectPolicy(selector: ProjectSelector) {
await this.authManager.ensureProjectAccess({
...selector,

View file

@ -33,6 +33,11 @@ export const resolvers: PolicyModule.Resolvers = {
project: project.id,
organization: project.orgId,
}),
parentSchemaPolicy: async (project, _, { injector }) =>
injector.get(SchemaPolicyProvider).getOrganizationPolicyForProject({
project: project.id,
organization: project.orgId,
}),
},
Target: {
schemaPolicy: async (target, _, { injector }) => {

View file

@ -17,16 +17,6 @@ const ProjectPolicyPageQuery = graphql(`
organization(selector: { organization: $organizationId }) {
organization {
id
schemaPolicy {
id
updatedAt
allowOverrides
rules {
rule {
id
}
}
}
me {
id
...CanAccessProject_MemberFragment
@ -43,6 +33,16 @@ const ProjectPolicyPageQuery = graphql(`
updatedAt
...PolicySettings_SchemaPolicyFragment
}
parentSchemaPolicy {
id
updatedAt
allowOverrides
rules {
rule {
id
}
}
}
}
organizations {
...ProjectLayout_OrganizationConnectionFragment
@ -160,11 +160,11 @@ function ProjectPolicyContent() {
)}
</CardHeader>
<CardContent>
{currentOrganization.schemaPolicy === null ||
currentOrganization.schemaPolicy?.allowOverrides ? (
{currentProject.parentSchemaPolicy === null ||
currentProject.parentSchemaPolicy?.allowOverrides ? (
<PolicySettings
saving={mutation.fetching}
rulesInParent={currentOrganization.schemaPolicy?.rules.map(r => r.rule.id)}
rulesInParent={currentProject.parentSchemaPolicy?.rules.map(r => r.rule.id)}
error={
mutation.error?.message ||
mutation.data?.updateSchemaPolicyForProject.error?.message