Skip to content

Commit 768c84d

Browse files
authored
Merge pull request #2603 from appwrite/org-filters
2 parents b750dc0 + b9c46e3 commit 768c84d

8 files changed

Lines changed: 48 additions & 16 deletions

File tree

src/lib/commandCenter/searchers/organizations.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { base } from '$app/paths';
33
import { sdk } from '$lib/stores/sdk';
44
import type { Searcher } from '../commands';
55
import { isCloud } from '$lib/system';
6+
import { Query } from '@appwrite.io/console';
7+
import { resolvedProfile } from '$lib/profiles/index.svelte';
68

79
export const orgSearcher = (async (query: string) => {
810
const { teams } = !isCloud
911
? await sdk.forConsole.teams.list()
10-
: await sdk.forConsole.billing.listOrganization();
12+
: await sdk.forConsole.billing.listOrganization([
13+
Query.equal('platform', resolvedProfile.organizationPlatform)
14+
]);
1115

1216
return teams
1317
.filter((organization) => organization.name.toLowerCase().includes(query.toLowerCase()))

src/lib/stores/billing.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,10 @@ export async function checkForMandate(org: Organization) {
557557

558558
export async function checkForMissingPaymentMethod() {
559559
const orgs = await sdk.forConsole.billing.listOrganization([
560-
Query.notEqual('billingPlan', BillingPlan.FREE),
560+
Query.notEqual('billingPlan', resolvedProfile.freeTier),
561561
Query.isNull('paymentMethodId'),
562-
Query.isNull('backupPaymentMethodId')
562+
Query.isNull('backupPaymentMethodId'),
563+
Query.equal('platform', resolvedProfile.organizationPlatform)
563564
]);
564565
if (orgs?.total) {
565566
orgMissingPaymentMethod.set(orgs.teams[0]);
@@ -592,7 +593,8 @@ export async function checkForNewDevUpgradePro(org: Organization) {
592593
if (now - accountCreated < 1000 * 60 * 60 * 24 * 7) return;
593594

594595
const organizations = await sdk.forConsole.billing.listOrganization([
595-
Query.notEqual('billingPlan', BillingPlan.FREE)
596+
Query.notEqual('billingPlan', resolvedProfile.freeTier),
597+
Query.equal('platform', resolvedProfile.organizationPlatform)
596598
]);
597599

598600
if (organizations?.total) return;

src/routes/(console)/account/organizations/+page.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
44
import { CARD_LIMIT } from '$lib/constants';
55
import type { PageLoad } from './$types';
66
import { isCloud } from '$lib/system';
7+
import { resolvedProfile } from '$lib/profiles/index.svelte';
78

89
export const load: PageLoad = async ({ url, route }) => {
910
const page = getPage(url);
1011
const limit = getLimit(url, route, CARD_LIMIT);
1112
const offset = pageToOffset(page, limit);
1213

13-
const queries = [Query.offset(offset), Query.limit(limit), Query.orderDesc('')];
14+
const queries = [
15+
Query.offset(offset),
16+
Query.limit(limit),
17+
Query.orderDesc(''),
18+
Query.equal('platform', resolvedProfile.organizationPlatform)
19+
];
1420

1521
const organizations = !isCloud
1622
? await sdk.forConsole.teams.list({ queries })

src/routes/(console)/organization-[organization]/domains/domain-[domain]/settings/+page.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { Dependencies } from '$lib/constants';
22
import { sdk } from '$lib/stores/sdk';
33
import { isCloud } from '$lib/system';
4+
import { Query } from '@appwrite.io/console';
5+
import { resolvedProfile } from '$lib/profiles/index.svelte';
46

57
export const load = async ({ parent, depends }) => {
68
depends(Dependencies.DOMAINS);
79

810
const organizations = !isCloud
911
? await sdk.forConsole.teams.list()
10-
: await sdk.forConsole.billing.listOrganization();
12+
: await sdk.forConsole.billing.listOrganization([
13+
Query.equal('platform', resolvedProfile.organizationPlatform)
14+
]);
1115

1216
const { domain } = await parent();
1317
return {

src/routes/(public)/functions/deploy/+page.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { sdk } from '$lib/stores/sdk.js';
22
import { redirect } from '@sveltejs/kit';
33
import { base } from '$app/paths';
44
import { isCloud } from '$lib/system';
5-
import { ID, type Models } from '@appwrite.io/console';
5+
import { ID, type Models, Query } from '@appwrite.io/console';
66
import type { OrganizationList } from '$lib/stores/organization';
77
import { redirectTo } from '$routes/store';
88
import type { PageLoad } from './$types';
@@ -66,7 +66,9 @@ export const load: PageLoad = async ({ parent, url }) => {
6666
// Get organizations
6767
let organizations: Models.TeamList<Record<string, unknown>> | OrganizationList | undefined;
6868
if (isCloud) {
69-
organizations = await sdk.forConsole.billing.listOrganization();
69+
organizations = await sdk.forConsole.billing.listOrganization([
70+
Query.equal('platform', resolvedProfile.organizationPlatform)
71+
]);
7072
} else {
7173
organizations = await sdk.forConsole.teams.list();
7274
}
@@ -90,7 +92,9 @@ export const load: PageLoad = async ({ parent, url }) => {
9092
}
9193

9294
if (isCloud) {
93-
organizations = await sdk.forConsole.billing.listOrganization();
95+
organizations = await sdk.forConsole.billing.listOrganization([
96+
Query.equal('platform', resolvedProfile.organizationPlatform)
97+
]);
9498
} else {
9599
organizations = await sdk.forConsole.teams.list();
96100
}

src/routes/(public)/sites/deploy/+page.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { sdk } from '$lib/stores/sdk.js';
22
import { redirect, error } from '@sveltejs/kit';
33
import { base } from '$app/paths';
44
import { isCloud } from '$lib/system';
5-
import { ID, type Models } from '@appwrite.io/console';
5+
import { ID, type Models, Query } from '@appwrite.io/console';
66
import type { OrganizationList } from '$lib/stores/organization';
77
import { redirectTo } from '$routes/store';
88
import type { PageLoad } from './$types';
@@ -83,7 +83,9 @@ export const load: PageLoad = async ({ parent, url }) => {
8383
let organizations: Models.TeamList<Record<string, unknown>> | OrganizationList | undefined;
8484

8585
if (isCloud) {
86-
organizations = await sdk.forConsole.billing.listOrganization();
86+
organizations = await sdk.forConsole.billing.listOrganization([
87+
Query.equal('platform', resolvedProfile.organizationPlatform)
88+
]);
8789
} else {
8890
organizations = await sdk.forConsole.teams.list();
8991
}
@@ -107,7 +109,9 @@ export const load: PageLoad = async ({ parent, url }) => {
107109

108110
// Refetch organizations after creation
109111
if (isCloud) {
110-
organizations = await sdk.forConsole.billing.listOrganization();
112+
organizations = await sdk.forConsole.billing.listOrganization([
113+
Query.equal('platform', resolvedProfile.organizationPlatform)
114+
]);
111115
} else {
112116
organizations = await sdk.forConsole.teams.list();
113117
}

src/routes/(public)/template-[template]/+page.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { BillingPlan } from '$lib/constants.js';
22
import { sdk } from '$lib/stores/sdk.js';
3-
import { ID, type Models } from '@appwrite.io/console';
3+
import { ID, type Models, Query } from '@appwrite.io/console';
44
import { isCloud } from '$lib/system.js';
55
import { error, redirect } from '@sveltejs/kit';
66
import type { OrganizationList } from '$lib/stores/organization.js';
77
import { redirectTo } from '$routes/store.js';
88
import { base } from '$app/paths';
9+
import { resolvedProfile } from '$lib/profiles/index.svelte';
910

1011
export const load = async ({ parent, url, params }) => {
1112
const { account } = await parent();
@@ -39,7 +40,11 @@ export const load = async ({ parent, url, params }) => {
3940

4041
let organizations: Models.TeamList<Record<string, unknown>> | OrganizationList | undefined;
4142
if (isCloud) {
42-
organizations = account?.$id ? await sdk.forConsole.billing.listOrganization() : undefined;
43+
organizations = account?.$id
44+
? await sdk.forConsole.billing.listOrganization([
45+
Query.equal('platform', resolvedProfile.organizationPlatform)
46+
])
47+
: undefined;
4348
} else {
4449
organizations = account?.$id ? await sdk.forConsole.teams.list() : undefined;
4550
}

src/routes/+layout.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import type { LayoutLoad } from './$types';
88
import { redirectTo } from './store';
99
import { base, resolve } from '$app/paths';
1010
import type { Account } from '$lib/stores/user';
11-
import type { AppwriteException } from '@appwrite.io/console';
11+
import { type AppwriteException, Query } from '@appwrite.io/console';
1212
import { isCloud, VARS } from '$lib/system';
1313
import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect';
14+
import { resolvedProfile } from '$lib/profiles/index.svelte';
1415

1516
export const ssr = false;
1617

@@ -42,7 +43,9 @@ export const load: LayoutLoad = async ({ depends, url, route }) => {
4243
account: account,
4344
organizations: !isCloud
4445
? await sdk.forConsole.teams.list()
45-
: await sdk.forConsole.billing.listOrganization()
46+
: await sdk.forConsole.billing.listOrganization([
47+
Query.equal('platform', resolvedProfile.organizationPlatform)
48+
])
4649
};
4750
}
4851

0 commit comments

Comments
 (0)