@@ -13,11 +13,11 @@ |
||
13 | 13 | |
14 | 14 | Route::group(['prefix' => 'settings'], function () { |
15 | 15 | |
16 | - Route::get('/', 'SettingController@index'); |
|
17 | - Route::get('/{id}', 'SettingController@find'); |
|
18 | - Route::put('/', 'SettingController@update'); |
|
19 | - Route::delete('/{id}', 'SettingController@delete'); |
|
20 | - Route::get('list/deleted', 'SettingController@deleted'); |
|
21 | - Route::patch('restore/{id}', 'SettingController@restore'); |
|
22 | - Route::post('save/many', 'SettingController@saveMany'); |
|
16 | + Route::get('/', 'SettingController@index'); |
|
17 | + Route::get('/{id}', 'SettingController@find'); |
|
18 | + Route::put('/', 'SettingController@update'); |
|
19 | + Route::delete('/{id}', 'SettingController@delete'); |
|
20 | + Route::get('list/deleted', 'SettingController@deleted'); |
|
21 | + Route::patch('restore/{id}', 'SettingController@restore'); |
|
22 | + Route::post('save/many', 'SettingController@saveMany'); |
|
23 | 23 | }); |
24 | 24 | \ No newline at end of file |
@@ -6,53 +6,53 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | - |
|
19 | - $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - //Bind Core Facade to the Service Container |
|
31 | - $this->app->singleton('Core', function () { |
|
32 | - return new \App\Modules\Core\Core; |
|
33 | - }); |
|
34 | - |
|
35 | - //Bind ErrorHandler Facade to the Service Container |
|
36 | - $this->app->singleton('ErrorHandler', function () { |
|
37 | - return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | - }); |
|
39 | - |
|
40 | - //Bind CoreConfig Facade to the Service Container |
|
41 | - $this->app->singleton('CoreConfig', function () { |
|
42 | - return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | - }); |
|
44 | - |
|
45 | - //Bind Media Facade to the Service Container |
|
46 | - $this->app->singleton('Media', function () { |
|
47 | - return new \App\Modules\Core\Utl\Media; |
|
48 | - }); |
|
49 | - |
|
50 | - //Bind ApiConsumer Facade to the Service Container |
|
51 | - $this->app->singleton('ApiConsumer', function () { |
|
52 | - $app = app(); |
|
53 | - return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | - }); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | + |
|
19 | + $this->loadMigrationsFrom(module_path('core', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('core', 'Database/Factories', 'app')); |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + //Bind Core Facade to the Service Container |
|
31 | + $this->app->singleton('Core', function () { |
|
32 | + return new \App\Modules\Core\Core; |
|
33 | + }); |
|
34 | + |
|
35 | + //Bind ErrorHandler Facade to the Service Container |
|
36 | + $this->app->singleton('ErrorHandler', function () { |
|
37 | + return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | + }); |
|
39 | + |
|
40 | + //Bind CoreConfig Facade to the Service Container |
|
41 | + $this->app->singleton('CoreConfig', function () { |
|
42 | + return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | + }); |
|
44 | + |
|
45 | + //Bind Media Facade to the Service Container |
|
46 | + $this->app->singleton('Media', function () { |
|
47 | + return new \App\Modules\Core\Utl\Media; |
|
48 | + }); |
|
49 | + |
|
50 | + //Bind ApiConsumer Facade to the Service Container |
|
51 | + $this->app->singleton('ApiConsumer', function () { |
|
52 | + $app = app(); |
|
53 | + return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | + }); |
|
55 | 55 | |
56 | - $this->app->register(RouteServiceProvider::class); |
|
57 | - } |
|
56 | + $this->app->register(RouteServiceProvider::class); |
|
57 | + } |
|
58 | 58 | } |
@@ -5,116 +5,116 @@ |
||
5 | 5 | |
6 | 6 | class CachingDecorator |
7 | 7 | { |
8 | - /** |
|
9 | - * The repo implementation. |
|
10 | - * |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - public $repo; |
|
8 | + /** |
|
9 | + * The repo implementation. |
|
10 | + * |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + public $repo; |
|
14 | 14 | |
15 | - /** |
|
16 | - * The cache implementation. |
|
17 | - * |
|
18 | - * @var object |
|
19 | - */ |
|
20 | - protected $cache; |
|
15 | + /** |
|
16 | + * The cache implementation. |
|
17 | + * |
|
18 | + * @var object |
|
19 | + */ |
|
20 | + protected $cache; |
|
21 | 21 | |
22 | - /** |
|
23 | - * The modelKey implementation. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $modelKey; |
|
22 | + /** |
|
23 | + * The modelKey implementation. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $modelKey; |
|
28 | 28 | |
29 | - /** |
|
30 | - * The model implementation. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - public $model; |
|
29 | + /** |
|
30 | + * The model implementation. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + public $model; |
|
35 | 35 | |
36 | - /** |
|
37 | - * The modelClass implementation. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $modelClass; |
|
36 | + /** |
|
37 | + * The modelClass implementation. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $modelClass; |
|
42 | 42 | |
43 | - /** |
|
44 | - * The cacheConfig implementation. |
|
45 | - * |
|
46 | - * @var mixed |
|
47 | - */ |
|
48 | - public $cacheConfig; |
|
43 | + /** |
|
44 | + * The cacheConfig implementation. |
|
45 | + * |
|
46 | + * @var mixed |
|
47 | + */ |
|
48 | + public $cacheConfig; |
|
49 | 49 | |
50 | - /** |
|
51 | - * The cacheTag implementation. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $cacheTag; |
|
50 | + /** |
|
51 | + * The cacheTag implementation. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $cacheTag; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Init new object. |
|
59 | - * |
|
60 | - * @param string $repo |
|
61 | - * @param Cache $cache |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function __construct($repo, Cache $cache) |
|
66 | - { |
|
67 | - $this->repo = $repo; |
|
68 | - $this->cache = $cache; |
|
69 | - $this->model = $this->repo->model; |
|
70 | - $this->modelClass = get_class($this->model); |
|
71 | - $repoClass = explode('\\', get_class($this->repo)); |
|
72 | - $repoName = end($repoClass); |
|
73 | - $this->cacheTag = lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))); |
|
74 | - } |
|
57 | + /** |
|
58 | + * Init new object. |
|
59 | + * |
|
60 | + * @param string $repo |
|
61 | + * @param Cache $cache |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function __construct($repo, Cache $cache) |
|
66 | + { |
|
67 | + $this->repo = $repo; |
|
68 | + $this->cache = $cache; |
|
69 | + $this->model = $this->repo->model; |
|
70 | + $this->modelClass = get_class($this->model); |
|
71 | + $repoClass = explode('\\', get_class($this->repo)); |
|
72 | + $repoName = end($repoClass); |
|
73 | + $this->cacheTag = lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Handle the cache mechanism for the called method |
|
78 | - * based the configurations. |
|
79 | - * |
|
80 | - * @param string $name the called method name |
|
81 | - * @param array $arguments the method arguments |
|
82 | - * @return object |
|
83 | - */ |
|
84 | - public function __call($name, $arguments) |
|
85 | - { |
|
86 | - $this->setCacheConfig($name); |
|
76 | + /** |
|
77 | + * Handle the cache mechanism for the called method |
|
78 | + * based the configurations. |
|
79 | + * |
|
80 | + * @param string $name the called method name |
|
81 | + * @param array $arguments the method arguments |
|
82 | + * @return object |
|
83 | + */ |
|
84 | + public function __call($name, $arguments) |
|
85 | + { |
|
86 | + $this->setCacheConfig($name); |
|
87 | 87 | |
88 | - if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
89 | - $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
90 | - $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
91 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
92 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
93 | - }); |
|
94 | - } elseif ($this->cacheConfig) { |
|
95 | - $this->cache->tags($this->cacheConfig)->flush(); |
|
96 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
97 | - } |
|
88 | + if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
89 | + $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
90 | + $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
91 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
92 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
93 | + }); |
|
94 | + } elseif ($this->cacheConfig) { |
|
95 | + $this->cache->tags($this->cacheConfig)->flush(); |
|
96 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
97 | + } |
|
98 | 98 | |
99 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
100 | - } |
|
99 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Set cache config based on the called method. |
|
104 | - * |
|
105 | - * @param string $name |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - private function setCacheConfig($name) |
|
109 | - { |
|
110 | - $config = \CoreConfig::getConfig(); |
|
111 | - $cacheConfig = Arr::get($config['cacheConfig'], $this->cacheTag, false); |
|
112 | - $this->cacheConfig = false; |
|
102 | + /** |
|
103 | + * Set cache config based on the called method. |
|
104 | + * |
|
105 | + * @param string $name |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + private function setCacheConfig($name) |
|
109 | + { |
|
110 | + $config = \CoreConfig::getConfig(); |
|
111 | + $cacheConfig = Arr::get($config['cacheConfig'], $this->cacheTag, false); |
|
112 | + $this->cacheConfig = false; |
|
113 | 113 | |
114 | - if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
115 | - $this->cacheConfig = 'cache'; |
|
116 | - } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
117 | - $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
118 | - } |
|
119 | - } |
|
114 | + if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
115 | + $this->cacheConfig = 'cache'; |
|
116 | + } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
117 | + $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
118 | + } |
|
119 | + } |
|
120 | 120 | } |
@@ -10,204 +10,204 @@ |
||
10 | 10 | |
11 | 11 | class BaseApiController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * The config implementation. |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $config; |
|
19 | - |
|
20 | - /** |
|
21 | - * The relations implementation. |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $relations; |
|
26 | - |
|
27 | - /** |
|
28 | - * The repo implementation. |
|
29 | - * |
|
30 | - * @var object |
|
31 | - */ |
|
32 | - protected $repo; |
|
33 | - |
|
34 | - /** |
|
35 | - * Init new object. |
|
36 | - * |
|
37 | - * @param mixed $repo |
|
38 | - * @param CoreConfig $config |
|
39 | - * @param string $modelResource |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function __construct($repo, $config, $modelResource) |
|
43 | - { |
|
44 | - $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | - $this->modelResource = $modelResource; |
|
46 | - $this->config = $config->getConfig(); |
|
47 | - $this->modelName = explode('\\', get_called_class()); |
|
48 | - $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | - $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | - |
|
54 | - $this->setSessions(); |
|
55 | - $this->checkPermission($route); |
|
56 | - $this->setRelations($route); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Fetch all records with relations from storage. |
|
61 | - * |
|
62 | - * @param Request $request |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function index(Request $request) |
|
66 | - { |
|
67 | - return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Fetch the single object with relations from storage. |
|
72 | - * |
|
73 | - * @param integer $id Id of the requested model. |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function find($id) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Delete by the given id from storage. |
|
83 | - * |
|
84 | - * @param integer $id Id of the deleted model. |
|
85 | - * @return \Illuminate\Http\Response |
|
86 | - */ |
|
87 | - public function delete($id) |
|
88 | - { |
|
89 | - return new GeneralResource($this->repo->delete($id)); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Return the deleted models in pages based on the given conditions. |
|
94 | - * |
|
95 | - * @param Request $request |
|
96 | - * @return \Illuminate\Http\Response |
|
97 | - */ |
|
98 | - public function deleted(Request $request) |
|
99 | - { |
|
100 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Restore the deleted model. |
|
105 | - * |
|
106 | - * @param integer $id Id of the restored model. |
|
107 | - * @return \Illuminate\Http\Response |
|
108 | - */ |
|
109 | - public function restore($id) |
|
110 | - { |
|
111 | - return new GeneralResource($this->repo->restore($id)); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Check if the logged in user can do the given permission. |
|
116 | - * |
|
117 | - * @param string $permission |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - private function checkPermission($permission) |
|
121 | - { |
|
122 | - \Auth::shouldUse('api'); |
|
123 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
13 | + /** |
|
14 | + * The config implementation. |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $config; |
|
19 | + |
|
20 | + /** |
|
21 | + * The relations implementation. |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $relations; |
|
26 | + |
|
27 | + /** |
|
28 | + * The repo implementation. |
|
29 | + * |
|
30 | + * @var object |
|
31 | + */ |
|
32 | + protected $repo; |
|
33 | + |
|
34 | + /** |
|
35 | + * Init new object. |
|
36 | + * |
|
37 | + * @param mixed $repo |
|
38 | + * @param CoreConfig $config |
|
39 | + * @param string $modelResource |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function __construct($repo, $config, $modelResource) |
|
43 | + { |
|
44 | + $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | + $this->modelResource = $modelResource; |
|
46 | + $this->config = $config->getConfig(); |
|
47 | + $this->modelName = explode('\\', get_called_class()); |
|
48 | + $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | + |
|
54 | + $this->setSessions(); |
|
55 | + $this->checkPermission($route); |
|
56 | + $this->setRelations($route); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Fetch all records with relations from storage. |
|
61 | + * |
|
62 | + * @param Request $request |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function index(Request $request) |
|
66 | + { |
|
67 | + return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Fetch the single object with relations from storage. |
|
72 | + * |
|
73 | + * @param integer $id Id of the requested model. |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function find($id) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Delete by the given id from storage. |
|
83 | + * |
|
84 | + * @param integer $id Id of the deleted model. |
|
85 | + * @return \Illuminate\Http\Response |
|
86 | + */ |
|
87 | + public function delete($id) |
|
88 | + { |
|
89 | + return new GeneralResource($this->repo->delete($id)); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Return the deleted models in pages based on the given conditions. |
|
94 | + * |
|
95 | + * @param Request $request |
|
96 | + * @return \Illuminate\Http\Response |
|
97 | + */ |
|
98 | + public function deleted(Request $request) |
|
99 | + { |
|
100 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Restore the deleted model. |
|
105 | + * |
|
106 | + * @param integer $id Id of the restored model. |
|
107 | + * @return \Illuminate\Http\Response |
|
108 | + */ |
|
109 | + public function restore($id) |
|
110 | + { |
|
111 | + return new GeneralResource($this->repo->restore($id)); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Check if the logged in user can do the given permission. |
|
116 | + * |
|
117 | + * @param string $permission |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + private function checkPermission($permission) |
|
121 | + { |
|
122 | + \Auth::shouldUse('api'); |
|
123 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
124 | 124 | |
125 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | - $user = \Auth::user(); |
|
127 | - $isPasswordClient = $user->token()->client->password_client; |
|
128 | - $this->updateLocaleAndTimezone($user); |
|
129 | - |
|
130 | - if ($user->blocked) { |
|
131 | - \ErrorHandler::userIsBlocked(); |
|
132 | - } |
|
133 | - |
|
134 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | - } else { |
|
137 | - \ErrorHandler::noPermissions(); |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Set sessions based on the given headers in the request. |
|
144 | - * |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - private function setSessions() |
|
148 | - { |
|
149 | - \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | - |
|
151 | - $locale = \Request::header('locale'); |
|
152 | - switch ($locale) { |
|
153 | - case 'en': |
|
154 | - \App::setLocale('en'); |
|
155 | - \Session::put('locale', 'en'); |
|
156 | - break; |
|
157 | - |
|
158 | - case 'ar': |
|
159 | - \App::setLocale('ar'); |
|
160 | - \Session::put('locale', 'ar'); |
|
161 | - break; |
|
162 | - |
|
163 | - case 'all': |
|
164 | - \App::setLocale('en'); |
|
165 | - \Session::put('locale', 'all'); |
|
166 | - break; |
|
167 | - |
|
168 | - default: |
|
169 | - \App::setLocale('en'); |
|
170 | - \Session::put('locale', 'en'); |
|
171 | - break; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Set relation based on the called api. |
|
177 | - * |
|
178 | - * @param string $route |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function setRelations($route) |
|
182 | - { |
|
183 | - $route = $route !== 'index' ? $route : 'list'; |
|
184 | - $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Update the logged in user locale and time zone. |
|
190 | - * |
|
191 | - * @param object $user |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - private function updateLocaleAndTimezone($user) |
|
195 | - { |
|
196 | - $update = false; |
|
197 | - $locale = \Session::get('locale'); |
|
198 | - $timezone = \Session::get('time-zone'); |
|
199 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | - $user->locale = $locale; |
|
201 | - $update = true; |
|
202 | - } |
|
203 | - |
|
204 | - if ($timezone && $timezone !== $user->timezone) { |
|
205 | - $user->timezone = $timezone; |
|
206 | - $update = true; |
|
207 | - } |
|
208 | - |
|
209 | - if ($update) { |
|
210 | - $user->save(); |
|
211 | - } |
|
212 | - } |
|
125 | + if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | + $user = \Auth::user(); |
|
127 | + $isPasswordClient = $user->token()->client->password_client; |
|
128 | + $this->updateLocaleAndTimezone($user); |
|
129 | + |
|
130 | + if ($user->blocked) { |
|
131 | + \ErrorHandler::userIsBlocked(); |
|
132 | + } |
|
133 | + |
|
134 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | + } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | + } else { |
|
137 | + \ErrorHandler::noPermissions(); |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Set sessions based on the given headers in the request. |
|
144 | + * |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + private function setSessions() |
|
148 | + { |
|
149 | + \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | + |
|
151 | + $locale = \Request::header('locale'); |
|
152 | + switch ($locale) { |
|
153 | + case 'en': |
|
154 | + \App::setLocale('en'); |
|
155 | + \Session::put('locale', 'en'); |
|
156 | + break; |
|
157 | + |
|
158 | + case 'ar': |
|
159 | + \App::setLocale('ar'); |
|
160 | + \Session::put('locale', 'ar'); |
|
161 | + break; |
|
162 | + |
|
163 | + case 'all': |
|
164 | + \App::setLocale('en'); |
|
165 | + \Session::put('locale', 'all'); |
|
166 | + break; |
|
167 | + |
|
168 | + default: |
|
169 | + \App::setLocale('en'); |
|
170 | + \Session::put('locale', 'en'); |
|
171 | + break; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Set relation based on the called api. |
|
177 | + * |
|
178 | + * @param string $route |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function setRelations($route) |
|
182 | + { |
|
183 | + $route = $route !== 'index' ? $route : 'list'; |
|
184 | + $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Update the logged in user locale and time zone. |
|
190 | + * |
|
191 | + * @param object $user |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + private function updateLocaleAndTimezone($user) |
|
195 | + { |
|
196 | + $update = false; |
|
197 | + $locale = \Session::get('locale'); |
|
198 | + $timezone = \Session::get('time-zone'); |
|
199 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | + $user->locale = $locale; |
|
201 | + $update = true; |
|
202 | + } |
|
203 | + |
|
204 | + if ($timezone && $timezone !== $user->timezone) { |
|
205 | + $user->timezone = $timezone; |
|
206 | + $update = true; |
|
207 | + } |
|
208 | + |
|
209 | + if ($update) { |
|
210 | + $user->save(); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | } |
@@ -6,32 +6,32 @@ |
||
6 | 6 | |
7 | 7 | class Setting extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Indicates if the resource's collection keys should be preserved. |
|
11 | - * |
|
12 | - * @var bool |
|
13 | - */ |
|
14 | - public $preserveKeys = true; |
|
9 | + /** |
|
10 | + * Indicates if the resource's collection keys should be preserved. |
|
11 | + * |
|
12 | + * @var bool |
|
13 | + */ |
|
14 | + public $preserveKeys = true; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Transform the resource into an array. |
|
18 | - * |
|
19 | - * @param Request $request |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function toArray($request) |
|
23 | - { |
|
24 | - if (! $this->resource) { |
|
25 | - return []; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Transform the resource into an array. |
|
18 | + * |
|
19 | + * @param Request $request |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function toArray($request) |
|
23 | + { |
|
24 | + if (! $this->resource) { |
|
25 | + return []; |
|
26 | + } |
|
27 | 27 | |
28 | - return [ |
|
29 | - 'id' => $this->id, |
|
30 | - 'name' => $this->name, |
|
31 | - 'value' => $this->value, |
|
32 | - 'key' => $this->key, |
|
33 | - 'created_at' => $this->created_at, |
|
34 | - 'updated_at' => $this->updated_at, |
|
35 | - ]; |
|
36 | - } |
|
28 | + return [ |
|
29 | + 'id' => $this->id, |
|
30 | + 'name' => $this->name, |
|
31 | + 'value' => $this->value, |
|
32 | + 'key' => $this->key, |
|
33 | + 'created_at' => $this->created_at, |
|
34 | + 'updated_at' => $this->updated_at, |
|
35 | + ]; |
|
36 | + } |
|
37 | 37 | } |
@@ -13,12 +13,12 @@ |
||
13 | 13 | |
14 | 14 | Route::group(['prefix' => 'reports'], function () { |
15 | 15 | |
16 | - Route::get('/', 'ReportController@index'); |
|
17 | - Route::get('/{id}', 'ReportController@find'); |
|
18 | - Route::post('/', 'ReportController@insert'); |
|
19 | - Route::put('/', 'ReportController@update'); |
|
20 | - Route::delete('/{id}', 'ReportController@delete'); |
|
21 | - Route::get('list/deleted', 'ReportController@deleted'); |
|
22 | - Route::patch('restore/{id}', 'ReportController@restore'); |
|
23 | - Route::post('get/{reportName}', 'ReportController@getReport'); |
|
16 | + Route::get('/', 'ReportController@index'); |
|
17 | + Route::get('/{id}', 'ReportController@find'); |
|
18 | + Route::post('/', 'ReportController@insert'); |
|
19 | + Route::put('/', 'ReportController@update'); |
|
20 | + Route::delete('/{id}', 'ReportController@delete'); |
|
21 | + Route::get('list/deleted', 'ReportController@deleted'); |
|
22 | + Route::patch('restore/{id}', 'ReportController@restore'); |
|
23 | + Route::post('get/{reportName}', 'ReportController@getReport'); |
|
24 | 24 | }); |
25 | 25 | \ No newline at end of file |
@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'reporting'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'reporting'); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'reporting'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'reporting'); |
|
18 | 18 | |
19 | - $this->loadMigrationsFrom(module_path('reporting', 'Database/Migrations', 'app')); |
|
20 | - $this->loadFactoriesFrom(module_path('reporting', 'Database/Factories', 'app')); |
|
21 | - } |
|
19 | + $this->loadMigrationsFrom(module_path('reporting', 'Database/Migrations', 'app')); |
|
20 | + $this->loadFactoriesFrom(module_path('reporting', 'Database/Factories', 'app')); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - $this->app->register(RouteServiceProvider::class); |
|
31 | - } |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + $this->app->register(RouteServiceProvider::class); |
|
31 | + } |
|
32 | 32 | } |
@@ -6,24 +6,24 @@ |
||
6 | 6 | |
7 | 7 | class Report extends JsonResource |
8 | 8 | { |
9 | - /** |
|
10 | - * Transform the resource into an array. |
|
11 | - * |
|
12 | - * @param Request $request |
|
13 | - * @return array |
|
14 | - */ |
|
15 | - public function toArray($request) |
|
16 | - { |
|
17 | - if (! $this->resource) { |
|
18 | - return []; |
|
19 | - } |
|
9 | + /** |
|
10 | + * Transform the resource into an array. |
|
11 | + * |
|
12 | + * @param Request $request |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function toArray($request) |
|
16 | + { |
|
17 | + if (! $this->resource) { |
|
18 | + return []; |
|
19 | + } |
|
20 | 20 | |
21 | - return [ |
|
22 | - 'id' => $this->id, |
|
23 | - 'report_name' => $this->report_name, |
|
24 | - 'view_name' => $this->view_name, |
|
25 | - 'created_at' => $this->created_at, |
|
26 | - 'updated_at' => $this->updated_at, |
|
27 | - ]; |
|
28 | - } |
|
21 | + return [ |
|
22 | + 'id' => $this->id, |
|
23 | + 'report_name' => $this->report_name, |
|
24 | + 'view_name' => $this->view_name, |
|
25 | + 'created_at' => $this->created_at, |
|
26 | + 'updated_at' => $this->updated_at, |
|
27 | + ]; |
|
28 | + } |
|
29 | 29 | } |
@@ -5,32 +5,32 @@ |
||
5 | 5 | |
6 | 6 | class GroupRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param AclGroup $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(AclGroup $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param AclGroup $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(AclGroup $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Assign the given permission ids to the given group. |
|
21 | - * |
|
22 | - * @param integer $groupId |
|
23 | - * @param array $permissionIds |
|
24 | - * @return object |
|
25 | - */ |
|
26 | - public function assignPermissions($groupId, $permissionIds) |
|
27 | - { |
|
28 | - \DB::transaction(function () use ($groupId, $permissionIds) { |
|
29 | - $group = $this->find($groupId); |
|
30 | - $group->permissions()->detach(); |
|
31 | - $group->permissions()->attach($permissionIds); |
|
32 | - }); |
|
19 | + /** |
|
20 | + * Assign the given permission ids to the given group. |
|
21 | + * |
|
22 | + * @param integer $groupId |
|
23 | + * @param array $permissionIds |
|
24 | + * @return object |
|
25 | + */ |
|
26 | + public function assignPermissions($groupId, $permissionIds) |
|
27 | + { |
|
28 | + \DB::transaction(function () use ($groupId, $permissionIds) { |
|
29 | + $group = $this->find($groupId); |
|
30 | + $group->permissions()->detach(); |
|
31 | + $group->permissions()->attach($permissionIds); |
|
32 | + }); |
|
33 | 33 | |
34 | - return $this->find($groupId); |
|
35 | - } |
|
34 | + return $this->find($groupId); |
|
35 | + } |
|
36 | 36 | } |