Skip to content

Commit

Permalink
feat(vue,php): Create an API for attaching a group to a workspace
Browse files Browse the repository at this point in the history
Fixes the issue where "Password confirmation is required" by allowing groups to be attached without needing password confirmation.
  • Loading branch information
zak39 committed Oct 15, 2024
1 parent 4421ab7 commit bbcfa5d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
'url' => '/api/group',
'verb' => 'POST',
],
[
'name' => 'group#attachGroupToSpace',
'url' => '/spaces/{spaceId}/group-attach',
'verb' => 'POST',
],
[
'name' => 'group#delete',
'url' => '/api/group/{gid}',
Expand Down
15 changes: 15 additions & 0 deletions lib/Controller/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\Workspace\Service\User\UserFormatter;
use OCA\Workspace\Service\User\UserWorkspace;
use OCA\Workspace\Service\UserService;
use OCA\Workspace\Space\SpaceManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
Expand All @@ -52,6 +53,7 @@ public function __construct(
private GroupsWorkspaceService $groupsWorkspace,
private IGroupManager $groupManager,
private LoggerInterface $logger,
private SpaceManager $spaceManager,
private IUserManager $userManager,
private UserFormatter $userFormatter,
private UserService $userService,
Expand Down Expand Up @@ -369,6 +371,19 @@ public function removeUser(
]);
}

/**
* @NoAdminRequired
* @GeneralManagerRequired
*/
public function attachGroupToSpace(int $spaceId, string $gid) {
$workspace = $this->spaceManager->get($spaceId);
$this->spaceManager->attachGroup($workspace['groupfolder_id'], $gid);

return new JSONResponse([
'message' => sprintf('The %s group is attached to the %s workspace (i.e groupfolder)', $gid, $workspace['name']),
], Http::STATUS_ACCEPTED);
}

/**
* @NoAdminRequired
* @GeneralManagerRequired
Expand Down
15 changes: 15 additions & 0 deletions lib/Space/SpaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ public function create(string $spacename): array {
];
}

public function get(int $spaceId): array {

$space = $this->spaceMapper->find($spaceId)->jsonSerialize();
$workspace = array_merge(
$this->folderHelper->getFolder($space['groupfolder_id'], $this->rootFolder->getRootFolderStorageId()),
$space
);

return $workspace;
}

public function attachGroup(int $folderId, string $gid): void {
$this->folderHelper->addApplicableGroup($folderId, $gid);
}

/**
* @param string $spaceName it's the space name
* @return string whithout the blank to start and end of the space name
Expand Down
23 changes: 23 additions & 0 deletions src/services/spaceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,26 @@ export function isSpaceUsers(group) {
const SPACE_USER_REGEX = new RegExp('^' + PREFIX_USER)
return SPACE_USER_REGEX.test(group)
}

/**
* @param {number} spaceId of a workspace
* @param {string} gid it's an id (string format) of a group
* @return {Promise}
* @throws {AddGroupToGroupfolderError}
*/
export function addGroupToWorkspace(spaceId, gid) {
return axios.post(generateUrl(`/apps/workspace/spaces/${spaceId}/group-attach`), {
gid

Check failure on line 113 in src/services/spaceService.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 tabs but found 6 spaces
})

Check failure on line 114 in src/services/spaceService.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 1 tab but found 4 spaces
.then(resp => {
return resp.data
})
.catch(error => {
showNotificationError(
'Error groups',
`Impossible to attach the ${error} group to workspace. May be a problem with the connection ?`,
5000)
console.error(`Impossible to attach the ${gid} group to workspace. May be a problem with the connection ?`, error)
throw new AddGroupToGroupfolderError('Error to add Space Manager group in the groupfolder')

Check failure on line 124 in src/services/spaceService.js

View workflow job for this annotation

GitHub Actions / lint

'AddGroupToGroupfolderError' is not defined
})
}
4 changes: 2 additions & 2 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

import { addGroupToGroupfolder } from '../services/groupfoldersService.js'
import { addGroupToWorkspace } from '../services/spaceService.js'
import { generateUrl } from '@nextcloud/router'
import { PREFIX_GID_SUBGROUP_SPACE, PREFIX_DISPLAYNAME_SUBGROUP_SPACE } from '../constants.js'
import axios from '@nextcloud/axios'
Expand Down Expand Up @@ -99,7 +99,7 @@ export default {
spaceId: space.id
})
.then((resp) => {
addGroupToGroupfolder(space.groupfolderId, resp.data.group.gid)
addGroupToWorkspace(space.id, resp.data.group.gid)
// Navigates to the g roup's details page
context.state.spaces[name].isOpen = true
router.push({
Expand Down

0 comments on commit bbcfa5d

Please sign in to comment.