@@ -10,36 +10,36 @@ |
||
| 10 | 10 | |
| 11 | 11 | class SettingController extends BaseApiController |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Init new object. |
|
| 15 | - * |
|
| 16 | - * @param SettingRepository $repo |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - public function __construct(SettingRepository $repo) |
|
| 20 | - { |
|
| 21 | - parent::__construct($repo, 'App\Modules\Core\Http\Resources\Setting'); |
|
| 22 | - } |
|
| 13 | + /** |
|
| 14 | + * Init new object. |
|
| 15 | + * |
|
| 16 | + * @param SettingRepository $repo |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + public function __construct(SettingRepository $repo) |
|
| 20 | + { |
|
| 21 | + parent::__construct($repo, 'App\Modules\Core\Http\Resources\Setting'); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Update the given model to storage. |
|
| 26 | - * |
|
| 27 | - * @param UpdateSetting $request |
|
| 28 | - * @return \Illuminate\Http\Response |
|
| 29 | - */ |
|
| 30 | - public function update(UpdateSetting $request) |
|
| 31 | - { |
|
| 32 | - return new $this->modelResource($this->repo->save($request->all())); |
|
| 33 | - } |
|
| 24 | + /** |
|
| 25 | + * Update the given model to storage. |
|
| 26 | + * |
|
| 27 | + * @param UpdateSetting $request |
|
| 28 | + * @return \Illuminate\Http\Response |
|
| 29 | + */ |
|
| 30 | + public function update(UpdateSetting $request) |
|
| 31 | + { |
|
| 32 | + return new $this->modelResource($this->repo->save($request->all())); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Save list of settings. |
|
| 37 | - * |
|
| 38 | - * @param Request $request |
|
| 39 | - * @return \Illuminate\Http\Response |
|
| 40 | - */ |
|
| 41 | - public function saveMany(Request $request) |
|
| 42 | - { |
|
| 43 | - return new GeneralResource($this->repo->saveMany($request->all())); |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Save list of settings. |
|
| 37 | + * |
|
| 38 | + * @param Request $request |
|
| 39 | + * @return \Illuminate\Http\Response |
|
| 40 | + */ |
|
| 41 | + public function saveMany(Request $request) |
|
| 42 | + { |
|
| 43 | + return new GeneralResource($this->repo->saveMany($request->all())); |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -8,33 +8,33 @@ |
||
| 8 | 8 | |
| 9 | 9 | class ReportController extends BaseApiController |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * List of all route actions that the base api controller |
|
| 13 | - * will skip permissions check for them. |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - protected $skipPermissionCheck = ['getReport']; |
|
| 11 | + /** |
|
| 12 | + * List of all route actions that the base api controller |
|
| 13 | + * will skip permissions check for them. |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + protected $skipPermissionCheck = ['getReport']; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Init new object. |
|
| 20 | - * |
|
| 21 | - * @param ReportRepository $repo |
|
| 22 | - * @return void |
|
| 23 | - */ |
|
| 24 | - public function __construct(ReportRepository $repo) |
|
| 25 | - { |
|
| 26 | - parent::__construct($repo, 'App\Modules\Reporting\Http\Resources\Report'); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Init new object. |
|
| 20 | + * |
|
| 21 | + * @param ReportRepository $repo |
|
| 22 | + * @return void |
|
| 23 | + */ |
|
| 24 | + public function __construct(ReportRepository $repo) |
|
| 25 | + { |
|
| 26 | + parent::__construct($repo, 'App\Modules\Reporting\Http\Resources\Report'); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Render the given report name with the given conditions. |
|
| 31 | - * |
|
| 32 | - * @param Request $request |
|
| 33 | - * @param string $reportName Name of the requested report |
|
| 34 | - * @return \Illuminate\Http\Response |
|
| 35 | - */ |
|
| 36 | - public function getReport(Request $request, $reportName) |
|
| 37 | - { |
|
| 38 | - return \Response::json($this->repo->getReport($reportName, $request->all(), $request->query('perPage')), 200); |
|
| 39 | - } |
|
| 29 | + /** |
|
| 30 | + * Render the given report name with the given conditions. |
|
| 31 | + * |
|
| 32 | + * @param Request $request |
|
| 33 | + * @param string $reportName Name of the requested report |
|
| 34 | + * @return \Illuminate\Http\Response |
|
| 35 | + */ |
|
| 36 | + public function getReport(Request $request, $reportName) |
|
| 37 | + { |
|
| 38 | + return \Response::json($this->repo->getReport($reportName, $request->all(), $request->query('perPage')), 200); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -9,64 +9,64 @@ |
||
| 9 | 9 | |
| 10 | 10 | class NotificationController extends BaseApiController |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * List of all route actions that the base api controller |
|
| 14 | - * will skip permissions check for them. |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - protected $skipPermissionCheck = ['markAsRead', 'markAllAsRead', 'index', 'unread']; |
|
| 12 | + /** |
|
| 13 | + * List of all route actions that the base api controller |
|
| 14 | + * will skip permissions check for them. |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + protected $skipPermissionCheck = ['markAsRead', 'markAllAsRead', 'index', 'unread']; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Init new object. |
|
| 21 | - * |
|
| 22 | - * @param NotificationRepository $repo |
|
| 23 | - * @return void |
|
| 24 | - */ |
|
| 25 | - public function __construct(NotificationRepository $repo) |
|
| 26 | - { |
|
| 27 | - parent::__construct($repo, 'App\Modules\Notifications\Http\Resources\Notification'); |
|
| 28 | - } |
|
| 19 | + /** |
|
| 20 | + * Init new object. |
|
| 21 | + * |
|
| 22 | + * @param NotificationRepository $repo |
|
| 23 | + * @return void |
|
| 24 | + */ |
|
| 25 | + public function __construct(NotificationRepository $repo) |
|
| 26 | + { |
|
| 27 | + parent::__construct($repo, 'App\Modules\Notifications\Http\Resources\Notification'); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Retrieve all notifications of the logged in user. |
|
| 32 | - * |
|
| 33 | - * @param Request $request |
|
| 34 | - * @return \Illuminate\Http\Response |
|
| 35 | - */ |
|
| 36 | - public function index(Request $request) |
|
| 37 | - { |
|
| 38 | - return $this->modelResource::collection($this->repo->my($request->query('perPage'))); |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * Retrieve all notifications of the logged in user. |
|
| 32 | + * |
|
| 33 | + * @param Request $request |
|
| 34 | + * @return \Illuminate\Http\Response |
|
| 35 | + */ |
|
| 36 | + public function index(Request $request) |
|
| 37 | + { |
|
| 38 | + return $this->modelResource::collection($this->repo->my($request->query('perPage'))); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Retrieve unread notifications of the logged in user. |
|
| 43 | - * |
|
| 44 | - * @param Request $request |
|
| 45 | - * @return \Illuminate\Http\Response |
|
| 46 | - */ |
|
| 47 | - public function unread(Request $request) |
|
| 48 | - { |
|
| 49 | - return $this->modelResource::collection($this->repo->unread($request->query('perPage'))); |
|
| 50 | - } |
|
| 41 | + /** |
|
| 42 | + * Retrieve unread notifications of the logged in user. |
|
| 43 | + * |
|
| 44 | + * @param Request $request |
|
| 45 | + * @return \Illuminate\Http\Response |
|
| 46 | + */ |
|
| 47 | + public function unread(Request $request) |
|
| 48 | + { |
|
| 49 | + return $this->modelResource::collection($this->repo->unread($request->query('perPage'))); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Mark the notification as read. |
|
| 54 | - * |
|
| 55 | - * @param integer $id Id of the notification. |
|
| 56 | - * @return \Illuminate\Http\Response |
|
| 57 | - */ |
|
| 58 | - public function markAsRead($id) |
|
| 59 | - { |
|
| 60 | - return new GeneralResource($this->repo->markAsRead($id)); |
|
| 61 | - } |
|
| 52 | + /** |
|
| 53 | + * Mark the notification as read. |
|
| 54 | + * |
|
| 55 | + * @param integer $id Id of the notification. |
|
| 56 | + * @return \Illuminate\Http\Response |
|
| 57 | + */ |
|
| 58 | + public function markAsRead($id) |
|
| 59 | + { |
|
| 60 | + return new GeneralResource($this->repo->markAsRead($id)); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Mark all notifications as read. |
|
| 65 | - * |
|
| 66 | - * @return \Illuminate\Http\Response |
|
| 67 | - */ |
|
| 68 | - public function markAllAsRead() |
|
| 69 | - { |
|
| 70 | - return new GeneralResource($this->repo->markAllAsRead()); |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * Mark all notifications as read. |
|
| 65 | + * |
|
| 66 | + * @return \Illuminate\Http\Response |
|
| 67 | + */ |
|
| 68 | + public function markAllAsRead() |
|
| 69 | + { |
|
| 70 | + return new GeneralResource($this->repo->markAllAsRead()); |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -10,58 +10,58 @@ |
||
| 10 | 10 | |
| 11 | 11 | class OauthClientController extends BaseApiController |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Init new object. |
|
| 15 | - * |
|
| 16 | - * @param OauthClientRepository $repo |
|
| 17 | - * @return void |
|
| 18 | - */ |
|
| 19 | - public function __construct(OauthClientRepository $repo) |
|
| 20 | - { |
|
| 21 | - parent::__construct($repo, 'App\Modules\OauthClients\Http\Resources\OauthClient'); |
|
| 22 | - } |
|
| 13 | + /** |
|
| 14 | + * Init new object. |
|
| 15 | + * |
|
| 16 | + * @param OauthClientRepository $repo |
|
| 17 | + * @return void |
|
| 18 | + */ |
|
| 19 | + public function __construct(OauthClientRepository $repo) |
|
| 20 | + { |
|
| 21 | + parent::__construct($repo, 'App\Modules\OauthClients\Http\Resources\OauthClient'); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Insert the given model to storage. |
|
| 26 | - * |
|
| 27 | - * @param InsertOauthClient $request |
|
| 28 | - * @return \Illuminate\Http\Response |
|
| 29 | - */ |
|
| 30 | - public function insert(InsertOauthClient $request) |
|
| 31 | - { |
|
| 32 | - return new $this->modelResource($this->repo->save($request->all())); |
|
| 33 | - } |
|
| 24 | + /** |
|
| 25 | + * Insert the given model to storage. |
|
| 26 | + * |
|
| 27 | + * @param InsertOauthClient $request |
|
| 28 | + * @return \Illuminate\Http\Response |
|
| 29 | + */ |
|
| 30 | + public function insert(InsertOauthClient $request) |
|
| 31 | + { |
|
| 32 | + return new $this->modelResource($this->repo->save($request->all())); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Update the given model to storage. |
|
| 37 | - * |
|
| 38 | - * @param UpdateOauthClient $request |
|
| 39 | - * @return \Illuminate\Http\Response |
|
| 40 | - */ |
|
| 41 | - public function update(UpdateOauthClient $request) |
|
| 42 | - { |
|
| 43 | - return new $this->modelResource($this->repo->save($request->all())); |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Update the given model to storage. |
|
| 37 | + * |
|
| 38 | + * @param UpdateOauthClient $request |
|
| 39 | + * @return \Illuminate\Http\Response |
|
| 40 | + */ |
|
| 41 | + public function update(UpdateOauthClient $request) |
|
| 42 | + { |
|
| 43 | + return new $this->modelResource($this->repo->save($request->all())); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Revoke the given client. |
|
| 48 | - * |
|
| 49 | - * @param integer $clientId Id of the client |
|
| 50 | - * @return \Illuminate\Http\Response |
|
| 51 | - */ |
|
| 52 | - public function revoke($clientId) |
|
| 53 | - { |
|
| 54 | - return new GeneralResource($this->repo->revoke($clientId)); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Revoke the given client. |
|
| 48 | + * |
|
| 49 | + * @param integer $clientId Id of the client |
|
| 50 | + * @return \Illuminate\Http\Response |
|
| 51 | + */ |
|
| 52 | + public function revoke($clientId) |
|
| 53 | + { |
|
| 54 | + return new GeneralResource($this->repo->revoke($clientId)); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Un revoke the given client. |
|
| 59 | - * |
|
| 60 | - * @param integer $clientId Id of the client |
|
| 61 | - * @return \Illuminate\Http\Response |
|
| 62 | - */ |
|
| 63 | - public function unRevoke($clientId) |
|
| 64 | - { |
|
| 65 | - return new GeneralResource($this->repo->unRevoke($clientId)); |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * Un revoke the given client. |
|
| 59 | + * |
|
| 60 | + * @param integer $clientId Id of the client |
|
| 61 | + * @return \Illuminate\Http\Response |
|
| 62 | + */ |
|
| 63 | + public function unRevoke($clientId) |
|
| 64 | + { |
|
| 65 | + return new GeneralResource($this->repo->unRevoke($clientId)); |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -6,42 +6,42 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ApiSkeletonServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Perform post-registration booting of services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function boot() |
|
| 15 | - { |
|
| 16 | - $this->publishes([ |
|
| 17 | - __DIR__.'/Modules' => app_path('Modules'), |
|
| 18 | - __DIR__.'/Modules/Core/Resources/Assets' => base_path('public/doc/assets'), |
|
| 19 | - __DIR__.'/../lang' => base_path('resources/lang'), |
|
| 20 | - __DIR__.'/../files/Handler.php' => app_path('Exceptions/Handler.php'), |
|
| 21 | - __DIR__.'/../files/AuthServiceProvider.php' => app_path('Providers/AuthServiceProvider.php'), |
|
| 22 | - __DIR__.'/../files/BroadcastServiceProvider.php' => app_path('Providers/BroadcastServiceProvider.php'), |
|
| 23 | - __DIR__.'/../files/Kernel.php' => app_path('Console/Kernel.php'), |
|
| 24 | - __DIR__.'/../files/HttpKernel.php' => app_path('Http/Kernel.php'), |
|
| 25 | - __DIR__.'/../files/channels.php' => base_path('routes/channels.php'), |
|
| 26 | - __DIR__.'/../phpcs.xml' => base_path('/phpcs.xml'), |
|
| 27 | - ]); |
|
| 9 | + /** |
|
| 10 | + * Perform post-registration booting of services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function boot() |
|
| 15 | + { |
|
| 16 | + $this->publishes([ |
|
| 17 | + __DIR__.'/Modules' => app_path('Modules'), |
|
| 18 | + __DIR__.'/Modules/Core/Resources/Assets' => base_path('public/doc/assets'), |
|
| 19 | + __DIR__.'/../lang' => base_path('resources/lang'), |
|
| 20 | + __DIR__.'/../files/Handler.php' => app_path('Exceptions/Handler.php'), |
|
| 21 | + __DIR__.'/../files/AuthServiceProvider.php' => app_path('Providers/AuthServiceProvider.php'), |
|
| 22 | + __DIR__.'/../files/BroadcastServiceProvider.php' => app_path('Providers/BroadcastServiceProvider.php'), |
|
| 23 | + __DIR__.'/../files/Kernel.php' => app_path('Console/Kernel.php'), |
|
| 24 | + __DIR__.'/../files/HttpKernel.php' => app_path('Http/Kernel.php'), |
|
| 25 | + __DIR__.'/../files/channels.php' => base_path('routes/channels.php'), |
|
| 26 | + __DIR__.'/../phpcs.xml' => base_path('/phpcs.xml'), |
|
| 27 | + ]); |
|
| 28 | 28 | |
| 29 | - $this->publishes([ |
|
| 30 | - __DIR__.'/../config/skeleton.php' => config_path('skeleton.php'), |
|
| 31 | - __DIR__.'/../files/auth.php' => config_path('auth.php'), |
|
| 32 | - ], 'config'); |
|
| 33 | - } |
|
| 29 | + $this->publishes([ |
|
| 30 | + __DIR__.'/../config/skeleton.php' => config_path('skeleton.php'), |
|
| 31 | + __DIR__.'/../files/auth.php' => config_path('auth.php'), |
|
| 32 | + ], 'config'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Register any package services. |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function register() |
|
| 41 | - { |
|
| 42 | - $this->mergeConfigFrom( |
|
| 43 | - __DIR__.'/../config/skeleton.php', |
|
| 44 | - 'skeleton' |
|
| 45 | - ); |
|
| 46 | - } |
|
| 35 | + /** |
|
| 36 | + * Register any package services. |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function register() |
|
| 41 | + { |
|
| 42 | + $this->mergeConfigFrom( |
|
| 43 | + __DIR__.'/../config/skeleton.php', |
|
| 44 | + 'skeleton' |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $factory->define(App\Modules\Core\Setting::class, function (Faker\Generator $faker) { |
| 4 | - return [ |
|
| 5 | - 'name' => $faker->randomElement(['Company Name', 'Title', 'Header Image']), |
|
| 6 | - 'value' => $faker->word(), |
|
| 7 | - 'key' => $faker->word(), |
|
| 8 | - 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
|
| 9 | - 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
|
| 10 | - ]; |
|
| 4 | + return [ |
|
| 5 | + 'name' => $faker->randomElement(['Company Name', 'Title', 'Header Image']), |
|
| 6 | + 'value' => $faker->word(), |
|
| 7 | + 'key' => $faker->word(), |
|
| 8 | + 'created_at' => $faker->dateTimeBetween('-1 years', 'now'), |
|
| 9 | + 'updated_at' => $faker->dateTimeBetween('-1 years', 'now') |
|
| 10 | + ]; |
|
| 11 | 11 | }); |
@@ -12,73 +12,73 @@ |
||
| 12 | 12 | |
| 13 | 13 | class CheckPermissions |
| 14 | 14 | { |
| 15 | - protected $route; |
|
| 16 | - protected $auth; |
|
| 17 | - protected $errorHandler; |
|
| 18 | - protected $authMiddleware; |
|
| 19 | - protected $core; |
|
| 20 | - protected $arr; |
|
| 15 | + protected $route; |
|
| 16 | + protected $auth; |
|
| 17 | + protected $errorHandler; |
|
| 18 | + protected $authMiddleware; |
|
| 19 | + protected $core; |
|
| 20 | + protected $arr; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Init new object. |
|
| 24 | - * |
|
| 25 | - * @param Route $route |
|
| 26 | - * @param Auth $auth |
|
| 27 | - * @param ErrorHandler $errorHandler |
|
| 28 | - * @param AuthMiddleware $authMiddleware |
|
| 29 | - * @param Core $core |
|
| 30 | - * @param Arr $arr |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public function __construct(Route $route, Auth $auth, ErrorHandler $errorHandler, AuthMiddleware $authMiddleware, Core $core, Arr $arr) |
|
| 35 | - { |
|
| 36 | - $this->route = $route; |
|
| 37 | - $this->auth = $auth; |
|
| 38 | - $this->errorHandler = $errorHandler; |
|
| 39 | - $this->authMiddleware = $authMiddleware; |
|
| 40 | - $this->core = $core; |
|
| 41 | - $this->arr = $arr; |
|
| 42 | - } |
|
| 22 | + /** |
|
| 23 | + * Init new object. |
|
| 24 | + * |
|
| 25 | + * @param Route $route |
|
| 26 | + * @param Auth $auth |
|
| 27 | + * @param ErrorHandler $errorHandler |
|
| 28 | + * @param AuthMiddleware $authMiddleware |
|
| 29 | + * @param Core $core |
|
| 30 | + * @param Arr $arr |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public function __construct(Route $route, Auth $auth, ErrorHandler $errorHandler, AuthMiddleware $authMiddleware, Core $core, Arr $arr) |
|
| 35 | + { |
|
| 36 | + $this->route = $route; |
|
| 37 | + $this->auth = $auth; |
|
| 38 | + $this->errorHandler = $errorHandler; |
|
| 39 | + $this->authMiddleware = $authMiddleware; |
|
| 40 | + $this->core = $core; |
|
| 41 | + $this->arr = $arr; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Handle an incoming request. |
|
| 46 | - * |
|
| 47 | - * @param \Illuminate\Http\Request $request |
|
| 48 | - * @param \Closure $next |
|
| 49 | - * @return mixed |
|
| 50 | - */ |
|
| 51 | - public function handle($request, Closure $next) |
|
| 52 | - { |
|
| 53 | - $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 54 | - $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 55 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 56 | - $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 57 | - $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 58 | - $modelName = explode('\\', $routeActions[0]); |
|
| 59 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 60 | - $permission = $routeActions[1]; |
|
| 44 | + /** |
|
| 45 | + * Handle an incoming request. |
|
| 46 | + * |
|
| 47 | + * @param \Illuminate\Http\Request $request |
|
| 48 | + * @param \Closure $next |
|
| 49 | + * @return mixed |
|
| 50 | + */ |
|
| 51 | + public function handle($request, Closure $next) |
|
| 52 | + { |
|
| 53 | + $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 54 | + $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 55 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 56 | + $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 57 | + $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 58 | + $modelName = explode('\\', $routeActions[0]); |
|
| 59 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 60 | + $permission = $routeActions[1]; |
|
| 61 | 61 | |
| 62 | - $this->auth->shouldUse('api'); |
|
| 63 | - if (! in_array($permission, $skipLoginCheck)) { |
|
| 64 | - $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 65 | - $user = $this->auth->user(); |
|
| 66 | - $isPasswordClient = $user->token()->client->password_client; |
|
| 62 | + $this->auth->shouldUse('api'); |
|
| 63 | + if (! in_array($permission, $skipLoginCheck)) { |
|
| 64 | + $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $skipLoginCheck, $permission) { |
|
| 65 | + $user = $this->auth->user(); |
|
| 66 | + $isPasswordClient = $user->token()->client->password_client; |
|
| 67 | 67 | |
| 68 | - if ($user->blocked) { |
|
| 69 | - $this->errorHandler->userIsBlocked(); |
|
| 70 | - } |
|
| 68 | + if ($user->blocked) { |
|
| 69 | + $this->errorHandler->userIsBlocked(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->core->users()->can($permission, $modelName))) { |
|
| 73 | - } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 74 | - } else { |
|
| 75 | - $this->errorHandler->noPermissions(); |
|
| 76 | - } |
|
| 77 | - }); |
|
| 78 | - } |
|
| 72 | + if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->core->users()->can($permission, $modelName))) { |
|
| 73 | + } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 74 | + } else { |
|
| 75 | + $this->errorHandler->noPermissions(); |
|
| 76 | + } |
|
| 77 | + }); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return $next($request); |
|
| 80 | + return $next($request); |
|
| 81 | 81 | |
| 82 | - //$this->middleware('auth:api', ['except' => $skipLoginCheck]); |
|
| 83 | - } |
|
| 82 | + //$this->middleware('auth:api', ['except' => $skipLoginCheck]); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -9,43 +9,43 @@ |
||
| 9 | 9 | |
| 10 | 10 | class SetRelations |
| 11 | 11 | { |
| 12 | - protected $arr; |
|
| 13 | - protected $route; |
|
| 14 | - protected $config; |
|
| 12 | + protected $arr; |
|
| 13 | + protected $route; |
|
| 14 | + protected $config; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Init new object. |
|
| 18 | - * |
|
| 19 | - * @param Route $route |
|
| 20 | - * @param Arr $arr |
|
| 21 | - * @param Config $config |
|
| 22 | - * |
|
| 23 | - * @return void |
|
| 24 | - */ |
|
| 25 | - public function __construct(Route $route, Arr $arr, Config $config) |
|
| 26 | - { |
|
| 27 | - $this->arr = $arr; |
|
| 28 | - $this->route = $route; |
|
| 29 | - $this->config = $config->getConfig(); |
|
| 30 | - } |
|
| 16 | + /** |
|
| 17 | + * Init new object. |
|
| 18 | + * |
|
| 19 | + * @param Route $route |
|
| 20 | + * @param Arr $arr |
|
| 21 | + * @param Config $config |
|
| 22 | + * |
|
| 23 | + * @return void |
|
| 24 | + */ |
|
| 25 | + public function __construct(Route $route, Arr $arr, Config $config) |
|
| 26 | + { |
|
| 27 | + $this->arr = $arr; |
|
| 28 | + $this->route = $route; |
|
| 29 | + $this->config = $config->getConfig(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Handle an incoming request. |
|
| 34 | - * |
|
| 35 | - * @param \Illuminate\Http\Request $request |
|
| 36 | - * @param \Closure $next |
|
| 37 | - * @return mixed |
|
| 38 | - */ |
|
| 39 | - public function handle($request, Closure $next) |
|
| 40 | - { |
|
| 41 | - $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 42 | - $modelName = explode('\\', $routeActions[0]); |
|
| 43 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 44 | - $route = explode('@', $this->route->currentRouteAction())[1]; |
|
| 45 | - $route = $route !== 'index' ? $route : 'list'; |
|
| 46 | - $relations = $this->arr->get($this->config['relations'], $modelName, false); |
|
| 47 | - $request->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
| 32 | + /** |
|
| 33 | + * Handle an incoming request. |
|
| 34 | + * |
|
| 35 | + * @param \Illuminate\Http\Request $request |
|
| 36 | + * @param \Closure $next |
|
| 37 | + * @return mixed |
|
| 38 | + */ |
|
| 39 | + public function handle($request, Closure $next) |
|
| 40 | + { |
|
| 41 | + $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 42 | + $modelName = explode('\\', $routeActions[0]); |
|
| 43 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 44 | + $route = explode('@', $this->route->currentRouteAction())[1]; |
|
| 45 | + $route = $route !== 'index' ? $route : 'list'; |
|
| 46 | + $relations = $this->arr->get($this->config['relations'], $modelName, false); |
|
| 47 | + $request->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
| 48 | 48 | |
| 49 | - return $next($request); |
|
| 50 | - } |
|
| 49 | + return $next($request); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -9,93 +9,93 @@ |
||
| 9 | 9 | |
| 10 | 10 | class BaseApiController extends Controller |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * The relations implementation. |
|
| 14 | - * |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - protected $relations; |
|
| 12 | + /** |
|
| 13 | + * The relations implementation. |
|
| 14 | + * |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + protected $relations; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The repo implementation. |
|
| 21 | - * |
|
| 22 | - * @var object |
|
| 23 | - */ |
|
| 24 | - protected $repo; |
|
| 19 | + /** |
|
| 20 | + * The repo implementation. |
|
| 21 | + * |
|
| 22 | + * @var object |
|
| 23 | + */ |
|
| 24 | + protected $repo; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * The modelResource implementation. |
|
| 28 | - * |
|
| 29 | - * @var object |
|
| 30 | - */ |
|
| 31 | - protected $modelResource; |
|
| 26 | + /** |
|
| 27 | + * The modelResource implementation. |
|
| 28 | + * |
|
| 29 | + * @var object |
|
| 30 | + */ |
|
| 31 | + protected $modelResource; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Init new object. |
|
| 35 | - * |
|
| 36 | - * @param mixed $repo |
|
| 37 | - * @param string $modelResource |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function __construct($repo, $modelResource) |
|
| 41 | - { |
|
| 42 | - $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 43 | - $this->modelResource = $modelResource; |
|
| 44 | - } |
|
| 33 | + /** |
|
| 34 | + * Init new object. |
|
| 35 | + * |
|
| 36 | + * @param mixed $repo |
|
| 37 | + * @param string $modelResource |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function __construct($repo, $modelResource) |
|
| 41 | + { |
|
| 42 | + $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 43 | + $this->modelResource = $modelResource; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Fetch all records with relations from storage. |
|
| 48 | - * |
|
| 49 | - * @param Request $request |
|
| 50 | - * @return \Illuminate\Http\Response |
|
| 51 | - */ |
|
| 52 | - public function index(Request $request) |
|
| 53 | - { |
|
| 54 | - return $this->modelResource::collection($this->repo->list($request->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Fetch all records with relations from storage. |
|
| 48 | + * |
|
| 49 | + * @param Request $request |
|
| 50 | + * @return \Illuminate\Http\Response |
|
| 51 | + */ |
|
| 52 | + public function index(Request $request) |
|
| 53 | + { |
|
| 54 | + return $this->modelResource::collection($this->repo->list($request->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Fetch the single object with relations from storage. |
|
| 59 | - * |
|
| 60 | - * @param Request $request |
|
| 61 | - * @param integer $id Id of the requested model. |
|
| 62 | - * @return \Illuminate\Http\Response |
|
| 63 | - */ |
|
| 64 | - public function find(Request $request, $id) |
|
| 65 | - { |
|
| 66 | - return new $this->modelResource($this->repo->find($id, $request->relations)); |
|
| 67 | - } |
|
| 57 | + /** |
|
| 58 | + * Fetch the single object with relations from storage. |
|
| 59 | + * |
|
| 60 | + * @param Request $request |
|
| 61 | + * @param integer $id Id of the requested model. |
|
| 62 | + * @return \Illuminate\Http\Response |
|
| 63 | + */ |
|
| 64 | + public function find(Request $request, $id) |
|
| 65 | + { |
|
| 66 | + return new $this->modelResource($this->repo->find($id, $request->relations)); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Delete by the given id from storage. |
|
| 71 | - * |
|
| 72 | - * @param integer $id Id of the deleted model. |
|
| 73 | - * @return \Illuminate\Http\Response |
|
| 74 | - */ |
|
| 75 | - public function delete($id) |
|
| 76 | - { |
|
| 77 | - return new GeneralResource($this->repo->delete($id)); |
|
| 78 | - } |
|
| 69 | + /** |
|
| 70 | + * Delete by the given id from storage. |
|
| 71 | + * |
|
| 72 | + * @param integer $id Id of the deleted model. |
|
| 73 | + * @return \Illuminate\Http\Response |
|
| 74 | + */ |
|
| 75 | + public function delete($id) |
|
| 76 | + { |
|
| 77 | + return new GeneralResource($this->repo->delete($id)); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Return the deleted models in pages based on the given conditions. |
|
| 82 | - * |
|
| 83 | - * @param Request $request |
|
| 84 | - * @return \Illuminate\Http\Response |
|
| 85 | - */ |
|
| 86 | - public function deleted(Request $request) |
|
| 87 | - { |
|
| 88 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 89 | - } |
|
| 80 | + /** |
|
| 81 | + * Return the deleted models in pages based on the given conditions. |
|
| 82 | + * |
|
| 83 | + * @param Request $request |
|
| 84 | + * @return \Illuminate\Http\Response |
|
| 85 | + */ |
|
| 86 | + public function deleted(Request $request) |
|
| 87 | + { |
|
| 88 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Restore the deleted model. |
|
| 93 | - * |
|
| 94 | - * @param integer $id Id of the restored model. |
|
| 95 | - * @return \Illuminate\Http\Response |
|
| 96 | - */ |
|
| 97 | - public function restore($id) |
|
| 98 | - { |
|
| 99 | - return new GeneralResource($this->repo->restore($id)); |
|
| 100 | - } |
|
| 91 | + /** |
|
| 92 | + * Restore the deleted model. |
|
| 93 | + * |
|
| 94 | + * @param integer $id Id of the restored model. |
|
| 95 | + * @return \Illuminate\Http\Response |
|
| 96 | + */ |
|
| 97 | + public function restore($id) |
|
| 98 | + { |
|
| 99 | + return new GeneralResource($this->repo->restore($id)); |
|
| 100 | + } |
|
| 101 | 101 | } |