feat(files_sharing): configure public share link base URL - #62146
Conversation
838a43c to
9df6210
Compare
Documentation for nextcloud/server#62146 Signed-off-by: Ali Aslam <ali.aslam@zohomail.com> Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
|
Documentation added in nextcloud/documentation#15361 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9df62106ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Assisted-by: Codex:GPT-5 Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: Codex:GPT-5 Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: Codex:GPT-5 Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: Codex:GPT-5 Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Build the share link path through the router instead of hardcoding
'/s/{token}' so instances without pretty URLs keep their '/index.php'
front controller prefix when a custom base URL is configured. The
instance webroot is still replaced by the configured base URL.
Also trim surrounding whitespace from the configured value and log a
warning (once per process) when a non-empty value is rejected, instead
of falling back silently.
Assisted-by: ClaudeCode:kimi-k3[1m]
Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
The share notification and note emails still built the share link with the instance URL generator, so recipients received links pointing at the internal host even when shareapi_public_link_base_url was set. Generate them through PublicShareUrlGenerator like the other public share links. Assisted-by: ClaudeCode:kimi-k3[1m] Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Assisted-by: ClaudeCode:kimi-k3[1m] Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
Wrap Server::get(ShareByMailProvider::class) in a try/catch so that if the provider's dependencies cannot be resolved (e.g. PublicShareUrlGenerator from files_sharing is not autoloaded when the app is disabled), the provider factory falls back to null instead of throwing, matching the pattern already used for registered share providers. Assisted-by: ClaudeCode:kimi-k3[1m] Signed-off-by: Ali Aslam <ali.aslam@zohomail.com>
9df6210 to
eded848
Compare
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
come-nc
left a comment
There was a problem hiding this comment.
I’m not entirely sold on the API design, but I’m not sure how I would’ve designed it either.
The fact that it sits in an application is also questionable, is it never needed for other application to get this public share URL?
It’s also ugly to have options in appconfig which are only meant to be set with occ, but it looks like there are precedent and this is not the only one under the core appid for sharing.
| private IGroupManager $groupManager, | ||
| private IUserManager $userManager, | ||
| private IRootFolder $rootFolder, | ||
| private IURLGenerator $urlGenerator, |
There was a problem hiding this comment.
The standard url generator is still used?
There was a problem hiding this comment.
Same question for the other classes where the new generator is injected.
There was a problem hiding this comment.
Yea the standard URL generator is still used for generating every link that’s not a share link. ShareAPIController, DefaultPublicShareTemplateProvider, and SharesReminderJob all still use it for internal URLs. Also, PublicShareUrlGenerator falls back on the standard URL generator when the custom base URL isn’t set.
| $ocs->cleanup(); | ||
| } | ||
|
|
||
| #[\PHPUnit\Framework\Attributes\Group(name: 'RoutingWeirdness')] |
There was a problem hiding this comment.
Why is it in RoutingWeirdness?
There was a problem hiding this comment.
I didn’t know exactly where to put it, RoutingWeirdness made sense since the result depends on the router config (checking if it contains /index.php). testCreateShareLink() uses the same group so I figured it made sense.
| try { | ||
| $this->shareByMailProvider = Server::get(ShareByMailProvider::class); | ||
| } catch (\Throwable $e) { | ||
| $this->logger->warning( | ||
| 'Could not load sharebymail share provider: {message}', | ||
| ['message' => $e->getMessage(), 'exception' => $e], | ||
| ); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Why is this method called when files_sharing is disabled? Does that mean there is a behavior change with this?
There was a problem hiding this comment.
Yea this is a good catch. I put a try/catch to disable sharebymail if we hit this edgecase, but that still creates an unnecessary dependency. In retrospect, putting the code inside of the files_sharing application might not have been the best move, since these are two independent applications and this PR makes sharebymail dependent on files_sharing. Should I move the shared URL generator to core? This is my first PR to the project, so I’m not sure of the exact right place to make this change. Any feedback would be appreciated. Thanks.
Summary
Adds an optional 'shareapi_public_link_base_url' config flag to set a custom base URL just for share links. When unset, Nextcloud behaves exactly the same.
The new "PublicShareUrlGenerator" reads the config value and validates that it's a valid HTTP(S) URL. If it's unset or if the URL is invalid, we fall back to Nextcloud's existing URL generator. Existing references to the current URL generator are replaced with this new one for the OCS Share API URL field, public shares, and public link reminder emails.
At the same time, all URLs unrelated to sharing remain unchanged and still use the standard UrlGenerator.
The web UI is also updated to use the OCS response's URL field, instead of reconstructing the share link from the current base URL. Again, if the flag is unset, we fall back to the existing local construction.
TYPE_EMAIL shares now expose a URL field in the OCS response. Also, ShareByMailProvider now takes PublicShareUrlGenerator, both email paths use it (sendEmail() and sendNote()).
This is my first contribution to this project, so I'd appreciate any feedback or guidance on how to approach the documentation and other details.
Assisted-by: Codex:GPT-5.6
Before:
After:
Updated Documentation PR
TODO
Manual live testing
Screenshots
Update documentation (
occ config:app:set core shareapi_public_link_base_url --value='https://example.com/')Checklist
3. to review, feature component)stable32)AI (if applicable)