fix: default organization resolution (#6875)

This commit is contained in:
Laurin Quast 2025-07-04 11:18:51 +02:00 committed by GitHub
parent 16ff694dcc
commit 73864f2b95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 14 deletions

View file

@ -0,0 +1,5 @@
---
'hive': patch
---
Fix default organization resolution and prevent missing permissions error.

View file

@ -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 });

View file

@ -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,
};
}
}

View file

@ -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'> & {

View file

@ -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 */