|
20 | 20 |
|
21 | 21 | class ProcessController extends Controller |
22 | 22 | { |
23 | | - public $skipPermissionCheckFor = ['triggerStartEvent']; |
| 23 | + public $skipPermissionCheckFor = ['triggerStartEvent', 'startProcesses']; |
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * Get list Process |
@@ -246,6 +246,65 @@ public function update(Request $request, Process $process) |
246 | 246 | return new Resource($process->refresh()); |
247 | 247 | } |
248 | 248 |
|
| 249 | + /** |
| 250 | + * Returns the list of processes that the user can start. |
| 251 | + * |
| 252 | + * @param Request $request |
| 253 | + * |
| 254 | + * @return ApiCollection |
| 255 | + * |
| 256 | + * * @OA\Get( |
| 257 | + * path="/start_processes", |
| 258 | + * summary="Returns the list of processes that the user can start", |
| 259 | + * operationId="startProcesses", |
| 260 | + * tags={"Process"}, |
| 261 | + * @OA\Parameter(ref="#/components/parameters/order_by"), |
| 262 | + * @OA\Parameter(ref="#/components/parameters/order_direction"), |
| 263 | + * @OA\Parameter(ref="#/components/parameters/per_page"), |
| 264 | + * @OA\Parameter(ref="#/components/parameters/include"), |
| 265 | + * |
| 266 | + * @OA\Response( |
| 267 | + * response=200, |
| 268 | + * description="list of processes that the user can start", |
| 269 | + * @OA\JsonContent( |
| 270 | + * type="object", |
| 271 | + * @OA\Property( |
| 272 | + * property="data", |
| 273 | + * type="array", |
| 274 | + * @OA\Items(ref="#/components/schemas/Process"), |
| 275 | + * ), |
| 276 | + * @OA\Property( |
| 277 | + * property="meta", |
| 278 | + * type="object", |
| 279 | + * allOf={@OA\Schema(ref="#/components/schemas/metadata")}, |
| 280 | + * ), |
| 281 | + * ), |
| 282 | + * ), |
| 283 | + * ) |
| 284 | + */ |
| 285 | + public function startProcesses(Request $request) |
| 286 | + { |
| 287 | + $orderBy = $this->getRequestSortBy($request, 'name'); |
| 288 | + $perPage = $this->getPerPage($request); |
| 289 | + $include = $this->getRequestInclude($request); |
| 290 | + |
| 291 | + $processes = Process::with($include) |
| 292 | + ->select('processes.*') |
| 293 | + ->leftJoin('process_categories as category', 'processes.process_category_id', '=', 'category.id') |
| 294 | + ->leftJoin('users as user', 'processes.user_id', '=', 'user.id') |
| 295 | + ->where('processes.status', 'ACTIVE') |
| 296 | + ->where('category.status', 'ACTIVE'); |
| 297 | + |
| 298 | + //Verify what processes the current user can initiate, user Administrator can start everything. |
| 299 | + if (!Auth::user()->is_administrator) { |
| 300 | + $processId = Auth::user()->startProcesses(); |
| 301 | + $processes->whereIn('processes.id', $processId); |
| 302 | + } |
| 303 | + $processes->orderBy(...$orderBy); |
| 304 | + |
| 305 | + return new ApiCollection($processes->paginate($perPage)); |
| 306 | + } |
| 307 | + |
249 | 308 | private function savePermission($process, $assignableType, $assignableId, $permissionId) |
250 | 309 | { |
251 | 310 | $processPerm = new ProcessPermission(); |
|
0 commit comments