Commit efa4906c authored by Viral Solani's avatar Viral Solani

Misc changes in APIs

parent 23b20325
......@@ -10,6 +10,7 @@ use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
class Handler extends ExceptionHandler
{
......@@ -75,22 +76,23 @@ class Handler extends ExceptionHandler
return $this->setStatusCode(422)->respondWithError($exception->validator->messages());
}
/*
* Redirect if token mismatch error
* Usually because user stayed on the same screen too long and their session expired
*/
if ($exception instanceof UnauthorizedHttpException) {
switch (get_class($exception->getPrevious())) {
case \App\Exceptions\Handler::class:
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token has not been provided.');
case \Tymon\JWTAuth\Exceptions\TokenExpiredException::class:
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token has expired.');
case \Tymon\JWTAuth\Exceptions\TokenInvalidException::class:
case \Tymon\JWTAuth\Exceptions\TokenBlacklistedException::class:
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token is invalid.');
}
}
}
/*
* Redirect if token mismatch error
* Usually because user stayed on the same screen too long and their session expired
*/
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException) {
switch (get_class($exception->getPrevious())) {
case \App\Exceptions\Handler::class:
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token has not been provided.');
case \Tymon\JWTAuth\Exceptions\TokenExpiredException::class:
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token has expired.');
case \Tymon\JWTAuth\Exceptions\TokenInvalidException::class:
case \Tymon\JWTAuth\Exceptions\TokenBlacklistedException::class:
return $this->setStatusCode($exception->getStatusCode())->respondWithError('Token is invalid.');
}
}
/*
* Redirect if token mismatch error
......
......@@ -21,6 +21,7 @@ class RoleResource extends Resource
'permission' => ($this->all) ? 'All' : optional($this->permissions)->pluck('display_name'),
'noofuses' => $this->users->count(),
'sort' => $this->sort,
'status' => $this->status
];
}
}
......@@ -49,6 +49,7 @@ class RoleRepository extends BaseRepository
config('access.roles_table').'.name',
config('access.roles_table').'.all',
config('access.roles_table').'.sort',
config('access.roles_table').'.status',
DB::raw("GROUP_CONCAT( DISTINCT permissions.display_name SEPARATOR '<br/>') as permission_name"),
DB::raw('(SELECT COUNT(role_user.id) FROM role_user LEFT JOIN users ON role_user.user_id = users.id WHERE role_user.role_id = roles.id AND users.deleted_at IS NULL) AS userCount'),
])
......
......@@ -36,6 +36,8 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
// Roles
Route::resource('roles', 'RolesController', ['except' => ['create', 'edit']]);
Route::post('roles/delete-all', 'RolesController@deleteAll');
// Permission
Route::resource('permission', 'PermissionController', ['except' => ['create', 'edit']]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment