mirror of
https://github.com/humhub/humhub.git
synced 2025-06-02 12:15:00 +02:00
Update CommentController.php (#5940)
It would be great if we could have the `parent::beforeAction($action)` before throwing exceptions. This would allow to run the `Controller::EVENT_BEFORE_ACTION` before. This is the way it's done in https://github.com/humhub/humhub/blob/master/protected/humhub/components/Controller.php#L206 and `yii\web\Controller` Thanks!
This commit is contained in:
parent
605e9dbe5c
commit
f10581f5ed
@ -62,21 +62,25 @@ class CommentController extends Controller
|
||||
*/
|
||||
public function beforeAction($action)
|
||||
{
|
||||
$modelClass = Yii::$app->request->get('objectModel', Yii::$app->request->post('objectModel'));
|
||||
$modelPk = (int)Yii::$app->request->get('objectId', Yii::$app->request->post('objectId'));
|
||||
if (parent::beforeAction($action)) {
|
||||
$modelClass = Yii::$app->request->get('objectModel', Yii::$app->request->post('objectModel'));
|
||||
$modelPk = (int)Yii::$app->request->get('objectId', Yii::$app->request->post('objectId'));
|
||||
|
||||
Helpers::CheckClassType($modelClass, [Comment::class, ContentActiveRecord::class]);
|
||||
$this->target = $modelClass::findOne(['id' => $modelPk]);
|
||||
Helpers::CheckClassType($modelClass, [Comment::class, ContentActiveRecord::class]);
|
||||
$this->target = $modelClass::findOne(['id' => $modelPk]);
|
||||
|
||||
if (!$this->target) {
|
||||
throw new NotFoundHttpException('Could not find underlying content or content addon record!');
|
||||
if (!$this->target) {
|
||||
throw new NotFoundHttpException('Could not find underlying content or content addon record!');
|
||||
}
|
||||
|
||||
if (!$this->target->content->canView()) {
|
||||
throw new ForbiddenHttpException();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$this->target->content->canView()) {
|
||||
throw new ForbiddenHttpException();
|
||||
}
|
||||
|
||||
return parent::beforeAction($action);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user