Skip to content

Commit

Permalink
Handle Added groups list (sidebar) and group's users list view
Browse files Browse the repository at this point in the history
  • Loading branch information
smarinier authored and zak39 committed Jun 14, 2024
1 parent 64e1d63 commit 9e4f5f8
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/Group/GroupBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return [];
}

$groups = $this->connectedGroups->getConnectedGroupsToSpace($gid);
$groups = $this->connectedGroups->getConnectedGroupsToSpaceGroup($gid);
if ($groups === null) {
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/Group/ConnectedGroupsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getConnectedSpaceToGroupIds(string $gid): ?array {
* @param string $spaceGid
* @return array|null
*/
public function getConnectedGroupsToSpace(string $spaceGid): ?array {
public function getConnectedGroupsToSpaceGroup(string $spaceGid): ?array {
if (!isset(self::$LINKED_SPACE_GROUPS[$spaceGid])) {
return null;
}
Expand All @@ -96,7 +96,7 @@ public function getConnectedGroupsToSpace(string $spaceGid): ?array {
* @param string $gid
* @return bool
*/
public function hasConnectedgroups(string $gid) : bool {
public function hasConnectedGroups(string $gid) : bool {
return isset(self::$LINKED_SPACE_GROUPS[$gid]);
}
}
21 changes: 17 additions & 4 deletions lib/Service/WorkspaceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace OCA\Workspace\Service;

use OCA\Workspace\Db\SpaceMapper;
use OCA\Workspace\Service\Group\ConnectedGroupsService;
use OCA\Workspace\Service\Group\GroupFormatter;
use OCA\Workspace\Service\Group\UserGroup;
use OCA\Workspace\Service\Group\WorkspaceManagerGroup;
Expand All @@ -47,7 +48,8 @@ public function __construct(
private SpaceMapper $spaceMapper,
private UserService $userService,
private ShareMembersOnlyFilter $shareMembersFilter,
private GroupMembersOnlyChecker $memberGroupOnlyChecker
private GroupMembersOnlyChecker $memberGroupOnlyChecker,
private ConnectedGroupsService $connectedGroups,
) {
}

Expand Down Expand Up @@ -194,12 +196,23 @@ public function addUsersInfo(string|array $workspace): \stdClass {
*
*/
public function addGroupsInfo(array|string $workspace): array {
if (!isset($workspace['groups'])) {
return $workspace;
}
$groups = array_map(
fn($gid) => $this->groupManager->get($gid),
array_keys($workspace['groups'])
);
fn($gid) => $this->groupManager->get($gid),
array_keys($workspace['groups'])
);
$addedGroups = [];
foreach(array_keys($workspace['groups']) as $gid) {
$addedToGroup = $this->connectedGroups->getConnectedGroupsToSpaceGroup($gid);
if ($addedToGroup !== null) {
$addedGroups = array_merge($addedGroups, $addedToGroup);
}
}

$workspace['groups'] = GroupFormatter::formatGroups($groups);
$workspace['addedGroups'] = GroupFormatter::formatGroups($addedGroups);

return $workspace;
}
Expand Down
10 changes: 8 additions & 2 deletions src/GroupDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{ $store.getters.groupName($route.params.space, $route.params.group) }}
</span>
</div>
<div class="group-actions">
<div v-if="!isAddedGroup" class="group-actions">
<div>
<NcActions default-icon="icon-add">
<NcActionButton icon="icon-add"
Expand Down Expand Up @@ -61,7 +61,7 @@
</NcActions>
</div>
</div>
<UserTable :space-name="$route.params.group" />
<UserTable :space-name="$route.params.group" :editable="!isAddedGroup" />
<NcModal v-if="showSelectUsersModal"
@close="toggleShowSelectUsersModal">
<SelectUsers :space-name="$route.params.group" @close="toggleShowSelectUsersModal" />
Expand Down Expand Up @@ -95,6 +95,12 @@ export default {
showSelectUsersModal: false, // true to display user selection Modal windows
}
},
computed: {
// The title to display at the top of the page
isAddedGroup() {
return this.$store.getters.isSpaceAddedGroup(this.$route.params.space, this.$route.params.group)
},
},
methods: {
deleteGroup() {
// Prevents deleting GE- and U- groups
Expand Down
6 changes: 5 additions & 1 deletion src/GroupMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export default {
spaceName: {
type: String,
required: true,
},
addedGroup: {
type: Boolean,
required: false,
default: false,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/SelectConnectedGroups.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="container-select-groups">
<header class="header-select-groups">
<h1>Connect a group</h1>
<h1>{{t('workspace', 'Add a group')}}</h1>
</header>

<div class="body-select-groups">
Expand Down
7 changes: 4 additions & 3 deletions src/SpaceDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@click="toggleShowSelectUsersModal" />
<NcActionButton v-show="!createGroup"
icon="icon-group"
:title="t('workspace', 'Create group')"
:title="t('workspace', 'Create a workspace group')"
class="no-bold"
@click="toggleCreateGroup" />
<NcActionInput v-show="createGroup"
Expand All @@ -60,8 +60,9 @@
@submit="onNewGroup">
{{ t('workspace', 'Group name') }}
</NcActionInput>
<NcActionButton name="Connect a group"
icon="icon-group"
<NcActionButton
:name="t('workspace', 'Add a group')"
icon="icon-added-group"
class="no-bold"
:close-after-click="true"
@click="toggleShowConnectedGroups" />
Expand Down
14 changes: 9 additions & 5 deletions src/SpaceMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@
{{ $store.getters.spaceUserCount(spaceName) }}
</NcCounterBubble>
<NcAppNavigationCaption
title="Workspace Groups" />
:title="t('workspace', 'Workspace groups')" />
<GroupMenuItem
v-for="group in sortedGroups(Object.values(space.groups), spaceName)"
v-for="group in sortedGroups(Object.values(space.groups ?? []), spaceName)"
:key="group.gid"
:group="group"
:space-name="spaceName" />
<NcAppNavigationCaption
title="Connected Groups" />
:title="t('workspace', 'Added groups')" />
<GroupMenuItem
v-for="group in sortedGroups(Object.values(space.addedGroups ?? []), spaceName)"
:key="group.gid"
:group="group"
:space-name="spaceName"
:added-group="true" />
</NcAppNavigationItem>
</template>

Expand Down Expand Up @@ -77,9 +83,7 @@ export default {
},
beforeMount() {
// console.debug(this.space.groups.types)
// const groupnames =
// const workspaceGroups = this.space.groups.filter((groupname))

// this.workspaceGroups.push()
},
methods: {
Expand Down
4 changes: 2 additions & 2 deletions src/UserTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@
: t('workspace', 'Remove admin rights')
}}
</NcActionButton>
<NcActionButton v-if="$route.params.group === undefined"
<NcActionButton v-if="($route.params.group === undefined) && !$store.getters.isFromAddedGroups(user, $route.params.space)"
icon="icon-delete"
:close-after-click="true"
@click="deleteUser(user)">
{{ t('workspace', 'Delete user') }}
</NcActionButton>
<NcActionButton v-if="$route.params.group !== undefined"
<NcActionButton v-if="(($route.params.group !== undefined) && !$store.getters.isSpaceAddedGroup($route.params.space, $route.params.group)) && (!$store.getters.isFromAddedGroups(user, $route.params.space) || ($store.getters.GEGroup($route.params.space) === $route.params.group))"
icon="icon-delete"
:close-after-click="true"
@click="removeFromGroup(user)">
Expand Down
2 changes: 1 addition & 1 deletion src/services/groupfoldersService.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function get(groupfolderId) {
const workspace = resp.data.ocs.data
return workspace
} else {
throw new GetGroupfolderError('Impossible to get the groupfolder. May be an error network ?')
return {} // might happen on empty workspaces
}
})
.catch((error) => {
Expand Down
24 changes: 22 additions & 2 deletions src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export const getters = {
},
// Returns the name of a group
groupName: state => (name, gid) => {
return state.spaces[name].groups[gid] ? state.spaces[name].groups[gid].displayName : '[' + gid + ']'
if (state.spaces[name].groups[gid]) {
return state.spaces[name].groups[gid].displayName
}
if (state.spaces[name].addedGroups[gid]) {
return state.spaces[name].addedGroups[gid].displayName
}
return '[' + gid + ']'
},
// Returns the number of users in a group
groupUserCount: state => (spaceName, gid) => {
Expand All @@ -47,6 +53,17 @@ export const getters = {
isSpaceAdmin: state => (user, spaceName) => {
return user.groups.includes(ManagerGroup.getGid(state.spaces[spaceName]))
},
// Test whether a user if from and added group from the space
isFromAddedGroups: state => (user, spaceName) => {
const addedGroups = Object.keys(state.spaces[spaceName].addedGroups)
const hasAddedGroups = user.groups.filter((group) => addedGroups.includes(group))
return hasAddedGroups.length > 0
},
// Test if group is from space added groups
isSpaceAddedGroup: state => (spaceName, groupName) => {
const space = state.spaces[spaceName]
return space.addedGroups[groupName]
},
// Tests wheter a group is the GE or U group of a space
isGEorUGroup: (state, getters) => (spaceName, gid) => {
return gid === getters.GEGroup(spaceName) || gid === getters.UGroup(spaceName)
Expand All @@ -66,8 +83,11 @@ export const getters = {
},
// Returns the number of users in a space
spaceUserCount: state => name => {
if (state.spaces[name] === undefined) {
return 0
}
const users = state.spaces[name].users
if (users.length === 0) {
if (users === undefined || users.length === 0) {
return 0
} else {
return Object.keys(users).length
Expand Down

0 comments on commit 9e4f5f8

Please sign in to comment.