Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ChristianSch/b396ca06078fde7a9f66b7e5eeb4bd10 to your computer and use it in GitHub Desktop.
Save ChristianSch/b396ca06078fde7a9f66b7e5eeb4bd10 to your computer and use it in GitHub Desktop.
workspaces.ts
import {
Namespace,
Context,
} from "@ory/permission-namespace-types";
class User implements Namespace {}
class Workspace implements Namespace {
related: {
owners: User[];
users: User[];
}
permits = {
// all users that are owners or users of this workspace can access it
view: (ctx: Context): boolean =>
this.related.users.includes(ctx.subject) ||
this.related.owners.includes(ctx.subject),
}
}
class Unit implements Namespace {
related: {
// the unit is only owned by one workspace, but all relations are many-to-many in keto
workspaces: Workspace[];
users: User[];
}
permits = {
// all workspace owners and users can view this unit
view: (ctx: Context): boolean =>
this.related.workspaces.traverse((w) =>
w.related.owners.includes(ctx.subject)
) || this.related.users.includes(ctx.subject),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment