@@ -172,36 +172,132 @@ export default {
this.$emit('close-sidebar')
const space = this.$store.state.spaces[this.$route.params.space]
this.allSelectedUsers.forEach(user => {
- let gid = ''
- if (this.$route.params.group !== undefined) {
- // Adding a user to a workspace 'subgroup
- this.$store.dispatch('addUserToGroup', {
- name: this.$route.params.space,
- gid: this.$route.params.group,
- user,
- })
- if (this.isWorkspaceManager(user.role)) {
- this.$store.dispatch('addUserToGroup', {
- name: this.$route.params.space,
- gid: ManagerGroup.getGid(space),
- user,
- })
+ if (this.$route.params.slug !== undefined) {
+ if (decodeURIComponent(this.$route.params.slug).startsWith('SPACE-U')) {
+ this.addUserFromUserGroup(user)
+ return
}
- } else {
- // Adding a user to the workspace
- if (this.isWorkspaceManager(user.role)) {
- gid = ManagerGroup.getGid(space)
+ if (decodeURIComponent(this.$route.params.slug).startsWith('SPACE-GE')) {
+ this.addUserFromManagerGroup(user, space)
+ return
+ }
+ if (Object.keys(space.users).includes(user.uid) && decodeURIComponent(this.$route.params.slug).startsWith('SPACE-G-')) {
+ this.addExistingUserFromSubgroup(user)
} else {
- gid = UserGroup.getGid(space)
+ this.addNewUserFromSubgroup(user, space)
}
- this.$store.dispatch('addUserToGroup', {
- name: this.$route.params.space,
- gid,
- user,
- })
+ } else {
+ this.addUserFromWorkspace(user, space)
}
})
},
+ addUserFromWorkspace(user, space) {
+ let gid = ''
+ if (user.role === 'wm') {
+ gid = ManagerGroup.getGid(space)
+ } else {
+ gid = UserGroup.getGid(space)
+ }
+ this.$store.dispatch('addUserToGroup', {
+ name: this.$route.params.space,
+ gid,
+ user,
+ })
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid,
+ })
+ this.$store.dispatch('incrementSpaceUserCount', {
+ spaceName: this.$route.params.space,
+ })
+ if (user.role === 'wm') {
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: UserGroup.getGid(space),
+ })
+ }
+ },
+ addExistingUserFromSubgroup(user) {
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ })
+ this.$store.dispatch('addUserToGroup', {
+ name: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ user,
+ })
+ },
+ addNewUserFromSubgroup(user, space) {
+ this.$store.dispatch('addUserToGroup', {
+ name: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ user,
+ })
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ })
+ this.$store.dispatch('incrementSpaceUserCount', {
+ spaceName: this.$route.params.space,
+ })
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: UserGroup.getGid(space),
+ })
+ if (user.role === 'wm') {
+ this.$store.dispatch('addUserToGroup', {
+ name: this.$route.params.space,
+ gid: ManagerGroup.getGid(space),
+ user,
+ })
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: ManagerGroup.getGid(space),
+ })
+ }
+ },
+ addUserFromManagerGroup(user, space) {
+ const usersBackup = [...Object.keys(space.users)]
+ this.$store.dispatch('addUserToGroup', {
+ name: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ user,
+ })
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ })
+ if (usersBackup.includes(user.uid)) {
+ return
+ }
+ this.$store.dispatch('addUserToGroup', {
+ name: this.$route.params.space,
+ gid: UserGroup.getGid(space),
+ user,
+ })
+ this.$store.dispatch('incrementSpaceUserCount', {
+ spaceName: this.$route.params.space,
+ })
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: UserGroup.getGid(space),
+ })
+ },
+ addUserFromUserGroup(user) {
+ this.$store.dispatch('addUserToGroup', {
+ name: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ user,
+ })
+ this.$store.dispatch('incrementGroupUserCount', {
+ spaceName: this.$route.params.space,
+ gid: decodeURIComponent(decodeURIComponent(this.$route.params.slug)),
+ })
+ this.$store.dispatch('incrementSpaceUserCount', {
+ spaceName: this.$route.params.space,
+ })
+ },
// Adds user to the batch when user selects user in the MultiSelect
addUserToBatch(user) {
this.allSelectedUsers.push(user)
diff --git a/src/AlertRemoveGroup.vue b/src/AlertRemoveGroup.vue
new file mode 100644
index 000000000..89555355d
--- /dev/null
+++ b/src/AlertRemoveGroup.vue
@@ -0,0 +1,71 @@
+
+ {{ message }}
- {{ t('workspace', 'Are you sure you want to delete the {space} workspace ?', { space }) }}
-
-
+ {{ t('workspace', 'Are you sure you want to delete the {space} workspace ?', { space }) }}
+
+
- {{ t('workspace', $store.getters.isSpaceAdmin(user, $route.params.space) ? 'admin' : 'user') }}
+ {{ t('workspace', $store.getters.isSpaceAdmin(user, $route.params.space) ? 'wm' : 'user') }}
{{ user.groups.map(group => $store.getters.groupName($route.params.space, group)).join(', ') }}
@@ -62,24 +62,36 @@
The error is: {error}', { error: e, group: gid })
+ const message = (e.response && e.response.data && e.response.data.msg) ?? e.message
+ const text = t('workspace', 'A network error occured while trying to create group {group}
The error is: {error}', { error: message, group: gid })
showNotificationError('Network error', text, 4000)
})
},
@@ -123,7 +149,7 @@ export default {
// Naviagte back to home
router.push({
- path: '/',
+ path: `/workspace/${name}`,
})
// Deletes group from backend
@@ -253,8 +279,26 @@ export default {
const space = context.state.spaces[name]
if (context.getters.isSpaceAdmin(user, name)) {
user.groups.splice(user.groups.indexOf(ManagerGroup.getGid(space)), 1)
+ context.commit('DECREMENT_GROUP_USER_COUNT', {
+ spaceName: space.name,
+ gid: ManagerGroup.getGid(space),
+ })
+ context.commit('CHANGE_USER_ROLE', {
+ spaceName: space.name,
+ user,
+ role: 'user',
+ })
} else {
user.groups.push(ManagerGroup.getGid(space))
+ context.commit('INCREMENT_GROUP_USER_COUNT', {
+ spaceName: space.name,
+ gid: ManagerGroup.getGid(space),
+ })
+ context.commit('CHANGE_USER_ROLE', {
+ spaceName: space.name,
+ user,
+ role: 'wm',
+ })
}
const spaceId = space.id
const userId = user.uid
@@ -294,6 +338,44 @@ export default {
updateSpace(context, { space }) {
context.commit('updateSpace', space)
},
+ removeConnectedGroup(context, { spaceId, gid, name }) {
+ axios.delete(generateUrl(`/apps/workspace/spaces/${spaceId}/connected-groups/${gid}`))
+ .then((resp) => {
+ })
+ .catch((e) => {
+ console.error('Error to remove connected group', e.message)
+ console.error(e)
+ })
+
+ context.commit('removeAddedGroupFromSpace', { name, gid })
+
+ // Naviagte back to home
+ router.push({
+ path: `/workspace/${name}`,
+ })
+ },
+ addConnectedGroupToWorkspace(context, { spaceId, group, name }) {
+ const space = context.state.spaces[name]
+ const result = axios.post(generateUrl(`/apps/workspace/spaces/${spaceId}/connected-groups/${group.gid}`))
+ .then(resp => {
+ context.commit('addConnectedGroupToWorkspace', { name, group, slug: resp.data.slug })
+ const users = resp.data.users
+ for (const user in users) {
+ context.commit('addUserToWorkspace', { name, user: users[user] })
+ context.commit('addUserToGroup', { name, gid: group.gid, user: users[user] })
+ context.commit('INCREMENT_ADDED_GROUP_USER_COUNT', { spaceName: name, gid: group.gid })
+ context.commit('INCREMENT_GROUP_USER_COUNT', { spaceName: name, gid: UserGroup.getGid(space) })
+ context.commit('INCREMENT_SPACE_USER_COUNT', { spaceName: name })
+ }
+ return resp.data
+ })
+ .catch(error => {
+ console.error('Error to add connected group', error.message)
+ console.error(error)
+ })
+
+ return result
+ },
setSpaceQuota(context, { name, quota }) {
// Updates frontend
const oldQuota = context.getters.quota(name)
@@ -362,4 +444,36 @@ export default {
})
return resp.data
},
+ loadUsers(context, { space }) {
+ context.commit('SET_LOADING_USERS_WAITTING', ({ activated: false }))
+ context.commit('SET_NO_USERS', ({ activated: false }))
+
+ if (Object.keys(space.users).length === space.userCount) {
+ return
+ }
+
+ context.commit('SET_LOADING_USERS_WAITTING', ({ activated: true }))
+
+ getUsers(space.id)
+ .then(users => {
+ if (Object.keys(users).length === 0) {
+ context.commit('SET_LOADING_USERS_WAITTING', ({ activated: false }))
+ context.commit('SET_NO_USERS', ({ activated: true }))
+ return
+ }
+
+ if (Object.keys(users).length > 0) {
+ context.commit('SET_LOADING_USERS_WAITTING', ({ activated: false }))
+ context.commit('SET_NO_USERS', ({ activated: false }))
+ context.commit('UPDATE_USERS', {
+ space,
+ users,
+ })
+ }
+ })
+ .catch(error => {
+ console.error('Impossible to get users for the workspace.')
+ console.error(error)
+ })
+ },
}
diff --git a/src/store/getters.js b/src/store/getters.js
index 79b378763..a428c4312 100644
--- a/src/store/getters.js
+++ b/src/store/getters.js
@@ -31,7 +31,19 @@ export const getters = {
},
// Returns the name of a group
groupName: state => (name, gid) => {
- return state.spaces[name].groups[gid].displayName
+ if (state.spaces[name].groups[gid]) {
+ return state.spaces[name].groups[gid].displayName
+ }
+ if (state.spaces[name].added_groups[gid]) {
+ return state.spaces[name].added_groups[gid].displayName
+ }
+ return '[' + gid + ']'
+ },
+ getGroupUserCount: state => (spaceName, gid) => {
+ return state.spaces[spaceName].groups[gid].usersCount
+ },
+ getSpaceUserCount: state => (name) => {
+ return state.spaces[name].userCount
},
// Returns the number of users in a group
groupUserCount: state => (spaceName, gid) => {
@@ -47,6 +59,18 @@ 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].added_groups)
+ 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]
+ const gids = Object.keys(space.added_groups)
+ return gids.includes(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)
@@ -66,9 +90,15 @@ export const getters = {
},
// Returns the number of users in a space
spaceUserCount: state => name => {
- const users = state.spaces[name].users
- if (users.length === 0) {
+ if (state.spaces[name] === undefined) {
return 0
+ }
+ if (state.spaces[name].userCount !== undefined && state.spaces[name].userCount > 0) {
+ return state.spaces[name].userCount
+ }
+ const users = state.spaces[name].users
+ if (users === undefined || users.length === 0) {
+ return -1
} else {
return Object.keys(users).length
}
diff --git a/src/store/index.js b/src/store/index.js
index 9cdf80efe..60b920939 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -33,6 +33,8 @@ Vue.config.devtools = true // Debug mode
const store = new Store({
state: {
loading: true,
+ noUsers: false,
+ loadingUsersWaitting: false,
spaces: {},
groupfolders: {},
},
diff --git a/src/store/mutations.js b/src/store/mutations.js
index 19735930b..4e4f3b4e7 100644
--- a/src/store/mutations.js
+++ b/src/store/mutations.js
@@ -80,7 +80,7 @@ const sortGroupfolders = (state) => {
export default {
// Adds a group to a space
- addGroupToSpace(state, { name, gid, displayName = undefined }) {
+ addGroupToSpace(state, { name, gid, displayName = undefined, slug }) {
if (displayName === undefined) {
displayName = gid
}
@@ -88,6 +88,8 @@ export default {
space.groups[gid] = {
gid,
displayName,
+ usersCount: 0,
+ slug,
}
VueSet(state.spaces, name, space)
sortSpaces(state)
@@ -97,6 +99,56 @@ export default {
state.spaces[space.name] = space
sortSpaces(state)
},
+ UPDATE_USERS(state, { space, users }) {
+ space.users = users
+ VueSet(state.spaces, space.name, space)
+ },
+ SET_LOADING_USERS_WAITTING(state, { activated }) {
+ state.loadingUsersWaitting = activated
+ },
+ SET_NO_USERS(state, { activated }) {
+ state.noUsers = activated
+ },
+ INCREMENT_GROUP_USER_COUNT(state, { spaceName, gid }) {
+ const space = state.spaces[spaceName]
+ space.groups[gid].usersCount++
+ VueSet(state.spaces, spaceName, space)
+ },
+ INCREMENT_ADDED_GROUP_USER_COUNT(state, { spaceName, gid }) {
+ const space = state.spaces[spaceName]
+ space.added_groups[gid].usersCount++
+ VueSet(state.spaces, spaceName, space)
+ },
+ INCREMENT_SPACE_USER_COUNT(state, { spaceName }) {
+ const space = state.spaces[spaceName]
+ space.userCount++
+ VueSet(state.spaces, spaceName, space)
+ },
+ DECREMENT_GROUP_USER_COUNT(state, { spaceName, gid }) {
+ const space = state.spaces[spaceName]
+ space.groups[gid].usersCount--
+ VueSet(state.spaces, spaceName, space)
+ },
+ DECREMENT_SPACE_USER_COUNT(state, { spaceName }) {
+ const space = state.spaces[spaceName]
+ space.userCount--
+ VueSet(state.spaces, spaceName, space)
+ },
+ SUBSTRACTION_SPACE_USER_COUNT(state, { spaceName, usersCount }) {
+ const space = state.spaces[spaceName]
+ space.userCount -= usersCount
+ VueSet(state.spaces, spaceName, space)
+ },
+ SUBSTRACTION_GROUP_USER_COUNT(state, { spaceName, gid, usersCount }) {
+ const space = state.spaces[spaceName]
+ space.groups[gid].usersCount -= usersCount
+ VueSet(state.spaces, spaceName, space)
+ },
+ CHANGE_USER_ROLE(state, { spaceName, user, role }) {
+ const space = state.spaces[spaceName]
+ space.users[user.uid].role = role
+ VueSet(state.spaces, spaceName, space)
+ },
// Adds a user to a group
addUserToGroup(state, { name, gid, user }) {
const space = state.spaces[name]
@@ -119,6 +171,12 @@ export default {
VueSet(state.spaces, name, space)
sortSpaces(state)
},
+ addConnectedGroupToWorkspace(state, { name, group, slug }) {
+ const space = state.spaces[name]
+ space.added_groups[group.gid] = { displayName: group.displayName, gid: group.gid, slug, usersCount: 0 }
+ VueSet(state.spaces, name, space)
+ sortSpaces(state)
+ },
// Removes a group from a space
removeGroupFromSpace(state, { name, gid }) {
const space = state.spaces[name]
@@ -136,6 +194,15 @@ export default {
VueSet(state.spaces, name, space)
sortSpaces(state)
},
+ removeAddedGroupFromSpace(state, { name, gid }) {
+ const space = state.spaces[name]
+ // Deletes the group from the space's groups attribute
+ delete space.added_groups[gid]
+ // Saves the space back in the store
+ delete state.spaces[space.name]
+ VueSet(state.spaces, name, space)
+ sortSpaces(state)
+ },
// Removes a user from a group
// TODO: We might need to update the user's groups property too here
removeUserFromGroup(state, { name, gid, user }) {
@@ -199,4 +266,9 @@ export default {
VueSet(state.groupfolders, groupfolder.mount_point, groupfolder)
sortGroupfolders(state)
},
+ TOGGLE_USER_CONNECTED(state, { name, user }) {
+ const space = state.spaces[name]
+ space.users[user.uid].is_connected = !space.users[user.uid].is_connected
+ VueSet(state.spaces, name, space)
+ },
}
diff --git a/src/tests/unit/addUsersTabs.test.js b/src/tests/unit/addUsersTabs.test.js
index bc4de553f..96a77c1a1 100644
--- a/src/tests/unit/addUsersTabs.test.js
+++ b/src/tests/unit/addUsersTabs.test.js
@@ -83,7 +83,7 @@ describe('AddUsersTabs component tests', () => {
]
wrappedSelectUsers.vm.$route.params.space = 'foobar'
- wrappedSelectUsers.vm.$route.params.group = 'subgroup-42'
+ wrappedSelectUsers.vm.$route.params.slug = 'subgroup-42'
wrappedSelectUsers.vm.addUsersToWorkspaceOrGroup()
const count = wrappedSelectUsers.vm.$store.getters.groupUserCount('foobar', 'subgroup-42')
@@ -102,7 +102,7 @@ describe('AddUsersTabs component tests', () => {
},
]
- wrappedSelectUsers.vm.$route.params.group = undefined
+ wrappedSelectUsers.vm.$route.params.slug = undefined
wrappedSelectUsers.vm.addUsersToWorkspaceOrGroup()
const count = wrappedSelectUsers.vm.$store.getters.groupUserCount('foobar', 'SPACE-U-42')
@@ -123,7 +123,7 @@ describe('AddUsersTabs component tests', () => {
},
]
- wrappedSelectUsers.vm.$route.params.group = undefined
+ wrappedSelectUsers.vm.$route.params.slug = undefined
wrappedSelectUsers.vm.addUsersToWorkspaceOrGroup()
const count = wrappedSelectUsers.vm.$store.getters.groupUserCount('foobar', 'SPACE-GE-42')
diff --git a/src/tests/unit/groupfoldersService.test.js b/src/tests/unit/groupfoldersService.test.js
index 19b3974a5..ad4d047fb 100644
--- a/src/tests/unit/groupfoldersService.test.js
+++ b/src/tests/unit/groupfoldersService.test.js
@@ -20,6 +20,7 @@
*
*/
+import { expect } from '@jest/globals'
import { getAll, formatGroups, formatUsers, checkGroupfolderNameExist, enableAcl, addGroupToGroupfolder, addGroupToManageACLForGroupfolder, removeGroupToManageACLForGroupfolder, createGroupfolder, destroy, rename } from '../../services/groupfoldersService.js'
import axios from '@nextcloud/axios'
@@ -285,11 +286,33 @@ describe('destroy', () => {
jest.resetAllMocks()
})
it('calls axios.delete method with proper parameters', async () => {
- axios.delete.mockResolvedValue(responseValue)
- await destroy('foobar')
- expect(axios.delete).toHaveBeenCalledWith('/apps/workspace/api/delete/space', {
- data: { workspace: 'foobar' },
+ const workspace = { id: 1, groupfolderId: 1 }
+ const spaceId = workspace.id
+
+ axios.delete.mockResolvedValue(
+ {
+ http: {
+ statuscode: 200,
+ message: 'The space is deleted.',
+ },
+ data: {
+ name: 'foobar',
+ groups: ['SPACE-WM-1', 'SPACE-U-1'],
+ space_id: 1,
+ groupfolder_id: 1,
+ state: 'delete',
+ },
+ },
+ )
+ axios.delete.mockResolvedValue({ status: 200, data: { ocs: { meta: { status: 'ok' } } } })
+
+ await destroy(workspace)
+
+ expect(axios.delete).toHaveBeenCalledWith(`/apps/workspace/spaces/${spaceId}`, {
+ data: { workspace },
})
+
+ expect(axios.delete).toHaveBeenCalledWith(`/apps/groupfolders/folders/${workspace.groupfolderId}`)
})
it('calls axios.delete 2 times and returns resp.data value', async () => {
const mockAxios = axios.delete.mockImplementationOnce(() => Promise.resolve({ status: 200, ...responseValue }))
diff --git a/src/tests/unit/store.test.js b/src/tests/unit/store.test.js
index 30c602d35..039b4a4cb 100644
--- a/src/tests/unit/store.test.js
+++ b/src/tests/unit/store.test.js
@@ -81,11 +81,15 @@ describe('Vuex store tests', () => {
mutations.addGroupToSpace(state, {
name: 'test-space',
gid: 'test-group',
+ slug: 'test-group',
+ usersCount: 0,
})
expect(state.spaces['test-space'].groups['test-group']).toEqual({
gid: 'test-group',
displayName: 'test-group',
+ slug: 'test-group',
+ usersCount: 0,
})
})
diff --git a/src/tests/unit/workspaceContent.test.js b/src/tests/unit/workspaceContent.test.js
index 32340b20d..6509a6862 100644
--- a/src/tests/unit/workspaceContent.test.js
+++ b/src/tests/unit/workspaceContent.test.js
@@ -125,10 +125,10 @@ describe('Creating spaces with different entries', () => {
{
type: 'group',
id: 'SPACE-GE-421',
- displayname: 'WM-Sri_Lanka'
- }
+ displayname: 'WM-Sri_Lanka',
+ },
],
- statuscode: 201
+ statuscode: 201,
},
})
diff --git a/tests/Unit/Service/UserServiceTest.php b/tests/Unit/Service/UserServiceTest.php
index 522c94ed4..d34e001a9 100644
--- a/tests/Unit/Service/UserServiceTest.php
+++ b/tests/Unit/Service/UserServiceTest.php
@@ -25,27 +25,31 @@
namespace OCA\Workspace\Tests\Unit\Service;
+use OCA\Workspace\Service\Group\ConnectedGroupsService;
use OCA\Workspace\Service\Group\ManagersWorkspace;
use OCA\Workspace\Service\UserService;
-use OCA\Workspace\Service\WorkspaceService;
use OCP\IGroup;
use OCP\IGroupManager;
+use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class UserServiceTest extends TestCase {
- private IGroupManager $groupManager;
- private IUser $user;
- private IUserSession $userSession;
- private LoggerInterface $logger;
- private WorkspaceService $workspaceService;
+ private MockObject&IGroupManager $groupManager;
+ private MockObject&IUser $user;
+ private MockObject&IUserSession $userSession;
+ private MockObject&LoggerInterface $logger;
+ private MockObject&ConnectedGroupsService $connectedGroupService;
+ private MockObject&IURLGenerator $urlGenerator;
public function setUp(): void {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
- $this->workspaceService = $this->createMock(WorkspaceService::class);
+ $this->connectedGroupService = $this->createMock(ConnectedGroupsService::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
// Sets up the user'session
$this->userSession = $this->createMock(IUserSession::class);
@@ -55,7 +59,7 @@ public function setUp(): void {
->willReturn($this->user);
}
- private function createTestUser($id, $name, $email): IUser {
+ private function createTestUser($id, $name, $email): MockObject&IUser {
$mockUser = $this->createMock(IUser::class);
$mockUser->expects($this->any())
->method('getUID')
@@ -69,7 +73,7 @@ private function createTestUser($id, $name, $email): IUser {
return $mockUser;
}
- private function createTestGroup($id, $name, $users): IGroup {
+ private function createTestGroup($id, $name, $users): MockObject&IGroup {
$mockGroup = $this->createMock(IGroup::class);
$mockGroup->expects($this->any())
->method('getGID')
@@ -103,7 +107,9 @@ public function testIsUserGeneralAdmin(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
- $this->logger);
+ $this->logger,
+ $this->connectedGroupService,
+ $this->urlGenerator);
// Runs the method to be tested
$result = $userService->isUserGeneralAdmin();
@@ -131,7 +137,9 @@ public function testIsNotUserGeneralAdmin(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
- $this->logger);
+ $this->logger,
+ $this->connectedGroupService,
+ $this->urlGenerator);
// Runs the method to be tested
$result = $userService->isUserGeneralAdmin();
@@ -146,12 +154,12 @@ public function testIsNotUserGeneralAdmin(): void {
public function testIsSpaceManager(): void {
// Let's say user is in a space manager group
$this->groupManager->expects($this->once())
- ->method('isInGroup')
- ->with($this->user->getUID(), 'SPACE-GE-Test')
+ ->method('isInGroup')
+ ->with($this->user->getUID(), 'SPACE-GE-Test')
->willReturn(true);
$groups = $this->createTestGroup('SPACE-GE-Test', 'GE-Test', [$this->user]);
$this->groupManager->expects($this->once())
- ->method('search')
+ ->method('search')
// TODO Use global constant instead of 'GE-'
->with('SPACE-GE-')
->willReturn([$groups]);
@@ -160,7 +168,9 @@ public function testIsSpaceManager(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
- $this->logger);
+ $this->logger,
+ $this->connectedGroupService,
+ $this->urlGenerator);
$this->userSession->expects($this->once())
->method('getUser')
@@ -180,12 +190,12 @@ public function testIsSpaceManager(): void {
public function testIsNotSpaceManager(): void {
// Let's say user is in a space manager group
$this->groupManager->expects($this->once())
- ->method('isInGroup')
- ->with($this->user->getUID(), 'SPACE-GE-Test')
+ ->method('isInGroup')
+ ->with($this->user->getUID(), 'SPACE-GE-Test')
->willReturn(true);
$groups = $this->createTestGroup('SPACE-GE-Test', 'GE-Test', [$this->user]);
$this->groupManager->expects($this->once())
- ->method('search')
+ ->method('search')
// TODO Use global constant instead of 'GE-'
->with('SPACE-GE-')
->willReturn([$groups]);
@@ -199,7 +209,9 @@ public function testIsNotSpaceManager(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
- $this->logger);
+ $this->logger,
+ $this->connectedGroupService,
+ $this->urlGenerator);
// Runs the method to be tested
$result = $userService->isSpaceManager();
@@ -215,8 +227,8 @@ public function testIsNotSpaceManagerOfSpace(): void {
// Let's say user is manager of the space
$group = $this->createTestGroup('SPACE-GE-1', 'GE-Test', [$this->user]);
$this->groupManager->expects($this->once())
- ->method('isInGroup')
- ->with($this->user->getUID(), $group->getGID())
+ ->method('isInGroup')
+ ->with($this->user->getUID(), $group->getGID())
->willReturn(true);
$this->userSession->expects($this->once())
@@ -228,7 +240,9 @@ public function testIsNotSpaceManagerOfSpace(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
- $this->logger);
+ $this->logger,
+ $this->connectedGroupService,
+ $this->urlGenerator);
// Runs the method to be tested
$result = $userService->isSpaceManagerOfSpace([
@@ -249,8 +263,8 @@ public function testIsSpaceManagerOfSpace(): void {
// Let's say user is not manager of the space
$group = $this->createTestGroup('SPACE-GE-1', 'GE-Test', []);
$this->groupManager->expects($this->once())
- ->method('isInGroup')
- ->with($this->user->getUID(), $group->getGID())
+ ->method('isInGroup')
+ ->with($this->user->getUID(), $group->getGID())
->willReturn(false);
$this->userSession->expects($this->once())
@@ -262,7 +276,9 @@ public function testIsSpaceManagerOfSpace(): void {
$userService = new UserService(
$this->groupManager,
$this->userSession,
- $this->logger);
+ $this->logger,
+ $this->connectedGroupService,
+ $this->urlGenerator);
// Runs the method to be tested
$result = $userService->isSpaceManagerOfSpace([
diff --git a/tests/Unit/Space/SpaceManagerTest.php b/tests/Unit/Space/SpaceManagerTest.php
index cc1e2cbc7..d04cff72c 100644
--- a/tests/Unit/Space/SpaceManagerTest.php
+++ b/tests/Unit/Space/SpaceManagerTest.php
@@ -31,15 +31,26 @@
use OCA\Workspace\Exceptions\BadRequestException;
use OCA\Workspace\Exceptions\WorkspaceNameExistException;
use OCA\Workspace\Folder\RootFolder;
+use OCA\Workspace\Group\AddedGroups\AddedGroups;
+use OCA\Workspace\Group\Admin\AdminGroup;
+use OCA\Workspace\Group\Admin\AdminUserGroup;
+use OCA\Workspace\Group\SubGroups\SubGroup;
+use OCA\Workspace\Group\User\UserGroup as UserWorkspaceGroup;
use OCA\Workspace\Helper\GroupfolderHelper;
use OCA\Workspace\Service\ColorCode;
+use OCA\Workspace\Service\Group\ConnectedGroupsService;
use OCA\Workspace\Service\Group\UserGroup;
use OCA\Workspace\Service\Group\WorkspaceManagerGroup;
+use OCA\Workspace\Service\User\UserFormatter;
+use OCA\Workspace\Service\UserService;
use OCA\Workspace\Service\Workspace\WorkspaceCheckService;
use OCA\Workspace\Space\SpaceManager;
+use OCP\AppFramework\Http;
use OCP\IGroup;
+use OCP\IGroupManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
class SpaceManagerTest extends TestCase {
@@ -57,6 +68,26 @@ class SpaceManagerTest extends TestCase {
private MockObject&ColorCode $colorCode;
+ private MockObject&AdminGroup $adminGroup;
+
+ private MockObject&AdminUserGroup $adminUserGroup;
+
+ private MockObject&AddedGroups $addedGroups;
+
+ private MockObject&SubGroup $subGroup;
+
+ private MockObject&UserWorkspaceGroup $userWorkspaceGroup;
+
+ private MockObject&ConnectedGroupsService $conntectedGroupService;
+
+ private MockObject&UserFormatter $userFormatter;
+
+ private MockObject&UserService $userService;
+
+ private MockObject&IGroupManager $groupManager;
+
+ private MockObject&LoggerInterface $logger;
+
private SpaceManager $spaceManager;
public function setUp(): void {
@@ -69,13 +100,34 @@ public function setUp(): void {
$this->spaceMapper = $this->createMock(SpaceMapper::class);
$this->workspaceManagerGroup = $this->createMock(WorkspaceManagerGroup::class);
$this->colorCode = $this->createMock(ColorCode::class);
+ $this->adminGroup = $this->createMock(AdminGroup::class);
+ $this->adminUserGroup = $this->createMock(AdminUserGroup::class);
+ $this->addedGroups = $this->createMock(AddedGroups::class);
+ $this->subGroup = $this->createMock(SubGroup::class);
+ $this->userWorkspaceGroup = $this->createMock(UserWorkspaceGroup::class);
+ $this->conntectedGroupService = $this->createMock(ConnectedGroupsService::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->userFormatter = $this->createMock(UserFormatter::class);
+ $this->userService = $this->createMock(UserService::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
+
$this->spaceManager = new SpaceManager(
$this->folderHelper,
$this->rootFolder,
$this->workspaceCheck,
$this->userGroup,
+ $this->adminGroup,
+ $this->adminUserGroup,
+ $this->addedGroups,
+ $this->subGroup,
+ $this->userWorkspaceGroup,
$this->spaceMapper,
+ $this->conntectedGroupService,
+ $this->logger,
+ $this->userFormatter,
+ $this->userService,
+ $this->groupManager,
$this->workspaceManagerGroup,
$this->colorCode
);
@@ -143,12 +195,24 @@ public function testArrayAfterCreatedTheEspace01Workspace(): void {
->willReturn('WM-Espace01')
;
+ $workspaceManagerGroupMock
+ ->expects($this->once())
+ ->method('count')
+ ->willReturn(0)
+ ;
+
$userGroupMock = $this->createMock(IGroup::class);
$userGroupMock
->expects($this->any())
->method('getGID')
->willReturn('SPACE-U-1')
;
+ $userGroupMock
+ ->expects($this->once())
+ ->method('count')
+ ->willReturn(0)
+ ;
+
$userGroupMock
->expects($this->any())
->method('getDisplayName')
@@ -186,12 +250,19 @@ public function testArrayAfterCreatedTheEspace01Workspace(): void {
'SPACE-GE-1' => [
'gid' => 'SPACE-GE-1',
'displayName' => 'WM-Espace01',
+ 'types' => [],
+ 'usersCount' => 0,
+ 'slug' => 'SPACE-GE-1'
],
'SPACE-U-1' => [
'gid' => 'SPACE-U-1',
'displayName' => 'U-Espace01',
+ 'types' => [],
+ 'usersCount' => 0,
+ 'slug' => 'SPACE-U-1'
],
],
+ 'added_groups' => (object)[],
'quota' => -3,
'size' => 0,
'acl' => true,
@@ -202,6 +273,7 @@ public function testArrayAfterCreatedTheEspace01Workspace(): void {
'displayname' => 'WM-Espace01',
],
],
+ 'userCount' => 0,
]
);
}
@@ -243,6 +315,7 @@ public function testWorkspaceAlreadyExist(): void {
$this->assertInstanceOf(AbstractNotification::class, $e);
$this->assertEquals('Error - Duplicate space name', $e->getTitle());
$this->assertEquals("This space or groupfolder already exist. Please, input another space.\nIf \"toto\" space exist, you cannot create the \"tOTo\" space.\nMake sure you the groupfolder doesn't exist.", $e->getMessage());
+ $this->assertEquals(Http::STATUS_CONFLICT, $e->getCode());
throw $e;
}
}