Fix: Allow using Space::canJoin($userId) in command line (#7066)

* Fix: Allow using Space::canJoin($userId) in command line

* Add PR ID to CHANGELOG

* Update protected/humhub/modules/space/models/Space.php

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>

* fix last commit

---------

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
Co-authored-by: Lucas Bartholemy <lucas@bartholemy.com>
This commit is contained in:
Marc Farré 2024-10-20 14:07:35 +01:00 committed by GitHub
parent 79e1b2dbf5
commit de0e7f2a23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View File

@ -55,6 +55,8 @@ HumHub Changelog
- Enh #7262: Disable `Like` on archived content
- Enh #7125: Prerequisites - Check test for pending migrations
- Fix #173 : Remove UISetting "Include Captcha in Registr
- Fix #7066: Allow using `Space::canJoin($userId)` in command line
1.16.3 (Unreleased)
--------------------------

View File

@ -21,9 +21,9 @@ use humhub\modules\space\components\UrlValidator;
use humhub\modules\space\Module;
use humhub\modules\space\permissions\CreatePrivateSpace;
use humhub\modules\space\permissions\CreatePublicSpace;
use humhub\modules\space\services\MemberListService;
use humhub\modules\user\behaviors\Followable;
use humhub\modules\user\helpers\AuthHelper;
use humhub\modules\space\services\MemberListService;
use humhub\modules\user\models\Follow;
use humhub\modules\user\models\GroupSpace;
use humhub\modules\user\models\Invite;
@ -331,25 +331,23 @@ class Space extends ContentContainerActiveRecord
/**
* Indicates that this user can join this workspace
*
* @param $userId User Id of User
* @param $userId int|string|null User Id of User
*/
public function canJoin($userId = '')
public function canJoin($userId = null): bool
{
if (Yii::$app->user->isGuest) {
// Take current userId if none is given
$userId ??= Yii::$app->user->id;
if (!$userId) {
return false;
}
// Take current userId if none is given
if ($userId == '') {
$userId = Yii::$app->user->id;
}
// Checks if User is already member
// Checks if User is already a member
if ($this->isMember($userId)) {
return false;
}
if ($this->join_policy == self::JOIN_POLICY_NONE) {
if ($this->join_policy === self::JOIN_POLICY_NONE) {
return false;
}