Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ function isFlagEnabled(name: string) {
}

export const flags = {
multiDb: isFlagEnabled('multi-db')
multiDb: isFlagEnabled('multi-db'),
granularProjectAccess: isFlagEnabled('granular-project-access')
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { isCloud, isSelfHosted } from '$lib/system';
import { roles, buildProjectRole } from '$lib/stores/billing';
import { flags } from '$lib/flags';
import { user } from '$lib/stores/user';
import InputSelect from '$lib/elements/forms/inputSelect.svelte';
import Roles from '$lib/components/roles/roles.svelte';
import { Icon, Popover, Layout } from '@appwrite.io/pink-svelte';
Expand All @@ -26,7 +28,11 @@
oncreated?: (team: Models.Membership) => void;
} = $props();

const supportsProjectRoles = $derived(isCloud && !!$currentPlan?.supportsOrganizationRoles);
const supportsProjectRoles = $derived(
isCloud &&
flags.granularProjectAccess({ account: $user, organization: $organization }) &&
!!$currentPlan?.supportsOrganizationRoles
);

let email = $state('');
let name = $state('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
} from '$lib/helpers/tooltipContent';
import { addNotification } from '$lib/stores/notifications';
import { currentPlan, newMemberModal, organization } from '$lib/stores/organization';
import { flags } from '$lib/flags';
import { isOwner } from '$lib/stores/roles';
import { sdk } from '$lib/stores/sdk';
import { user } from '$lib/stores/user';
import type { Models } from '@appwrite.io/console';
import Delete from '../deleteMember.svelte';
import Edit from './edit.svelte';
Expand Down Expand Up @@ -60,6 +62,10 @@
$: isLimited = limit !== 0 && limit < Infinity;
$: isButtonDisabled =
isCloud && (($readOnly && !GRACE_PERIOD_OVERRIDE) || (isLimited && memberCount >= limit));
$: supportsProjectRoles =
isCloud &&
flags.granularProjectAccess({ account: $user, organization: $organization }) &&
$currentPlan?.supportsOrganizationRoles;
Comment on lines +65 to +68
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The supportsProjectRoles reactive statement does not coerce the last operand to boolean, so its type is boolean | undefined rather than boolean. While Svelte's {#if} treats undefined as falsy, the equivalent derived values in createMember.svelte and edit.svelte both use !! for consistency. Keeping the same style avoids subtle surprises if this value is ever passed to a function that checks strict type equality.

Suggested change
$: supportsProjectRoles =
isCloud &&
flags.granularProjectAccess({ account: $user, organization: $organization }) &&
$currentPlan?.supportsOrganizationRoles;
$: supportsProjectRoles =
isCloud &&
flags.granularProjectAccess({ account: $user, organization: $organization }) &&
!!$currentPlan?.supportsOrganizationRoles;

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


const resend = async (member: Models.Membership) => {
try {
Expand Down Expand Up @@ -156,7 +162,7 @@
</Typography.Text>
</Table.Cell>
<Table.Cell column="roles" {root}>
{#if member.roles.some(isProjectSpecificRole)}
{#if supportsProjectRoles && member.roles.some(isProjectSpecificRole)}
{@const projectRoles = member.roles.filter(isProjectSpecificRole)}
{@const firstRole = projectRoles[0]}
{@const firstParsed = parseProjectRole(firstRole)}
Expand Down Expand Up @@ -217,7 +223,7 @@
</Button.Button>
<div style:min-width="232px" slot="tooltip">
<ActionMenu.Root>
{#if isCloud && $currentPlan?.supportsOrganizationRoles}
{#if supportsProjectRoles}
<ActionMenu.Item.Button
trailingIcon={IconPencil}
on:click={() => {
Expand Down
20 changes: 13 additions & 7 deletions src/routes/(console)/organization-[organization]/members/+page.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
import { flags } from '$lib/flags';
import { getLimit, getPage, getSearch, pageToOffset } from '$lib/helpers/load';
import { sdk } from '$lib/stores/sdk';
import { Query } from '@appwrite.io/console';
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ url, params, route, depends }) => {
export const load: PageLoad = async ({ url, params, route, depends, parent }) => {
const { account, organization } = await parent();
depends(Dependencies.ORGANIZATION);
depends(Dependencies.MEMBERS);
Comment on lines +8 to 11
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 depends() is called after await parent(), reversing the original order. If parent() throws (e.g., triggers a SvelteKit redirect), the depends() registrations are never reached. In practice the parent layout already registers both dependencies, so this is safe today, but moving the calls before the await matches the pre-existing convention and is more defensive.

Suggested change
export const load: PageLoad = async ({ url, params, route, depends, parent }) => {
const { account, organization } = await parent();
depends(Dependencies.ORGANIZATION);
depends(Dependencies.MEMBERS);
export const load: PageLoad = async ({ url, params, route, depends, parent }) => {
depends(Dependencies.ORGANIZATION);
depends(Dependencies.MEMBERS);
const { account, organization } = await parent();


Expand All @@ -13,18 +15,22 @@ export const load: PageLoad = async ({ url, params, route, depends }) => {
const limit = getLimit(url, route, PAGE_LIMIT);
const offset = pageToOffset(page, limit);

const supportsProjectRoles = flags.granularProjectAccess({ account, organization });

const [organizationMembers, orgProjects] = await Promise.all([
sdk.forConsole.teams.listMemberships({
teamId: params.organization,
queries: [Query.limit(limit), Query.offset(offset)],
search
}),
sdk.forConsole
.organization(params.organization)
.listProjects({
queries: [Query.limit(100), Query.equal('teamId', params.organization)]
})
.catch(() => null)
supportsProjectRoles
? sdk.forConsole
.organization(params.organization)
.listProjects({
queries: [Query.limit(100), Query.equal('teamId', params.organization)]
})
.catch(() => null)
: null
]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
buildProjectRole
} from '$lib/stores/billing';
import { isCloud, isSelfHosted } from '$lib/system';
import { flags } from '$lib/flags';
import { user } from '$lib/stores/user';
import ProjectAccessSelector from '../projectAccessSelector.svelte';

let {
Expand All @@ -31,7 +33,11 @@
onupdated?: (membership: Models.Membership) => void;
} = $props();

const supportsProjectRoles = $derived(isCloud && !!$currentPlan?.supportsOrganizationRoles);
const supportsProjectRoles = $derived(
isCloud &&
flags.granularProjectAccess({ account: $user, organization: $organization }) &&
!!$currentPlan?.supportsOrganizationRoles
);
const defaultRole = isSelfHosted ? 'owner' : 'developer';

let error = $state<string>(null);
Expand Down