Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Controller/ConnectedGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function addGroup(int $spaceId, string $gid): JSONResponse {
}

$space = $this->spaceMapper->find($spaceId);
$spaceArray = $this->spaceManager->get($spaceId);

$this->folderHelper->addApplicableGroup(
$space->getGroupfolderId(),
Expand Down
19 changes: 12 additions & 7 deletions lib/Db/GroupFoldersGroupsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;
use PDO;

class GroupFoldersGroupsMapper extends QBMapper {
protected $db;
Expand Down Expand Up @@ -124,22 +125,26 @@ public function findAddedGroups($groupfolderId) : array|false {
return empty($result) ? false : $result;
}

public function isUserConnectedGroup(string $uid, string $gid): mixed {
/**
* Return all userids from DB user group
*
* @param string $gid
* @return array userids
*/
public function getStrictSpaceUserIds(string $gid): array {

$qb = $this->db->getQueryBuilder();

$query = $qb
->select('*')
->select('uid')
->from('group_user')
->where('uid = :uid')
->andWhere('gid = :gid')
->where('gid = :gid')
->setParameters([
'uid' => $uid,
'gid' => $gid
])
;

$res = $query->executeQuery();

return $res->fetch();
return $res->fetchAll(PDO::FETCH_COLUMN);
}
}
46 changes: 9 additions & 37 deletions lib/Service/Group/ConnectedGroupsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ConnectedGroupsService {

private ?array $linkedSpaceGroups = null;
private array $linkedGroupsWSGroups = [];
private array $strictSpaceUsers = [];

public function __construct(
private IGroupManager $groupManager,
Expand Down Expand Up @@ -162,43 +163,14 @@ public function add(IGroup $group, Space $space): bool {
return true;
}

public function isUserConnectedGroup(string $uid, array $space): bool {

$userIsInConnectedGroup = $this->isUserMemberOfConnectedGroup($uid, $space);
$userIsInUserGroup = $this->isUserMemberOfUserGroup($uid, $space);

return $userIsInConnectedGroup && $userIsInUserGroup;
}

private function isUserMemberOfConnectedGroup(string $uid, array $space): bool {
if (isset($space['groupfolder_id'])) {
$groupfolderId = $space['groupfolder_id'];
} elseif (isset($space['groupfolderId'])) {
$groupfolderId = $space['groupfolderId'];
} else {
$groupfolderId = 0;
}

$connectedGroups = $groupfolderId ? $this->mapper->findAddedGroups($groupfolderId) : false;

if ($connectedGroups === false) {
return false;
}

$user = $this->userManager->get($uid);
$groups = array_map(fn ($group) => $this->groupManager->get($group->getGid()), $connectedGroups);

foreach ($groups as $group) {
if ($group->inGroup($user)) {
return true;
}
/**
* @param string $uid user UID
* @param string $spaceUserGid space-u group
*/
public function isStrictSpaceUser(string $uid, string $spaceUserGid) {
if (!isset($this->strictSpaceUsers[$spaceUserGid])) {
$this->strictSpaceUsers[$spaceUserGid] = $this->mapper->getStrictSpaceUserIds($spaceUserGid);
}

return false;
}

private function isUserMemberOfUserGroup(string $uid, array $space): bool {
$userGroup = $this->userGroup->get($space['id']);
return empty($this->mapper->isUserConnectedGroup($uid, $userGroup));
return in_array($uid, $this->strictSpaceUsers[$spaceUserGid]);
}
}
5 changes: 3 additions & 2 deletions lib/Service/User/UserFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct(
*/
public function formatUsers(array $users, array $groupfolder, string $spaceId): array {
$groupWorkspaceManager = $this->groupsWorkspace->getWorkspaceManagerGroup($spaceId);
$spaceUserGid = UserGroup::get($spaceId);

$usersFormatted = [];
foreach ($users as $user) {
Expand All @@ -56,15 +57,15 @@ public function formatUsers(array $users, array $groupfolder, string $spaceId):
$role = Roles::User;
}

$isConnected = $this->connectedGroupsService->isUserConnectedGroup($user->getUID(), $groupfolder);
$isStrictSpaceUser = $this->connectedGroupsService->isStrictSpaceUser($user->getUID(), $spaceUserGid);

$usersFormatted[$user->getUID()] = [
'uid' => $user->getUID(),
'name' => $user->getDisplayName(),
'email' => $user->getEmailAddress(),
'subtitle' => $user->getEmailAddress(),
'groups' => $this->groupsWorkspace->getGroupsUserFromGroupfolder($user, $groupfolder, $spaceId),
'is_connected' => $isConnected,
'is_connected' => !$isStrictSpaceUser,
'profile' => $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $user->getUID()]),
'role' => $role
];
Expand Down
6 changes: 3 additions & 3 deletions lib/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function formatUser(IUser $user, array $space, string $role): ?array {
$groups = [];

if (!isset($space['groups'])) {
throw new \Exception('The "groups" key is not presetn');
throw new \Exception('The "groups" key is not present');
}

if (!is_array($space['groups'])) {
Expand All @@ -86,7 +86,7 @@ public function formatUser(IUser $user, array $space, string $role): ?array {
}
}

$isConnected = $this->connectedGroups->isUserConnectedGroup($user->getUID(), $space);
$isStrictSpaceUser = $this->connectedGroups->isStrictSpaceUser($user->getUID(), UserGroup::get($space['id']));

return [
'uid' => $user->getUID(),
Expand All @@ -95,7 +95,7 @@ public function formatUser(IUser $user, array $space, string $role): ?array {
'subtitle' => $user->getEmailAddress(),
'groups' => $groups,
'role' => $role,
'is_connected' => $isConnected,
'is_connected' => !$isStrictSpaceUser,
'profile' => $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $user->getUID()])
];
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Users/UserFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ public function formatUser(IUser $user, array $space, string $role): array {
}
}

$spaceUserGid = UserGroup::get($space['id']);

return [
'uid' => $user->getUID(),
'name' => $user->getDisplayName(),
'email' => $user->getEmailAddress(),
'subtitle' => $user->getEmailAddress(),
'groups' => $groups,
'is_connected' => $this->connectedGroupsService->isUserConnectedGroup($user->getUID(), $space),
'is_connected' => !$this->connectedGroupsService->isStrictSpaceUser($user->getUID(), $spaceUserGid),
'profile' => $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $user->getUID()]),
'role' => $role
];
Expand Down
Loading