-
Notifications
You must be signed in to change notification settings - Fork 68
feat: automatically create a teamfolder upon team creation #2675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stediefan
wants to merge
3
commits into
nextcloud:master
Choose a base branch
from
Dataport:feature/teams-auto-folder-creation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| /* extracted by css-entry-points-plugin */ | ||
| @import './dashboard-BQNkvnbt.chunk.css'; | ||
| @import './logger-CNf09jSX.chunk.css'; | ||
| @import './NcActionRouter-vYFtIOzD-BuuqIKuh.chunk.css'; | ||
| @import './NcAvatar-DX-Nk9Es-DvtEJIrI.chunk.css'; | ||
| @import './dashboard-DsW2gQLu.chunk.css'; | ||
| @import './index-UyurHCn6.chunk.css'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,3 @@ | ||
| /* extracted by css-entry-points-plugin */ | ||
| @import './main-D5fDg73W.chunk.css'; | ||
| @import './logger-CNf09jSX.chunk.css'; | ||
| @import './NcCheckboxRadioSwitch-BVTMQSAg-rNRsAuW3.chunk.css'; | ||
| @import './NcActionRouter-vYFtIOzD-BuuqIKuh.chunk.css'; | ||
| @import './index-B8JF8h-K.chunk.css'; | ||
| @import './NcAvatar-DX-Nk9Es-DvtEJIrI.chunk.css'; | ||
| @import './index-bfXBK-tQ.chunk.css'; | ||
| @import './index--xyrXnuf.chunk.css'; | ||
| @import './NcSettingsSection-DmfxX2se-D7mIRwIy.chunk.css'; | ||
| @import './main-CFgzRPpb.chunk.css'; | ||
| @import './index-UyurHCn6.chunk.css'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| /* extracted by css-entry-points-plugin */ | ||
| @import './settings-admin-D9UlOAjC.chunk.css'; | ||
| @import './logger-CNf09jSX.chunk.css'; | ||
| @import './NcCheckboxRadioSwitch-BVTMQSAg-rNRsAuW3.chunk.css'; | ||
| @import './NcSettingsSection-DmfxX2se-D7mIRwIy.chunk.css'; | ||
| @import './settings-admin-BEZBKJuE.chunk.css'; | ||
| @import './index-UyurHCn6.chunk.css'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /* extracted by css-entry-points-plugin */ | ||
| @import './settings-team-folders-Kw2lcKKl.chunk.css'; | ||
| @import './index-UyurHCn6.chunk.css'; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Circles\Controller; | ||
|
|
||
| use OCA\Circles\Db\CircleRequest; | ||
| use OCA\Circles\Exceptions\CircleNotFoundException; | ||
| use OCA\Circles\Exceptions\InsufficientPermissionException; | ||
| use OCA\Circles\Service\PermissionService; | ||
| use OCA\Circles\Service\TeamFolderPolicy; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\AppFramework\OCS\OCSException; | ||
| use OCP\AppFramework\OCS\OCSNotFoundException; | ||
| use OCP\AppFramework\OCSController; | ||
| use OCP\AppFramework\Http\Attribute\NoAdminRequired; | ||
| use OCP\IRequest; | ||
| use OCP\IUser; | ||
| use OCP\IUserSession; | ||
| use OCP\Teams\ITeamManager; | ||
| use OCP\Teams\Team; | ||
|
|
||
| class TeamFolderController extends OCSController { | ||
| public function __construct( | ||
| string $appName, | ||
| IRequest $request, | ||
| private readonly ITeamManager $teamManager, | ||
| private readonly TeamFolderPolicy $policy, | ||
| private readonly CircleRequest $circleRequest, | ||
| private readonly PermissionService $permissionService, | ||
| private readonly IUserSession $userSession, | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
| } | ||
|
|
||
| #[NoAdminRequired] | ||
| public function getTeamFolder(string $circleId): DataResponse { | ||
| $this->requireMember($circleId); | ||
| $folder = $this->getProvider()->getTeamFolder($circleId); | ||
| if ($folder === null) { | ||
| throw new OCSNotFoundException('No team folder linked to this team'); | ||
| } | ||
|
|
||
| return new DataResponse($folder->jsonSerialize()); | ||
| } | ||
|
|
||
| #[NoAdminRequired] | ||
| public function upgradeTeamFolder(string $circleId): DataResponse { | ||
| $circle = $this->getCircle($circleId); | ||
| $this->requireTeamAdmin($circleId); | ||
| $folder = $this->getProvider()->createTeamFolder( | ||
| new Team( | ||
| teamId: $circle->getSingleId(), | ||
| displayName: $circle->getDisplayName(), | ||
| link: null, | ||
| ), | ||
| $this->policy->getDefaultQuota(), | ||
| ); | ||
|
|
||
| return new DataResponse([ | ||
| 'success' => true, | ||
| 'folderId' => $folder->getId(), | ||
| 'folder' => $folder->jsonSerialize(), | ||
| ]); | ||
| } | ||
|
|
||
| #[NoAdminRequired] | ||
| public function unlinkTeamFolder(string $circleId, bool $deleteFolder = false): DataResponse { | ||
| $this->requireTeamOwner($circleId); | ||
| $provider = $this->getProvider(); | ||
| if ($deleteFolder) { | ||
| $changed = $provider->removeTeamFolder($circleId); | ||
| } else { | ||
| $changed = $provider->unlinkTeamFolder($circleId) !== null; | ||
| } | ||
| if (!$changed) { | ||
| throw new OCSNotFoundException('No team folder linked to this team'); | ||
| } | ||
|
|
||
| return new DataResponse(['success' => true]); | ||
| } | ||
|
|
||
| private function getProvider(): \OCP\Teams\ITeamFolderProvider { | ||
| $provider = $this->teamManager->getTeamFolderProvider(); | ||
| if ($provider === null) { | ||
| throw new OCSNotFoundException('No team folder provider is enabled'); | ||
| } | ||
|
|
||
| return $provider; | ||
| } | ||
|
|
||
| private function getCircle(string $circleId): \OCA\Circles\Model\Circle { | ||
| try { | ||
| return $this->circleRequest->getCircle($circleId); | ||
| } catch (CircleNotFoundException) { | ||
| throw new OCSNotFoundException('Team not found'); | ||
| } | ||
| } | ||
|
|
||
| private function requireMember(string $circleId): void { | ||
|
stediefan marked this conversation as resolved.
Outdated
|
||
| try { | ||
| $this->permissionService->userMustBeMember($this->getAuthenticatedUser()->getUID(), $circleId); | ||
| } catch (InsufficientPermissionException $e) { | ||
| throw new OCSException($e->getMessage(), Http::STATUS_FORBIDDEN); | ||
| } | ||
| } | ||
|
|
||
| private function requireTeamAdmin(string $circleId): void { | ||
| try { | ||
| $this->permissionService->userMustBeAtLeastTeamAdminOrServerAdmin($this->getAuthenticatedUser()->getUID(), $circleId); | ||
| } catch (InsufficientPermissionException $e) { | ||
| throw new OCSException($e->getMessage(), Http::STATUS_FORBIDDEN); | ||
| } | ||
| } | ||
|
|
||
| private function requireTeamOwner(string $circleId): void { | ||
| try { | ||
| $member = $this->permissionService->userMustBeMember($this->getAuthenticatedUser()->getUID(), $circleId); | ||
| $this->permissionService->memberMustBeOwner($member); | ||
| } catch (InsufficientPermissionException $e) { | ||
| throw new OCSException($e->getMessage(), Http::STATUS_FORBIDDEN); | ||
| } | ||
| } | ||
|
|
||
| private function getAuthenticatedUser(): IUser { | ||
| $user = $this->userSession->getUser(); | ||
| if ($user === null) { | ||
| throw new OCSException('Authentication required', Http::STATUS_UNAUTHORIZED); | ||
| } | ||
|
|
||
| return $user; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should handle this on on this PR, but rather upon release on a separate PR