diff --git a/src/locales/ar/main.json b/src/locales/ar/main.json index 8e0367bf1d9..409215745d3 100644 --- a/src/locales/ar/main.json +++ b/src/locales/ar/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "إنشاء مساحة عمل جديدة", "failedToSwitch": "فشل في تبديل مساحة العمل", "managedByOrganization": "تدير مؤسستك مساحات العمل الخاصة بك، لذا لا يمكنك إنشاء واحدة.", - "maxWorkspacesReached": "يمكنك امتلاك ١٠ مساحات عمل فقط. احذف واحدة لإنشاء مساحة جديدة.", + "maxWorkspacesReached": "يمكنك امتلاك {max} مساحات عمل فقط. احذف واحدة لإنشاء مساحة جديدة.", "personal": "شخصي", "roleMember": "عضو", "roleOwner": "المالك", diff --git a/src/locales/de/main.json b/src/locales/de/main.json index d0255c9712c..620b98a080b 100644 --- a/src/locales/de/main.json +++ b/src/locales/de/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "Arbeitsbereich erstellen", "failedToSwitch": "Arbeitsbereich konnte nicht gewechselt werden", "managedByOrganization": "Ihre Organisation verwaltet Ihre Workspaces, daher können Sie keinen erstellen.", - "maxWorkspacesReached": "Sie können nur 10 Arbeitsbereiche besitzen. Löschen Sie einen, um einen neuen zu erstellen.", + "maxWorkspacesReached": "Sie können nur {max} Arbeitsbereiche besitzen. Löschen Sie einen, um einen neuen zu erstellen.", "personal": "Persönlich", "roleMember": "Mitglied", "roleOwner": "Inhaber", diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 5dd715c263b..68df98d16fb 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -4112,7 +4112,7 @@ "roleOwner": "Owner", "roleMember": "Member", "createWorkspace": "Create a workspace", - "maxWorkspacesReached": "You can only own 10 workspaces. Delete one to create a new one.", + "maxWorkspacesReached": "You can only own {max} workspace. Delete it to create a new one. | You can only own {max} workspaces. Delete one to create a new one.", "managedByOrganization": "Your organization manages your workspaces, so you can't create one.", "cannotCreateWorkspace": "You can't create a workspace on this account right now.", "failedToSwitch": "Failed to switch workspace" diff --git a/src/locales/es/main.json b/src/locales/es/main.json index 783160edfc3..d6415c061e1 100644 --- a/src/locales/es/main.json +++ b/src/locales/es/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "Crear nuevo espacio de trabajo", "failedToSwitch": "No se pudo cambiar el espacio de trabajo", "managedByOrganization": "Tu organización administra tus espacios de trabajo, por lo que no puedes crear uno.", - "maxWorkspacesReached": "Solo puedes ser propietario de 10 espacios de trabajo. Elimina uno para crear uno nuevo.", + "maxWorkspacesReached": "Solo puedes ser propietario de {max} espacios de trabajo. Elimina uno para crear uno nuevo.", "personal": "Personal", "roleMember": "Miembro", "roleOwner": "Propietario", diff --git a/src/locales/fa/main.json b/src/locales/fa/main.json index 4ecfaf5a716..0ddfeaaea25 100644 --- a/src/locales/fa/main.json +++ b/src/locales/fa/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "ایجاد محیط کاری جدید", "failedToSwitch": "تغییر فضای کاری ناموفق بود", "managedByOrganization": "سازمان شما workspaceهایتان را مدیریت می‌کند؛ بنابراین نمی‌توانید workspace جدیدی ایجاد کنید.", - "maxWorkspacesReached": "شما فقط می‌توانید مالک ۱۰ محیط کاری باشید. برای ایجاد محیط کاری جدید، یکی را حذف کنید.", + "maxWorkspacesReached": "شما فقط می‌توانید مالک {max} محیط کاری باشید. برای ایجاد محیط کاری جدید، یکی را حذف کنید.", "personal": "شخصی", "roleMember": "عضو", "roleOwner": "مالک", diff --git a/src/locales/fr/main.json b/src/locales/fr/main.json index 6354005d07c..edb6089f586 100644 --- a/src/locales/fr/main.json +++ b/src/locales/fr/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "Créer un nouvel espace de travail", "failedToSwitch": "Échec du changement d’espace de travail", "managedByOrganization": "Votre organisation gère vos espaces de travail, vous ne pouvez donc pas en créer.", - "maxWorkspacesReached": "Vous ne pouvez posséder que 10 espaces de travail. Supprimez-en un pour en créer un nouveau.", + "maxWorkspacesReached": "Vous ne pouvez posséder que {max} espaces de travail. Supprimez-en un pour en créer un nouveau.", "personal": "Personnel", "roleMember": "Membre", "roleOwner": "Propriétaire", diff --git a/src/locales/he/main.json b/src/locales/he/main.json index cdccb9a3185..d1ed7101944 100644 --- a/src/locales/he/main.json +++ b/src/locales/he/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "יצירת סביבת עבודה חדשה", "failedToSwitch": "המעבר לסביבת העבודה נכשל", "managedByOrganization": "הארגון שלך מנהל את סביבות העבודה שלך, ולכן אין באפשרותך ליצור אחת.", - "maxWorkspacesReached": "ניתן להיות בעלים של 10 סביבות עבודה בלבד. מחק אחת כדי ליצור חדשה.", + "maxWorkspacesReached": "ניתן להיות בעלים של {max} סביבות עבודה בלבד. מחק אחת כדי ליצור חדשה.", "personal": "אישי", "roleMember": "חבר", "roleOwner": "בעלים", diff --git a/src/locales/it/main.json b/src/locales/it/main.json index 4c26a9b7217..e1b3b41b160 100644 --- a/src/locales/it/main.json +++ b/src/locales/it/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "Crea un workspace", "failedToSwitch": "Cambio workspace non riuscito", "managedByOrganization": "La tua organizzazione gestisce i tuoi workspace, quindi non puoi crearne uno.", - "maxWorkspacesReached": "Puoi possedere solo 10 workspace. Elimina uno per crearne uno nuovo.", + "maxWorkspacesReached": "Puoi possedere solo {max} workspace. Elimina uno per crearne uno nuovo.", "personal": "Personale", "roleMember": "Membro", "roleOwner": "Proprietario", diff --git a/src/locales/ja/main.json b/src/locales/ja/main.json index b465dd1963c..5f631cf1d8b 100644 --- a/src/locales/ja/main.json +++ b/src/locales/ja/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "新しいワークスペースを作成", "failedToSwitch": "ワークスペースの切り替えに失敗しました", "managedByOrganization": "組織がワークスペースを管理しているため、新しいワークスペースを作成できません。", - "maxWorkspacesReached": "所有できるワークスペースは10個までです。新しく作成するには1つ削除してください。", + "maxWorkspacesReached": "所有できるワークスペースは{max}個までです。新しく作成するには1つ削除してください。", "personal": "個人用", "roleMember": "メンバー", "roleOwner": "オーナー", diff --git a/src/locales/ko/main.json b/src/locales/ko/main.json index ec3765a3929..01c59f88a2c 100644 --- a/src/locales/ko/main.json +++ b/src/locales/ko/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "새 워크스페이스 만들기", "failedToSwitch": "워크스페이스 전환에 실패했습니다", "managedByOrganization": "조직에서 워크스페이스를 관리하므로 새로 만들 수 없습니다.", - "maxWorkspacesReached": "최대 10개의 워크스페이스만 소유할 수 있습니다. 새로 만들려면 하나를 삭제하세요.", + "maxWorkspacesReached": "최대 {max}개의 워크스페이스만 소유할 수 있습니다. 새로 만들려면 하나를 삭제하세요.", "personal": "개인", "roleMember": "멤버", "roleOwner": "소유자", diff --git a/src/locales/pt-BR/main.json b/src/locales/pt-BR/main.json index ea374a5619e..19859c65d76 100644 --- a/src/locales/pt-BR/main.json +++ b/src/locales/pt-BR/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "Criar novo espaço de trabalho", "failedToSwitch": "Falha ao trocar de espaço de trabalho", "managedByOrganization": "Sua organização gerencia seus espaços de trabalho, portanto você não pode criar um.", - "maxWorkspacesReached": "Você só pode possuir 10 espaços de trabalho. Exclua um para criar um novo.", + "maxWorkspacesReached": "Você só pode possuir {max} espaços de trabalho. Exclua um para criar um novo.", "personal": "Pessoal", "roleMember": "Membro", "roleOwner": "Proprietário", diff --git a/src/locales/ru/main.json b/src/locales/ru/main.json index 5ab053defdd..d336e0e0750 100644 --- a/src/locales/ru/main.json +++ b/src/locales/ru/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "Создать новое рабочее пространство", "failedToSwitch": "Не удалось переключить рабочее пространство", "managedByOrganization": "Ваша организация управляет вашими рабочими пространствами, поэтому вы не можете создать новое.", - "maxWorkspacesReached": "Вы можете владеть только 10 рабочими пространствами. Удалите одно, чтобы создать новое.", + "maxWorkspacesReached": "Вы можете владеть только {max} рабочими пространствами. Удалите одно, чтобы создать новое.", "personal": "Личное", "roleMember": "Участник", "roleOwner": "Владелец", diff --git a/src/locales/tr/main.json b/src/locales/tr/main.json index 9ec8daff1d4..c658c8260c4 100644 --- a/src/locales/tr/main.json +++ b/src/locales/tr/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "Yeni çalışma alanı oluştur", "failedToSwitch": "Çalışma alanı değiştirilemedi", "managedByOrganization": "Kuruluşunuz çalışma alanlarınızı yönettiği için çalışma alanı oluşturamazsınız.", - "maxWorkspacesReached": "Yalnızca 10 çalışma alanına sahip olabilirsiniz. Yeni bir tane oluşturmak için birini silin.", + "maxWorkspacesReached": "Yalnızca {max} çalışma alanına sahip olabilirsiniz. Yeni bir tane oluşturmak için birini silin.", "personal": "Kişisel", "roleMember": "Üye", "roleOwner": "Sahip", diff --git a/src/locales/zh-TW/main.json b/src/locales/zh-TW/main.json index ebb86c33c42..39d2693cc51 100644 --- a/src/locales/zh-TW/main.json +++ b/src/locales/zh-TW/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "建立新工作區", "failedToSwitch": "切換工作區失敗", "managedByOrganization": "您的組織管理您的工作區,因此您無法建立工作區。", - "maxWorkspacesReached": "您最多只能擁有 10 個工作區。請刪除一個以建立新工作區。", + "maxWorkspacesReached": "您最多只能擁有 {max} 個工作區。請刪除一個以建立新工作區。", "personal": "個人", "roleMember": "成員", "roleOwner": "擁有者", diff --git a/src/locales/zh/main.json b/src/locales/zh/main.json index 0fc02304ab9..9927ed82b0c 100644 --- a/src/locales/zh/main.json +++ b/src/locales/zh/main.json @@ -6186,7 +6186,7 @@ "createWorkspace": "创建新工作区", "failedToSwitch": "切换工作区失败", "managedByOrganization": "您的组织管理您的工作区,因此您无法创建工作区。", - "maxWorkspacesReached": "您最多只能拥有10个工作区。请删除一个以创建新工作区。", + "maxWorkspacesReached": "您最多只能拥有{max}个工作区。请删除一个以创建新工作区。", "personal": "个人", "roleMember": "成员", "roleOwner": "所有者", diff --git a/src/platform/account/components/WorkspaceSwitcherPopover.test.ts b/src/platform/account/components/WorkspaceSwitcherPopover.test.ts index 3ffeef5b18f..f9e9c768432 100644 --- a/src/platform/account/components/WorkspaceSwitcherPopover.test.ts +++ b/src/platform/account/components/WorkspaceSwitcherPopover.test.ts @@ -38,7 +38,7 @@ const i18n = createI18n({ 'Runs that use partner nodes spend credits from this workspace. Unlike on Cloud, every workspace saves to your usual output folder.', createWorkspace: 'Create a team workspace', maxWorkspacesReached: - 'You can only own 10 workspaces. Delete one to create a new one.', + 'You can only own {max} workspace. Delete it to create a new one. | You can only own {max} workspaces. Delete one to create a new one.', managedByOrganization: "Your organization manages your workspaces, so you can't create one.", cannotCreateWorkspace: @@ -275,32 +275,38 @@ describe('WorkspaceSwitcherPopover', () => { expect(list).not.toContainElement(createWorkspaceButton) }) - it('says why creation is off when an organization manages the workspaces', async () => { - const store = useTeamWorkspaceStore() - store.$patch({ - serverRefusesCreation: true, - workspacesManagedByOrganization: true - }) - const { emitted } = renderComponent() - - await userEvent.click( - screen.getByText(/Your organization manages your workspaces/) - ) - - expect(screen.queryByText('Create a team workspace')).toBeNull() - expect(emitted().create).toBeUndefined() - }) + it.for([ + { + reason: 'organization_managed', + notice: /Your organization manages your workspaces/ + }, + { + reason: 'owned_workspace_limit', + notice: /You can only own 25 workspaces/ + }, + { + reason: 'owned_workspace_limit', + max: 1, + notice: /You can only own 1 workspace\. Delete it/ + }, + { reason: undefined, notice: /can't create a workspace on this account/ } + ] as const)( + 'renders the served refusal ($reason) in place of creating', + async ({ reason, notice, max = 25 }) => { + const store = useTeamWorkspaceStore() + store.$patch({ + serverRefusesCreation: true, + creationDeniedReason: reason, + maxOwnedWorkspaces: max + }) + const { emitted } = renderComponent() - it('does not blame an organization when the server gives no reason', () => { - const store = useTeamWorkspaceStore() - store.$patch({ serverRefusesCreation: true }) - renderComponent() + await userEvent.click(screen.getByText(notice)) - expect( - screen.getByText(/can't create a workspace on this account/) - ).toBeInTheDocument() - expect(screen.queryByText(/Your organization manages/)).toBeNull() - }) + expect(screen.queryByText('Create a team workspace')).toBeNull() + expect(emitted().create).toBeUndefined() + } + ) it('hides the create-workspace footer on non-cloud distributions', () => { distributionMocks.isCloud = false diff --git a/src/platform/account/components/dialogs/TeamWorkspacesDialogContent.test.ts b/src/platform/account/components/dialogs/TeamWorkspacesDialogContent.test.ts index fa347df9e6e..ea1ce2b5c5c 100644 --- a/src/platform/account/components/dialogs/TeamWorkspacesDialogContent.test.ts +++ b/src/platform/account/components/dialogs/TeamWorkspacesDialogContent.test.ts @@ -120,7 +120,7 @@ describe('TeamWorkspacesDialogContent', () => { workspaceStore = useTeamWorkspaceStore(pinia) workspaceStore.workspaces = [] workspaceStore.serverRefusesCreation = false - workspaceStore.workspacesManagedByOrganization = false + workspaceStore.creationDeniedReason = undefined }) describe('workspace listing', () => { @@ -207,52 +207,39 @@ describe('TeamWorkspacesDialogContent', () => { ).toBeNull() } - it('replaces the create form with the organization notice', () => { - setOwnedWorkspaces() - workspaceStore.serverRefusesCreation = true - workspaceStore.workspacesManagedByOrganization = true - mountComponent() - expectNoCreateControls() - expect( - screen.getByText('workspaceSwitcher.managedByOrganization') - ).toBeInTheDocument() - expect(screen.getByText('Team Alpha')).toBeInTheDocument() - }) - - it('explains the owned-workspace limit', () => { - workspaceStore.workspaces = Array.from({ length: 10 }, (_, i) => - createTeamWorkspace({ id: `ws-${i}`, name: `Team ${i}`, role: 'owner' }) - ) - mountComponent() - expectNoCreateControls() - expect( - screen.getByText('workspaceSwitcher.maxWorkspacesReached') - ).toBeInTheDocument() - }) - - it('uses neutral copy when the server refuses without a known reason', () => { - setOwnedWorkspaces() - workspaceStore.serverRefusesCreation = true - mountComponent() - expectNoCreateControls() - expect( - screen.getByText('workspaceSwitcher.cannotCreateWorkspace') - ).toBeInTheDocument() - }) + it.for([ + { + reason: 'organization_managed', + notice: 'workspaceSwitcher.managedByOrganization' + }, + { + reason: 'owned_workspace_limit', + notice: 'workspaceSwitcher.maxWorkspacesReached' + }, + { reason: undefined, notice: 'workspaceSwitcher.cannotCreateWorkspace' } + ] as const)( + 'replaces the create form with the served $reason notice', + ({ reason, notice }) => { + setOwnedWorkspaces() + workspaceStore.serverRefusesCreation = true + workspaceStore.creationDeniedReason = reason + mountComponent() + expectNoCreateControls() + expect(screen.getByText(notice)).toBeInTheDocument() + expect(screen.getByText('Team Alpha')).toBeInTheDocument() + } + ) - it('keeps a server refusal neutral at the owned-workspace limit', () => { + it('keeps the create form when the server allows creation at any owned count', () => { workspaceStore.workspaces = Array.from({ length: 10 }, (_, i) => createTeamWorkspace({ id: `ws-${i}`, name: `Team ${i}`, role: 'owner' }) ) - workspaceStore.serverRefusesCreation = true mountComponent() - expectNoCreateControls() expect( - screen.getByText('workspaceSwitcher.cannotCreateWorkspace') + screen.getByRole('button', { + name: 'teamWorkspacesDialog.createWorkspace' + }) ).toBeInTheDocument() - expect( - screen.queryByText('workspaceSwitcher.maxWorkspacesReached') - ).toBeNull() }) }) diff --git a/src/platform/workspace/composables/useCreateWorkspaceRefusal.ts b/src/platform/workspace/composables/useCreateWorkspaceRefusal.ts index 7d2b7bdd8b4..9b824ac3b28 100644 --- a/src/platform/workspace/composables/useCreateWorkspaceRefusal.ts +++ b/src/platform/workspace/composables/useCreateWorkspaceRefusal.ts @@ -5,19 +5,25 @@ import { useI18n } from 'vue-i18n' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' const REFUSAL_KEYS = { - organization: 'workspaceSwitcher.managedByOrganization', - limit: 'workspaceSwitcher.maxWorkspacesReached', + organization_managed: 'workspaceSwitcher.managedByOrganization', + owned_workspace_limit: 'workspaceSwitcher.maxWorkspacesReached', unknown: 'workspaceSwitcher.cannotCreateWorkspace' } as const /** The notice shown in place of creating a workspace, or null when creation is allowed. */ export function useCreateWorkspaceRefusal() { const { t } = useI18n() - const { createWorkspaceRefusal } = storeToRefs(useTeamWorkspaceStore()) + const { createWorkspaceRefusal, maxOwnedWorkspaces } = storeToRefs( + useTeamWorkspaceStore() + ) return computed(() => createWorkspaceRefusal.value - ? t(REFUSAL_KEYS[createWorkspaceRefusal.value]) + ? t( + REFUSAL_KEYS[createWorkspaceRefusal.value], + { max: maxOwnedWorkspaces.value }, + maxOwnedWorkspaces.value ?? 0 + ) : null ) } diff --git a/src/platform/workspace/stores/teamWorkspaceStore.test.ts b/src/platform/workspace/stores/teamWorkspaceStore.test.ts index b27bb7e02f5..8151279793a 100644 --- a/src/platform/workspace/stores/teamWorkspaceStore.test.ts +++ b/src/platform/workspace/stores/teamWorkspaceStore.test.ts @@ -226,7 +226,6 @@ describe('useTeamWorkspaceStore', () => { expect(store.personalWorkspace).toBeNull() expect(store.isInPersonalWorkspace).toBe(false) expect(store.sharedWorkspaces).toEqual([]) - expect(store.ownedWorkspacesCount).toBe(0) expect(store.canCreateWorkspace).toBe(true) expect(store.members).toEqual([]) expect(store.pendingInvites).toEqual([]) @@ -1477,21 +1476,6 @@ describe('useTeamWorkspaceStore', () => { expect(store.sharedWorkspaces[0].id).toBe(mockTeamWorkspace.id) }) - it('ownedWorkspacesCount counts owned workspaces', async () => { - mockWorkspaceApi.list.mockResolvedValue({ - workspaces: [ - mockPersonalWorkspace, - mockTeamWorkspace, - mockMemberWorkspace - ] - }) - - const store = useTeamWorkspaceStore() - await store.initialize() - - expect(store.ownedWorkspacesCount).toBe(2) - }) - it.for([ { canCreate: false, expected: false }, { canCreate: true, expected: true }, @@ -1521,33 +1505,45 @@ describe('useTeamWorkspaceStore', () => { it.for([ { - reason: 'organization', + reason: 'organization_managed', response: { - workspaces: [mockPersonalWorkspace, mockTeamWorkspace], - default_workspace_id: mockTeamWorkspace.id, - can_create_workspace: false + workspaces: [mockTeamWorkspace], + can_create_workspace: false, + max_owned_workspaces: 10, + denied_reasons: { can_create_workspace: 'organization_managed' } } }, { - reason: 'unknown', + reason: 'owned_workspace_limit', response: { - workspaces: [mockPersonalWorkspace, ...ownedTeams(9)], - can_create_workspace: false + workspaces: [mockPersonalWorkspace], + can_create_workspace: false, + max_owned_workspaces: 25, + denied_reasons: { can_create_workspace: 'owned_workspace_limit' } } }, { reason: 'unknown', response: { - workspaces: [mockPersonalWorkspace], - can_create_workspace: false + workspaces: [mockPersonalWorkspace, mockTeamWorkspace], + default_workspace_id: mockTeamWorkspace.id, + can_create_workspace: false, + max_owned_workspaces: 10 } }, { - reason: 'limit', - response: { workspaces: [mockPersonalWorkspace, ...ownedTeams(9)] } + reason: 'unknown', + response: { + workspaces: [mockPersonalWorkspace], + can_create_workspace: false, + max_owned_workspaces: 10, + denied_reasons: { + can_create_workspace: 'a_reason_this_build_predates' + } + } } - ])( - 'names the $reason refusal from the workspace list', + ] as const)( + 'names the served $reason refusal', async ({ reason, response }) => { mockWorkspaceApi.list.mockResolvedValue(response) @@ -1556,29 +1552,40 @@ describe('useTeamWorkspaceStore', () => { expect(store.canCreateWorkspace).toBe(false) expect(store.createWorkspaceRefusal).toBe(reason) + expect(store.maxOwnedWorkspaces).toBe(response.max_owned_workspaces) } ) - it('canCreateWorkspace respects limit', async () => { - const manyWorkspaces = Array.from({ length: 10 }, (_, i) => ({ - id: `ws-owned-${i}`, - name: `Owned ${i}`, - type: 'team' as const, - role: 'owner' as const, - created_at: `2026-${String(i + 1).padStart(2, '0')}-01T00:00:00Z`, - joined_at: `2026-${String(i + 1).padStart(2, '0')}-01T00:00:00Z` - })) - - mockWorkspaceApi.list.mockResolvedValue({ - workspaces: [mockPersonalWorkspace, ...manyWorkspaces] - }) + it.for([ + { + name: 'a denial reason beside can_create_workspace true', + response: { + workspaces: [mockPersonalWorkspace], + can_create_workspace: true, + max_owned_workspaces: 10, + denied_reasons: { can_create_workspace: 'owned_workspace_limit' } + } + }, + { + name: 'an owned count past the served limit', + response: { + workspaces: [mockPersonalWorkspace, ...ownedTeams(11)], + can_create_workspace: true, + max_owned_workspaces: 10 + } + } + ] as const)( + 'offers creation when the server allows it despite $name', + async ({ response }) => { + mockWorkspaceApi.list.mockResolvedValue(response) - const store = useTeamWorkspaceStore() - await store.initialize() + const store = useTeamWorkspaceStore() + await store.initialize() - expect(store.ownedWorkspacesCount).toBe(11) - expect(store.canCreateWorkspace).toBe(false) - }) + expect(store.canCreateWorkspace).toBe(true) + expect(store.createWorkspaceRefusal).toBeNull() + } + ) }) describe('overlapping member and invite reads', () => { diff --git a/src/platform/workspace/stores/teamWorkspaceStore.ts b/src/platform/workspace/stores/teamWorkspaceStore.ts index bf030aae055..1ef2a79585b 100644 --- a/src/platform/workspace/stores/teamWorkspaceStore.ts +++ b/src/platform/workspace/stores/teamWorkspaceStore.ts @@ -185,6 +185,29 @@ type ListedWorkspaces = Omit & default_workspace_id?: string } +type CreationDeniedReason = NonNullable< + NonNullable['can_create_workspace'] +> + +const CREATION_DENIED_REASONS: Record = { + organization_managed: true, + owned_workspace_limit: true +} + +function isCreationDeniedReason( + reason: string +): reason is CreationDeniedReason { + return Object.hasOwn(CREATION_DENIED_REASONS, reason) +} + +function parseCreationDeniedReason( + reason: string | undefined +): CreationDeniedReason | undefined { + return reason !== undefined && isCreationDeniedReason(reason) + ? reason + : undefined +} + function reportSsoLanding( { default_workspace_id }: ListedWorkspaces, workspaceId: string @@ -194,7 +217,6 @@ function reportSsoLanding( ) } -const MAX_OWNED_WORKSPACES = 10 const MAX_INIT_RETRIES = 3 const BASE_RETRY_DELAY_MS = 1000 const INIT_READ_WITHOUT_STATUS_RETRY = { skipStatusRetry: true } @@ -262,35 +284,29 @@ export const useTeamWorkspaceStore = defineStore('teamWorkspace', () => { workspaces.value.filter((w) => w.type !== 'personal') ) - const ownedWorkspacesCount = computed( - () => workspaces.value.filter((w) => w.role === 'owner').length - ) - const serverRefusesCreation = ref(false) + const creationDeniedReason = ref() + const maxOwnedWorkspaces = ref() - const workspacesManagedByOrganization = ref(false) - - const canCreateWorkspace = computed( - () => - !serverRefusesCreation.value && - ownedWorkspacesCount.value < MAX_OWNED_WORKSPACES - ) + const canCreateWorkspace = computed(() => !serverRefusesCreation.value) const createWorkspaceRefusal = computed< - 'organization' | 'limit' | 'unknown' | null - >(() => { - if (canCreateWorkspace.value) return null - if (workspacesManagedByOrganization.value) return 'organization' - if (serverRefusesCreation.value) return 'unknown' - return 'limit' - }) + CreationDeniedReason | 'unknown' | null + >(() => + serverRefusesCreation.value + ? (creationDeniedReason.value ?? 'unknown') + : null + ) function applyWorkspaceList(response: ListedWorkspaces): void { workspaces.value = sortWorkspaces( response.workspaces.map(createWorkspaceState) ) serverRefusesCreation.value = response.can_create_workspace === false - workspacesManagedByOrganization.value = !!response.default_workspace_id + creationDeniedReason.value = parseCreationDeniedReason( + response.denied_reasons?.can_create_workspace + ) + maxOwnedWorkspaces.value = response.max_owned_workspaces } const members = computed( @@ -1160,7 +1176,8 @@ export const useTeamWorkspaceStore = defineStore('teamWorkspace', () => { initState.value = 'uninitialized' workspaces.value = [] serverRefusesCreation.value = false - workspacesManagedByOrganization.value = false + creationDeniedReason.value = undefined + maxOwnedWorkspaces.value = undefined mutableActiveWorkspaceId.value = null error.value = null isCreating.value = false @@ -1190,10 +1207,10 @@ export const useTeamWorkspaceStore = defineStore('teamWorkspace', () => { personalWorkspace, isInPersonalWorkspace, sharedWorkspaces, - ownedWorkspacesCount, canCreateWorkspace, serverRefusesCreation, - workspacesManagedByOrganization, + creationDeniedReason, + maxOwnedWorkspaces, createWorkspaceRefusal, members, membersLoaded,