Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

1.3 KB
Raw Blame
import { usePage } from '@inertiajs/vue3';
import { computed } from 'vue';

/**
 * Capability flags for the current workspace, mirroring the backend
 * `WorkspacePolicy` abilities. Reads `auth.currentWorkspace`.
 */
export const useWorkspaceAbilities = () => {
    const page = usePage();

    const workspace = computed(() => page.props.auth?.currentWorkspace ?? null);
    const isOwner = computed(() => workspace.value?.is_owner === true);
    const canManageWorkspace = computed(
        () => isOwner.value || workspace.value?.is_admin === true,
    );
    const requiresApproval = computed(
        () => !isOwner.value && workspace.value?.requires_approval === true,
    );
    const canPublishDirectly = computed(
        () => workspace.value !== null && !requiresApproval.value,
    );
    const canCreatePost = computed(() => workspace.value !== null);

    return {
        isOwner,
        canManageWorkspace,
        canPublishDirectly,
        canApprove: canPublishDirectly,
        requiresApproval,
        canCreatePost,
        canManageRepurposes: canPublishDirectly,
        canManageAccounts: canManageWorkspace,
        canManageWebhooks: canManageWorkspace,
        canManageTeam: canManageWorkspace,
        canManageBilling: isOwner,
        canCreateWorkspace: isOwner,
    };
};