Hi, in keto can we restrict the subjects you add i...
# talk-keto
e
Hi, in keto can we restrict the subjects you add in a relation? For example in this schema, can i restrict that only 1 parent is allowed for a specific file? if we can not do it with just keto, any recommendations on how should we go about doing it?
Copy code
class Folder implements Namespace {
  related: {
    parents: (File | Folder)[];
    viewers: SubjectSet<Group, "members">[];
  };

  permits = {
    view: (ctx: Context): boolean =>
      this.related.viewers.includes(ctx.subject) ||
      this.related.parents.traverse((p) => p.permits.view(ctx)),
  };
}

class File implements Namespace {
  related: {
    parents: (File | Folder)[];
    viewers: (User | SubjectSet<Group, "members">)[];
    owners: (User | SubjectSet<Group, "members">)[];
  };

  permits = {
    view: (ctx: Context): boolean =>
      this.related.parents.traverse((p) => p.permits.view(ctx)) ||
      this.related.viewers.includes(ctx.subject) ||
      this.related.owners.includes(ctx.subject),

    edit: (ctx: Context) => this.related.owners.includes(ctx.subject),
  };
}