mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix(permissions): render member roles instead of marking them unresolvable
parsePermission only recognised user and team, so a member role fell
through to the invalid branch: it rendered as a raw truncated string in
the styling reserved for a deleted entity, and its hover card showed the
missing-entity avatar — presenting a perfectly valid grant as broken.
It also called onNotFound. Nothing passes that callback today, but
d36135f5b wired it to auto-remove stale roles before row.svelte moved to
runes turned the event into a prop and left the consumer behind. If that
wiring is restored, member roles would be silently deleted from any
resource a user merely opened.
A membership can only be read through its team or its user, and the role
string carries neither, so the ID stands in for a name. That is still an
improvement on the raw role: the badge now reads Member and the hover
card offers the membership ID to copy.
This commit is contained in:
1 parent
e35810404a
commit
9baccd3407
2 files changed
+51
-9
No files matched your search
@@ -34,8 +34,8 @@
|
||||
required
|
||||
id="custom-permission"
|
||||
label="Role"
|
||||
placeholder="user:[USER_ID] or team:[TEAM_ID]/[ROLE]"
|
||||
helper="A permission should be formatted as: user:[USER_ID] or team:[TEAM_ID]/[ROLE]¸"
|
||||
placeholder="user:[USER_ID], team:[TEAM_ID]/[ROLE] or member:[MEMBERSHIP_ID]"
|
||||
helper="A permission should be formatted as: user:[USER_ID], team:[TEAM_ID]/[ROLE] or member:[MEMBERSHIP_ID]"
|
||||
bind:value />
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
Typography
|
||||
} from '@appwrite.io/pink-svelte';
|
||||
import Avatar from '../avatar.svelte';
|
||||
import { IconAnonymous, IconMinusSm } from '@appwrite.io/pink-icons-svelte';
|
||||
import { IconAnonymous, IconMinusSm, IconUsers } from '@appwrite.io/pink-icons-svelte';
|
||||
import { page } from '$app/state';
|
||||
import { menuOpen } from '$lib/components/menu/store';
|
||||
import { base } from '$app/paths';
|
||||
@@ -39,8 +39,10 @@
|
||||
|
||||
let { role, placement = 'bottom-start', children, onNotFound }: Props = $props();
|
||||
|
||||
const parsedRole = $derived(parsePermission(role));
|
||||
|
||||
type ParsedPermission = {
|
||||
type: 'user' | 'team' | 'other';
|
||||
type: 'user' | 'team' | 'member' | 'other';
|
||||
id: string;
|
||||
roleName?: string;
|
||||
isValid: boolean;
|
||||
@@ -58,9 +60,9 @@
|
||||
return { type: 'other', id: permission, isValid: false };
|
||||
}
|
||||
|
||||
if (type === 'user' || type === 'team') {
|
||||
if (type === 'user' || type === 'team' || type === 'member') {
|
||||
return {
|
||||
type: type as 'user' | 'team',
|
||||
type: type as 'user' | 'team' | 'member',
|
||||
id,
|
||||
roleName,
|
||||
isValid: true
|
||||
@@ -78,6 +80,12 @@
|
||||
return { notFound: true, roleName: parsed.roleName, customName: parsed.id };
|
||||
}
|
||||
|
||||
// A membership can only be read through its team or its user, neither of which the role
|
||||
// carries, so the ID is shown as-is rather than reported as a role that no longer exists.
|
||||
if (parsed.type === 'member') {
|
||||
return { roleName: parsed.roleName, customName: parsed.id };
|
||||
}
|
||||
|
||||
if (parsed.type === 'user') {
|
||||
try {
|
||||
return await sdk
|
||||
@@ -177,7 +185,7 @@
|
||||
{role}
|
||||
{:then data}
|
||||
{formatName(
|
||||
data.name ?? data?.email ?? data?.phone ?? '-',
|
||||
data.name ?? data?.email ?? data?.phone ?? data?.customName ?? '-',
|
||||
$isSmallViewport ? 16 : 20
|
||||
)}
|
||||
{/await}
|
||||
@@ -185,7 +193,11 @@
|
||||
<Badge
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
content={role.startsWith('user') ? 'User' : 'Team'} />
|
||||
content={parsedRole.type === 'member'
|
||||
? 'Member'
|
||||
: parsedRole.type === 'user'
|
||||
? 'User'
|
||||
: 'Team'} />
|
||||
</Layout.Stack>
|
||||
{/if}
|
||||
</button>
|
||||
@@ -205,7 +217,37 @@
|
||||
<Spinner />
|
||||
</Layout.Stack>
|
||||
{:then data}
|
||||
{#if data.notFound}
|
||||
{#if parsedRole.type === 'member'}
|
||||
<Layout.Stack gap="s" alignItems="flex-start">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
gap="s"
|
||||
alignItems="center"
|
||||
justifyContent="flex-start">
|
||||
<Avatar alt="avatar" size="m">
|
||||
<Icon icon={IconUsers} size="s" />
|
||||
</Avatar>
|
||||
|
||||
<Layout.Stack alignItems="flex-start" gap="xxs">
|
||||
<Layout.Stack style="padding-left: 0.25rem;">
|
||||
<Typography.Text
|
||||
size="m"
|
||||
color="--fgcolor-neutral-primary">
|
||||
Team membership
|
||||
</Typography.Text>
|
||||
</Layout.Stack>
|
||||
<InteractiveText
|
||||
isVisible
|
||||
variant="copy"
|
||||
text={formatName(
|
||||
parsedRole.id,
|
||||
$isSmallViewport ? 20 : 28
|
||||
)}
|
||||
value={parsedRole.id} />
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
</Layout.Stack>
|
||||
{:else if data.notFound}
|
||||
<Layout.Stack gap="s" alignItems="flex-start">
|
||||
<Layout.Stack
|
||||
direction="row"
|
||||
|
||||
Reference in new issue
Block a user