Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
checkAccess, checkUpdateAllowed, checkDeleteAllowed - description
  • Loading branch information
siggi-k committed Dec 18, 2024
commit c7f54e3039f53f606809709d472834e592437d9d
17 changes: 16 additions & 1 deletion src/actions/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,25 @@ class DeleteAction extends JsonApiAction
public $scenario = Model::SCENARIO_DEFAULT;

/**
* @var callable|null a PHP callable that checks if deletion is allowed.
* @var callable|null A PHP callable that will be called to determine
* whether the deletion of a model is allowed. If not set, no deletion
* check will be performed. The callable should have the following signature:
*
* @example
* ```php
* function ($action, $model) {
* // $model is the model instance being deleted.
*
* // If the deletion is not allowed, an error should be thrown. For example:
* if ($model->status !== 'draft') {
* throw new MethodNotAllowedHttpException('The model can only be deleted if its status is "draft".');
* }
* }
* ```
*/
public $checkDeleteAllowed;


/**
* @var callable|Closure Callback after save model with all relations
* @example
Expand Down
15 changes: 11 additions & 4 deletions src/actions/JsonApiAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ class JsonApiAction extends Action
public $findModel;

/**
* @var callable a PHP callable that will be called when running an action to determine
* if the current user has the permission to execute the action. If not set, the access
* check will not be performed. The signature of the callable should be as follows,
* @var callable|null A PHP callable that will be called when running an action to determine
* whether the current user has permission to execute the action. If not set, no access
* check will be performed. The callable should have the following signature:
*
* @example
* ```php
* function ($action, $model = null) {
* // $model is the requested model instance.
* // If null, it means no specific model (e.g. IndexAction)
* // If null, it indicates no specific model (e.g., IndexAction).
*
* // If the user does not have the required permissions, an error should be thrown. For example:
* if (!Yii::$app->user->can('admin')) {
* throw new ForbiddenHttpException();
* }
* }
* ```
*/
Expand Down
16 changes: 15 additions & 1 deletion src/actions/UpdateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ class UpdateAction extends JsonApiAction
public $scenario = Model::SCENARIO_DEFAULT;

/**
* @var callable|null a PHP callable that checks if updating is allowed.
* @var callable|null A PHP callable that will be called to determine
* whether the update of a model is allowed. If not set, no update
* check will be performed. The callable should have the following signature:
*
* @example
* ```php
* function ($action, $model) {
* // $model is the model instance being updated.
*
* // If the update is not allowed, an error should be thrown. For example:
* if ($model->status === 'archived') {
* throw new MethodNotAllowedHttpException('The model cannot be updated when its status is "archived".');
* }
* }
* ```
*/
public $checkUpdateAllowed;

Expand Down
Loading