Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/GroupsController.php
Show All 26 Lines | class GroupsController extends Controller | ||||
* Delete a group. | * Delete a group. | ||||
* | * | ||||
* @param int $id Group identifier | * @param int $id Group identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse The response | * @return \Illuminate\Http\JsonResponse The response | ||||
*/ | */ | ||||
public function destroy($id) | public function destroy($id) | ||||
{ | { | ||||
$group = Group::withEnvTenant()->find($id); | $group = Group::find($id); | ||||
if (empty($group)) { | if (!$this->checkTenant($group)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
if (!$this->guard()->user()->canDelete($group)) { | if (!$this->guard()->user()->canDelete($group)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$group->delete(); | $group->delete(); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | class GroupsController extends Controller | ||||
* Display information of a group specified by $id. | * Display information of a group specified by $id. | ||||
* | * | ||||
* @param int $id The group to show information for. | * @param int $id The group to show information for. | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function show($id) | public function show($id) | ||||
{ | { | ||||
$group = Group::withEnvTenant()->find($id); | $group = Group::find($id); | ||||
if (empty($group)) { | if (!$this->checkTenant($group)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
if (!$this->guard()->user()->canRead($group)) { | if (!$this->guard()->user()->canRead($group)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$response = $group->toArray(); | $response = $group->toArray(); | ||||
$response = array_merge($response, self::groupStatuses($group)); | $response = array_merge($response, self::groupStatuses($group)); | ||||
$response['statusInfo'] = self::statusInfo($group); | $response['statusInfo'] = self::statusInfo($group); | ||||
return response()->json($response); | return response()->json($response); | ||||
} | } | ||||
/** | /** | ||||
* Fetch group status (and reload setup process) | * Fetch group status (and reload setup process) | ||||
* | * | ||||
* @param int $id Group identifier | * @param int $id Group identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse | * @return \Illuminate\Http\JsonResponse | ||||
*/ | */ | ||||
public function status($id) | public function status($id) | ||||
{ | { | ||||
$group = Group::withEnvTenant()->find($id); | $group = Group::find($id); | ||||
if (empty($group)) { | if (!$this->checkTenant($group)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
if (!$this->guard()->user()->canRead($group)) { | if (!$this->guard()->user()->canRead($group)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
$response = self::statusInfo($group); | $response = self::statusInfo($group); | ||||
▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | class GroupsController extends Controller | ||||
* | * | ||||
* @param \Illuminate\Http\Request $request The API request. | * @param \Illuminate\Http\Request $request The API request. | ||||
* @param string $id Group identifier | * @param string $id Group identifier | ||||
* | * | ||||
* @return \Illuminate\Http\JsonResponse The response | * @return \Illuminate\Http\JsonResponse The response | ||||
*/ | */ | ||||
public function update(Request $request, $id) | public function update(Request $request, $id) | ||||
{ | { | ||||
$group = Group::withEnvTenant()->find($id); | $group = Group::find($id); | ||||
if (empty($group)) { | if (!$this->checkTenant($group)) { | ||||
return $this->errorResponse(404); | return $this->errorResponse(404); | ||||
} | } | ||||
$current_user = $this->guard()->user(); | $current_user = $this->guard()->user(); | ||||
if (!$current_user->canUpdate($group)) { | if (!$current_user->canUpdate($group)) { | ||||
return $this->errorResponse(403); | return $this->errorResponse(403); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 186 Lines • Show Last 20 Lines |