Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions ProcessMaker/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,37 @@ public function boot()
if ($user->is_administrator) {
return true;
}

// Let other policies handle the request.
return null;
});

try {
$permissions = Permission::select('name')->get();
// Define the Gate permissions
$permissions->each(function ($permission) {
Gate::define($permission->name, function (User $user, ...$params) use ($permission) {
$authorized = false;

// Check if the user has the permission
if ($user->hasPermission($permission->name)) {
return true;
}

// If the user has no projects, return false.
$projects = $this->getProjectsForUser($user->id);
if (empty($projects)) {
return false;
}

// Check if the user has 'create-projects' permission and the request is from specific endpoints
// Users that ONLY have 'create-projects' permission are allowed to access specific endpoints
$isAllowedEndpoint = $this->checkAllowedEndpoints($projects, request()->path());

if ($user->hasPermission('create-projects') && $isAllowedEndpoint) {
return $this->isProjectAsset($permission, $params);
$authorized = $this->isProjectAsset($permission, $params);
}

return false;
return $authorized;
});
});
} catch (\Exception $e) {
Expand Down