-
Notifications
You must be signed in to change notification settings - Fork 32
enh(Sharing): backend infrastructre for read-only link shares #2211
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
blizzz
wants to merge
2
commits into
main
Choose a base branch
from
enh/noid/link-share-biz
base: main
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ Share your tables and views with users and groups within your cloud. | |
| Have a good time and manage whatever you want. | ||
|
|
||
| ]]></description> | ||
| <version>2.0.0-alpha.1</version> | ||
| <version>2.0.0-alpha.2</version> | ||
| <licence>agpl</licence> | ||
| <author mail="[email protected]">Florian Steffens</author> | ||
| <namespace>Tables</namespace> | ||
|
|
||
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,35 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Tables\Controller; | ||
|
|
||
| use OCA\Tables\Errors\BadRequestError; | ||
| use OCA\Tables\Errors\InternalError; | ||
| use OCA\Tables\Errors\NotFoundError; | ||
| use OCA\Tables\Errors\PermissionError; | ||
| use OCA\Tables\Service\ColumnService; | ||
|
|
||
| abstract class ACommonColumnsController extends AOCSController { | ||
| protected ColumnService $service; | ||
|
|
||
| /** | ||
| * @throws PermissionError | ||
| * @throws NotFoundError | ||
| * @throws InternalError | ||
| * @throws BadRequestError | ||
| */ | ||
| protected function getColumnsFromTableOrView(string $nodeType, int $nodeId, ?string $overriddenUserid = null): array { | ||
| if ($nodeType === 'table') { | ||
| return $this->service->findAllByTable($nodeId, $overriddenUserid); | ||
| } | ||
| if ($nodeType === 'view') { | ||
| return $this->service->findAllByView($nodeId, $overriddenUserid); | ||
| } | ||
| throw new BadRequestError('Invalid node type provided'); | ||
| } | ||
| } |
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,86 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Tables\Controller; | ||
|
|
||
| use InvalidArgumentException; | ||
| use OCA\Tables\Errors\BadRequestError; | ||
| use OCA\Tables\Errors\InternalError; | ||
| use OCA\Tables\Errors\NotFoundError; | ||
| use OCA\Tables\Errors\PermissionError; | ||
| use OCA\Tables\ResponseDefinitions; | ||
| use OCA\Tables\Service\ColumnService; | ||
| use OCA\Tables\Service\ShareService; | ||
| use OCA\Tables\Service\ValueObject\ShareToken; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\Attribute\ApiRoute; | ||
| use OCP\AppFramework\Http\Attribute\OpenAPI; | ||
| use OCP\AppFramework\Http\Attribute\PublicPage; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\IL10N; | ||
| use OCP\IRequest; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| /** | ||
| * @psalm-import-type TablesPublicColumn from ResponseDefinitions | ||
| */ | ||
| class ApiPublicColumnsController extends ACommonColumnsController { | ||
|
|
||
| public function __construct( | ||
| protected ColumnService $service, | ||
| protected ShareService $shareService, | ||
| IRequest $request, | ||
| LoggerInterface $logger, | ||
| IL10N $l, | ||
| ) { | ||
| parent::__construct($request, $logger, $l, ''); | ||
| } | ||
|
|
||
| /** | ||
| * [api v2] Get all columns for a table or a view shared by link | ||
| * | ||
| * Return an empty array if no columns were found | ||
| * | ||
| * @param string $token The share token | ||
| * @return DataResponse<Http::STATUS_OK, list<TablesPublicColumn>, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}> | ||
| * | ||
| * 200: Columns are returned | ||
| * 400: Invalid request parameters | ||
| * 403: No permissions | ||
| * 404: Not found | ||
| * 500: Internal error | ||
| */ | ||
| #[PublicPage] | ||
| #[ApiRoute(verb: 'GET', url: '/api/2/public/{token}/columns')] | ||
| #[OpenAPI] | ||
| public function indexByPublicLink(string $token): DataResponse { | ||
| try { | ||
| $shareToken = new ShareToken($token); | ||
| } catch (InvalidArgumentException $e) { | ||
| return $this->handleBadRequestError(new BadRequestError( | ||
| 'Invalid share token', $e->getCode(), $e | ||
| )); | ||
| } | ||
|
|
||
| try { | ||
| $share = $this->shareService->findByToken($shareToken); | ||
| $columns = $this->getColumnsFromTableOrView($share->getNodeType(), $share->getNodeId(), ''); | ||
|
|
||
| $formattedTableColumns = $this->service->formatColumnsForPublicShare($columns); | ||
| return new DataResponse($formattedTableColumns); | ||
| } catch (PermissionError $e) { | ||
| return $this->handlePermissionError($e); | ||
| } catch (InternalError $e) { | ||
| return $this->handleError($e); | ||
| } catch (NotFoundError $e) { | ||
| return $this->handleNotFoundError($e); | ||
| } catch (BadRequestError $e) { | ||
| return $this->handleBadRequestError($e); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
we don't use
#[AssertShareToken]here too?