Checks if the agent has write rights by traversing the graph. Recursive function.
(
store: Store,
agent: string,
child?: string,
)
| 56 | |
| 57 | /** Checks if the agent has write rights by traversing the graph. Recursive function. */ |
| 58 | async canWrite( |
| 59 | store: Store, |
| 60 | agent: string, |
| 61 | child?: string, |
| 62 | ): Promise<[boolean, string | null]> { |
| 63 | const writeArray = this.get(properties.write); |
| 64 | if (writeArray && valToArray(writeArray).includes(agent)) { |
| 65 | return [true, null]; |
| 66 | } |
| 67 | const parentSubject = this.get(properties.parent) as string; |
| 68 | if (parentSubject == undefined) { |
| 69 | return [false, `No write right or parent in ${this.getSubject()}`]; |
| 70 | } |
| 71 | // This should not happen, but it prevents an infinite loop |
| 72 | if (child == parentSubject) { |
| 73 | console.warn('Circular parent', child); |
| 74 | return [true, `Circular parent in ${this.getSubject()}`]; |
| 75 | } |
| 76 | const parent: Resource = await store.getResourceAsync(parentSubject); |
| 77 | // The recursive part |
| 78 | return await parent.canWrite(store, agent, this.getSubject()); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Creates a clone of the Resource, which makes sure the reference is |
no test coverage detected