codex/api-application-access #52
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Actions\Permissions\PermissionService;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
@@ -69,4 +71,17 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->hasMany(Ticket::class, 'author_user_id');
|
||||
}
|
||||
|
||||
public function scopeVisibleToProject(Builder $query, Project $project): Builder
|
||||
{
|
||||
$permissionService = app(PermissionService::class);
|
||||
|
||||
return $query->where(function (Builder $builder) use ($permissionService, $project): void {
|
||||
foreach (User::query()->select('id')->cursor() as $candidate) {
|
||||
if ($permissionService->allows($candidate, \App\Enums\Permission::ProjectRead, $project)) {
|
||||
$builder->orWhereKey($candidate->id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user