Merge pull request #2651 from appwrite/add-scopes

Add: missing cloud scopes on Key
This commit is contained in:
Jake Barnby
2025-11-27 09:16:07 +00:00
committed by GitHub
2 changed files with 60 additions and 5 deletions
+39
View File
@@ -467,6 +467,45 @@ export const scopes: {
}
];
export const cloudOnlyBackupScopes = [
{
scope: 'policies.read',
description: 'Access to read your database backup policies',
category: 'Database',
icon: 'database'
},
{
scope: 'policies.write',
description: 'Access to create, update and delete your backup policies',
category: 'Database',
icon: 'database'
},
{
scope: 'archives.read',
description: 'Access to read your database backup archives',
category: 'Database',
icon: 'database'
},
{
scope: 'archives.write',
description: 'Access to create and delete your backup archives',
category: 'Database',
icon: 'database'
},
{
scope: 'restorations.read',
description: 'Access to read your backup restorations',
category: 'Database',
icon: 'database'
},
{
scope: 'restorations.write',
description: 'Access to create backup restorations',
category: 'Database',
icon: 'database'
}
];
export type EventService = {
name: string;
resources: EventResource[];
@@ -26,17 +26,16 @@
</script>
<script lang="ts">
import { Button } from '$lib/elements/forms';
import { scopes as allScopes } from '$lib/constants';
import { onMount } from 'svelte';
import { isCloud } from '$lib/system';
import { Button } from '$lib/elements/forms';
import { symmetricDifference } from '$lib/helpers/array';
import { scopes as allScopes, cloudOnlyBackupScopes } from '$lib/constants';
import { Accordion, Divider, Layout, Selector } from '@appwrite.io/pink-svelte';
export let scopes: string[];
const scopeCatalog = new Set(allScopes.map((s) => s.scope));
const filteredScopes = allScopes.filter((scope) => {
const baseFilteredScopes = allScopes.filter((scope) => {
const val = scope.scope;
if (!val) return false;
@@ -44,6 +43,23 @@
return !legacyPrefixes.some((prefix) => val.startsWith(prefix));
});
// insert cloud-only scopes right after databases.write
const databasesWriteIndex = baseFilteredScopes.findIndex((s) => s.scope === 'databases.write');
const filteredScopes =
isCloud && databasesWriteIndex !== -1
? [
...baseFilteredScopes.slice(0, databasesWriteIndex + 1),
...cloudOnlyBackupScopes,
...baseFilteredScopes.slice(databasesWriteIndex + 1)
]
: baseFilteredScopes;
// include all scopes
const scopeCatalog = new Set([
...allScopes.map((s) => s.scope),
...(isCloud ? cloudOnlyBackupScopes.map((s) => s.scope) : [])
]);
enum Category {
Auth = 'Auth',
Database = 'Database',