Fix #4743: LikeLink also when no CanLike permission

This commit is contained in:
Yuriy Bakhtin 2021-01-07 15:15:50 +03:00 committed by GitHub
parent 44237e1eaf
commit 5d2db8ad73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 8 deletions

View File

@ -12,6 +12,7 @@ HumHub Changelog
- Fix #4649: Success message rendered although password validation failed - Fix #4649: Success message rendered although password validation failed
- Fix #4717: Repsonsive layout alignment issue on small screens - Fix #4717: Repsonsive layout alignment issue on small screens
- Fix #4715: Call to `Content::canArchive()` throws error on global content - Fix #4715: Call to `Content::canArchive()` throws error on global content
- Fix #4743: Hide "Like" link when no permission "Can like"
1.7.1 (November 27, 2020) 1.7.1 (November 27, 2020)

View File

@ -92,10 +92,6 @@ class Events extends \yii\base\BaseObject
*/ */
public static function onWallEntryLinksInit($event) public static function onWallEntryLinksInit($event)
{ {
if (!static::getModule()->isEnabled) {
return;
}
$event->sender->addWidget(widgets\LikeLink::class, ['object' => $event->sender->object], ['sortOrder' => 10]); $event->sender->addWidget(widgets\LikeLink::class, ['object' => $event->sender->object], ['sortOrder' => 10]);
} }

View File

@ -8,6 +8,9 @@ use yii\helpers\Html;
use humhub\modules\like\Module; use humhub\modules\like\Module;
use humhub\modules\like\models\Like as LikeModel; use humhub\modules\like\models\Like as LikeModel;
use humhub\modules\content\components\ContentActiveRecord; use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\like\permissions\CanLike;
/** /**
* This widget is used to show a like link inside the wall entry controls. * This widget is used to show a like link inside the wall entry controls.
* *
@ -24,15 +27,26 @@ class LikeLink extends \yii\base\Widget
*/ */
public $object; public $object;
/**
* @inheritdoc
*/
public function beforeRun()
{
if (!Yii::$app->getModule('like')->isEnabled ||
!isset($this->object->content->container) ||
!($this->object->content->container instanceof ContentContainerActiveRecord) ||
!$this->object->content->container->can(CanLike::class)) {
return false;
}
return parent::beforeRun();
}
/** /**
* Executes the widget. * Executes the widget.
*/ */
public function run() public function run()
{ {
if (Yii::$app->getModule('like')->isEnabled === false) {
return;
}
$currentUserLiked = false; $currentUserLiked = false;
/** @var Module $module */ /** @var Module $module */
$module = Yii::$app->getModule('like'); $module = Yii::$app->getModule('like');