Skip to content

Public share middleware & controller - #9518

Merged
rullzer merged 15 commits into
masterfrom
feature/5986/public_share_controller_middleware
Jun 21, 2018
Merged

Public share middleware & controller#9518
rullzer merged 15 commits into
masterfrom
feature/5986/public_share_controller_middleware

Conversation

@rullzer

@rullzerrullzer commented May 18, 2018

Copy link
Copy Markdown
Member

Fixes#5986

@juliushaertl as discussed.

Todo:

  • integrate Do not logout on auth on public share page #9756
  • add since tags etc
  • Maybe nog change functions for publci sharing?
  • Move PublicFileShareController just to files_sharing
  • Move basic auth templates to core (so they are default by default as well)
  • add tests

Once merged:

@rullzerrullzer added this to the Nextcloud 14 milestone May 18, 2018
@rullzer
rullzer requested a review from juliusknorrMay 18, 2018 10:45
@rullzerrullzer added 2. developing Work in progress and removed 3. to review Waiting for reviews labels May 18, 2018
* Show the authentication page
* The form has to submit to the authenticate method route
*/
abstract public function showAuthenticate(string $token): TemplateResponse;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have a general showAuthenticate implementation here as well, since most of the time, we will just render a passwort request form.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that sure.. just server it from the core app I guess then.

@juliusknorr

Copy link
Copy Markdown
Member

@rullzer The IShareManager is just to be used by files, right? So calendar or other apps still need to implement their own sharing logic.

@rullzer

Copy link
Copy Markdown
MemberAuthor

@juliushaertl that is correct.

Ok let me think how to make it more generic then.
And then maybe have a FilesPublicShareController for all the apps that want to share files that implements some extra stuff.

@rullzer
rullzerforce-pushed the feature/5986/public_share_controller_middleware branch from cd160d7 to a30b48eCompareMay 18, 2018 19:53
@rullzer

Copy link
Copy Markdown
MemberAuthor

@juliushaertl ok abstracted away some more ;) This should work for all types of shares I guess

@rullzer

Copy link
Copy Markdown
MemberAuthor

Ok so it probably should be even further split up. Some controllers just need to know you are properly authenticated (like preview endpoints). If not they will just 404... I'll look into that more next week.

@rullzer
rullzerforce-pushed the feature/5986/public_share_controller_middleware branch from a30b48e to f351b9dCompareMay 23, 2018 09:17
@codecov

codecovBot commented May 23, 2018

Copy link
Copy Markdown

Codecov Report

Merging #9518 into master will increase coverage by 0.02%.
The diff coverage is 65.47%.

@@ Coverage Diff @@## master #9518 +/- ##
============================================
+ Coverage 52.1% 52.12% +0.02% - Complexity 25910 25946 +36 
============================================
Files 1642 1645 +3 Lines 95721 96130 +409 Branches 1289 1373 +84 ============================================
+ Hits 49871 50108 +237 - Misses 45850 46021 +171 - Partials 0 1 +1
Impacted FilesCoverage ΔComplexity Δ
..._sharing/lib/Middleware/SharingCheckMiddleware.php83.78% <ø> (-3.98%)15 <0> (-6)
apps/files_sharing/js/public.js47.42% <0%> (ø)0 <0> (ø)⬇️
core/templates/publicshareauth.php0% <0%> (ø)0 <0> (?)
apps/files_sharing/appinfo/routes.php0% <0%> (ø)0 <0> (ø)⬇️
lib/private/legacy/template/functions.php9.3% <0%> (ø)0 <0> (ø)⬇️
...e/AppFramework/DependencyInjection/DIContainer.php83.18% <100%> (+0.3%)54 <2> (ø)⬇️
...sharing/lib/Controller/PublicPreviewController.php30.3% <21.05%> (-6.07%)22 <5> (+4)
...s/files_sharing/lib/Controller/ShareController.php37.85% <37.5%> (-9.7%)55 <24> (-9)
.../public/AppFramework/AuthPublicShareController.php76.08% <76.08%> (ø)13 <13> (?)
lib/public/AppFramework/PublicShareController.php82.35% <82.35%> (ø)8 <8> (?)
... and 12 more

