Refactor visible project users into query scope
This commit is contained in:
@@ -59,24 +59,10 @@ class BuildProjectBacklogPayload
|
||||
)->resolve(),
|
||||
'users' => UserResource::collection(
|
||||
User::query()
|
||||
->whereIn('id', $this->visibleUserIds($project))
|
||||
->visibleToProject($project)
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
)->resolve(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
private function visibleUserIds(Project $project): array
|
||||
{
|
||||
return User::query()
|
||||
->get()
|
||||
->filter(fn (User $candidate): bool => $this->permissionService->allows($candidate, Permission::ProjectRead, $project))
|
||||
->pluck('id')
|
||||
->map(fn (mixed $userId): int => (int) $userId)
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,24 +116,10 @@ class BuildProjectTicketDetailPayload
|
||||
'ticketTypes' => TicketTypeResource::collection($project->ticketTypes()->get())->resolve(),
|
||||
'users' => UserResource::collection(
|
||||
User::query()
|
||||
->whereIn('id', $this->visibleUserIds($project))
|
||||
->visibleToProject($project)
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
)->resolve(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, int>
|
||||
*/
|
||||
private function visibleUserIds(Project $project): array
|
||||
{
|
||||
return User::query()
|
||||
->get()
|
||||
->filter(fn (User $candidate): bool => $this->permissionService->allows($candidate, Permission::ProjectRead, $project))
|
||||
->pluck('id')
|
||||
->map(fn (mixed $userId): int => (int) $userId)
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user