Skip to content

Commit 73864f2

Browse files
authored
fix: default organization resolution (#6875)
1 parent 16ff694 commit 73864f2

File tree

5 files changed

+25
-14
lines changed

5 files changed

+25
-14
lines changed

.changeset/tasty-geese-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
Fix default organization resolution and prevent missing permissions error.

packages/services/api/src/modules/organization/providers/organization-manager.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ export class OrganizationManager {
7878
return this.storage.getOrganization(selector);
7979
}
8080

81+
async getOrganizationOrNull(organizationId: string) {
82+
const canAccessOrganization = await this.session.canPerformAction({
83+
action: 'organization:describe',
84+
organizationId,
85+
params: {
86+
organizationId,
87+
},
88+
});
89+
90+
if (canAccessOrganization === false) {
91+
return null;
92+
}
93+
94+
return this.storage.getOrganization({ organizationId });
95+
}
96+
8197
async getOrganizationBySlug(organizationSlug: string): Promise<Organization | null> {
8298
const organization = await this.storage.getOrganizationBySlug({ slug: organizationSlug });
8399

packages/services/api/src/modules/organization/resolvers/Query/myDefaultOrganization.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ export const myDefaultOrganization: NonNullable<QueryResolvers['myDefaultOrganiz
4141
});
4242

4343
if (orgId) {
44-
const org = await organizationManager.getOrganization({
45-
organizationId: orgId,
46-
});
44+
const organization = await organizationManager.getOrganizationOrNull(orgId);
4745

48-
if (org) {
46+
if (organization) {
4947
return {
5048
selector: {
51-
organizationSlug: org.slug,
49+
organizationSlug: organization.slug,
5250
},
53-
organization: org,
51+
organization,
5452
};
5553
}
5654
}

packages/services/api/src/modules/shared/providers/storage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export interface Storage {
9292
installationId: string;
9393
}): Promise<Organization | null>;
9494
getOrganization(_: { organizationId: string }): Promise<Organization | never>;
95-
getMyOrganization(_: { userId: string }): Promise<Organization | null>;
9695
getOrganizations(_: { userId: string }): Promise<readonly Organization[] | never>;
9796
createOrganization(
9897
_: Pick<Organization, 'slug'> & {

packages/services/storage/src/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,13 +1335,6 @@ export async function createStorage(
13351335
),
13361336
);
13371337
},
1338-
async getMyOrganization({ userId: user }) {
1339-
const org = await pool.maybeOne<Slonik<organizations>>(
1340-
sql`/* getMyOrganization */ SELECT * FROM organizations WHERE user_id = ${user} AND type = ${'PERSONAL'} LIMIT 1`,
1341-
);
1342-
1343-
return org ? transformOrganization(org) : null;
1344-
},
13451338
async getOrganizations({ userId: user }) {
13461339
const results = await pool.query<Slonik<organizations>>(
13471340
sql`/* getOrganizations */

0 commit comments

Comments
 (0)