UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06). Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Service;
|
||||
|
||||
use OCA\Circles\CirclesManager;
|
||||
use OCA\Circles\Model\Member;
|
||||
use OCA\Circles\Model\Membership;
|
||||
use OCA\Talk\Model\Attendee;
|
||||
use OCA\Talk\Model\AttendeeMapper;
|
||||
use OCA\Talk\Room;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\Server;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class MembershipService {
|
||||
|
||||
public function __construct(
|
||||
protected IAppManager $appManager,
|
||||
protected IGroupManager $groupManager,
|
||||
protected AttendeeMapper $attendeeMapper,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param IUser[] $users
|
||||
* @return IUser[]
|
||||
*/
|
||||
public function getUsersWithoutOtherMemberships(Room $room, array $users): array {
|
||||
$users = $this->filterUsersWithOtherGroupMemberships($room, $users);
|
||||
$users = $this->filterUsersWithOtherCircleMemberships($room, $users);
|
||||
return $users;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param IUser[] $users
|
||||
* @return IUser[]
|
||||
*/
|
||||
protected function filterUsersWithOtherGroupMemberships(Room $room, array $users): array {
|
||||
$groupAttendees = $this->attendeeMapper->getActorsByType($room->getId(), Attendee::ACTOR_GROUPS);
|
||||
$groupIds = array_map(static function (Attendee $attendee) {
|
||||
return $attendee->getActorId();
|
||||
}, $groupAttendees);
|
||||
|
||||
if (empty($groupIds)) {
|
||||
return $users;
|
||||
}
|
||||
|
||||
return array_filter($users, function (IUser $user) use ($groupIds) {
|
||||
// Only delete users when the user is not member via another group
|
||||
$userGroups = $this->groupManager->getUserGroupIds($user);
|
||||
return empty(array_intersect($userGroups, $groupIds));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Room $room
|
||||
* @param IUser[] $users
|
||||
* @return IUser[]
|
||||
*/
|
||||
protected function filterUsersWithOtherCircleMemberships(Room $room, array $users): array {
|
||||
if (empty($users)) {
|
||||
return $users;
|
||||
}
|
||||
$anyUser = reset($users);
|
||||
if (!$this->appManager->isEnabledForUser('circles', $anyUser)) {
|
||||
Server::get(LoggerInterface::class)->debug('Circles not enabled', ['app' => 'spreed']);
|
||||
return $users;
|
||||
}
|
||||
|
||||
$circleAttendees = $this->attendeeMapper->getActorsByType($room->getId(), Attendee::ACTOR_CIRCLES);
|
||||
$circleIds = array_map(static function (Attendee $attendee) {
|
||||
return $attendee->getActorId();
|
||||
}, $circleAttendees);
|
||||
|
||||
if (empty($circleIds)) {
|
||||
return $users;
|
||||
}
|
||||
|
||||
$circlesManager = Server::get(CirclesManager::class);
|
||||
return array_filter($users, static function (IUser $user) use ($circlesManager, $circleIds) {
|
||||
// Only delete users when the user is not member via another circle
|
||||
$federatedUser = $circlesManager->getFederatedUser($user->getUID(), Member::TYPE_USER);
|
||||
$memberships = $federatedUser->getMemberships();
|
||||
$userCircles = array_map(static function (Membership $membership) {
|
||||
return $membership->getCircleId();
|
||||
}, $memberships);
|
||||
return empty(array_intersect($userCircles, $circleIds));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user