src/controllers/DefaultController.php
public function actionCanEdit(): Response
    {
        $this->requireAcceptsJson();
        $this->requirePostRequest();

        $assetId = Craft::$app->getRequest()->getRequiredBodyParam('assetId');
        $asset = Asset::find()->id($assetId)->one();

        if (!$asset) {
            return $this->asJson([
                'success' => false
            ]);
        }

        /** @var Volume $volume */
        $volume = $asset->getVolume();
        $user = Craft::$app->getUser()->getIdentity();

        return $this->asJson([
            'success' => (
                $user->can('saveAssetInVolume:' . $volume->uid) &&
                $user->can('deleteFilesAndFoldersInVolume:' . $volume->uid)
            ),
        ]);
    }
public function actionCanEdit(): Response
    {
        $this->requireAcceptsJson();
        $this->requirePostRequest();

        $assetId = Craft::$app->getRequest()->getRequiredBodyParam('assetId');
        $asset = Asset::find()->id($assetId)->one();

        if (!$asset) {
            return $this->asJson([
                'success' => false
            ]);
        }

        /** @var Volume $volume */
        $volume = $asset->getVolume();
        $user = Craft::$app->getUser()->getIdentity();

        return $this->asJson([
            'success' => (
                $user->can('saveAssetInVolume:' . $volume->uid) &&
                $user->can('deleteFilesAndFoldersInVolume:' . $volume->uid)
            ),
        ]);
    }
public function actionCanEdit ( ) : Response { $ this -> requireAcceptsJson ( ) ; $ this -> requirePostRequest ( ) ; $ assetId = Craft :: $ app -> getRequest ( ) -> getRequiredBodyParam ( 'assetId' ) ; $ asset = Asset :: find ( ) -> id ( $ assetId ) -> one ( ) ; if ( ! $ asset ) { return $ this -> asJson ( [ 'success' => false ] ) ; } /** @var Volume $volume */ $ volume = $ asset -> getVolume ( ) ; $ user = Craft :: $ app -> getUser ( ) -> getIdentity ( ) ; return $ this -> asJson ( [ 'success' => ( $ user -> can ( 'saveAssetInVolume:' . $ volume -> uid ) && $ user -> can ( 'deleteFilesAndFoldersInVolume:' . $ volume -> uid ) ) , ] ) ; }
Check if user allowed to edit an Asset

@return Response
@throws \yii\base\InvalidConfigException
@throws \yii\web\BadRequestHttpException
Check if user allowed to edit an Asset