| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/client-portal-laravel/releases/20260626120707/app/Policies/ |
Upload File : |
<?php
namespace App\Policies;
use App\Models\Core\User;
use App\Models\Files\ProjectFile;
class ProjectFilePolicy
{
/**
* Determine whether the user can view any project files.
*/
public function viewAny(User $user): bool
{
// Admin can view all files
// Client users can view the list (but it will be scoped to their visible files)
return true;
}
/**
* Determine whether the user can view the project file.
*/
public function view(User $user, ProjectFile $projectFile): bool
{
if ($user->isAdmin()) {
return true;
}
// Client users can only view files that are marked as client visible
// and belong to their client's project
return $projectFile->is_client_visible
&& $user->belongsToClient($projectFile->project->client);
}
/**
* Determine whether the user can create project files.
*/
public function create(User $user): bool
{
// Both admins and clients can upload files
return true;
}
/**
* Determine whether the user can upload files to a specific project.
*/
public function upload(User $user, ProjectFile $projectFile): bool
{
if ($user->isAdmin()) {
return true;
}
// Clients can upload to their own projects
return $user->belongsToClient($projectFile->project->client);
}
/**
* Determine whether the user can download the project file.
*/
public function download(User $user, ProjectFile $projectFile): bool
{
if ($user->isAdmin()) {
return true;
}
// Client users can only download files that are marked as client visible
// and belong to their client's project
return $projectFile->is_client_visible
&& $user->belongsToClient($projectFile->project->client);
}
/**
* Determine whether the user can update the project file.
*/
public function update(User $user, ProjectFile $projectFile): bool
{
if ($user->isAdmin()) {
return true;
}
// Users can update files they uploaded
return $projectFile->uploaded_by === $user->id;
}
/**
* Determine whether the user can delete the project file.
*/
public function delete(User $user, ProjectFile $projectFile): bool
{
if ($user->isAdmin()) {
return true;
}
// Users can delete files they uploaded
return $projectFile->uploaded_by === $user->id;
}
/**
* Determine whether the user can restore the project file.
*/
public function restore(User $user, ProjectFile $projectFile): bool
{
return $user->isAdmin();
}
/**
* Determine whether the user can permanently delete the project file.
*/
public function forceDelete(User $user, ProjectFile $projectFile): bool
{
return $user->isAdmin();
}
}