File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,11 @@ class DeleteAction extends JsonApiAction
3737 */
3838 public $ scenario = Model::SCENARIO_DEFAULT ;
3939
40+ /**
41+ * @var callable|null a PHP callable that checks if deletion is allowed.
42+ */
43+ public $ checkDeleteAllowed ;
44+
4045 /**
4146 * @var callable|Closure Callback after save model with all relations
4247 * @example
@@ -80,6 +85,10 @@ public function run($id):void
8085 call_user_func ($ this ->checkAccess , $ this ->id , $ model );
8186 }
8287
88+ if ($ this ->checkDeleteAllowed ) {
89+ call_user_func ($ this ->checkDeleteAllowed , $ this ->id , $ model );
90+ }
91+
8392 if ($ model ->delete () === false ) {
8493 throw new ServerErrorHttpException ('Failed to delete the object for unknown reason. ' );
8594 }
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ class UpdateAction extends JsonApiAction
6666 * ```
6767 */
6868 public $ scenario = Model::SCENARIO_DEFAULT ;
69+
70+ /**
71+ * @var callable|null a PHP callable that checks if updating is allowed.
72+ */
73+ public $ checkUpdateAllowed ;
74+
6975 /**
7076 * @var callable|Closure Callback after save model with all relations
7177 * @example
@@ -74,6 +80,7 @@ class UpdateAction extends JsonApiAction
7480 * }
7581 */
7682 public $ afterSave = null ;
83+
7784 /**
7885 * @throws \yii\base\InvalidConfigException
7986 */
@@ -113,6 +120,10 @@ public function run($id):Item
113120 call_user_func ($ this ->checkAccess , $ this ->id , $ model );
114121 }
115122
123+ if ($ this ->checkUpdateAllowed ) {
124+ call_user_func ($ this ->checkUpdateAllowed , $ this ->id , $ model );
125+ }
126+
116127 $ originalModel = clone $ model ;
117128 RelationshipManager::validateRelationships ($ model , $ this ->getResourceRelationships (), $ this ->allowedRelations );
118129 if (empty ($ this ->getResourceAttributes ()) && $ this ->hasResourceRelationships ()) {
You can’t perform that action at this time.
0 commit comments