Skip to content

Commit b09f410

Browse files
committed
models/crate: Add hasOwnerUser() fn that relies on loadOwnerUserTask
This extracts functionality from `isOwner` as a more generic method. The data is loaded explicitly with `loadOwnerUserTask` to avoid deprecations. A debugging assert is also included to inform if perform() is not called before using it.
1 parent 2e536ff commit b09f410

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

app/models/crate.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export default class Crate extends Model {
6767
return new Set(map.values());
6868
}
6969

70+
hasOwnerUser(userId) {
71+
let { last } = this.loadOwnerUserTask;
72+
assert('`loadOwnerUserTask.perform()` must be called before calling `hasOwnerUser()`', last != null);
73+
return (last?.value ?? []).some(({ id }) => id === userId);
74+
}
75+
7076
get owners() {
7177
let { last } = this.loadOwnersTask;
7278
assert('`loadOwnersTask.perform()` must be called before accessing `owners`', last != null);
@@ -103,6 +109,10 @@ export default class Crate extends Model {
103109
}
104110
}
105111

112+
loadOwnerUserTask = task(async () => {
113+
return (await this.owner_user) ?? [];
114+
});
115+
106116
loadOwnersTask = task(async () => {
107117
let [teams, users] = await Promise.all([this.owner_team, this.owner_user]);
108118
return [...(teams ?? []), ...(users ?? [])];

0 commit comments

Comments
 (0)