-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(federation): auto-accept shares from trusted servers #49973
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f753d2f
fix(federation): comply to `sharing.federation.allowSelfSignedCertifi…
skjnldsv 771584f
fix(files_sharing): external share parsing
skjnldsv 5c359e4
feat(federatedfilesharing): auto-accept shares from trusted servers
skjnldsv f6f66d7
fix(federation): settings layout and error handling
skjnldsv b434750
chore(federation): add trusted server auto accept integration tests
skjnldsv e7f6e16
feat(federatedfilesharing): improve admin docs and settings
skjnldsv 669e6ca
chore(federation): cleanup SettingsController and legacy AddServerMid…
skjnldsv 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
Prev
Previous commit
chore(federation): cleanup SettingsController and legacy AddServerMid…
…dleware Signed-off-by: skjnldsv <[email protected]>
- Loading branch information
commit 669e6cadd6bcb73df3f2cf8774e8ee2e3bfb7c77
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
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
skjnldsv marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
|---|---|---|
|
|
@@ -10,18 +10,23 @@ | |
| use OCA\Federation\Settings\Admin; | ||
| use OCA\Federation\TrustedServers; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\Attribute\ApiRoute; | ||
| use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting; | ||
| use OCP\AppFramework\Http\JSONResponse; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\AppFramework\OCS\OCSException; | ||
| use OCP\AppFramework\OCS\OCSNotFoundException; | ||
| use OCP\AppFramework\OCSController; | ||
| use OCP\IL10N; | ||
| use OCP\IRequest; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| class SettingsController extends OCSController { | ||
| public function __construct( | ||
| string $AppName, | ||
| IRequest $request, | ||
| private IL10N $l, | ||
| private TrustedServers $trustedServers, | ||
| private LoggerInterface $logger, | ||
| ) { | ||
| parent::__construct($AppName, $request); | ||
| } | ||
|
|
@@ -31,67 +36,63 @@ public function __construct( | |
| * Add server to the list of trusted Nextcloud servers | ||
| * | ||
| * @param string $url The URL of the server to add | ||
| * @return JSONResponse<Http::STATUS_OK, array{data: array{id: int, message: string, url: string}, status: 'ok'}, array{}>|JSONResponse<Http::STATUS_NOT_FOUND|Http::STATUS_CONFLICT, array{data: array{hint: string, message: string}, status: 'error'}, array{}> | ||
| * @return DataResponse<Http::STATUS_OK, array{id: int, message: string, url: string}, array{}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_CONFLICT, array{message: string}, array{}> | ||
| * | ||
| * 200: Server added successfully | ||
| * 404: Server not found at the given URL | ||
| * 409: Server is already in the list of trusted servers | ||
| */ | ||
| #[AuthorizedAdminSetting(settings: Admin::class)] | ||
| public function addServer(string $url): JSONResponse { | ||
| $check = $this->checkServer(trim($url)); | ||
| if ($check instanceof JSONResponse) { | ||
| return $check; | ||
| } | ||
| #[ApiRoute(verb: 'POST', url: '/trusted-servers')] | ||
| public function addServer(string $url): DataResponse { | ||
| $this->checkServer(trim($url)); | ||
|
|
||
| // Add the server to the list of trusted servers, all is well | ||
| $id = $this->trustedServers->addServer(trim($url)); | ||
skjnldsv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new JSONResponse([ | ||
| 'status' => 'ok', | ||
| 'data' => [ | ||
| 'url' => $url, | ||
| 'id' => $id, | ||
| 'message' => $this->l->t('Added to the list of trusted servers') | ||
| ], | ||
| return new DataResponse([ | ||
| 'url' => $url, | ||
| 'id' => $id, | ||
| 'message' => $this->l->t('Added to the list of trusted servers') | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Add server to the list of trusted Nextcloud servers | ||
| * | ||
| * @param int $id The ID of the trusted server to remove | ||
| * @return JSONResponse<Http::STATUS_OK, array{data: array{id: int}, status: 'ok'}, array{}>|JSONResponse<Http::STATUS_NOT_FOUND, array{data: array{message: string}, status: 'error'}, array{}> | ||
| * @return DataResponse<Http::STATUS_OK, array{id: int}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}> | ||
| * | ||
| * 200: Server removed successfully | ||
| * 404: Server not found at the given ID | ||
| */ | ||
| #[AuthorizedAdminSetting(settings: Admin::class)] | ||
| public function removeServer(int $id): JSONResponse { | ||
| #[ApiRoute(verb: 'DELETE', url: '/trusted-servers/{id}', requirements: ['id' => '\d+'])] | ||
| public function removeServer(int $id): DataResponse { | ||
| try { | ||
| $this->trustedServers->getServer($id); | ||
| } catch (\Exception $e) { | ||
| throw new OCSNotFoundException($this->l->t('No server found with ID: %s', [$id])); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be something else as well, other than server not found. Log the exception at debug level. |
||
| } | ||
|
|
||
| try { | ||
| $this->trustedServers->removeServer($id); | ||
| return new JSONResponse([ | ||
| 'status' => 'ok', | ||
| 'data' => ['id' => $id], | ||
| ]); | ||
| return new DataResponse(['id' => $id]); | ||
| } catch (\Exception $e) { | ||
| return new JSONResponse([ | ||
| 'status' => 'error', | ||
| 'data' => [ | ||
| 'message' => $e->getMessage(), | ||
| ], | ||
| ], Http::STATUS_NOT_FOUND); | ||
| $this->logger->error($e->getMessage(), ['e' => $e]); | ||
| throw new OCSException($this->l->t('Could not remove server'), Http::STATUS_INTERNAL_SERVER_ERROR); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * List all trusted servers | ||
| * | ||
| * @return JSONResponse<Http::STATUS_OK, array{data: list<array{id: int, status: int, url: string}>, status: 'ok'}, array{}> | ||
| * @return DataResponse<Http::STATUS_OK, list<array{id: int, status: int, url: string}>, array{}> | ||
| * | ||
| * 200: List of trusted servers | ||
| */ | ||
| #[AuthorizedAdminSetting(settings: Admin::class)] | ||
| public function getServers(): JSONResponse { | ||
| #[ApiRoute(verb: 'GET', url: '/trusted-servers')] | ||
| public function getServers(): DataResponse { | ||
| $servers = $this->trustedServers->getServers(); | ||
skjnldsv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // obfuscate the shared secret | ||
|
|
@@ -104,47 +105,21 @@ public function getServers(): JSONResponse { | |
| }, $servers); | ||
|
|
||
| // return the list of trusted servers | ||
| return new JSONResponse([ | ||
| 'status' => 'ok', | ||
| 'data' => $servers, | ||
| ]); | ||
| return new DataResponse($servers); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Check if the server should be added to the list of trusted servers or not. | ||
| * | ||
| * @return JSONResponse<Http::STATUS_NOT_FOUND|Http::STATUS_CONFLICT, array{data: array{hint: string, message: string}, status: 'error'}, array{}>|null | ||
| * | ||
| * 404: Server not found at the given URL | ||
| * 409: Server is already in the list of trusted servers | ||
| */ | ||
| #[AuthorizedAdminSetting(settings: Admin::class)] | ||
| protected function checkServer(string $url): ?JSONResponse { | ||
| protected function checkServer(string $url): void { | ||
| if ($this->trustedServers->isTrustedServer($url) === true) { | ||
| $message = 'Server is already in the list of trusted servers.'; | ||
| $hint = $this->l->t('Server is already in the list of trusted servers.'); | ||
| return new JSONResponse([ | ||
| 'status' => 'error', | ||
| 'data' => [ | ||
| 'message' => $message, | ||
| 'hint' => $hint, | ||
| ], | ||
| ], Http::STATUS_CONFLICT); | ||
| throw new OCSException($this->l->t('Server is already in the list of trusted servers.'), Http::STATUS_CONFLICT); | ||
| } | ||
|
|
||
| if ($this->trustedServers->isNextcloudServer($url) === false) { | ||
| $message = 'No server to federate with found'; | ||
| $hint = $this->l->t('No server to federate with found'); | ||
| return new JSONResponse([ | ||
| 'status' => 'error', | ||
| 'data' => [ | ||
| 'message' => $message, | ||
| 'hint' => $hint, | ||
| ], | ||
| ], Http::STATUS_NOT_FOUND); | ||
| throw new OCSNotFoundException($this->l->t('No server to federate with found')); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.