Hello ! I've something i need to understand ! In o...
# talk-keto
b
Hello ! I've something i need to understand ! In organization i have projects. so in class Project, i have a related : parents: Organization[ ]. The owner of the organization can access to all projects related to this organization. In relationship in ory console, i have my_id_user is "owners" of "Organization:id_org" and "id_org" is parents of "project_id". there is my rules
Copy code
class Organization implements Namespace {related: {
    // Roles de Base
    owners: User[],
    administrators: User[],
    operators: User[],
    helpdesks: User[],

    //Roles spécifiques
    standartUsers: User[],
    readonlyUsers: User[],

    projects: Project[]
  }

  permits = {
    read: (ctx: Context): boolean =>
      this.related.owners.includes(ctx.subject) ||
      this.related.administrators.includes(ctx.subject) ||
      this.related.operators.includes(ctx.subject) ||
      this.related.helpdesks.includes(ctx.subject) ||
      this.related.standartUsers.includes(ctx.subject) ||
      this.related.readonlyUsers.includes(ctx.subject),
    edit: (ctx: Context): boolean =>
      this.related.owners.includes(ctx.subject) ||
      this.related.administrators.includes(ctx.subject),
    create: (ctx: Context): boolean =>
      this.related.owners.includes(ctx.subject) ||
      this.related.administrators.includes(ctx.subject) ||
      this.related.operators.includes(ctx.subject),
    delete: (ctx: Context): boolean =>
      this.related.owners.includes(ctx.subject),
    share: (ctx: Context): boolean =>
      this.related.owners.includes(ctx.subject) ||
      this.related.administrators.includes(ctx.subject),
    billing: (ctx: Context): boolean =>
      this.related.owners.includes(ctx.subject) ||
      this.related.administrators.includes(ctx.subject),
    administrate: (ctx: Context): boolean =>
      this.related.owners.includes(ctx.subject) ||
      this.related.administrators.includes(ctx.subject),

  }
}

class Project implements Namespace {

  related: {
    // Roles de Base
    owners: User[],
    administrators: User[],
    operators: User[],
    helpdesks: User[],

    //Roles spécifiques
    standartUsers: User[],
    readonlyUsers: User[],

    //Parent
    parents: Organization[]
  }

  permits = {
    read: (ctx: Context): boolean =>
      this.related.parents.traverse((parent) => parent.permits.edit(ctx)),
    edit: (ctx: Context): boolean =>
      this.related.operators.includes(ctx.subject) ||
      this.related.standartUsers.includes(ctx.subject) ||
      this.related.parents.traverse((parent) => parent.permits.edit(ctx)),
    create: (ctx: Context): boolean =>
      this.related.operators.includes(ctx.subject) ||
      this.related.standartUsers.includes(ctx.subject) ||
      this.related.parents.traverse((parent) => parent.permits.edit(ctx)),
    delete: (ctx: Context): boolean =>
      this.related.operators.includes(ctx.subject) ||
      this.related.standartUsers.includes(ctx.subject) ||
      this.related.parents.traverse((parent) => parent.permits.edit(ctx)),
    share: (ctx: Context): boolean =>
      this.related.operators.includes(ctx.subject) ||
      this.related.parents.traverse((parent) => parent.permits.edit(ctx)),
  }
}