@@ -5,54 +5,54 @@ |
||
5 | 5 | */ |
6 | 6 | class AclUserObserver { |
7 | 7 | |
8 | - public function saving($model) |
|
9 | - { |
|
10 | - // |
|
11 | - } |
|
12 | - |
|
13 | - public function saved($model) |
|
14 | - { |
|
15 | - // |
|
16 | - } |
|
17 | - |
|
18 | - public function creating($model) |
|
19 | - { |
|
20 | - // |
|
21 | - } |
|
22 | - |
|
23 | - public function created($model) |
|
24 | - { |
|
25 | - // |
|
26 | - } |
|
27 | - |
|
28 | - public function updating($model) |
|
29 | - { |
|
30 | - // |
|
31 | - } |
|
32 | - |
|
33 | - public function updated($model) |
|
34 | - { |
|
35 | - // |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Soft delete user logs. |
|
40 | - * |
|
41 | - * @param object $model the delted model. |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function deleting($model) |
|
45 | - { |
|
46 | - if ($model->getOriginal()['id'] == \JWTAuth::parseToken()->authenticate()->id) |
|
47 | - { |
|
48 | - \ErrorHandler::noPermissions(); |
|
49 | - } |
|
50 | - $model->logs()->delete(); |
|
51 | - } |
|
52 | - |
|
53 | - public function deleted($model) |
|
54 | - { |
|
55 | - // |
|
56 | - } |
|
8 | + public function saving($model) |
|
9 | + { |
|
10 | + // |
|
11 | + } |
|
12 | + |
|
13 | + public function saved($model) |
|
14 | + { |
|
15 | + // |
|
16 | + } |
|
17 | + |
|
18 | + public function creating($model) |
|
19 | + { |
|
20 | + // |
|
21 | + } |
|
22 | + |
|
23 | + public function created($model) |
|
24 | + { |
|
25 | + // |
|
26 | + } |
|
27 | + |
|
28 | + public function updating($model) |
|
29 | + { |
|
30 | + // |
|
31 | + } |
|
32 | + |
|
33 | + public function updated($model) |
|
34 | + { |
|
35 | + // |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Soft delete user logs. |
|
40 | + * |
|
41 | + * @param object $model the delted model. |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function deleting($model) |
|
45 | + { |
|
46 | + if ($model->getOriginal()['id'] == \JWTAuth::parseToken()->authenticate()->id) |
|
47 | + { |
|
48 | + \ErrorHandler::noPermissions(); |
|
49 | + } |
|
50 | + $model->logs()->delete(); |
|
51 | + } |
|
52 | + |
|
53 | + public function deleted($model) |
|
54 | + { |
|
55 | + // |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
59 | 59 | \ No newline at end of file |
@@ -5,42 +5,42 @@ |
||
5 | 5 | |
6 | 6 | class Log extends Model{ |
7 | 7 | |
8 | - use SoftDeletes; |
|
9 | - protected $table = 'logs'; |
|
10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | - protected $hidden = ['deleted_at', 'item_type']; |
|
12 | - protected $guarded = ['id']; |
|
13 | - protected $fillable = ['action', 'item_name', 'item_type', 'item_id', 'user_id']; |
|
14 | - public $searchable = ['action', 'item_name', 'item_type']; |
|
15 | - |
|
16 | - public function getCreatedAtAttribute($value) |
|
17 | - { |
|
18 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | - } |
|
20 | - |
|
21 | - public function getUpdatedAtAttribute($value) |
|
22 | - { |
|
23 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | - } |
|
25 | - |
|
26 | - public function getDeletedAtAttribute($value) |
|
27 | - { |
|
28 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | - } |
|
8 | + use SoftDeletes; |
|
9 | + protected $table = 'logs'; |
|
10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | + protected $hidden = ['deleted_at', 'item_type']; |
|
12 | + protected $guarded = ['id']; |
|
13 | + protected $fillable = ['action', 'item_name', 'item_type', 'item_id', 'user_id']; |
|
14 | + public $searchable = ['action', 'item_name', 'item_type']; |
|
15 | + |
|
16 | + public function getCreatedAtAttribute($value) |
|
17 | + { |
|
18 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | + } |
|
20 | + |
|
21 | + public function getUpdatedAtAttribute($value) |
|
22 | + { |
|
23 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | + } |
|
25 | + |
|
26 | + public function getDeletedAtAttribute($value) |
|
27 | + { |
|
28 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | + } |
|
30 | 30 | |
31 | - public function user() |
|
32 | - { |
|
33 | - return $this->belongsTo('App\Modules\V1\Acl\AclUser'); |
|
34 | - } |
|
35 | - |
|
36 | - public function item() |
|
37 | - { |
|
38 | - return $this->morphTo(); |
|
39 | - } |
|
40 | - |
|
41 | - public static function boot() |
|
42 | - { |
|
43 | - parent::boot(); |
|
44 | - parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\LogObserver')); |
|
45 | - } |
|
31 | + public function user() |
|
32 | + { |
|
33 | + return $this->belongsTo('App\Modules\V1\Acl\AclUser'); |
|
34 | + } |
|
35 | + |
|
36 | + public function item() |
|
37 | + { |
|
38 | + return $this->morphTo(); |
|
39 | + } |
|
40 | + |
|
41 | + public static function boot() |
|
42 | + { |
|
43 | + parent::boot(); |
|
44 | + parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\LogObserver')); |
|
45 | + } |
|
46 | 46 | } |
@@ -6,215 +6,215 @@ |
||
6 | 6 | |
7 | 7 | class BaseApiController extends Controller |
8 | 8 | { |
9 | - /** |
|
10 | - * The model implementation. |
|
11 | - * |
|
12 | - * @var model |
|
13 | - */ |
|
14 | - protected $model; |
|
15 | - |
|
16 | - /** |
|
17 | - * The config implementation. |
|
18 | - * |
|
19 | - * @var config |
|
20 | - */ |
|
21 | - protected $config; |
|
22 | - |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
9 | + /** |
|
10 | + * The model implementation. |
|
11 | + * |
|
12 | + * @var model |
|
13 | + */ |
|
14 | + protected $model; |
|
15 | + |
|
16 | + /** |
|
17 | + * The config implementation. |
|
18 | + * |
|
19 | + * @var config |
|
20 | + */ |
|
21 | + protected $config; |
|
22 | + |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
26 | 26 | |
27 | - $this->config = \CoreConfig::getConfig(); |
|
28 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
29 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
30 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
31 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
32 | - $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
33 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
34 | - $this->checkPermission($route); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Fetch all records with relations from model repository. |
|
39 | - * |
|
40 | - * @return \Illuminate\Http\Response |
|
41 | - */ |
|
42 | - public function index() |
|
43 | - { |
|
44 | - if ($this->model) |
|
45 | - { |
|
46 | - $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
47 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Fetch the single object with relations from model repository. |
|
53 | - * |
|
54 | - * @param integer $id |
|
55 | - * @return \Illuminate\Http\Response |
|
56 | - */ |
|
57 | - public function find($id) |
|
58 | - { |
|
59 | - if ($this->model) |
|
60 | - { |
|
61 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
62 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Paginate all records with relations from model repository |
|
68 | - * that matche the given query. |
|
69 | - * |
|
70 | - * @param string $query |
|
71 | - * @param integer $perPage |
|
72 | - * @param string $sortBy |
|
73 | - * @param boolean $desc |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
77 | - { |
|
78 | - if ($this->model) |
|
79 | - { |
|
80 | - $relations = $this->relations && $this->relations['search'] ? $this->relations['search'] : []; |
|
81 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Fetch records from the storage based on the given |
|
87 | - * condition. |
|
88 | - * |
|
89 | - * @param \Illuminate\Http\Request $request |
|
90 | - * @param string $sortBy |
|
91 | - * @param boolean $desc |
|
92 | - * @return \Illuminate\Http\Response |
|
93 | - */ |
|
94 | - public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
95 | - { |
|
96 | - if ($this->model) |
|
97 | - { |
|
98 | - $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
99 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Fetch the first record from the storage based on the given |
|
105 | - * condition. |
|
106 | - * |
|
107 | - * @param \Illuminate\Http\Request $request |
|
108 | - * @return \Illuminate\Http\Response |
|
109 | - */ |
|
110 | - public function first(Request $request) |
|
111 | - { |
|
112 | - if ($this->model) |
|
113 | - { |
|
114 | - $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
115 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Paginate all records with relations from model repository. |
|
121 | - * |
|
122 | - * @param integer $perPage |
|
123 | - * @param string $sortBy |
|
124 | - * @param boolean $desc |
|
125 | - * @return \Illuminate\Http\Response |
|
126 | - */ |
|
127 | - public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
128 | - { |
|
129 | - if ($this->model) |
|
130 | - { |
|
131 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
132 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Fetch all records with relations based on |
|
138 | - * the given condition from storage in pages. |
|
139 | - * |
|
140 | - * @param \Illuminate\Http\Request $request |
|
141 | - * @param integer $perPage |
|
142 | - * @param string $sortBy |
|
143 | - * @param boolean $desc |
|
144 | - * @return \Illuminate\Http\Response |
|
145 | - */ |
|
146 | - public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
147 | - { |
|
148 | - if ($this->model) |
|
149 | - { |
|
150 | - $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
151 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Save the given model to repository. |
|
157 | - * |
|
158 | - * @param \Illuminate\Http\Request $request |
|
159 | - * @return \Illuminate\Http\Response |
|
160 | - */ |
|
161 | - public function save(Request $request) |
|
162 | - { |
|
163 | - foreach ($this->validationRules as &$rule) |
|
164 | - { |
|
165 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
166 | - { |
|
167 | - $rule .= ',deleted_at,NULL'; |
|
168 | - } |
|
169 | - |
|
170 | - if ($request->has('id')) |
|
171 | - { |
|
172 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
173 | - } |
|
174 | - else |
|
175 | - { |
|
176 | - $rule = str_replace(',{id}', '', $rule); |
|
177 | - } |
|
178 | - } |
|
27 | + $this->config = \CoreConfig::getConfig(); |
|
28 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
29 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
30 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
31 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
32 | + $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
33 | + $route = explode('@',\Route::currentRouteAction())[1]; |
|
34 | + $this->checkPermission($route); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Fetch all records with relations from model repository. |
|
39 | + * |
|
40 | + * @return \Illuminate\Http\Response |
|
41 | + */ |
|
42 | + public function index() |
|
43 | + { |
|
44 | + if ($this->model) |
|
45 | + { |
|
46 | + $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
47 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Fetch the single object with relations from model repository. |
|
53 | + * |
|
54 | + * @param integer $id |
|
55 | + * @return \Illuminate\Http\Response |
|
56 | + */ |
|
57 | + public function find($id) |
|
58 | + { |
|
59 | + if ($this->model) |
|
60 | + { |
|
61 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
62 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Paginate all records with relations from model repository |
|
68 | + * that matche the given query. |
|
69 | + * |
|
70 | + * @param string $query |
|
71 | + * @param integer $perPage |
|
72 | + * @param string $sortBy |
|
73 | + * @param boolean $desc |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
77 | + { |
|
78 | + if ($this->model) |
|
79 | + { |
|
80 | + $relations = $this->relations && $this->relations['search'] ? $this->relations['search'] : []; |
|
81 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Fetch records from the storage based on the given |
|
87 | + * condition. |
|
88 | + * |
|
89 | + * @param \Illuminate\Http\Request $request |
|
90 | + * @param string $sortBy |
|
91 | + * @param boolean $desc |
|
92 | + * @return \Illuminate\Http\Response |
|
93 | + */ |
|
94 | + public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
95 | + { |
|
96 | + if ($this->model) |
|
97 | + { |
|
98 | + $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
99 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Fetch the first record from the storage based on the given |
|
105 | + * condition. |
|
106 | + * |
|
107 | + * @param \Illuminate\Http\Request $request |
|
108 | + * @return \Illuminate\Http\Response |
|
109 | + */ |
|
110 | + public function first(Request $request) |
|
111 | + { |
|
112 | + if ($this->model) |
|
113 | + { |
|
114 | + $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
115 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Paginate all records with relations from model repository. |
|
121 | + * |
|
122 | + * @param integer $perPage |
|
123 | + * @param string $sortBy |
|
124 | + * @param boolean $desc |
|
125 | + * @return \Illuminate\Http\Response |
|
126 | + */ |
|
127 | + public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
128 | + { |
|
129 | + if ($this->model) |
|
130 | + { |
|
131 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
132 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Fetch all records with relations based on |
|
138 | + * the given condition from storage in pages. |
|
139 | + * |
|
140 | + * @param \Illuminate\Http\Request $request |
|
141 | + * @param integer $perPage |
|
142 | + * @param string $sortBy |
|
143 | + * @param boolean $desc |
|
144 | + * @return \Illuminate\Http\Response |
|
145 | + */ |
|
146 | + public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
147 | + { |
|
148 | + if ($this->model) |
|
149 | + { |
|
150 | + $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
151 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Save the given model to repository. |
|
157 | + * |
|
158 | + * @param \Illuminate\Http\Request $request |
|
159 | + * @return \Illuminate\Http\Response |
|
160 | + */ |
|
161 | + public function save(Request $request) |
|
162 | + { |
|
163 | + foreach ($this->validationRules as &$rule) |
|
164 | + { |
|
165 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
166 | + { |
|
167 | + $rule .= ',deleted_at,NULL'; |
|
168 | + } |
|
169 | + |
|
170 | + if ($request->has('id')) |
|
171 | + { |
|
172 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
173 | + } |
|
174 | + else |
|
175 | + { |
|
176 | + $rule = str_replace(',{id}', '', $rule); |
|
177 | + } |
|
178 | + } |
|
179 | 179 | |
180 | - $this->validate($request, $this->validationRules); |
|
181 | - |
|
182 | - if ($this->model) |
|
183 | - { |
|
184 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Delete by the given id from model repository. |
|
190 | - * |
|
191 | - * @param integer $id |
|
192 | - * @return \Illuminate\Http\Response |
|
193 | - */ |
|
194 | - public function delete($id) |
|
195 | - { |
|
196 | - if ($this->model) |
|
197 | - { |
|
198 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Check if the logged in user can do the given permission. |
|
204 | - * |
|
205 | - * @param string $permission |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - private function checkPermission($permission) |
|
209 | - { |
|
210 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
211 | - if ( ! in_array($permission, $this->skipLoginCheck)) |
|
212 | - { |
|
213 | - \JWTAuth::parseToken()->authenticate(); |
|
214 | - if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
215 | - { |
|
216 | - \ErrorHandler::noPermissions(); |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
180 | + $this->validate($request, $this->validationRules); |
|
181 | + |
|
182 | + if ($this->model) |
|
183 | + { |
|
184 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Delete by the given id from model repository. |
|
190 | + * |
|
191 | + * @param integer $id |
|
192 | + * @return \Illuminate\Http\Response |
|
193 | + */ |
|
194 | + public function delete($id) |
|
195 | + { |
|
196 | + if ($this->model) |
|
197 | + { |
|
198 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Check if the logged in user can do the given permission. |
|
204 | + * |
|
205 | + * @param string $permission |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + private function checkPermission($permission) |
|
209 | + { |
|
210 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
211 | + if ( ! in_array($permission, $this->skipLoginCheck)) |
|
212 | + { |
|
213 | + \JWTAuth::parseToken()->authenticate(); |
|
214 | + if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
215 | + { |
|
216 | + \ErrorHandler::noPermissions(); |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
220 | 220 | } |
@@ -5,32 +5,32 @@ |
||
5 | 5 | |
6 | 6 | class Settings extends Model{ |
7 | 7 | |
8 | - use SoftDeletes; |
|
9 | - protected $table = 'settings'; |
|
10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | - protected $hidden = ['deleted_at']; |
|
12 | - protected $guarded = ['id', 'key']; |
|
13 | - protected $fillable = ['name','value']; |
|
14 | - public $searchable = ['name', 'value', 'key']; |
|
8 | + use SoftDeletes; |
|
9 | + protected $table = 'settings'; |
|
10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | + protected $hidden = ['deleted_at']; |
|
12 | + protected $guarded = ['id', 'key']; |
|
13 | + protected $fillable = ['name','value']; |
|
14 | + public $searchable = ['name', 'value', 'key']; |
|
15 | 15 | |
16 | - public function getCreatedAtAttribute($value) |
|
17 | - { |
|
18 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | - } |
|
16 | + public function getCreatedAtAttribute($value) |
|
17 | + { |
|
18 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function getUpdatedAtAttribute($value) |
|
22 | - { |
|
23 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | - } |
|
21 | + public function getUpdatedAtAttribute($value) |
|
22 | + { |
|
23 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
24 | + } |
|
25 | 25 | |
26 | - public function getDeletedAtAttribute($value) |
|
27 | - { |
|
28 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | - } |
|
26 | + public function getDeletedAtAttribute($value) |
|
27 | + { |
|
28 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
29 | + } |
|
30 | 30 | |
31 | - public static function boot() |
|
32 | - { |
|
33 | - parent::boot(); |
|
34 | - parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\SettingsObserver')); |
|
35 | - } |
|
31 | + public static function boot() |
|
32 | + { |
|
33 | + parent::boot(); |
|
34 | + parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\SettingsObserver')); |
|
35 | + } |
|
36 | 36 | } |
@@ -8,35 +8,35 @@ |
||
8 | 8 | |
9 | 9 | class GroupsController extends BaseApiController |
10 | 10 | { |
11 | - /** |
|
12 | - * The name of the model that is used by the base api controller |
|
13 | - * to preform actions like (add, edit ... etc). |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $model = 'groups'; |
|
11 | + /** |
|
12 | + * The name of the model that is used by the base api controller |
|
13 | + * to preform actions like (add, edit ... etc). |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $model = 'groups'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * The validations rules used by the base api controller |
|
20 | - * to check before add. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $validationRules = [ |
|
24 | - 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
25 | - ]; |
|
18 | + /** |
|
19 | + * The validations rules used by the base api controller |
|
20 | + * to check before add. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $validationRules = [ |
|
24 | + 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
25 | + ]; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Handle an assign permissions to group request. |
|
29 | - * |
|
30 | - * @param \Illuminate\Http\Request $request |
|
31 | - * @return \Illuminate\Http\Response |
|
32 | - */ |
|
33 | - public function assignpermissions(Request $request) |
|
34 | - { |
|
35 | - $this->validate($request, [ |
|
36 | - 'permission_ids' => 'required|exists:permissions,id', |
|
37 | - 'group_id' => 'required|array|exists:groups,id' |
|
38 | - ]); |
|
27 | + /** |
|
28 | + * Handle an assign permissions to group request. |
|
29 | + * |
|
30 | + * @param \Illuminate\Http\Request $request |
|
31 | + * @return \Illuminate\Http\Response |
|
32 | + */ |
|
33 | + public function assignpermissions(Request $request) |
|
34 | + { |
|
35 | + $this->validate($request, [ |
|
36 | + 'permission_ids' => 'required|exists:permissions,id', |
|
37 | + 'group_id' => 'required|array|exists:groups,id' |
|
38 | + ]); |
|
39 | 39 | |
40 | - return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
41 | - } |
|
40 | + return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
41 | + } |
|
42 | 42 | } |
@@ -29,6 +29,6 @@ |
||
29 | 29 | $group->permissions()->attach($permission_ids); |
30 | 30 | }); |
31 | 31 | |
32 | - return $this->find($group_id); |
|
32 | + return $this->find($group_id); |
|
33 | 33 | } |
34 | 34 | } |
@@ -2,119 +2,119 @@ |
||
2 | 2 | |
3 | 3 | interface RepositoryInterface |
4 | 4 | { |
5 | - /** |
|
6 | - * Fetch all records with relations from the storage. |
|
7 | - * |
|
8 | - * @param array $relations |
|
9 | - * @param array $sortBy |
|
10 | - * @param array $desc |
|
11 | - * @param array $columns |
|
12 | - * @return collection |
|
13 | - */ |
|
14 | - public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
5 | + /** |
|
6 | + * Fetch all records with relations from the storage. |
|
7 | + * |
|
8 | + * @param array $relations |
|
9 | + * @param array $sortBy |
|
10 | + * @param array $desc |
|
11 | + * @param array $columns |
|
12 | + * @return collection |
|
13 | + */ |
|
14 | + public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
15 | 15 | |
16 | - /** |
|
17 | - * Fetch all records with relations from storage in pages |
|
18 | - * that matche the given query. |
|
19 | - * |
|
20 | - * @param string $query |
|
21 | - * @param integer $perPage |
|
22 | - * @param array $relations |
|
23 | - * @param array $sortBy |
|
24 | - * @param array $desc |
|
25 | - * @param array $columns |
|
26 | - * @return collection |
|
27 | - */ |
|
28 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
16 | + /** |
|
17 | + * Fetch all records with relations from storage in pages |
|
18 | + * that matche the given query. |
|
19 | + * |
|
20 | + * @param string $query |
|
21 | + * @param integer $perPage |
|
22 | + * @param array $relations |
|
23 | + * @param array $sortBy |
|
24 | + * @param array $desc |
|
25 | + * @param array $columns |
|
26 | + * @return collection |
|
27 | + */ |
|
28 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Fetch all records with relations from storage in pages. |
|
32 | - * |
|
33 | - * @param integer $perPage |
|
34 | - * @param array $relations |
|
35 | - * @param array $sortBy |
|
36 | - * @param array $desc |
|
37 | - * @param array $columns |
|
38 | - * @return collection |
|
39 | - */ |
|
40 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
30 | + /** |
|
31 | + * Fetch all records with relations from storage in pages. |
|
32 | + * |
|
33 | + * @param integer $perPage |
|
34 | + * @param array $relations |
|
35 | + * @param array $sortBy |
|
36 | + * @param array $desc |
|
37 | + * @param array $columns |
|
38 | + * @return collection |
|
39 | + */ |
|
40 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Fetch all records with relations based on |
|
44 | - * the given condition from storage in pages. |
|
45 | - * |
|
46 | - * @param array $conditions array of conditions |
|
47 | - * @param integer $perPage |
|
48 | - * @param array $relations |
|
49 | - * @param array $sortBy |
|
50 | - * @param array $desc |
|
51 | - * @param array $columns |
|
52 | - * @return collection |
|
53 | - */ |
|
54 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
42 | + /** |
|
43 | + * Fetch all records with relations based on |
|
44 | + * the given condition from storage in pages. |
|
45 | + * |
|
46 | + * @param array $conditions array of conditions |
|
47 | + * @param integer $perPage |
|
48 | + * @param array $relations |
|
49 | + * @param array $sortBy |
|
50 | + * @param array $desc |
|
51 | + * @param array $columns |
|
52 | + * @return collection |
|
53 | + */ |
|
54 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Save the given model/models to the storage. |
|
58 | - * |
|
59 | - * @param array $data |
|
60 | - * @param boolean $saveLog |
|
61 | - * @return object |
|
62 | - */ |
|
63 | - public function save(array $data, $saveLog = true); |
|
56 | + /** |
|
57 | + * Save the given model/models to the storage. |
|
58 | + * |
|
59 | + * @param array $data |
|
60 | + * @param boolean $saveLog |
|
61 | + * @return object |
|
62 | + */ |
|
63 | + public function save(array $data, $saveLog = true); |
|
64 | 64 | |
65 | - /** |
|
66 | - * Update record in the storage based on the given |
|
67 | - * condition. |
|
68 | - * |
|
69 | - * @param var $value condition value |
|
70 | - * @param array $data |
|
71 | - * @param string $attribute condition column name |
|
72 | - * @return integer affected rows |
|
73 | - */ |
|
74 | - public function update($value, array $data, $attribute = 'id'); |
|
65 | + /** |
|
66 | + * Update record in the storage based on the given |
|
67 | + * condition. |
|
68 | + * |
|
69 | + * @param var $value condition value |
|
70 | + * @param array $data |
|
71 | + * @param string $attribute condition column name |
|
72 | + * @return integer affected rows |
|
73 | + */ |
|
74 | + public function update($value, array $data, $attribute = 'id'); |
|
75 | 75 | |
76 | - /** |
|
77 | - * Delete record from the storage based on the given |
|
78 | - * condition. |
|
79 | - * |
|
80 | - * @param var $value condition value |
|
81 | - * @param string $attribute condition column name |
|
82 | - * @return integer affected rows |
|
83 | - */ |
|
84 | - public function delete($value, $attribute = 'id'); |
|
76 | + /** |
|
77 | + * Delete record from the storage based on the given |
|
78 | + * condition. |
|
79 | + * |
|
80 | + * @param var $value condition value |
|
81 | + * @param string $attribute condition column name |
|
82 | + * @return integer affected rows |
|
83 | + */ |
|
84 | + public function delete($value, $attribute = 'id'); |
|
85 | 85 | |
86 | - /** |
|
87 | - * Fetch records from the storage based on the given |
|
88 | - * id. |
|
89 | - * |
|
90 | - * @param integer $id |
|
91 | - * @param array $relations |
|
92 | - * @param array $columns |
|
93 | - * @return object |
|
94 | - */ |
|
95 | - public function find($id, $relations = [], $columns = array('*')); |
|
86 | + /** |
|
87 | + * Fetch records from the storage based on the given |
|
88 | + * id. |
|
89 | + * |
|
90 | + * @param integer $id |
|
91 | + * @param array $relations |
|
92 | + * @param array $columns |
|
93 | + * @return object |
|
94 | + */ |
|
95 | + public function find($id, $relations = [], $columns = array('*')); |
|
96 | 96 | |
97 | - /** |
|
98 | - * Fetch records from the storage based on the given |
|
99 | - * condition. |
|
100 | - * |
|
101 | - * @param array $conditions array of conditions |
|
102 | - * @param array $relations |
|
103 | - * @param array $sortBy |
|
104 | - * @param array $desc |
|
105 | - * @param array $columns |
|
106 | - * @return collection |
|
107 | - */ |
|
108 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
97 | + /** |
|
98 | + * Fetch records from the storage based on the given |
|
99 | + * condition. |
|
100 | + * |
|
101 | + * @param array $conditions array of conditions |
|
102 | + * @param array $relations |
|
103 | + * @param array $sortBy |
|
104 | + * @param array $desc |
|
105 | + * @param array $columns |
|
106 | + * @return collection |
|
107 | + */ |
|
108 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*')); |
|
109 | 109 | |
110 | - /** |
|
111 | - * Fetch the first record fro the storage based on the given |
|
112 | - * condition. |
|
113 | - * |
|
114 | - * @param array $conditions array of conditions |
|
115 | - * @param array $relations |
|
116 | - * @param array $columns |
|
117 | - * @return object |
|
118 | - */ |
|
119 | - public function first($conditions, $relations = [], $columns = array('*')); |
|
110 | + /** |
|
111 | + * Fetch the first record fro the storage based on the given |
|
112 | + * condition. |
|
113 | + * |
|
114 | + * @param array $conditions array of conditions |
|
115 | + * @param array $relations |
|
116 | + * @param array $columns |
|
117 | + * @return object |
|
118 | + */ |
|
119 | + public function first($conditions, $relations = [], $columns = array('*')); |
|
120 | 120 | } |
121 | 121 | \ No newline at end of file |
@@ -15,23 +15,23 @@ |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
18 | - * Set the notification notified to true. |
|
19 | - * |
|
20 | - * @param integer $id |
|
21 | - * @return object |
|
22 | - */ |
|
23 | - public function notified($id) |
|
24 | - { |
|
25 | - return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | - } |
|
18 | + * Set the notification notified to true. |
|
19 | + * |
|
20 | + * @param integer $id |
|
21 | + * @return object |
|
22 | + */ |
|
23 | + public function notified($id) |
|
24 | + { |
|
25 | + return $this->save(['id' => $id, 'notified' => 1]); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Set the notification notified to all. |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function notifyAll() |
|
34 | - { |
|
35 | - $this->update(false, ['notified' => 1], 'notified'); |
|
36 | - } |
|
28 | + /** |
|
29 | + * Set the notification notified to all. |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function notifyAll() |
|
34 | + { |
|
35 | + $this->update(false, ['notified' => 1], 'notified'); |
|
36 | + } |
|
37 | 37 | } |
@@ -2,93 +2,93 @@ |
||
2 | 2 | |
3 | 3 | class ErrorHandler |
4 | 4 | { |
5 | - public function unAuthorized() |
|
6 | - { |
|
7 | - $error = ['status' => 401, 'message' => 'Please login before any action']; |
|
8 | - abort($error['status'], $error['message']); |
|
9 | - } |
|
5 | + public function unAuthorized() |
|
6 | + { |
|
7 | + $error = ['status' => 401, 'message' => 'Please login before any action']; |
|
8 | + abort($error['status'], $error['message']); |
|
9 | + } |
|
10 | 10 | |
11 | - public function tokenExpired() |
|
12 | - { |
|
13 | - $error = ['status' => 403, 'message' => 'Login token expired']; |
|
14 | - abort($error['status'], $error['message']); |
|
15 | - } |
|
11 | + public function tokenExpired() |
|
12 | + { |
|
13 | + $error = ['status' => 403, 'message' => 'Login token expired']; |
|
14 | + abort($error['status'], $error['message']); |
|
15 | + } |
|
16 | 16 | |
17 | - public function noPermissions() |
|
18 | - { |
|
19 | - $error = ['status' => 403, 'message' => 'No permissions']; |
|
20 | - abort($error['status'], $error['message']); |
|
21 | - } |
|
17 | + public function noPermissions() |
|
18 | + { |
|
19 | + $error = ['status' => 403, 'message' => 'No permissions']; |
|
20 | + abort($error['status'], $error['message']); |
|
21 | + } |
|
22 | 22 | |
23 | - public function loginFailed() |
|
24 | - { |
|
25 | - $error = ['status' => 400, 'message' => 'Wrong mail or password']; |
|
26 | - abort($error['status'], $error['message']); |
|
27 | - } |
|
23 | + public function loginFailed() |
|
24 | + { |
|
25 | + $error = ['status' => 400, 'message' => 'Wrong mail or password']; |
|
26 | + abort($error['status'], $error['message']); |
|
27 | + } |
|
28 | 28 | |
29 | - public function loginFailedSocial() |
|
30 | - { |
|
31 | - $error = ['status' => 400, 'message' => 'Wrong auth code or acces token']; |
|
32 | - abort($error['status'], $error['message']); |
|
33 | - } |
|
29 | + public function loginFailedSocial() |
|
30 | + { |
|
31 | + $error = ['status' => 400, 'message' => 'Wrong auth code or acces token']; |
|
32 | + abort($error['status'], $error['message']); |
|
33 | + } |
|
34 | 34 | |
35 | - public function noSocialEmail() |
|
36 | - { |
|
37 | - $error = ['status' => 400, 'message' => 'Couldn\'t retrieve email']; |
|
38 | - abort($error['status'], $error['message']); |
|
39 | - } |
|
35 | + public function noSocialEmail() |
|
36 | + { |
|
37 | + $error = ['status' => 400, 'message' => 'Couldn\'t retrieve email']; |
|
38 | + abort($error['status'], $error['message']); |
|
39 | + } |
|
40 | 40 | |
41 | - public function redisNotRunning() |
|
42 | - { |
|
43 | - $error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running']; |
|
44 | - abort($error['status'], $error['message']); |
|
45 | - } |
|
41 | + public function redisNotRunning() |
|
42 | + { |
|
43 | + $error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running']; |
|
44 | + abort($error['status'], $error['message']); |
|
45 | + } |
|
46 | 46 | |
47 | - public function dbQueryError() |
|
48 | - { |
|
49 | - $error = ['status' => 400, 'message' => 'Please check the given inputes']; |
|
50 | - abort($error['status'], $error['message']); |
|
51 | - } |
|
47 | + public function dbQueryError() |
|
48 | + { |
|
49 | + $error = ['status' => 400, 'message' => 'Please check the given inputes']; |
|
50 | + abort($error['status'], $error['message']); |
|
51 | + } |
|
52 | 52 | |
53 | - public function cannotCreateSetting() |
|
54 | - { |
|
55 | - $error = ['status' => 400, 'message' => 'Can\'t create setting']; |
|
56 | - abort($error['status'], $error['message']); |
|
57 | - } |
|
53 | + public function cannotCreateSetting() |
|
54 | + { |
|
55 | + $error = ['status' => 400, 'message' => 'Can\'t create setting']; |
|
56 | + abort($error['status'], $error['message']); |
|
57 | + } |
|
58 | 58 | |
59 | - public function cannotUpdateSettingKey() |
|
60 | - { |
|
61 | - $error = ['status' => 400, 'message' => 'Can\'t update setting key']; |
|
62 | - abort($error['status'], $error['message']); |
|
63 | - } |
|
59 | + public function cannotUpdateSettingKey() |
|
60 | + { |
|
61 | + $error = ['status' => 400, 'message' => 'Can\'t update setting key']; |
|
62 | + abort($error['status'], $error['message']); |
|
63 | + } |
|
64 | 64 | |
65 | - public function userIsBlocked() |
|
66 | - { |
|
67 | - $error = ['status' => 403, 'message' => 'You have been blocked']; |
|
68 | - abort($error['status'], $error['message']); |
|
69 | - } |
|
65 | + public function userIsBlocked() |
|
66 | + { |
|
67 | + $error = ['status' => 403, 'message' => 'You have been blocked']; |
|
68 | + abort($error['status'], $error['message']); |
|
69 | + } |
|
70 | 70 | |
71 | - public function invalidResetToken() |
|
72 | - { |
|
73 | - $error = ['status' => 400, 'message' => 'Reset password token is invalid']; |
|
74 | - abort($error['status'], $error['message']); |
|
75 | - } |
|
71 | + public function invalidResetToken() |
|
72 | + { |
|
73 | + $error = ['status' => 400, 'message' => 'Reset password token is invalid']; |
|
74 | + abort($error['status'], $error['message']); |
|
75 | + } |
|
76 | 76 | |
77 | - public function invalidResetPassword() |
|
78 | - { |
|
79 | - $error = ['status' => 400, 'message' => 'Reset password is invalid']; |
|
80 | - abort($error['status'], $error['message']); |
|
81 | - } |
|
77 | + public function invalidResetPassword() |
|
78 | + { |
|
79 | + $error = ['status' => 400, 'message' => 'Reset password is invalid']; |
|
80 | + abort($error['status'], $error['message']); |
|
81 | + } |
|
82 | 82 | |
83 | - public function notFound($text) |
|
84 | - { |
|
85 | - $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found']; |
|
86 | - abort($error['status'], $error['message']); |
|
87 | - } |
|
83 | + public function notFound($text) |
|
84 | + { |
|
85 | + $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found']; |
|
86 | + abort($error['status'], $error['message']); |
|
87 | + } |
|
88 | 88 | |
89 | - public function generalError() |
|
90 | - { |
|
91 | - $error = ['status' => 400, 'message' => 'Something went wrong']; |
|
92 | - abort($error['status'], $error['message']); |
|
93 | - } |
|
89 | + public function generalError() |
|
90 | + { |
|
91 | + $error = ['status' => 400, 'message' => 'Something went wrong']; |
|
92 | + abort($error['status'], $error['message']); |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | \ No newline at end of file |