Skip to content

Commit 580329a

Browse files
committed
Use device permission cache for map access
1 parent c2188b3 commit 580329a

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

app/Models/CustomMap.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,15 @@ public function hasReadAccess(User $user): bool
101101
return true;
102102
}
103103

104-
public function scopeHasAccess($query, User $user)
104+
public function scopeHasAccess(Builder $query, User $user): Builder
105105
{
106106
if ($user->hasGlobalRead()) {
107107
return $query;
108108
}
109109

110-
// Allow only if the user has access to all devices on the map
111-
return $query->withCount([
112-
'nodes as device_nodes_count' => function (Builder $q): void {
113-
$q->whereNotNull('device_id');
114-
},
115-
'nodes as device_nodes_allowed_count' => function (Builder $q) use ($user): void {
116-
$this->hasDeviceAccess($q, $user, 'custom_map_nodes');
117-
},
118-
])
119-
->havingRaw('device_nodes_count = device_nodes_allowed_count')
120-
->having('device_nodes_count', '>', 0);
110+
// Only show maps where ALL device nodes are accessible by the user
111+
return $query->whereHas('nodes', fn ($q) => $q->whereNotNull('device_id'))
112+
->whereDoesntHave('nodes', fn ($q) => $q->whereNotNull('device_id')->whereNotIn('device_id', \Permissions::devicesForUser($user)));
121113
}
122114

123115
/**

0 commit comments

Comments
 (0)