Skip to content

fix: correct project limit warnings for multi-organization users #2194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 11, 2025

Conversation

HarshMN2345
Copy link
Member

What does this PR do?

Fixes issue where users with multiple organizations (Free/Pro/Scale)
saw incorrect project limit warnings and "Manage projects" modal
showing projects from other organizations.

Test Plan

image

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

yes

Copy link

appwrite bot commented Aug 7, 2025

Console

Project ID: 688b7bf400350cbd60e9

Sites (2)
Site Status Logs Preview QR
 console-qa
688b7cf6003b1842c9dc
Ready Ready View Logs Preview URL QR Code
 console-cloud
688b7c18002b9b871a8f
Ready Ready View Logs Preview URL QR Code

Note

You can use Avatars API to generate QR code for any text or URLs.

Comment on lines 30 to 33
const orgProjects = await sdk.forConsole.projects.list([
Query.equal('teamId', page.data.organization.$id),
Query.limit(1000)
]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do also not have this same thing on upper level +layout.ts? lets see which one we can avoid. this is massive data :\

@@ -167,7 +168,7 @@
</DropList>
</div>

{#if isCloud && $currentPlan?.projects && $currentPlan?.projects > 0 && data.organization.projects.length > 0 && data.projects.total > 2 && $canWriteProjects}
{#if isCloud && $currentPlan?.projects && $currentPlan?.projects > 0 && data.organization.projects.length > 0 && data.projects.total > $currentPlan.projects && $canWriteProjects && data.organization.billingPlan === BillingPlan.FREE}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the free plan check, lets see if the currentPlan.projects or whatever the variable is. We need to avoid hardcoded billing plan name/id checks.

@HarshMN2345 HarshMN2345 requested a review from Copilot August 8, 2025 11:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes project limit warnings for users with multiple organizations, ensuring that project limits and related UI elements display correctly based on the current organization's plan rather than showing incorrect information from other organizations.

  • Updates project limit validation to use organization-specific project counts instead of global counts
  • Modifies the project selection modal to only show projects from the current organization
  • Dynamically displays correct project limits in UI messages based on the current plan

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/routes/(console)/organization-[organization]/+page.svelte Updates alert condition to compare against actual plan project limit instead of hardcoded value
src/routes/(console)/+layout.svelte Adds organization-specific project count validation before calling limit check
src/lib/stores/billing.ts Modifies project limit check to accept optional organization project count parameter
src/lib/layout/createProject.svelte Dynamically displays project limit from current plan instead of hardcoded "2 projects"
src/lib/components/billing/alerts/selectProjectCloud.svelte Filters projects to only show those from current organization and uses dynamic limit text

const plan = await sdk.forConsole.billing.getOrganizationPlan(org.$id);
if (!plan) return;
if (plan.$id !== BillingPlan.FREE) return;
if (org.projects?.length > 0) return;

if (plan.projects > 0 && projects > plan.projects) {
let projectCount = orgProjectCount;
if (projectCount === undefined) return;
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early return when projectCount is undefined may silently skip important project limit checks. Consider logging this condition or providing a fallback mechanism to fetch the project count when it's not provided.

Suggested change
if (projectCount === undefined) return;
if (projectCount === undefined) {
console.warn('checkForProjectsLimit: projectCount is undefined, attempting to fetch project count for org', org?.$id);
try {
// Attempt to fetch the project count as a fallback
const projectsList = await sdk.forConsole.projects.list([Query.equal('organizationId', org.$id)]);
projectCount = projectsList?.total ?? projectsList?.projects?.length ?? 0;
} catch (err) {
console.error('checkForProjectsLimit: Failed to fetch project count for org', org?.$id, err);
return;
}
}

Copilot uses AI. Check for mistakes.

projects = page.data.allProjects?.projects || [];
const currentOrgId = page.data.organization?.$id;
projects =
page.data.currentOrgId === currentOrgId ? page.data.allProjects?.projects || [] : [];
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The ternary operator condition could be clearer. Consider extracting this logic into a well-named variable or function to improve readability and make the organization filtering intent more explicit.

Suggested change
page.data.currentOrgId === currentOrgId ? page.data.allProjects?.projects || [] : [];
const isCurrentOrganizationSelected = page.data.currentOrgId === currentOrgId;
projects =
isCurrentOrganizationSelected ? page.data.allProjects?.projects || [] : [];

Copilot uses AI. Check for mistakes.

@HarshMN2345 HarshMN2345 requested review from ItzNotABug and Meldiron and removed request for Meldiron August 8, 2025 12:43
@Meldiron Meldiron merged commit 29e8501 into main Aug 11, 2025
4 checks passed
@Meldiron Meldiron deleted the fix-SER-228-fix-project-limit-warnings branch August 11, 2025 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants