mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
Merge pull request #2315 from appwrite/fix-plan-service-limit-check
Fix: remove hacks on determining service limits
This commit is contained in:
2 files changed
+25
-16
No files matched your search
+17
-13
@@ -138,6 +138,7 @@ export type PlanServices =
|
||||
| 'logs'
|
||||
| 'memberAddon'
|
||||
| 'members'
|
||||
| 'projects'
|
||||
| 'platforms'
|
||||
| 'realtime'
|
||||
| 'realtimeAddon'
|
||||
@@ -154,20 +155,23 @@ export type PlanServices =
|
||||
export function getServiceLimit(serviceId: PlanServices, tier: Tier = null, plan?: Plan): number {
|
||||
if (!isCloud) return 0;
|
||||
if (!serviceId) return 0;
|
||||
const info = get(plansInfo);
|
||||
if (!info) return 0;
|
||||
plan ??= info.get(tier ?? get(organization)?.billingPlan);
|
||||
// members are no longer a variable on plan itself!
|
||||
// the correct info for members/seats, resides in `addons`.
|
||||
// plan > addons > seats/others
|
||||
|
||||
plan ??= get(currentPlan);
|
||||
|
||||
if (tier) {
|
||||
const info = get(plansInfo);
|
||||
if (!info) return 0;
|
||||
plan ??= info.get(tier);
|
||||
}
|
||||
|
||||
if (serviceId === 'members') {
|
||||
// pro and scale plans have unlimited seats (per-project NEW pricing model)
|
||||
const currentTier = tier ?? get(organization)?.billingPlan;
|
||||
if (currentTier === BillingPlan.PRO || currentTier === BillingPlan.SCALE) {
|
||||
return Infinity; // unlimited seats for Pro and Scale plans
|
||||
}
|
||||
// Free plan still has 1 member limit
|
||||
return (plan?.['addons']['seats'] || [])['limit'] ?? 1;
|
||||
if (!plan?.addons?.seats) return Infinity;
|
||||
return plan.addons.seats?.limit ?? 1;
|
||||
}
|
||||
|
||||
if (serviceId === 'projects') {
|
||||
if (!plan?.addons?.projects) return Infinity;
|
||||
return plan.addons.projects?.limit ?? 1;
|
||||
}
|
||||
|
||||
return plan?.[serviceId] ?? 0;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
} from '$lib/components';
|
||||
import { trackEvent, Click } from '$lib/actions/analytics';
|
||||
import { type Models } from '@appwrite.io/console';
|
||||
import { readOnly, upgradeURL } from '$lib/stores/billing';
|
||||
import { getServiceLimit, readOnly, upgradeURL } from '$lib/stores/billing';
|
||||
import { onMount, type ComponentType } from 'svelte';
|
||||
import { canWriteProjects } from '$lib/stores/roles';
|
||||
import { checkPricingRefAndRedirect } from '$lib/helpers/pricingRedirect';
|
||||
@@ -79,6 +79,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: projectCreationDisabled =
|
||||
(isCloud && getServiceLimit('projects') <= data.allProjectsCount) ||
|
||||
($readOnly && !GRACE_PERIOD_OVERRIDE) ||
|
||||
!$canWriteProjects;
|
||||
|
||||
$: $registerCommands([
|
||||
{
|
||||
label: 'Create project',
|
||||
@@ -86,7 +91,7 @@
|
||||
showCreate = true;
|
||||
},
|
||||
keys: ['c'],
|
||||
disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteProjects,
|
||||
disabled: projectCreationDisabled,
|
||||
group: 'projects',
|
||||
icon: IconPlus
|
||||
}
|
||||
@@ -125,7 +130,7 @@
|
||||
<Button
|
||||
on:click={handleCreateProject}
|
||||
event="create_project"
|
||||
disabled={$readOnly && !GRACE_PERIOD_OVERRIDE}>
|
||||
disabled={projectCreationDisabled}>
|
||||
<Icon icon={IconPlus} slot="start" size="s" />
|
||||
Create project
|
||||
</Button>
|
||||
|
||||
Reference in new issue
Block a user