17 lines
518 B
TypeScript
17 lines
518 B
TypeScript
import type { EntityTypeRegistration, ShareContext } from "./module";
|
|
|
|
export async function ensureEntityShareAuthorized(
|
|
registration: EntityTypeRegistration,
|
|
entityId: string,
|
|
ctx: ShareContext,
|
|
): Promise<void> {
|
|
if (!registration.canShareEntity) {
|
|
throw new Error(`Entity type "${registration.type}" does not support share authorization`);
|
|
}
|
|
|
|
const allowed = await registration.canShareEntity(entityId, ctx);
|
|
if (!allowed) {
|
|
throw new Error("You are not allowed to share this entity");
|
|
}
|
|
}
|