mirror of
https://github.com/humhub/humhub.git
synced 2025-01-29 12:28:06 +01:00
Space db search handle visibility and membership
This commit is contained in:
parent
d45d23f7f6
commit
050b79f753
@ -9,8 +9,12 @@
|
||||
|
||||
namespace humhub\modules\space\components;
|
||||
|
||||
use humhub\modules\space\models\Membership;
|
||||
use humhub\modules\user\components\ActiveQueryUser;
|
||||
use humhub\modules\user\models\User;
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
|
||||
|
||||
/**
|
||||
@ -25,10 +29,32 @@ class ActiveQuerySpace extends ActiveQuery
|
||||
/**
|
||||
* Only returns spaces which are visible for this user
|
||||
*
|
||||
* @param User|null $user
|
||||
* @return ActiveQuerySpace the query
|
||||
*/
|
||||
public function visible()
|
||||
public function visible(User $user = null)
|
||||
{
|
||||
if ($user === null && !Yii::$app->user->isGuest) {
|
||||
try {
|
||||
$user = Yii::$app->user->getIdentity();
|
||||
} catch (\Throwable $e) {
|
||||
Yii::error($e, 'space');
|
||||
}
|
||||
}
|
||||
|
||||
if ($user !== null) {
|
||||
|
||||
$spaceIds = array_map(function (Membership $membership) {
|
||||
return $membership->space_id;
|
||||
}, Membership::findAll(['user_id' => $user->id]));
|
||||
|
||||
$this->andWhere(['OR',
|
||||
['space.visibility' => 1],
|
||||
['IN', 'space.id', $spaceIds]
|
||||
]);
|
||||
} else {
|
||||
$this->andWhere(['space.visibility' => 1]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user