From 2432635fbaf5dc6bfda215856eb925eae2f93af9 Mon Sep 17 00:00:00 2001
From: ernstmul
Date: Thu, 19 Dec 2024 16:05:35 +0100
Subject: [PATCH] Add feature flag checks
---
src/lib/sdk/billing.ts | 1 +
.../billing/budgetCap.svelte | 5 ++---
.../(console)/project-[project]/+layout.ts | 6 +++++-
.../auth/security/updateMockNumbers.svelte | 6 ++----
.../auth/templates/+page.svelte | 6 ++----
.../database-[database]/backups/+page.svelte | 17 ++++++-----------
.../backups/containerHeader.svelte | 19 +++++++------------
7 files changed, 25 insertions(+), 35 deletions(-)
diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts
index 811dce6d4..8cb3b58a9 100644
--- a/src/lib/sdk/billing.ts
+++ b/src/lib/sdk/billing.ts
@@ -286,6 +286,7 @@ export type Plan = {
supportsMockNumbers: boolean;
backupsEnabled: boolean;
backupPolicies: number;
+ emailBranding: boolean;
};
export type PlansInfo = {
diff --git a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte
index cfec9bea0..e313d59a5 100644
--- a/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte
+++ b/src/routes/(console)/organization-[organization]/billing/budgetCap.svelte
@@ -6,7 +6,7 @@
import { Button, Form, FormList, InputNumber, InputSwitch } from '$lib/elements/forms';
import { showUsageRatesModal, upgradeURL } from '$lib/stores/billing';
import { addNotification } from '$lib/stores/notifications';
- import { organization } from '$lib/stores/organization';
+ import { organization, currentPlan } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { onMount } from 'svelte';
@@ -59,8 +59,7 @@
class="link">Learn more about usage rates.
-
- {#if $organization?.billingPlan === BillingPlan.FREE}
+ {#if !$currentPlan.budgeting}
Budget caps are a Pro plan feature
diff --git a/src/routes/(console)/project-[project]/+layout.ts b/src/routes/(console)/project-[project]/+layout.ts
index 57df9d528..018462d75 100644
--- a/src/routes/(console)/project-[project]/+layout.ts
+++ b/src/routes/(console)/project-[project]/+layout.ts
@@ -7,9 +7,11 @@ import { failedInvoice } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import type { Organization } from '$lib/stores/organization';
import { defaultRoles, defaultScopes } from '$lib/constants';
+import type { Plan } from '$lib/sdk/billing';
export const load: LayoutLoad = async ({ params, depends }) => {
depends(Dependencies.PROJECT);
+ let currentPlan: Plan = null;
try {
const project = await sdk.forConsole.projects.get(params.project);
@@ -27,6 +29,7 @@ export const load: LayoutLoad = async ({ params, depends }) => {
let roles = isCloud ? [] : defaultRoles;
let scopes = isCloud ? [] : defaultScopes;
if (isCloud) {
+ currentPlan = await sdk.forConsole.billing.getPlan(project.teamId);
const res = await sdk.forConsole.billing.getRoles(project.teamId);
roles = res.roles;
scopes = res.scopes;
@@ -39,7 +42,8 @@ export const load: LayoutLoad = async ({ params, depends }) => {
project,
organization,
roles,
- scopes
+ scopes,
+ currentPlan
};
} catch (e) {
error(e.code, e.message);
diff --git a/src/routes/(console)/project-[project]/auth/security/updateMockNumbers.svelte b/src/routes/(console)/project-[project]/auth/security/updateMockNumbers.svelte
index 9ceb59758..cd1830a26 100644
--- a/src/routes/(console)/project-[project]/auth/security/updateMockNumbers.svelte
+++ b/src/routes/(console)/project-[project]/auth/security/updateMockNumbers.svelte
@@ -9,8 +9,7 @@
import { addNotification } from '$lib/stores/notifications';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
- import { organization } from '$lib/stores/organization';
- import { BillingPlan } from '$lib/constants';
+ import { currentPlan } from '$lib/stores/organization';
import { isCloud, isSelfHosted } from '$lib/system';
import MockNumbersLight from './mock-numbers-light.png';
import MockNumbersDark from './mock-numbers-dark.png';
@@ -26,9 +25,8 @@
$: initialNumbers = $project?.authMockNumbers?.map((num) => ({ ...num })) ?? [];
$: isSubmitDisabled = JSON.stringify(numbers) === JSON.stringify(initialNumbers);
- //TODO check for plan details on if mocknumbers is allowed
let isComponentDisabled: boolean =
- isSelfHosted || (isCloud && $organization?.billingPlan === BillingPlan.FREE);
+ isSelfHosted || (isCloud && !$currentPlan.supportsMockNumbers);
let emptyStateTitle: string = isSelfHosted
? 'Available on Appwrite Cloud'
: 'Upgrade to add mock phone numbers';
diff --git a/src/routes/(console)/project-[project]/auth/templates/+page.svelte b/src/routes/(console)/project-[project]/auth/templates/+page.svelte
index 6b10dc048..278fb0ca7 100644
--- a/src/routes/(console)/project-[project]/auth/templates/+page.svelte
+++ b/src/routes/(console)/project-[project]/auth/templates/+page.svelte
@@ -50,8 +50,7 @@
// import { baseEmailTemplate, baseSmsTemplate, emailTemplate, smsTemplate } from './store';
import { baseEmailTemplate, emailTemplate } from './store';
import { Button } from '$lib/elements/forms';
- import { organization } from '$lib/stores/organization';
- import { BillingPlan } from '$lib/constants';
+ import { currentPlan } from '$lib/stores/organization';
import EmailSignature from './emailSignature.svelte';
import { isCloud } from '$lib/system';
import type {
@@ -268,8 +267,7 @@
-->
-
- {#if isCloud && $organization?.billingPlan === BillingPlan.FREE}
+ {#if isCloud && !$currentPlan.emailBranding}
{/if}
diff --git a/src/routes/(console)/project-[project]/databases/database-[database]/backups/+page.svelte b/src/routes/(console)/project-[project]/databases/database-[database]/backups/+page.svelte
index d449d5a32..f7d3b0bb2 100644
--- a/src/routes/(console)/project-[project]/databases/database-[database]/backups/+page.svelte
+++ b/src/routes/(console)/project-[project]/databases/database-[database]/backups/+page.svelte
@@ -11,9 +11,9 @@
import { addNotification, dismissAllNotifications } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { invalidate } from '$app/navigation';
- import { BillingPlan, Dependencies } from '$lib/constants';
+ import { Dependencies } from '$lib/constants';
import { isCloud, isSelfHosted } from '$lib/system';
- import { organization } from '$lib/stores/organization';
+ import { currentPlan } from '$lib/stores/organization';
import { onMount } from 'svelte';
import { feedback } from '$lib/stores/feedback';
import { cronExpression, type UserBackupPolicy } from '$lib/helpers/backups';
@@ -24,19 +24,12 @@
let policyCreateError: string;
let totalPolicies: UserBackupPolicy[] = [];
- // TODO: check the plan to see if the custom policies are disabled
- let isDisabled = isSelfHosted || (isCloud && $organization?.billingPlan === BillingPlan.FREE);
+ let isDisabled = isSelfHosted || (isCloud && !$currentPlan.backupsEnabled);
export let data: PageData;
$: hasPolicyCreationLimitations = () => {
- // allow when on Pro and no policy exists
- // TODO: check the plan to see if the custom policies are disabled and limitations
- if ($organization?.billingPlan === BillingPlan.PRO) {
- return data.policies.total > 0;
- } else if ($organization?.billingPlan === BillingPlan.SCALE) {
- return false;
- }
+ return data.policies.total >= $currentPlan.backupPolicies;
};
const showFeedbackNotification = () => {
@@ -187,6 +180,8 @@
buttonType="secondary"
buttonDisabled={isDisabled}
hasLimitations={hasPolicyCreationLimitations()}
+ maxPolicies={$currentPlan.backupPolicies}
+ policiesCreated={data.policies.total}
buttonMethod={() => {
$showCreatePolicy = true;
trackEvent('click_policy_create');
diff --git a/src/routes/(console)/project-[project]/databases/database-[database]/backups/containerHeader.svelte b/src/routes/(console)/project-[project]/databases/database-[database]/backups/containerHeader.svelte
index a01b1c581..ce79b0d15 100644
--- a/src/routes/(console)/project-[project]/databases/database-[database]/backups/containerHeader.svelte
+++ b/src/routes/(console)/project-[project]/databases/database-[database]/backups/containerHeader.svelte
@@ -4,14 +4,13 @@
import { Pill } from '$lib/elements';
import { wizard } from '$lib/stores/wizard';
import SupportWizard from '$routes/(console)/supportWizard.svelte';
- import { BillingPlan } from '$lib/constants';
- import { organization } from '$lib/stores/organization';
export let isFlex = true;
export let title: string;
export let buttonText: string = null;
- export let hasLimitations: boolean = true;
+ export let policiesCreated: number = 0;
+ export let maxPolicies: number = 0;
export let buttonMethod: () => void = null;
export let buttonEvent: string = buttonText?.toLocaleLowerCase();
export let buttonDisabled = false;
@@ -27,16 +26,16 @@
{title}
- {#if hasLimitations && $organization.billingPlan === BillingPlan.PRO}
+ {#if title === 'Policies' && policiesCreated >= maxPolicies}
(showDropdown = true)}>
- 1/1 created
+ {policiesCreated}/{maxPolicies} created
- You are limited to one policy on Pro plan.
+ You are limited to one policy on your plan.
{
@@ -52,14 +51,10 @@
{/if}
- {#if !hasLimitations}
+ {#if title === 'Backups' || policiesCreated < maxPolicies}
{
- showDropdown = true;
- }
- : buttonMethod}
+ on:click={buttonMethod}
disabled={buttonDisabled}
text={buttonType === 'text'}
secondary={buttonType === 'secondary'}>