diff --git a/.gitignore b/.gitignore index 1121fa3..0ff52df 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ public/docs/* composer.phar .phpunit.result.cache /storage/api-docs -build \ No newline at end of file +.build \ No newline at end of file diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 280a208..04b7642 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -7,9 +7,12 @@ use Illuminate\Database\QueryException; use Illuminate\Validation\ValidationException; use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; +use Laravel\Passport\Exceptions\OAuthServerException as LaravelOAuthServerException; +use League\OAuth2\Server\Exception\OAuthServerException as LeagueOAuthServerException; use Spatie\Permission\Exceptions\RoleAlreadyExists; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\HttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; class Handler extends ExceptionHandler @@ -24,6 +27,8 @@ class Handler extends ExceptionHandler HttpException::class, ModelNotFoundException::class, ValidationException::class, + LeagueOAuthServerException::class, + LaravelOAuthServerException::class, ]; /** @@ -52,7 +57,13 @@ public function report(Throwable $exception) */ public function render($request, Throwable $exception) { - if ($exception instanceof RoleAlreadyExists) { + if (method_exists($exception, 'getStatusCode') && blank($exception->getMessage())) { + if ($exception->getStatusCode() == Response::HTTP_NOT_FOUND) { + $exception = new NotFoundHttpException('404 Not Found', $exception); + } else { + $exception = new HttpException($exception->getStatusCode(), 'Error '.$exception->getStatusCode()); + } + } elseif ($exception instanceof RoleAlreadyExists) { $exception = new HttpException( Response::HTTP_UNPROCESSABLE_ENTITY, $exception->getMessage(), diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a4f8489..ef8052e 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -30,7 +30,7 @@ class Controller extends BaseController * @OA\Post( * path="/oauth/token", * summary="Generate access token", - * tags={"Authorization"}, + * tags={"Authentication"}, * @OA\RequestBody( * @OA\MediaType( * mediaType="application/json", @@ -106,6 +106,10 @@ class Controller extends BaseController * ) * * @OA\Tag( + * name="Authentication", + * description="API Endpoints of Authentication" + * ) + * @OA\Tag( * name="Authorization", * description="API Endpoints of Authorization" * ) @@ -113,7 +117,19 @@ class Controller extends BaseController * name="Localizations", * description="API Endpoints of Localizations" * ) + * @OA\Tag( + * name="Access", + * description="API Endpoints of Access" + * ) * + * @OA\Schema( + * schema="Error", + * required={"message"}, + * @OA\Property( + * property="message", + * type="string" + * ) + * ), */ diff --git a/app/Http/Controllers/V1/Backend/Auth/Authorization/AuthorizationController.php b/app/Http/Controllers/V1/Backend/Auth/Authorization/AuthorizationController.php index 95ec2dc..9e3dced 100644 --- a/app/Http/Controllers/V1/Backend/Auth/Authorization/AuthorizationController.php +++ b/app/Http/Controllers/V1/Backend/Auth/Authorization/AuthorizationController.php @@ -1,10 +1,4 @@ - * Date: 12/26/18 - * Time: 4:43 PM - */ namespace App\Http\Controllers\V1\Backend\Auth\Authorization; @@ -16,22 +10,11 @@ use App\Transformers\Auth\UserTransformer; use Illuminate\Http\Request; -/** - * Class AuthorizationController - * - * @package App\Http\Controllers\V1\Backend\Auth\Authorization - */ class AuthorizationController extends Controller { protected UserRepository $userRepository; protected RoleRepository $roleRepository; - /** - * AuthorizationController constructor. - * - * @param \App\Repositories\Auth\User\UserRepository $userRepository - * @param \App\Repositories\Auth\Role\RoleRepository $roleRepository - */ public function __construct(UserRepository $userRepository, RoleRepository $roleRepository) { $this->middleware('permission:'.config('setting.permission.permission_names.manage_authorization')); @@ -47,17 +30,29 @@ public function __construct(UserRepository $userRepository, RoleRepository $role * summary="Assign role to user", * tags={"Authorization"}, * security={{"passport":{}}}, + * @OA\Parameter( + * name="include", + * in="query", + * required=false, + * @OA\Schema( + * type="array", + * @OA\Items( + * type="string", + * enum = {"roles", "permissions"}, + * ) + * ) + * ), * @OA\RequestBody( * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * @OA\Property( - * description="User hashed id", + * description="User key", * property="user_id", * type="int", * ), * @OA\Property( - * description="Role hashed id", + * description="Role key", * property="role_id", * type="int", * ), @@ -68,41 +63,21 @@ public function __construct(UserRepository $userRepository, RoleRepository $role * ) * ) * ), - * @OA\Response( - * response="200", - * description="ok", - * content={ - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * @OA\Property( - * property="access_token", - * type="string", - * description="JWT access token" - * ), - * @OA\Property( - * property="token_type", - * type="string", - * description="Token type" - * ), - * @OA\Property( - * property="expires_in", - * type="integer", - * description="Token expiration in miliseconds", - * @OA\Items - * ), - * example={ - * "access_token": "eyJ0eXAiOiJKV1QiLCJhbGc...", - * "token_type": "bearer", - * "expires_in": 3600 - * } - * ) - * ) - * } + * @OA\Response( + * response=200, + * description="OK", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/UserTransformer") + * ), * ), * @OA\Response( * response="401", - * description="Unauthorized" + * description="Unauthorized", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/Error") + * ), * ), * ) * @@ -136,11 +111,50 @@ public function assignRoleToUser(Request $request) } /** + * @OA\Delete( + * path="/auth/authorizations/revoke-role-from-user", + * summary="Revoke role from user", + * tags={"Authorization"}, + * security={{"passport":{}}}, + * @OA\RequestBody( + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * @OA\Property( + * description="User key", + * property="user_id", + * type="int", + * ), + * @OA\Property( + * description="Role keyd", + * property="role_id", + * type="int", + * ), + * example={ + * "user_id": "user-at-usercom", + * "role_id": 1 + * } + * ) + * ) + * ), + * @OA\Response( + * response=204, + * description="The resource was revoked successfully.", + * ), + * @OA\Response( + * response="401", + * description="Unauthorized", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/Error") + * ), + * ), + * ) * @param \Illuminate\Http\Request $request * - * @return \Spatie\Fractal\Fractal + * @return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory * @throws \Illuminate\Validation\ValidationException - * @api {post} /auth/authorizations/revoke-role-from-user Revoke role form user + * @api {delete} /auth/authorizations/revoke-role-from-user Revoke role form user * @apiName revoke-role-from-user * @apiGroup Authorization * @apiVersion 1.0.0 @@ -162,11 +176,65 @@ public function revokeRoleFormUser(Request $request) $this->userRepository->removeRole($attributes['user_id'], $attributes['role_id']); - $user = $this->userRepository->findByRouteKeyName($attributes['user_id']); - return $this->fractal($user, new UserTransformer()); + return response('', 204); } /** + * @OA\Post( + * path="/auth/authorizations/assign-permission-to-user", + * summary="Assign permission to user", + * tags={"Authorization"}, + * security={{"passport":{}}}, + * @OA\Parameter( + * name="include", + * in="query", + * required=false, + * @OA\Schema( + * type="array", + * @OA\Items( + * type="string", + * enum = {"roles", "permissions"}, + * ) + * ) + * ), + * @OA\RequestBody( + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * @OA\Property( + * description="User key", + * property="user_id", + * type="int", + * ), + * @OA\Property( + * description="Permission key", + * property="permission_id", + * type="int", + * ), + * example={ + * "user_id": "user-at-usercom", + * "permission_id": 1 + * } + * ) + * ) + * ), + * @OA\Response( + * response=200, + * description="OK", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/UserTransformer") + * ), + * ), + * @OA\Response( + * response="401", + * description="Unauthorized", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/Error") + * ), + * ), + * ) * @param \Illuminate\Http\Request $request * * @return \Spatie\Fractal\Fractal @@ -197,11 +265,50 @@ public function assignPermissionToUser(Request $request) } /** + * @OA\Delete( + * path="/auth/authorizations/revoke-permission-from-user", + * summary="Revoke permission from user", + * tags={"Authorization"}, + * security={{"passport":{}}}, + * @OA\RequestBody( + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * @OA\Property( + * description="User key", + * property="user_id", + * type="int", + * ), + * @OA\Property( + * description="Permission key", + * property="permission_id", + * type="int", + * ), + * example={ + * "user_id": "user-at-usercom", + * "permission_id": 1 + * } + * ) + * ) + * ), + * @OA\Response( + * response=204, + * description="The resource was revoked successfully.", + * ), + * @OA\Response( + * response="401", + * description="Unauthorized", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/Error") + * ), + * ), + * ) * @param \Illuminate\Http\Request $request * - * @return \Spatie\Fractal\Fractal + * @return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory * @throws \Illuminate\Validation\ValidationException - * @api {post} /auth/authorizations/revoke-permission-from-user Revoke permission from user + * @api {delete} /auth/authorizations/revoke-permission-from-user Revoke permission from user * @apiName revoke-permission-from-user * @apiGroup Authorization * @apiVersion 1.0.0 @@ -223,10 +330,65 @@ public function revokePermissionFromUser(Request $request) $this->userRepository->revokePermissionTo($attributes['user_id'], $attributes['permission_id']); - return $this->fractal($this->userRepository->findByRouteKeyName($attributes['user_id']), new UserTransformer()); + return response('', 204); } /** + * @OA\Post( + * path="/auth/authorizations/attach-permission-to-role", + * summary="Attach permission to role", + * tags={"Authorization"}, + * security={{"passport":{}}}, + * @OA\Parameter( + * name="include", + * in="query", + * required=false, + * @OA\Schema( + * type="array", + * @OA\Items( + * type="string", + * enum = {"roles", "permissions"}, + * ) + * ) + * ), + * @OA\RequestBody( + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * @OA\Property( + * description="Role key", + * property="role_id", + * type="int", + * ), + * @OA\Property( + * description="Permission key", + * property="permission_id", + * type="int", + * ), + * example={ + * "role_id": 1, + * "permission_id": 1 + * } + * ) + * ) + * ), + * @OA\Response( + * response=200, + * description="OK", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/UserTransformer") + * ), + * ), + * @OA\Response( + * response="401", + * description="Unauthorized", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/Error") + * ), + * ), + * ) * @param \Illuminate\Http\Request $request * * @return \Spatie\Fractal\Fractal @@ -257,11 +419,50 @@ public function attachPermissionToRole(Request $request) } /** + * @OA\Delete( + * path="/auth/authorizations/revoke-permission-from-role", + * summary="Revoke permission from role", + * tags={"Authorization"}, + * security={{"passport":{}}}, + * @OA\RequestBody( + * @OA\MediaType( + * mediaType="application/json", + * @OA\Schema( + * @OA\Property( + * description="Role key", + * property="role_id", + * type="int", + * ), + * @OA\Property( + * description="Permission key", + * property="permission_id", + * type="int", + * ), + * example={ + * "role_id": 1, + * "permission_id": 1 + * } + * ) + * ) + * ), + * @OA\Response( + * response=204, + * description="The resource was revoked successfully.", + * ), + * @OA\Response( + * response="401", + * description="Unauthorized", + * @OA\JsonContent( + * type="array", + * @OA\Items(ref="#/components/schemas/Error") + * ), + * ), + * ) * @param \Illuminate\Http\Request $request * - * @return \Spatie\Fractal\Fractal + * @return \Illuminate\Http\Response|\Laravel\Lumen\Http\ResponseFactory * @throws \Illuminate\Validation\ValidationException - * @api {post} /auth/authorizations/revoke-permission-from-role Revoke permission from role + * @api {delete} /auth/authorizations/revoke-permission-from-role Revoke permission from role * @apiName revoke-permission-from-role * @apiGroup Authorization * @apiVersion 1.0.0 @@ -283,7 +484,7 @@ public function revokePermissionFromRole(Request $request) $this->roleRepository->revokePermissionTo($attributes['role_id'], $attributes['permission_id']); - return $this->fractal($this->roleRepository->findByRouteKeyName($attributes['role_id']), new RoleTransformer()); + return response('', 204); } diff --git a/app/Http/Controllers/V1/Backend/Auth/Permission/PermissionController.php b/app/Http/Controllers/V1/Backend/Auth/Permission/PermissionController.php index d0b7802..3e929ee 100644 --- a/app/Http/Controllers/V1/Backend/Auth/Permission/PermissionController.php +++ b/app/Http/Controllers/V1/Backend/Auth/Permission/PermissionController.php @@ -1,10 +1,4 @@ - * Date: 12/16/18 - * Time: 11:25 AM - */ namespace App\Http\Controllers\V1\Backend\Auth\Permission; @@ -14,49 +8,10 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; -/** - * Class PermissionController - * - * @package App\Http\Controllers\V1\Backend\Auth\Permission - */ class PermissionController extends Controller { protected PermissionRepository $permissionRepository; - /** - * - * @OA\Get( - * path="/samplesss/{category}/things", - * operationId="/samplesss/category/things", - * tags={"yourtag"}, - * @OA\Parameter( - * name="category", - * in="path", - * description="The category parameter in path", - * required=true, - * @OA\Schema(type="string") - * ), - * @OA\Parameter( - * name="criteria", - * in="query", - * description="Some optional other parameter", - * required=false, - * @OA\Schema(type="string") - * ), - * @OA\Response( - * response="200", - * description="Returns some sample category things", - * @OA\JsonContent() - * ), - * @OA\Response( - * response="400", - * description="Error: Bad request. When required parameters were not supplied.", - * ), - * ) - * PermissionController constructor. - * - * @param \App\Repositories\Auth\Permission\PermissionRepository $permissionRepository - */ public function __construct(PermissionRepository $permissionRepository) { $permissions = $permissionRepository->makeModel()::PERMISSIONS; diff --git a/app/Http/Controllers/V1/Backend/Auth/Role/RoleController.php b/app/Http/Controllers/V1/Backend/Auth/Role/RoleController.php index 8ce7088..a661342 100644 --- a/app/Http/Controllers/V1/Backend/Auth/Role/RoleController.php +++ b/app/Http/Controllers/V1/Backend/Auth/Role/RoleController.php @@ -1,10 +1,4 @@ - * Date: 12/16/18 - * Time: 11:25 AM - */ namespace App\Http\Controllers\V1\Backend\Auth\Role; @@ -14,50 +8,10 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; -/** - * Class RoleController - * - * @package App\Http\Controllers\V1\Backend\Auth\Role - */ class RoleController extends Controller { protected RoleRepository $roleRepository; - /** - * - * @OA\Get( - * path="/sampsdfle/{category}/things", - * operationId="/sdf/category/things", - * tags={"yourtag"}, - * @OA\Parameter( - * name="category", - * in="path", - * description="The category parameter in path", - * required=true, - * @OA\Schema(type="string") - * ), - * @OA\Parameter( - * name="criteria", - * in="query", - * description="Some optional other parameter", - * required=false, - * @OA\Schema(type="string") - * ), - * @OA\Response( - * response="200", - * description="Returns some sample category things", - * @OA\JsonContent() - * ), - * @OA\Response( - * response="400", - * description="Error: Bad request. When required parameters were not supplied.", - * ), - * ) - * - * RoleController constructor. - * - * @param \App\Repositories\Auth\Role\RoleRepository $roleRepository - */ public function __construct(RoleRepository $roleRepository) { $permissions = $roleRepository->makeModel()::PERMISSIONS; diff --git a/app/Http/Controllers/V1/Backend/Auth/User/UserController.php b/app/Http/Controllers/V1/Backend/Auth/User/UserController.php index d1568fe..4cf1d15 100644 --- a/app/Http/Controllers/V1/Backend/Auth/User/UserController.php +++ b/app/Http/Controllers/V1/Backend/Auth/User/UserController.php @@ -8,20 +8,10 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; -/** - * Class UserController - * - * @package App\Http\Controllers\V1\Backend\Auth\User - */ class UserController extends Controller { protected UserRepository $userRepository; - /** - * UserController constructor. - * - * @param \App\Repositories\Auth\User\UserRepository $userRepository - */ public function __construct(UserRepository $userRepository) { $permissions = $userRepository->makeModel()::PERMISSIONS; @@ -112,34 +102,6 @@ public function store(Request $request) } /** - * @OA\Get( - * path="/sampzzle/{category}/things", - * operationId="/samxxxple/category/things", - * tags={"yourtag"}, - * @OA\Parameter( - * name="category", - * in="path", - * description="The category parameter in path", - * required=true, - * @OA\Schema(type="string") - * ), - * @OA\Parameter( - * name="criteria", - * in="query", - * description="Some optional other parameter", - * required=false, - * @OA\Schema(type="string") - * ), - * @OA\Response( - * response="200", - * description="Returns some sample category things", - * @OA\JsonContent() - * ), - * @OA\Response( - * response="400", - * description="Error: Bad request. When required parameters were not supplied.", - * ), - * ) * * @param \Illuminate\Http\Request $request * @param string $id diff --git a/app/Http/Controllers/V1/Backend/Auth/User/UserDeleteController.php b/app/Http/Controllers/V1/Backend/Auth/User/UserDeleteController.php index 440b102..0bfcc91 100644 --- a/app/Http/Controllers/V1/Backend/Auth/User/UserDeleteController.php +++ b/app/Http/Controllers/V1/Backend/Auth/User/UserDeleteController.php @@ -1,10 +1,4 @@ - * Date: 12/2/18 - * Time: 4:08 PM - */ namespace App\Http\Controllers\V1\Backend\Auth\User; @@ -15,49 +9,10 @@ use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; -/** - * Class UserDeleteController - * - * @package App\Http\Controllers\V1\Backend\Auth\User - */ class UserDeleteController extends Controller { protected UserRepository $userRepository; - /** - * @OA\Get( - * path="/sampxccle/{category}/things", - * operationId="/sambvbvple/category/things", - * tags={"yourtag"}, - * @OA\Parameter( - * name="category", - * in="path", - * description="The category parameter in path", - * required=true, - * @OA\Schema(type="string") - * ), - * @OA\Parameter( - * name="criteria", - * in="query", - * description="Some optional other parameter", - * required=false, - * @OA\Schema(type="string") - * ), - * @OA\Response( - * response="200", - * description="Returns some sample category things", - * @OA\JsonContent() - * ), - * @OA\Response( - * response="400", - * description="Error: Bad request. When required parameters were not supplied.", - * ), - * ) - * - * UserDeleteController constructor. - * - * @param \App\Repositories\Auth\User\UserRepository $userRepository - */ public function __construct(UserRepository $userRepository) { $permissions = $userRepository->makeModel()::PERMISSIONS; diff --git a/app/Http/Controllers/V1/Frontend/User/UserAccessController.php b/app/Http/Controllers/V1/Frontend/User/UserAccessController.php index 2da3a19..05ab3a9 100644 --- a/app/Http/Controllers/V1/Frontend/User/UserAccessController.php +++ b/app/Http/Controllers/V1/Frontend/User/UserAccessController.php @@ -1,27 +1,16 @@ - * Date: 12/2/18 - * Time: 4:52 PM - */ namespace App\Http\Controllers\V1\Frontend\User; use App\Http\Controllers\Controller; use App\Transformers\Auth\UserTransformer; -/** - * Class UserAccessController - * - * @package App\Http\Controllers\V1\Backend\Auth\User - */ class UserAccessController extends Controller { /** * @OA\Get( * path="/profile", - * tags={"Authorization"}, + * tags={"Access"}, * summary="Get current logged in user profile", * security={{"passport":{}}}, * @OA\Response( diff --git a/app/Http/Controllers/V1/LocalizationController.php b/app/Http/Controllers/V1/LocalizationController.php index 2dc8902..ac84718 100644 --- a/app/Http/Controllers/V1/LocalizationController.php +++ b/app/Http/Controllers/V1/LocalizationController.php @@ -1,10 +1,4 @@ - * Date: 2/3/19 - * Time: 5:22 AM - */ namespace App\Http\Controllers\V1; @@ -12,11 +6,6 @@ use App\Transformers\LocalizationTransformer; use App\Values\Localizations\Localization; -/** - * Class LocalizationController - * - * @package App\Http\Controllers\V1 - */ class LocalizationController extends Controller { /** diff --git a/app/Transformers/Auth/UserTransformer.php b/app/Transformers/Auth/UserTransformer.php index 44852b7..72d6903 100644 --- a/app/Transformers/Auth/UserTransformer.php +++ b/app/Transformers/Auth/UserTransformer.php @@ -11,6 +11,34 @@ use App\Models\Auth\User\User; use App\Transformers\BaseTransformer; +/** + * @OA\Schema( + * schema="UserTransformer", + * type="object", + * properties={ + * @OA\Property(property="id", type="string"), + * @OA\Property(property="attributes", type="object", properties={ + * + * @OA\Property(property="first_name", type="string"), + * @OA\Property(property="last_name", type="string"), + * @OA\Property(property="email", type="string"), + * @OA\Property(property="created_at", type="string"), + * @OA\Property(property="created_at_readable", type="string"), + * @OA\Property(property="updated_at", type="string"), + * @OA\Property(property="updated_at_readable", type="string") + * + * }), + * @OA\Property(property="relationships", type="array", @OA\Items({ + * + * })), + * @OA\Property(property="meta", type="array", @OA\Items({ + * + * @OA\Property(property="include", type="array", @OA\Items({ + * })), + * })), + * } + * ) + */ class UserTransformer extends BaseTransformer { /** diff --git a/config/swagger-lume.php b/config/swagger-lume.php index ebf06e2..2ae2d50 100644 --- a/config/swagger-lume.php +++ b/config/swagger-lume.php @@ -72,7 +72,10 @@ | Absolute path to directory containing the swagger annotations are stored. |-------------------------------------------------------------------------- */ - 'annotations' => __DIR__.'/../app/Http/Controllers',//base_path('app'), + 'annotations' => [ + __DIR__.'/../app/Http/Controllers', + __DIR__.'/../app/Transformers', + ],//base_path('app'), /* |-------------------------------------------------------------------------- diff --git a/phpunit.xml b/phpunit.xml index ed42269..bdcfde9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,9 +10,9 @@ ./app - - - + + + diff --git a/readme.md b/readme.md index a34f41f..1b64196 100644 --- a/readme.md +++ b/readme.md @@ -60,7 +60,7 @@ Use the `Client ID` and `Client Secret` of password grant for OAuth2 - Login (Pa You can visit the generated API documentation in http://lumen-boilerplate.test/documentation in your local machine. (working in progress) -![](https://user-images.githubusercontent.com/8251344/92990619-6de18700-f510-11ea-9e05-e6062b709bc4.png) +![Screenshot from 2020-09-13 00-36-59](https://user-images.githubusercontent.com/8251344/93000197-44991900-f559-11ea-8c0d-6e076d4ceb41.png) or here's the published postman [here](https://documenter.getpostman.com/view/4366674/SWEDzudy) @@ -75,8 +75,8 @@ vendor/bin/phpunit ``` **Notes:** -- If you run this via [Homestead's](https://laravel.com/docs/5.7/homestead) ssh, you can this command: `phpunit` (in your project directory). -- After running testing, you can check generated code coverage from `build` folder. +- If you run this via [Homestead's](https://laravel.com/docs/homestead) ssh, you can this command: `phpunit` (in your project directory). +- After running testing, you can check generated code coverage from `.build` folder. ## Built With diff --git a/routes/v1/backend/auth/authorization.php b/routes/v1/backend/auth/authorization.php index 1798666..88a0ea2 100644 --- a/routes/v1/backend/auth/authorization.php +++ b/routes/v1/backend/auth/authorization.php @@ -17,7 +17,7 @@ function () use ($router) { 'uses' => 'AuthorizationController@assignRoleToUser', ] ); - $router->post( + $router->delete( '/revoke-role-from-user', [ 'as' => 'revoke-role-from-user', @@ -33,7 +33,7 @@ function () use ($router) { 'uses' => 'AuthorizationController@assignPermissionToUser', ] ); - $router->post( + $router->delete( '/revoke-permission-from-user', [ 'as' => 'revoke-permission-from-user', @@ -49,7 +49,7 @@ function () use ($router) { 'uses' => 'AuthorizationController@attachPermissionToRole', ] ); - $router->post( + $router->delete( '/revoke-permission-from-role', [ 'as' => 'revoke-permission-from-role', diff --git a/tests/Auth/Authorization/ManageTest.php b/tests/Auth/Authorization/ManageTest.php index 6cc559e..8a85f10 100644 --- a/tests/Auth/Authorization/ManageTest.php +++ b/tests/Auth/Authorization/ManageTest.php @@ -48,7 +48,7 @@ public function revoke_role_from_user() // $this->showModelWithRelation('backend.users.show', $user, $role, 'roles'); - $this->post( + $this->delete( route('backend.authorizations.revoke-role-from-user').'?include=roles', [ 'role_id' => self::forId($role), @@ -56,9 +56,10 @@ public function revoke_role_from_user() ], $this->addHeaders() ); - $this->assertResponseOk(); + $this->assertResponseStatus(204); - $this->seeJsonApiRelation($role, 'roles', 'dontSeeJson'); + $this->assertFalse($user->refresh()->hasRole($role)); +// $this->seeJsonApiRelation($role, 'roles', 'dontSeeJson'); // $this->showModelWithRelation('backend.users.show', $user, $role, 'roles', 'dontSeeJson'); } @@ -93,7 +94,7 @@ public function revoke_permission_to_user() // $this->showModelWithRelation('backend.users.show', $user, $permission, 'permissions'); - $this->post( + $this->delete( route('backend.authorizations.revoke-permission-from-user').'?include=permissions', [ 'permission_id' => self::forId($permission), @@ -101,9 +102,10 @@ public function revoke_permission_to_user() ], $this->addHeaders() ); - $this->assertResponseOk(); + $this->assertResponseStatus(204); - $this->seeJsonApiRelation($permission, 'permissions', 'dontSeeJson'); + $this->assertFalse($user->refresh()->hasPermissionTo($permission)); +// $this->seeJsonApiRelation($permission, 'permissions', 'dontSeeJson'); // $this->showModelWithRelation('backend.users.show', $user, $permission, 'permissions', 'dontSeeJson'); } @@ -137,7 +139,7 @@ public function revoke_permission_from_role() // $this->showModelWithRelation('backend.roles.show', $role, $permission, 'permissions'); - $this->post( + $this->delete( route('backend.authorizations.revoke-permission-from-role').'?include=permissions', [ 'permission_id' => self::forId($permission), @@ -145,9 +147,10 @@ public function revoke_permission_from_role() ], $this->addHeaders() ); - $this->assertResponseOk(); + $this->assertResponseStatus(204); - $this->seeJsonApiRelation($permission, 'permissions', 'dontSeeJson'); + $this->assertFalse($role->refresh()->hasPermissionTo($permission)); +// $this->seeJsonApiRelation($permission, 'permissions', 'dontSeeJson'); // $this->showModelWithRelation('backend.roles.show', $role, $permission, 'permissions', 'dontSeeJson'); } } \ No newline at end of file