diff --git a/app/models/crate.js b/app/models/crate.js index 1bf87694a8..2c8db61646 100644 --- a/app/models/crate.js +++ b/app/models/crate.js @@ -68,6 +68,12 @@ export default class Crate extends Model { return new Set(map.values()); } + hasOwnerUser(userId) { + let { last } = this.loadOwnerUserTask; + assert('`loadOwnerUserTask.perform()` must be called before calling `hasOwnerUser()`', last != null); + return (last?.value ?? []).some(({ id }) => id === userId); + } + get owners() { let { last } = this.loadOwnersTask; assert('`loadOwnersTask.perform()` must be called before accessing `owners`', last != null); @@ -104,6 +110,10 @@ export default class Crate extends Model { } } + loadOwnerUserTask = task(async () => { + return (await this.owner_user) ?? []; + }); + loadOwnersTask = task(async () => { let [teams, users] = await Promise.all([this.owner_team, this.owner_user]); return [...(teams ?? []), ...(users ?? [])];