Skip to content

Conversation

@PVince81
Copy link
Contributor

Description

Adds a new checkbox to disable sharing in user-mount external storages.

Since ConfigAdapterTest was missing I had to write all of it from scratch.
It turned out that some interfaces had missing methods for mocking (IStorageFactory::wrap), so I added it.
And also added Temporary::getAvailability() for the temporary test storage to avoid a DB round trip which would fail in this test.

Related Issue

Fixes #28636

Motivation and Context

See ticket

How Has This Been Tested?

  • TEST: manual testing in web UI
    • TEST: when allowed, user mount has "Enable sharing" option visible. Share action visible in files UI.
    • TEST: when disallowed, user mount has no "Enable sharing" option visible. Share action not visible in files UI
    • TEST: when disallowed, system mounts can still have sharing enabled
  • TEST: unit tests

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.


protected function setUp() {
$this->config = $this->createMock(IConfig::class);
// FIXME: cannot mock the interface because the UserTrait functions are not on them
Copy link
Member

Choose a reason for hiding this comment

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

but I'd say it's okay to mock the implementation

<?php endforeach; ?>
<br/>
<input type="checkbox" name="allowUserMountSharing" id="allowUserMountSharing" class="checkbox"
value="1" <?php if ($_['allowUserMountSharing'] == 'yes') print_unescaped(' checked="checked"'); ?> />
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to use '===' unless it's explicitly told otherwise (with the corresponding explanation)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah... this was just copy-pasted from the other block

*
* @since 10.0.3
*/
public function wrap(IMountPoint $mountPoint, $storage);
Copy link
Member

Choose a reason for hiding this comment

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

Is this being used? It doesn't appear in the changes of this PR.

Is it the best place for the method? I see 2 different responsabilities for the storage factory: create the objects via getInstance and wrap the storages. From my point of view, the factory should focus on creating objects, if that object is wrapped somehow, that should be an implementation detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately it is being used in the StorageFactory implementation, and it seems the calling code is assuming that the method always exists: https://github.com/owncloud/core/blob/master/lib/private/Files/Mount/MountPoint.php#L97

I only added it here to be able to mock it...

Copy link
Member

Choose a reason for hiding this comment

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

I don't know what to do with this. Bad solutions everywhere. I guess this is the "less bad" option we have.

  • Moving the method to the interface -> bad
  • Typecasting the interface in the MountPoint class -> bad
  • Checking if the implementation has the method -> bad
  • Removing the interface and use the class directly -> unexpected consecuences
  • Create a new interface and make the implementation implement also the new one -> too much work + adding a non-planned interface

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason I added it is because @DeepDiver1975 said to use this opportunity to add it. I discovered it while testing and do not wish to hold this PR much longer due to this.

My solution would be to resort to mocking StorageFactory instead and raise a tech debt ticket about "review all these weird FS classes where the method wasn't on the interface"

@PVince81
Copy link
Contributor Author

I decided to remote IStorageFactory::wrap for now and mocking the StorageFactory class.
Other comments addressed as well: removed "FIXME" and used "===".

Please review

@PVince81
Copy link
Contributor Author

Raised StorageFactory tech debt issue here #28656 as it seems to be more complex to fix than just adding the method on the interface

}

public function getAvailability() {
return ['available' => true];
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if the 'last_checked' key is optional. The PHPDoc doesn't say anything, so it should be required.
If it isn't being actively used, we could adjust the PHPDoc to say the 'last_checked' key is optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class is supposed to be used only by unit tests. Maybe we should move it to the "tests" folder.

@PVince81 PVince81 added the p1-urgent Critical issue, need to consider hotfix with just that issue label Aug 15, 2017
@PVince81 PVince81 force-pushed the extstorage-noshare-checkbox branch from 702dd03 to fc910be Compare August 15, 2017 14:20
@PVince81
Copy link
Contributor Author

@jvillafanez I've added "last_checked => 0" and squashed. Please rereview.

@PVince81 PVince81 merged commit c15c0c3 into master Aug 16, 2017
@PVince81 PVince81 deleted the extstorage-noshare-checkbox branch August 16, 2017 11:06
@PVince81
Copy link
Contributor Author

stable10: #28706

@lock
Copy link

lock bot commented Aug 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3 - To Review p1-urgent Critical issue, need to consider hotfix with just that issue status/STALE

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ext storage checkbox to disallow sharing on user-created mounts

5 participants