hide project resource create and update buttons based on scope

This commit is contained in:
Damodar Lohani committed 2024-09-03 17:28:46 +05:45
1 parent b4827a36d9
commit f348f82db6
10 files changed
+54 -20

No files matched your search

+3
View File
@@ -11,6 +11,7 @@
export let target: string = null;
export let href: string = null;
export let marginTop = false;
export let allowCreate = false;
function track() {
if (target) {
@@ -54,9 +55,11 @@
text
event="empty_documentation"
ariaLabel="create {target}">Documentation</Button>
{#if allowCreate}
<Button secondary on:click on:click={track}>
Create {target}
</Button>
{/if}
</div>
</slot>
</div>
+1
View File
@@ -18,6 +18,7 @@ export const canWriteWebhooks = derived(scopes, ($scopes) => $scopes.includes("w
export const canWritePlatforms = derived(scopes, ($scopes) => $scopes.includes("platforms.write"));
export const canWriteTargets = derived(scopes, ($scopes) => $scopes.includes("targets.write"));
export const canWriteUsers = derived(scopes, ($scopes) => $scopes.includes("users.write"));
export const canWriteTeams = derived(scopes, ($scopes) => $scopes.includes("teams.write"));
export const canWriteCollections = derived(scopes, ($scopes) => $scopes.includes("collections.write"));
export const canWriteExecutions = derived(scopes, ($scopes) => $scopes.includes("executions.write"));
export const canWriteSubscribers = derived(scopes, ($scopes) => $scopes.includes("subscribers.write"));
+3 -1
View File
@@ -34,6 +34,8 @@ export const load: LayoutLoad = async ({ fetch, depends, parent }) => {
return {
consoleVariables: variables,
version: data?.version ?? null,
plansInfo
plansInfo,
roles: [],
scopes: []
};
};
@@ -32,6 +32,7 @@
import type { PageData } from './$types';
import Create from './createUser.svelte';
import { tooltip } from '$lib/actions/tooltip';
import { canWriteUsers } from '$lib/stores/roles';
export let data: PageData;
@@ -44,6 +45,7 @@
<Container>
<ContainerHeader title="Users" isFlex={false} total={data.users.total} let:isButtonDisabled>
<SearchQuery search={data.search} placeholder="Search by name, email, phone, or ID">
{#if $canWriteUsers}
<div
use:tooltip={{
content: `Upgrade to add more users`,
@@ -56,7 +58,9 @@
<span class="icon-plus" aria-hidden="true" />
<span class="text">Create user</span>
</Button>
</div></SearchQuery>
</div>
{/if}
</SearchQuery>
</ContainerHeader>
{#if data.users.total}
<Table>
@@ -152,6 +156,7 @@
single
href="https://appwrite.io/docs/references/cloud/server-nodejs/users"
target="user"
allowCreate={$canWriteUsers}
on:click={() => showCreateUser.set(true)} />
{/if}
</Container>
@@ -3,6 +3,7 @@
import { Tab, Tabs } from '$lib/components';
import { isTabSelected } from '$lib/helpers/load';
import { Cover, CoverTitle } from '$lib/layout';
import { canWriteUsers } from '$lib/stores/roles';
const projectId = $page.params.project;
const path = `/console/project-${projectId}/auth`;
@@ -19,28 +20,36 @@
hasChildren: true,
event: 'teams'
},
{
href: `${path}/security`,
title: 'Security',
event: 'security'
},
{
href: `${path}/templates`,
title: 'Templates',
hasChildren: false,
event: 'templates'
},
...($canWriteUsers
? [
{
href: `${path}/security`,
title: 'Security',
event: 'security'
},
{
href: `${path}/templates`,
title: 'Templates',
hasChildren: false,
event: 'templates'
}
]
: []),
{
href: `${path}/usage`,
title: 'Usage',
hasChildren: true,
event: 'usage'
},
{
href: `${path}/settings`,
title: 'Settings',
event: 'settings'
}
...($canWriteUsers
? [
{
href: `${path}/settings`,
title: 'Settings',
event: 'settings'
}
]
: [])
];
</script>
@@ -32,6 +32,7 @@
import { writable } from 'svelte/store';
import { readOnly } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import { canWriteTeams } from '$lib/stores/roles';
export let data: PageData;
@@ -49,6 +50,7 @@
buttonDisabled={isCloud && $readOnly}
let:isButtonDisabled>
<SearchQuery search={data.search} placeholder="Search by name">
{#if $canWriteTeams}
<div
use:tooltip={{
content: `Upgrade to add more teams`,
@@ -62,6 +64,7 @@
<span class="text">Create team</span>
</Button>
</div>
{/if}
</SearchQuery>
</ContainerHeader>
@@ -110,6 +113,7 @@
{:else}
<Empty
single
allowCreate={$canWriteTeams}
on:click={() => ($showCreateTeam = true)}
href="https://appwrite.io/docs/references/cloud/client-web/teams"
target="team" />
@@ -14,6 +14,7 @@
import Table from './table.svelte';
import { registerCommands } from '$lib/commandCenter';
import { tooltip } from '$lib/actions/tooltip';
import { canWriteDatabases } from '$lib/stores/roles';
export let data: PageData;
@@ -55,6 +56,7 @@
view={data.view}
hideColumns={!data.databases.total}
hideView={!data.databases.total} />
{#if $canWriteDatabases}
<div
use:tooltip={{
content: `Upgrade to add more databases`,
@@ -68,6 +70,7 @@
<span class="text">Create database</span>
</Button>
</div>
{/if}
</div>
</svelte:fragment>
</ContainerHeader>
@@ -89,6 +92,7 @@
single
href="https://appwrite.io/docs/products/databases/databases"
target="database"
allowCreate={$canWriteDatabases}
on:click={() => (showCreate = true)} />
{/if}
</Container>
@@ -20,6 +20,7 @@
import { parseExpression } from 'cron-parser';
import { onMount } from 'svelte';
import { functionsList } from './store';
import { canWriteFunctions } from '$lib/stores/roles';
export let data;
@@ -72,7 +73,7 @@
<Container>
<ContainerHeader
title="Functions"
buttonText="Create function"
buttonText={$canWriteFunctions ? "Create function" : ""}
buttonEvent="create_function"
buttonMethod={openWizard}
total={data.functions.total} />
@@ -17,6 +17,7 @@
import { isServiceLimited } from '$lib/stores/billing';
import type { Runtime } from '$lib/stores/marketplace.js';
import { organization } from '$lib/stores/organization';
import { canWriteFunctions } from '$lib/stores/roles';
import { connectTemplate } from '$lib/wizards/functions/cover.svelte';
import { functionsList } from '../store';
@@ -226,7 +227,7 @@
text>
<span class="text">View details</span>
</Button>
{#if $canWriteFunctions}
<ContainerButton
title="functions"
disabled={buttonDisabled}
@@ -235,6 +236,7 @@
showIcon={false}
buttonText="Create function"
buttonEvent="create_function" />
{/if}
</div>
</article>
</li>
@@ -13,6 +13,7 @@
import { isServiceLimited } from '$lib/stores/billing';
import { organization } from '$lib/stores/organization';
import { functionsList } from '../../store';
import { canWriteFunctions } from '$lib/stores/roles';
const isVcsEnabled = $consoleVariables?._APP_VCS_ENABLED === true;
@@ -99,6 +100,7 @@
View source
<span class="icon-external-link" />
</Button>
{#if $canWriteFunctions}
<ContainerButton
title="functions"
disabled={buttonDisabled || (isSelfHosted && !isVcsEnabled)}
@@ -106,6 +108,7 @@
showIcon={false}
buttonText="Create function"
buttonEvent="create_function" />
{/if}
</div>
</Card>
</section>