File tree 3 files changed +42
-6
lines changed
3 files changed +42
-6
lines changed Original file line number Diff line number Diff line change @@ -38,10 +38,25 @@ class DeleteAction extends JsonApiAction
38
38
public $ scenario = Model::SCENARIO_DEFAULT ;
39
39
40
40
/**
41
- * @var callable|null a PHP callable that checks if deletion is allowed.
41
+ * @var callable|null A PHP callable that will be called to determine
42
+ * whether the deletion of a model is allowed. If not set, no deletion
43
+ * check will be performed. The callable should have the following signature:
44
+ *
45
+ * @example
46
+ * ```php
47
+ * function ($action, $model) {
48
+ * // $model is the model instance being deleted.
49
+ *
50
+ * // If the deletion is not allowed, an error should be thrown. For example:
51
+ * if ($model->status !== 'draft') {
52
+ * throw new MethodNotAllowedHttpException('The model can only be deleted if its status is "draft".');
53
+ * }
54
+ * }
55
+ * ```
42
56
*/
43
57
public $ checkDeleteAllowed ;
44
58
59
+
45
60
/**
46
61
* @var callable|Closure Callback after save model with all relations
47
62
* @example
Original file line number Diff line number Diff line change @@ -61,13 +61,20 @@ class JsonApiAction extends Action
61
61
public $ findModel ;
62
62
63
63
/**
64
- * @var callable a PHP callable that will be called when running an action to determine
65
- * if the current user has the permission to execute the action. If not set, the access
66
- * check will not be performed. The signature of the callable should be as follows,
64
+ * @var callable A PHP callable that will be called when running an action to determine
65
+ * whether the current user has permission to execute the action. If not set, no access
66
+ * check will be performed. The callable should have the following signature:
67
+ *
68
+ * @example
67
69
* ```php
68
70
* function ($action, $model = null) {
69
71
* // $model is the requested model instance.
70
- * // If null, it means no specific model (e.g. IndexAction)
72
+ * // If null, it indicates no specific model (e.g., IndexAction).
73
+ *
74
+ * // If the user does not have the required permissions, an error should be thrown. For example:
75
+ * if (!Yii::$app->user->can('admin')) {
76
+ * throw new ForbiddenHttpException();
77
+ * }
71
78
* }
72
79
* ```
73
80
*/
Original file line number Diff line number Diff line change @@ -68,7 +68,21 @@ class UpdateAction extends JsonApiAction
68
68
public $ scenario = Model::SCENARIO_DEFAULT ;
69
69
70
70
/**
71
- * @var callable|null a PHP callable that checks if updating is allowed.
71
+ * @var callable|null A PHP callable that will be called to determine
72
+ * whether the update of a model is allowed. If not set, no update
73
+ * check will be performed. The callable should have the following signature:
74
+ *
75
+ * @example
76
+ * ```php
77
+ * function ($action, $model) {
78
+ * // $model is the model instance being updated.
79
+ *
80
+ * // If the update is not allowed, an error should be thrown. For example:
81
+ * if ($model->status === 'archived') {
82
+ * throw new MethodNotAllowedHttpException('The model cannot be updated when its status is "archived".');
83
+ * }
84
+ * }
85
+ * ```
72
86
*/
73
87
public $ checkUpdateAllowed ;
74
88
You can’t perform that action at this time.
0 commit comments