Skip to content

Commit

Permalink
refactor: Remove group folder handling from the back-end
Browse files Browse the repository at this point in the history
  • Loading branch information
zak39 committed Oct 30, 2024
1 parent b438446 commit 9b52774
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
],
[
'name' => 'workspace#destroy',
'url' => '/api/delete/space',
'url' => '/spaces/{spaceId}',
'verb' => 'DELETE'
],
[
Expand Down
21 changes: 14 additions & 7 deletions lib/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCA\Workspace\Service\UserService;
use OCA\Workspace\Service\Workspace\WorkspaceCheckService;
use OCA\Workspace\Service\WorkspaceService;
use OCA\Workspace\Space\SpaceManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
Expand All @@ -64,6 +65,7 @@ public function __construct(
private WorkspaceService $workspaceService,
private UserGroup $userGroup,
private WorkspaceManagerGroup $workspaceManagerGroup,
private SpaceManager $spaceManager,
public $AppName
) {
parent::__construct($AppName, $request);
Expand Down Expand Up @@ -140,12 +142,15 @@ public function createWorkspace(string $spaceName,
*
* @NoAdminRequired
* @GeneralManagerRequired
* @param array $workspace
* @param int $spaceId
*
*/
public function destroy(array $workspace): JSONResponse {
public function destroy(int $spaceId): JSONResponse {
$this->logger->debug('Removing GE users from the WorkspacesManagers group if needed.');
$GEGroup = $this->groupManager->get(WorkspaceManagerGroup::get($workspace['id']));
$space = $this->spaceManager->get($spaceId);
$folderId = $space['groupfolder_id'];

$GEGroup = $this->groupManager->get(WorkspaceManagerGroup::get($spaceId));
foreach ($GEGroup->getUsers() as $user) {
if ($this->userService->canRemoveWorkspaceManagers($user)) {
$this->userService->removeGEFromWM($user);
Expand All @@ -155,21 +160,23 @@ public function destroy(array $workspace): JSONResponse {
// Removes all workspaces groups
$groups = [];
$this->logger->debug('Removing workspaces groups.');
foreach (array_keys($workspace['groups']) as $group) {
foreach (array_keys($space['groups']) as $group) {
$groups[] = $group;
$this->groupManager->get($group)->delete();
}

$this->folderHelper->removeFolder($folderId);

return new JSONResponse([
'http' => [
'statuscode' => 200,
'message' => 'The space is deleted.'
],
'data' => [
'name' => $workspace['name'],
'name' => $space['name'],
'groups' => $groups,
'space_id' => $workspace['id'],
'groupfolder_id' => $workspace['groupfolderId'],
'space_id' => $space['id'],
'groupfolder_id' => $space['groupfolderId'],
'state' => 'delete'
]
]);
Expand Down
8 changes: 8 additions & 0 deletions lib/Helper/GroupfolderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ public function setFolderQuota(int $folderId, int $quota): void {
throw new GroupFolderFunctionException($e->getMessage() . 'Impossible to use the setFolderQuota from FolderManager.');
}
}

public function removeFolder(int $folderId): void {
try {
$this->folderManager->removeFolder($folderId);
} catch (\Exception $e) {
throw new GroupFolderFunctionException($e->getMessage() . 'Impossible to use the removeFolder from FolderManager.');
}
}
}
1 change: 1 addition & 0 deletions lib/Middleware/IsGeneralManagerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\IRequest;
use PHPUnit\Util\Json;

class IsGeneralManagerMiddleware extends Middleware {
public function __construct(
Expand Down
7 changes: 4 additions & 3 deletions src/SpaceDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import SelectUsers from './SelectUsers.vue'
import RemoveSpace from './RemoveSpace.vue'
import UserTable from './UserTable.vue'
import { destroy, rename, checkGroupfolderNameExist } from './services/groupfoldersService.js'

Check failure on line 111 in src/SpaceDetails.vue

View workflow job for this annotation

GitHub Actions / lint

'destroy' is defined but never used
import { removeWorkspace } from './services/spaceService.js'
import showNotificationError from './services/Notifications/NotificationError.js'

export default {
Expand Down Expand Up @@ -148,12 +149,12 @@ export default {
methods: {
// Deletes a space
deleteSpace() {
const space = this.$route.params.space
destroy(this.$store.state.spaces[space])
const space = this.$store.state.spaces[this.$route.params.space]
removeWorkspace(space.id)
.then(resp => {
if (resp.http.statuscode === 200) {
this.$store.dispatch('removeSpace', {
space: this.$store.state.spaces[space],
space,
})
this.$router.push({
path: '/',
Expand Down
31 changes: 16 additions & 15 deletions src/services/groupfoldersService.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ export function getAll() {
* @return {Promise}
* @throws {GetGroupfolderError}
*/
export function get(groupfolderId) {
return axios.get(generateUrl(`/apps/groupfolders/folders/${groupfolderId}`))
.then(resp => {
if (resp.data.ocs.meta.status === 'ok') {
const workspace = resp.data.ocs.data
return workspace
} else {
throw new GetGroupfolderError('Impossible to get the groupfolder. May be an error network ?')
}
})
.catch((error) => {
showNotificationError('Error to get the groupfolder', error.message, 5000)
throw new Error(error.message)
})
}
// export function get(groupfolderId) {
// return axios.get(generateUrl(`/apps/groupfolders/folders/${groupfolderId}`))

Check failure on line 61 in src/services/groupfoldersService.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected tab character
// .then(resp => {

Check failure on line 62 in src/services/groupfoldersService.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected tab character
// if (resp.data.ocs.meta.status === 'ok') {

Check failure on line 63 in src/services/groupfoldersService.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected tab character
// const workspace = resp.data.ocs.data

Check failure on line 64 in src/services/groupfoldersService.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected tab character
// return workspace

Check failure on line 65 in src/services/groupfoldersService.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected tab character
// } else {

Check failure on line 66 in src/services/groupfoldersService.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected tab character
// throw new GetGroupfolderError('Impossible to get the groupfolder. May be an error network ?')

Check failure on line 67 in src/services/groupfoldersService.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected tab character
// }
// })
// .catch((error) => {
// showNotificationError('Error to get the groupfolder', error.message, 5000)
// throw new Error(error.message)
// })
// }

/**
*
Expand Down Expand Up @@ -257,6 +257,7 @@ export function createGroupfolder(spaceName) {

/**
* @param {object} workspace it's an object relative to workspace
* @deprecated
* @return {Promise}
*/
export function destroy(workspace) {
Expand Down
16 changes: 16 additions & 0 deletions src/services/spaceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,19 @@ export function addGroupToWorkspace(spaceId, gid) {
throw new AddGroupToGroupfolderError('Error to add Space Manager group in the groupfolder')
})
}

/**
* @param {integer} spaceId it's the id relative to workspace
* @return {Promise}
*/
export function removeWorkspace(spaceId) {
const result = axios.delete(generateUrl(`/apps/workspace/spaces/${spaceId}`))
.then(resp => {
console.log(`The workspace with the ${spaceId} id, is deleted.`)
return resp.data
})
.catch(error => {
console.error('Error to delete a workspace. May be a problem network ?', error)
})
return result
}

0 comments on commit 9b52774

Please sign in to comment.