fix: block assistan user and team creation on readOnly

This commit is contained in:
Arman committed 2023-12-10 20:54:35 +01:00
1 parent cc7576fd6b
commit 615fe7ced1
4 files changed
+47 -17

No files matched your search

+8 -6
View File
@@ -105,12 +105,14 @@
{/if}
{#if !$page.url.pathname.includes('/console/account') && $readOnly}
<Pill danger button on:click={() => ($showExcess = true)}>
<div>
<span class="icon-exclamation-circle" aria-hidden="true" />
<span>limit reached</span>
</div>
</Pill>
<div style="min-inline-size: fit-content">
<Pill danger button on:click={() => ($showExcess = true)}>
<div>
<span class="icon-exclamation-circle" aria-hidden="true" />
<span>limit reached</span>
</div>
</Pill>
</div>
{/if}
<div class="main-header-end">
@@ -2,8 +2,11 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
import { registerCommands, updateCommandGroupRanks } from '$lib/commandCenter';
import { isServiceLimited, readOnly } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { project } from '../store';
import { showCreateUser } from './+page.svelte';
import { userList } from './store';
import { showCreateTeam } from './teams/+page.svelte';
$: $registerCommands([
@@ -19,7 +22,9 @@
group: 'users',
icon: 'plus',
rank: $page.url.pathname.endsWith('auth') ? 10 : 0
rank: $page.url.pathname.endsWith('auth') ? 10 : 0,
disabled:
$readOnly || isServiceLimited('users', $organization.billingPlan, $userList.total)
},
{
label: 'Create team',
@@ -33,7 +38,8 @@
group: 'teams',
icon: 'plus',
rank: $page.url.pathname.endsWith('teams') ? 10 : 0
rank: $page.url.pathname.endsWith('teams') ? 10 : 0,
disabled: $readOnly
},
{
label: 'Go to teams',
@@ -26,13 +26,14 @@
TableRowLink
} from '$lib/elements/table';
import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date';
import { Container } from '$lib/layout';
import { Container, ContainerHeader } from '$lib/layout';
import type { Models } from '@appwrite.io/console';
import { writable } from 'svelte/store';
import type { PageData } from './$types';
import Create from './createUser.svelte';
import { readOnly } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import { tooltip } from '$lib/actions/tooltip';
export let data: PageData;
@@ -43,14 +44,27 @@
</script>
<Container>
<SearchQuery search={data.search} placeholder="Search by name, email, phone, or ID">
<Button
on:click={() => ($showCreateUser = true)}
event="create_user"
disabled={isCloud && $readOnly}>
<span class="icon-plus" aria-hidden="true" /> <span class="text">Create user</span>
</Button>
</SearchQuery>
<ContainerHeader
title="Users"
isFlex={false}
total={data.users.total}
buttonDisabled={isCloud && $readOnly}
let:isButtonDisabled>
<SearchQuery search={data.search} placeholder="Search by name, email, phone, or ID">
<div
use:tooltip={{
content: `Upgrade to add more users`,
disabled: !isButtonDisabled
}}>
<Button
on:click={() => ($showCreateUser = true)}
event="create_user"
disabled={isCloud && $readOnly}>
<span class="icon-plus" aria-hidden="true" />
<span class="text">Create user</span>
</Button>
</div></SearchQuery>
</ContainerHeader>
{#if data.users.total}
<Table>
<TableHeader>
@@ -0,0 +1,8 @@
import { page } from '$app/stores';
import type { Models } from '@appwrite.io/console';
import { derived } from 'svelte/store';
export const userList = derived(
page,
($page) => $page.data.users as unknown as Models.UserList<Record<string, unknown>>
);