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
37
37
*/
38
38
public $ scenario = Model::SCENARIO_DEFAULT ;
39
39
40
+ /**
41
+ * @var callable|null a PHP callable that checks if deletion is allowed.
42
+ */
43
+ public $ checkDeleteAllowed ;
44
+
40
45
/**
41
46
* @var callable|Closure Callback after save model with all relations
42
47
* @example
@@ -80,6 +85,10 @@ public function run($id):void
80
85
call_user_func ($ this ->checkAccess , $ this ->id , $ model );
81
86
}
82
87
88
+ if ($ this ->checkDeleteAllowed ) {
89
+ call_user_func ($ this ->checkDeleteAllowed , $ this ->id , $ model );
90
+ }
91
+
83
92
if ($ model ->delete () === false ) {
84
93
throw new ServerErrorHttpException ('Failed to delete the object for unknown reason. ' );
85
94
}
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ class UpdateAction extends JsonApiAction
66
66
* ```
67
67
*/
68
68
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
+
69
75
/**
70
76
* @var callable|Closure Callback after save model with all relations
71
77
* @example
@@ -74,6 +80,7 @@ class UpdateAction extends JsonApiAction
74
80
* }
75
81
*/
76
82
public $ afterSave = null ;
83
+
77
84
/**
78
85
* @throws \yii\base\InvalidConfigException
79
86
*/
@@ -113,6 +120,10 @@ public function run($id):Item
113
120
call_user_func ($ this ->checkAccess , $ this ->id , $ model );
114
121
}
115
122
123
+ if ($ this ->checkUpdateAllowed ) {
124
+ call_user_func ($ this ->checkUpdateAllowed , $ this ->id , $ model );
125
+ }
126
+
116
127
$ originalModel = clone $ model ;
117
128
RelationshipManager::validateRelationships ($ model , $ this ->getResourceRelationships (), $ this ->allowedRelations );
118
129
if (empty ($ this ->getResourceAttributes ()) && $ this ->hasResourceRelationships ()) {
You can’t perform that action at this time.
0 commit comments