Initial import of space_profiles module
This commit is contained in:
37
helpers/ProfileAccess.php
Normal file
37
helpers/ProfileAccess.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\space_profiles\helpers;
|
||||
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\user\models\User;
|
||||
use Yii;
|
||||
|
||||
class ProfileAccess
|
||||
{
|
||||
public static function canView(Space $space, User $user = null): bool
|
||||
{
|
||||
if ($space->status === Space::STATUS_DISABLED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = $user ?: (!Yii::$app->user->isGuest ? Yii::$app->user->getIdentity() : null);
|
||||
|
||||
if ($user && method_exists($user, 'isSystemAdmin') && $user->isSystemAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($user && method_exists($space, 'isMember') && $space->isMember($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($space->visibility === Space::VISIBILITY_ALL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($space->visibility === Space::VISIBILITY_REGISTERED_ONLY) {
|
||||
return $user !== null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user