steep-lamp-91158
steep-lamp-91158
class Project implements Namespace {
related: {
reader: User[]
writer: User[]
identityReader: User[]
identityWriter: User[]
permissionReader: User[]
permissionWriter: User[]
}
permits = {
"identities.read": (ctx: Context) =>
this.related.reader.includes(ctx.subject) ||
this.related.identityReader.includes(ctx.subject),
"identities.write": (ctx: Context) =>
this.related.writer.includes(ctx.subject) ||
this.related.identityWriter.includes(ctx.subject),
"permissions.read": (ctx: Context) =>
this.related.reader.includes(ctx.subject) ||
this.related.permissionReader.includes(ctx.subject),
"permissions.write": (ctx: Context) =>
this.related.writer.includes(ctx.subject) ||
this.related.permissionWriter.includes(ctx.subject),
}
}
This works, but you can easily see how that gets out of hand and hard to review.steep-lamp-91158
class Identity extends SubNamespace<Project> {
related: {
reader: User[]
writer: User[]
}
permits = {
read: (ctx: Context) =>
this.related.reader.includes(ctx.subject) ||
this.parent.permits.read(ctx),
write: (ctx: Context) =>
this.related.writer.includes(ctx.subject) ||
this.parent.permits.write(ctx),
}
}
class Project implements Namespace {
embed: {
identities: Identity[],
}
related: {
reader: User[]
writer: User[]
}
permits = {
read: (ctx: Context) => this.related.reader.includes(ctx.subject),
write: (ctx: Context) => this.related.writer.includes(ctx.subject),
}
}
The difference is now that relations of subnamespaces cannot be created, but instead one has to create the relation identities.reader
. Same with permissions, on the API level they get flattened.
Do you think that would help you with bigger models? Also consider that we might create an import mechanism down the road.steep-lamp-91158
embed
field, as the project would probably not want to use identity relations or permissions, but maybe there is a use-case where it would? This way we have kind of a circular dependency between identites and projects, as both can reference the other.