-
Notifications
You must be signed in to change notification settings - Fork 6
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
Integrate files_sharing_webapppassword #61
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c2c80b
Integrate files_sharing_webapppassword
aleixq ffba8f2
Fix share api part settings
aleixq 5256b5f
Fix settings and css of origins sharing api options
aleixq 5151acb
Fix Readme.md url
aleixq ca23896
Rename to match classname
aleixq 4811fda
Concise settings title for webdav
aleixq d159d83
Screenshot with file sharing api
aleixq 1e6ce9f
Change system config key
aleixq 591197b
Clear settings and typo
aleixq 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 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 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 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 |
---|---|---|
|
@@ -9,3 +9,7 @@ | |
#webapppassword-origins { | ||
width: 100%; | ||
} | ||
|
||
#files-sharing-webapppassword-origins { | ||
width: 100%; | ||
} |
This file contains 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 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 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,80 @@ | ||
<?php | ||
declare(strict_types=1); | ||
// SPDX-FileCopyrightText: Aleix Quintana Alsius <kinta@communia.org> | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
namespace OCA\WebAppPassword\Controller; | ||
|
||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCS\OCSNotFoundException; | ||
|
||
trait AccessControl { | ||
/** | ||
* Checks the origin of a request and modifies response. | ||
* | ||
* @param DataResponse $response | ||
* @return DataResponse | ||
* @throws NotFoundException | ||
* @throws OCSBadRequestException | ||
* @throws OCSException | ||
* @throws OCSForbiddenException | ||
* @throws OCSNotFoundException | ||
* @throws InvalidPathException | ||
* @suppress PhanUndeclaredClassMethod | ||
*/ | ||
protected function checkOrigin( DataResponse $response | ||
): DataResponse { | ||
$origins_allowed = $this->getOriginList(); | ||
if (in_array('access-control-allow-origin', $response->getHeaders())) { | ||
throw new OCSNotFoundException($this->l->t('Could not create share')); | ||
} | ||
|
||
$origin = $this->request->getHeader('origin'); | ||
if (empty($origin) || !in_array($origin, $origins_allowed, true)) { | ||
throw new OCSNotFoundException($this->l->t('Could not create share')); | ||
} | ||
|
||
$response->addHeader('access-control-allow-origin', $origin); | ||
$response->addHeader('access-control-allow-methods', $this->request->getHeader('access-control-request-method')); | ||
$response->addHeader('access-control-allow-headers', $this->request->getHeader('access-control-request-headers')); | ||
$response->addHeader('access-control-expose-headers', 'etag, dav'); | ||
$response->addHeader('access-control-allow-credentials', 'true'); | ||
return $response; | ||
} | ||
|
||
/** | ||
* Serializes the allowed origins in a string. | ||
* | ||
* @return string | ||
* List allowed origins separated by commas. | ||
* | ||
*/ | ||
protected function getOrigins(): string | ||
{ | ||
// TODO DI $this->config->getAppValue('files_sharing_origins', 'origins'); | ||
// __construct must be reimplemented as config prop in parent is private... | ||
$config = \OC::$server->getConfig(); | ||
$origins = $config->getAppValue('webapppassword', 'files_sharing_origins'); | ||
|
||
if ($origins === '') { | ||
$origins = implode(',', $config->getSystemValue('webapppassword.files_sharing_origins', [])); | ||
} | ||
|
||
if ($origins === null) { | ||
$origins = ''; | ||
} | ||
|
||
return implode(',', array_map('trim', explode(',', $origins))); | ||
} | ||
|
||
/** | ||
* Gets an array of the defined allowed origins | ||
* | ||
* @return array | ||
* List of allowed origins. | ||
*/ | ||
protected function getOriginList() | ||
{ | ||
return explode(',', $this->getOrigins()); | ||
} | ||
} |
This file contains 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.
Aren't those Nextcloud routes? Why do they need to be included in webapppassword?
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.
In fact it is reimplementing the files_sharing api in webapppassword namespace to be able to apply the filtering of origins.
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.
Ok, I see. This really should belong into Nextcloud core. 😅
Can you please mention that there are new sharing endpoints on the settings, like you did in the README.
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.
Added, and restructured the settings to sections. It may include the copy url button and the real base url but this may add noise to this MR. maybe in next merge requests...