@rullzer

Copy link
Copy Markdown
MemberAuthor

@juliushaertl even more splitup now. It is a lot of abstraction and not maybe 100% efficient. But better to have it secure I guess ;)

@rullzer
rullzerforce-pushed the feature/5986/public_share_controller_middleware branch from f351b9d to a68d26cCompareJune 5, 2018 11:24

@juliusknorrjuliusknorr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rullzer Looks good to me now in terms of separation 👍

- Move basic auth templates to core (so they are default by default as well)

👍

$token = $this->request->getParam('token');
$share = $this->shareManager->getShareByToken($token);
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK
&& !$this->isLinkSharingEnabled()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That check should probably also be in the PublicShareController, right?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm good point.

Yeah probably makes sense to not allow any public shares when it is disabled.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;

abstract class FilesPublicShareController extends AuthPublicShareController {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would probably make more sense to move this to the files_sharing app, since it is limited to be used with the ShareManager. At least I cannot think of how an app would require to use this.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory gallery could use it for example. BUt I agree. I'll move it. So the new code we add stays simple. If it turns out we duplicate it again in a lot (>4) places. Then we can think how to unify again.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rullzer
rullzerforce-pushed the feature/5986/public_share_controller_middleware branch 5 times, most recently from da5ed84 to c855295CompareJune 14, 2018 12:16
@rullzer

Copy link
Copy Markdown
MemberAuthor

Failing test is unrelated

@rullzerrullzer added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jun 14, 2018
@rullzer

Copy link
Copy Markdown
MemberAuthor

@MorrisJobke yes that happens because you go directly to the auth page. So there is no state stored yet. Anyways let me fix that.

@rullzer

Copy link
Copy Markdown
MemberAuthor

@danxuliu ah you are right. Yes the tests need to be updated.

@rullzer
rullzerforce-pushed the feature/5986/public_share_controller_middleware branch from ed23248 to ab4939aCompareJune 19, 2018 19:46
rullzer added 14 commits June 20, 2018 08:53
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Now this is in core so the basics (that 99% of the app will want to
use) looks always the same.
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
* Removed tests that are now handled by the middleware
* Updated tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
* They are handled now by the overal sharing public page middleware
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@rullzer
rullzerforce-pushed the feature/5986/public_share_controller_middleware branch from ab4939a to 5805159CompareJune 20, 2018 06:57
@rullzer

Copy link
Copy Markdown
MemberAuthor

All happy!

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works 👍

Comment threadapps/files_sharing/js/public.js Outdated
urlSpec.t = $('#dirToken').val();
return OC.generateUrl('/apps/files_sharing/ajax/publicpreview.php?') + $.param(urlSpec);
var token = $('#dirToken').val();
return OC.linkTo('files_sharing', '/publicpreview/'+token) + '?' + OC.buildQueryString(urlSpec);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be OC.generateUrl(OC.linkTo(...)) otherwise index.php prefix isn't added.

juliusknorr
juliusknorr previously requested changes Jun 20, 2018

@juliusknorrjuliusknorr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small issue with public previews on my instance, but besides that 👍

Comment threadapps/files_sharing/js/public.js Outdated
}
else if (previewSupported === 'true') {
$('#imgframe > video').attr('poster', OC.filePath('files_sharing', 'ajax', 'publicpreview.php') + '?' + OC.buildQueryString(params));
$('#imgframe > video').attr('poster', OC.linkTo('files_sharing', '/publicpreview/'+token) + '?' + OC.buildQueryString(params));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be OC.generateUrl(OC.linkTo(...)) otherwise index.php prefix isn't added.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@MorrisJobkeMorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Jun 20, 2018
@rullzer
rullzer merged commit 8ebc3d9 into masterJun 21, 2018
@rullzer
rullzer deleted the feature/5986/public_share_controller_middleware branch June 21, 2018 08:09
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to releaseReady to be released and/or waiting for tests to finishenhancementfeature: sharing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@rullzer@juliusknorr@MorrisJobke@danxuliu