mirror of
https://github.com/graphql-hive/console
synced 2026-04-21 14:37:17 +00:00
fix: default organization resolution (#6875)
This commit is contained in:
parent
16ff694dcc
commit
73864f2b95
5 changed files with 25 additions and 14 deletions
5
.changeset/tasty-geese-train.md
Normal file
5
.changeset/tasty-geese-train.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'hive': patch
|
||||
---
|
||||
|
||||
Fix default organization resolution and prevent missing permissions error.
|
||||
|
|
@ -78,6 +78,22 @@ export class OrganizationManager {
|
|||
return this.storage.getOrganization(selector);
|
||||
}
|
||||
|
||||
async getOrganizationOrNull(organizationId: string) {
|
||||
const canAccessOrganization = await this.session.canPerformAction({
|
||||
action: 'organization:describe',
|
||||
organizationId,
|
||||
params: {
|
||||
organizationId,
|
||||
},
|
||||
});
|
||||
|
||||
if (canAccessOrganization === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.storage.getOrganization({ organizationId });
|
||||
}
|
||||
|
||||
async getOrganizationBySlug(organizationSlug: string): Promise<Organization | null> {
|
||||
const organization = await this.storage.getOrganizationBySlug({ slug: organizationSlug });
|
||||
|
||||
|
|
|
|||
|
|
@ -41,16 +41,14 @@ export const myDefaultOrganization: NonNullable<QueryResolvers['myDefaultOrganiz
|
|||
});
|
||||
|
||||
if (orgId) {
|
||||
const org = await organizationManager.getOrganization({
|
||||
organizationId: orgId,
|
||||
});
|
||||
const organization = await organizationManager.getOrganizationOrNull(orgId);
|
||||
|
||||
if (org) {
|
||||
if (organization) {
|
||||
return {
|
||||
selector: {
|
||||
organizationSlug: org.slug,
|
||||
organizationSlug: organization.slug,
|
||||
},
|
||||
organization: org,
|
||||
organization,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ export interface Storage {
|
|||
installationId: string;
|
||||
}): Promise<Organization | null>;
|
||||
getOrganization(_: { organizationId: string }): Promise<Organization | never>;
|
||||
getMyOrganization(_: { userId: string }): Promise<Organization | null>;
|
||||
getOrganizations(_: { userId: string }): Promise<readonly Organization[] | never>;
|
||||
createOrganization(
|
||||
_: Pick<Organization, 'slug'> & {
|
||||
|
|
|
|||
|
|
@ -1335,13 +1335,6 @@ export async function createStorage(
|
|||
),
|
||||
);
|
||||
},
|
||||
async getMyOrganization({ userId: user }) {
|
||||
const org = await pool.maybeOne<Slonik<organizations>>(
|
||||
sql`/* getMyOrganization */ SELECT * FROM organizations WHERE user_id = ${user} AND type = ${'PERSONAL'} LIMIT 1`,
|
||||
);
|
||||
|
||||
return org ? transformOrganization(org) : null;
|
||||
},
|
||||
async getOrganizations({ userId: user }) {
|
||||
const results = await pool.query<Slonik<organizations>>(
|
||||
sql`/* getOrganizations */
|
||||
|
|
|
|||
Loading…
Reference in a new issue