Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

3.4 KB
Raw Blame
import { WorkspaceRole } from "@prisma/client";

const PERMISSION_ACTIONS = [
  "workspaces.read",
  "workspaces.write",
  "links.read",
  "links.write",
  "tags.read",
  "tags.write",
  "analytics.read",
  "domains.read",
  "domains.write",
  "tokens.read",
  "tokens.write",
  "oauth_apps.read",
  "oauth_apps.write",
  "integrations.read",
  "integrations.write",
  "webhooks.read",
  "webhooks.write",
  "folders.read",
  "folders.write",
  "customers.read",
  "customers.write",
  "billing.write",
] as const;

export type PermissionAction = (typeof PERMISSION_ACTIONS)[number];

export const ROLE_PERMISSIONS: {
  action: PermissionAction;
  description: string;
  roles: WorkspaceRole[];
}[] = [
  {
    action: "links.read",
    description: "access links",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "links.write",
    description: "manage links",
    roles: ["owner", "member"],
  },
  {
    action: "analytics.read",
    description: "access analytics",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "workspaces.read",
    description: "access workspaces",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "workspaces.write",
    description: "manage workspace settings",
    roles: ["owner"],
  },
  {
    action: "domains.read",
    description: "access domains",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "domains.write",
    description: "manage domains",
    roles: ["owner"],
  },
  {
    action: "tags.read",
    description: "access tags",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "tags.write",
    description: "manage tags",
    roles: ["owner", "member"],
  },
  {
    action: "tokens.read",
    description: "access API keys",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "tokens.write",
    description: "manage API keys",
    roles: ["owner"],
  },
  {
    action: "oauth_apps.read",
    description: "access OAuth apps",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "oauth_apps.write",
    description: "manage OAuth apps",
    roles: ["owner"],
  },
  {
    action: "integrations.read",
    description: "access integrations",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "integrations.write",
    description: "manage integrations",
    roles: ["owner", "member"],
  },
  {
    action: "webhooks.read",
    description: "access webhooks",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "webhooks.write",
    description: "manage webhooks",
    roles: ["owner"],
  },
  {
    action: "folders.read",
    description: "access folders",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "folders.write",
    description: "manage folders",
    roles: ["owner", "member"],
  },
  {
    action: "billing.write",
    description: "manage billing details",
    roles: ["owner", "billing"],
  },
  {
    action: "customers.read",
    description: "access customers",
    roles: ["owner", "member", "viewer", "billing"],
  },
  {
    action: "customers.write",
    description: "manage customers",
    roles: ["owner", "member"],
  },
];

// Get permissions for a role
export const getPermissionsByRole = (role: WorkspaceRole) => {
  return ROLE_PERMISSIONS.filter(({ roles }) => roles.includes(role)).map(
    ({ action }) => action,
  );
};