Fix visibility of "NEW UPDATES AVAILABLE!" for space creator (#6053)

This commit is contained in:
Yuriy Bakhtin 2023-01-23 13:21:30 +04:00 committed by GitHub
parent 35e0701c5f
commit 2b0aa5b6b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

@ -16,6 +16,7 @@ HumHub Changelog
- Fix #6026: Fix visibility members counter for guests
- Fix #6041: Fix search of obsolete cached objects
- Fix #6043: Fix permission to lock/unlock comment for admin
- Fix #6051: Fix visibility of "NEW UPDATES AVAILABLE!" for space creator
1.13.0 (December 21, 2022)
--------------------------

View File

@ -401,16 +401,21 @@ class SpaceModelMembership extends Behavior
* This can happens after an clicking "Request Membership" Link
* after Approval or accepting an invite.
*
* @param integer $userId
* @param integer $canLeave 0: user cannot cancel membership | 1: can cancel membership | 2: depending on space flag members_can_leave
* @param int $userId
* @param int $canLeave 0: user cannot cancel membership | 1: can cancel membership | 2: depending on space flag members_can_leave
* @param bool $silent add member without any notifications
* @param string $groupId
* @return bool
* @throws \Throwable
* @throws \yii\base\InvalidConfigException
*/
public function addMember($userId, $canLeave = 1, $silent = false)
public function addMember(int $userId, int $canLeave = 1, bool $silent = false, string $groupId = Space::USERGROUP_MEMBER): bool
{
$user = User::findOne(['id' => $userId]);
if (!$user) {
return false;
}
$membership = $this->getMembership($userId);
if ($membership === null) {
@ -419,7 +424,7 @@ class SpaceModelMembership extends Behavior
'space_id' => $this->owner->id,
'user_id' => $userId,
'status' => Membership::STATUS_MEMBER,
'group_id' => Space::USERGROUP_MEMBER,
'group_id' => $groupId,
'can_cancel_membership' => $canLeave
]);
@ -453,9 +458,12 @@ class SpaceModelMembership extends Behavior
// Update Membership
$membership->status = Membership::STATUS_MEMBER;
$membership->group_id = $groupId;
}
$membership->save();
if (!$membership->save()) {
return false;
}
MemberEvent::trigger(Membership::class, Membership::EVENT_MEMBER_ADDED, new MemberEvent([
'space' => $this->owner, 'user' => $user
@ -474,6 +482,8 @@ class SpaceModelMembership extends Behavior
// Delete pending approval request notifications for this user
ApprovalRequest::instance()->from($user)->about($this->owner)->delete();
return true;
}
/**

View File

@ -262,12 +262,7 @@ class Space extends ContentContainerActiveRecord implements Searchable
if ($insert) {
// Auto add creator as admin
$membership = new Membership();
$membership->space_id = $this->id;
$membership->user_id = $user->id;
$membership->status = Membership::STATUS_MEMBER;
$membership->group_id = self::USERGROUP_ADMIN;
$membership->save();
$this->addMember($user->id, 1, true, self::USERGROUP_ADMIN);
$activity = new Created;
$activity->source = $this;