diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index c5ee15c6e8..ad19bc0ba4 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -5,7 +5,7 @@ HumHub Change Log --------------------- - Enh: Added BaseURL setting protocol scheme validation - +- Fix #2849: ActiveQueryContent doesn't find public profile content when guest access is enabled 1.2.4 (December 13, 2017) -------------------------- diff --git a/protected/humhub/modules/content/components/ActiveQueryContent.php b/protected/humhub/modules/content/components/ActiveQueryContent.php index 2c1dbdd678..21b79e3969 100644 --- a/protected/humhub/modules/content/components/ActiveQueryContent.php +++ b/protected/humhub/modules/content/components/ActiveQueryContent.php @@ -2,7 +2,7 @@ /** * @link https://www.humhub.org/ - * @copyright Copyright (c) 2015 HumHub GmbH & Co. KG + * @copyright Copyright (c) 2017 HumHub GmbH & Co. KG * @license https://www.humhub.com/licences */ @@ -46,10 +46,13 @@ class ActiveQueryContent extends \yii\db\ActiveQuery $this->joinWith(['content', 'content.contentContainer', 'content.createdBy']); + $this->leftJoin('space', 'contentcontainer.pk=space.id AND contentcontainer.class=:spaceClass', [':spaceClass' => Space::className()]); + $this->leftJoin('user cuser', 'contentcontainer.pk=cuser.id AND contentcontainer.class=:userClass', [':userClass' => User::className()]); + $conditionSpace = ''; + $conditionUser = ''; + if ($user !== null) { $this->leftJoin('space_membership', 'contentcontainer.pk=space_membership.space_id AND contentcontainer.class=:spaceClass AND space_membership.user_id=:userId', [':userId' => $user->id, ':spaceClass' => Space::className()]); - $this->leftJoin('space', 'contentcontainer.pk=space.id AND contentcontainer.class=:spaceClass', [':spaceClass' => Space::className()]); - $this->leftJoin('user cuser', 'contentcontainer.pk=cuser.id AND contentcontainer.class=:userClass', [':userClass' => User::className()]); // Build Access Check based on Space Content Container $conditionSpace = 'space.id IS NOT NULL AND ('; // space content @@ -66,15 +69,14 @@ class ActiveQueryContent extends \yii\db\ActiveQuery $conditionUser .= ' OR (content.visibility = 0 AND cff.id IS NOT NULL)'; // users are friends } $conditionUser .= ')'; - + // Created content of is always visible $conditionUser .= 'OR content.created_by=' . $user->id; - - $this->andWhere("{$conditionSpace} OR {$conditionUser}"); } else { - $this->leftJoin('space', 'contentcontainer.pk=space.id AND contentcontainer.class=:spaceClass', [':spaceClass' => Space::className()]); - $this->andWhere('space.id IS NOT NULL and space.visibility=' . Space::VISIBILITY_ALL . ' AND content.visibility=1'); + $conditionSpace = 'space.id IS NOT NULL and space.visibility=' . Space::VISIBILITY_ALL . ' AND content.visibility=1'; + $conditionUser = 'cuser.id IS NOT NULL and cuser.visibility=' . User::VISIBILITY_ALL . ' AND content.visibility=1'; } + $this->andWhere("{$conditionSpace} OR {$conditionUser}");