Skip to content
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

Accept user share notification #30106

Merged
merged 14 commits into from
May 30, 2018
Merged

Accept user share notification #30106

merged 14 commits into from
May 30, 2018

Conversation

PVince81
Copy link
Contributor

@PVince81 PVince81 commented Jan 11, 2018

Description

New notification to accept shares and pending shares list

  • Reusing the "oc_share.accepted" field to store share states.
  • Added checkbox in settings page to enable automatically accepting shares, this defaults to enabled currently. Unchecking this option will prompt users to accept or reject shares through notifications
  • Added pending and rejected shares in the "Shared with you" view
  • The "unshare from self" action now changes the state of shares to "Rejected" instead of deleting directly

Related Issue

#19153

Motivation and Context

How Has This Been Tested?

TODO - for testcases see #30106 (comment)

Screenshots (if appropriate):

fireshot capture 21 - mit ihnen geteilt - owncloud_ - http___localhost_8000_index php_apps_files_

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.

TODOs:

  • expose share state value in PHP API
  • add setting in share settings page to switch on this feature
  • send notification to user
  • send notification to group members
  • implement endpoint for accepting share
  • implement endpoint for declining share
  • discard notification if share is deleted
  • discard notification if target user is not member of the group any more
  • add missing unit tests
  • do not render folder favorite start

@PVince81
Copy link
Contributor Author

To test you need to untick the new auto accept option in the admin settings for sharing

switch ($notification->getSubject()) {
case 'local_share':
$params = $notification->getSubjectParameters();
if ($params[0] !== $params[1] && $params[1] !== null) {
Copy link
Member

Choose a reason for hiding this comment

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

Theorically, only share notifications should reach this point, and we expect that all the share notifications to have 2 parameters. Taking this into account, I'm not sure if we should add additional checks here.

@@ -76,6 +79,7 @@ class Share implements \OCP\Share\IShare {
public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
$this->rootFolder = $rootFolder;
$this->userManager = $userManager;
$this->state = Constants::STATE_ACCEPTED;
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 setting "accepted" as default value for the state is a good idea. Maybe setting null as default and enforcing that the state has a valid value just before saving it in the DB is a better idea.

// TODO: discard if target user is not in target group any more

switch ($notification->getSubject()) {
case 'local_share':
Copy link
Member

Choose a reason for hiding this comment

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

We should move this block to a private function. If it's implemented as "case" I expect more cases (public shares, federated shares, etc) that will eventually be implemented. Those cases will follow what is implemented here, so there will be more big blocks increasing the lines of this function making it more difficult to read.

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 code is copied from the Notifier in the federatedfileshare app which has "remote_share" here, so not sure. We could provide a more generic share notifier with these type by refactoring.

Copy link
Member

Choose a reason for hiding this comment

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

My point isn't refactor, it's just move the code block to a private function in order to make this swicth block as compact as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved

);
} else {
$notification->setParsedSubject(
(string)$l->t('User %1$s shared "%3$s" with you', $params)
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after the typecasting (for consistency with the rest of the code)

@PVince81 PVince81 modified the milestones: development, planned Jan 12, 2018
@PVince81
Copy link
Contributor Author

PVince81 commented Jan 16, 2018

  • if autoaccept disabled, do send a notification to the receiver that a new share was added (note: we could even do this as a separate PR as this can be standalone)
  • if autoaccept enabled, send notification to share sender about acceptation/rejection => we decided to not send any notification for now

@codecov
Copy link

codecov bot commented Jan 16, 2018

Codecov Report

Merging #30106 into master will increase coverage by 0.09%.
The diff coverage is 82.13%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #30106      +/-   ##
============================================
+ Coverage     62.72%   62.82%   +0.09%     
- Complexity    18292    18369      +77     
============================================
  Files          1148     1151       +3     
  Lines         68669    69051     +382     
  Branches       1234     1260      +26     
============================================
+ Hits          43076    43381     +305     
- Misses        25232    25301      +69     
- Partials        361      369       +8
Flag Coverage Δ Complexity Δ
#javascript 52.39% <71.91%> (+0.34%) 0 <0> (ø) ⬇️
#phpunit 64.02% <86.51%> (+0.08%) 18369 <113> (+77) ⬆️
Impacted Files Coverage Δ Complexity Δ
core/js/share.js 32.56% <ø> (ø) 0 <0> (ø) ⬇️
apps/files_sharing/list.php 0% <0%> (ø) 0 <0> (ø) ⬇️
settings/templates/panels/admin/filesharing.php 17.5% <0%> (-0.93%) 0 <0> (ø)
apps/files_sharing/templates/list.php 0% <0%> (ø) 0 <0> (ø) ⬇️
apps/files_sharing/appinfo/app.php 40% <0%> (-1.87%) 0 <0> (ø)
core/Migrations/Version20180302155233.php 0% <0%> (ø) 1 <1> (?)
...ederatedfilesharing/lib/FederatedShareProvider.php 63.42% <100%> (+0.18%) 78 <1> (+1) ⬆️
settings/Panels/Admin/FileSharing.php 100% <100%> (ø) 6 <0> (ø) ⬇️
apps/files_sharing/appinfo/routes.php 98.5% <100%> (+0.2%) 0 <0> (ø) ⬇️
lib/private/Share20/Manager.php 97.21% <100%> (-0.03%) 227 <1> (-4)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0376174...10197f6. Read the comment docs.

@PVince81
Copy link
Contributor Author

Added notification when autoaccept is disabled. It includes a private link for the accepted share.

Also added notification icon.

@PVince81
Copy link
Contributor Author

PVince81 commented Jan 19, 2018

  • TODO: migrate permissions=0 to accepted=1 and make sure old permissions zero code still works in case of old data

@PVince81
Copy link
Contributor Author

  • needs extensive testing with reshares...

@PVince81
Copy link
Contributor Author

PVince81 commented Jan 19, 2018

  • TODO: feedback after rejecting/accepted button from notification:
    • refresh file view
    • display yellow notification

@PVince81
Copy link
Contributor Author

I've pushed some changes.

It is already possible to accept and reject shares from the notification buttons.
Unshare from self now implicitly triggers a rejection of a share. This means that user or group share are not getting deleted but just marked as rejected.

This is still very rough and I'm afraid we might have side effects. I'm not happy by the fact that we have a single endpoint "/shares" for both outgoing and received shares and also common code for formatShare() which is supposed to cover both cases. This is all still very messy and might need another round of refactoring, but probably another time as we don't want to break more.

I've added some todos above, we need to make sure this works with reshare / share initiator. It will anyway require a full retest of the sharing feature for user/group and also the "shared with me" and "shared with you" file lists, which seem to be affected by the share state somehow.

The endpoint "/shares?shared_with_me=true" now has an additional arguments "state":

  • if omitted, it defaults to 0 (accepted). This is to prevent breaking any clients which expect only receiving a list of already accepted shares
  • if set to empty string state= or state=all, it will retrieve shares with all possible states
  • if set to a specific value, it will return only the shares with the given state. (0 = accepted, 1 = pending, 2 = rejected)

From here on we'll be able to adjust the "shared with you" list to also visually display pending and rejected shares.

@jvillafanez
Copy link
Member

if set to empty string state= or state=all, it will retrieve shares with all possible states

I don't think that state= and state=all should have the same behaviour. To have consistency across all the API calls, state= should either cause an error due to invalid arguments, or use the default value.

It might be nice if the state can accept a list, something like state=0,1 or state=0,2, but taking into account that I don't think there will be more states, it's probably too much work for a little gain. I don't have a use case where this could be useful at the moment.

@PVince81
Copy link
Contributor Author

PVince81 commented Jan 22, 2018

I don't think that state= and state=all should have the same behaviour.

Thanks for your comment. I wasn't sure either.

  • "state=" should use the default value. Keep "all" for all.

I don't want to add muultiple state values as input as it would introduce a lot more logic for not much gain as you said.

@PVince81
Copy link
Contributor Author

PVince81 commented Feb 1, 2018

Now struggling with the fileactions part: the "Shared with you" list already displays the pending shares now. We need to adjust the file actions menu to display "accept" and "reject" actions or others, but not the default actions.

Currently, the FileActions object was designed based on its legacy: to define file actions based on mime type + permissions. Ideally it should be refactored to provide custom actions with custom filtering behavior instead of mime/permissions. This way we could have the custom handler filter out actions based on the current file row that was clicked. Whatever change we do, we need to keep it compatible with the old way to avoid breaking apps that register their actions.

@PVince81
Copy link
Contributor Author

I've made a new PR to look into making file actions more flexible: #30478

@PVince81
Copy link
Contributor Author

PVince81 commented Feb 26, 2018

Pending shares can now be accepted in "shared with you", but with many bugs:

  • prevent sidebar to open for pending/rejected shares
  • implement custom sort by state
  • prevent "unshare from self" from removing element: redisplay it in rejected mode instead
  • do we really need three states ? => to be discussed after usability testing
  • missing star placeholder / alignment when pending share is the only entry

@PVince81
Copy link
Contributor Author

the favorite star is missing so the first column is not wide enough for pending shares:
image

I wonder if we could reuse that space to display the icon as a state ? @felixheidecke

@jvillafanez
Copy link
Member

Rebased to fix conflict in the ManagerTest. Note that 7ded301 has been added due to a bad conflict resolution (probably) since that piece wasn't there before the rebase.

@PVince81
Copy link
Contributor Author

@jvillafanez seems you discarded @individual-it's commit, likely because you guys updated at the same time. @individual-it can you push it again ?

@PVince81
Copy link
Contributor Author

commit was 66584e1

Vincent Petry and others added 14 commits May 30, 2018 19:54
- Reusing the "oc_share.accepted" field to store share states.
- Added checkbox in settings page to enable automatically accepting
shares, this defaults to enabled currently. Unchecking this option will
prompt users to accept or reject shares through notifications
- Added pending and rejected shares in the "Shared with you" view
- The "unshare from self" action now changes the state of shares to
"Rejected" instead of deleting directly

Introduce updateShareForRecipient methods

- New method updateShareForRecipient on share manager and default share
provider to update both "files_target" and "accepted" fields.
- Rewired moveShare and updateShareForRecipient to use
updateShareForRecipient.
- Moved most of the validation code to the share provider

Migrate oc_share.permissions zero to accepted field

Added migration that sets oc_share.accepted to 2 (rejected) for all
sub-share entries that had oc_share.permissions=0.

The zero permissions is left there to avoid expensive migration and is
now gracefully ignored by the current code.
Improve visual share status (icons)
Shared with you can now be sorted by share state In that order: accepted, pending, rejected and then by file name.

Better error handling when switching share state

Pending share support for multiple received shares

Whenever multiple shares for the same node are received
through different, the accept/reject endpoint now properly
sets the state for all related shares.

Make pending shares unclickable

Exclude share owner and initiatior from notifications

Hack to make share file lists reload properly

Fixes issue with Firefox soft reload due to hidden field keeping its
value.

Deduplicate share target directly when accepting share

Solves issue where the order in which the deduplication is done in the
mount provider doesn't always match the accepting order

Resolve private link for shared with you

Sharing's notification publisher now rely on symfony event

Notification is sent on share.afterCreate and discarded on
share.afterDelete

Share object is now passed through share creation event so no need to
get it.

Remove notification on auto accept
remove class .disable-click; .share-state-rejected handles the job

Default cursor for folder and sharer in pending state
better xpath for finding file on Trashbin

use better behat steps in tests

API test to reaccept shares

enable apps via APPS_TO_ENABLE in api test script

UI tests to check notifications

API tests to check notifications

check notifications with regular expressions

enable auto_accept_share between tests

api tests for Discard notification if target user is not member of the group anymore

test notification link redirection
Remove the notification once an action has been taken

Remote shares will keep the old behaviour
run sharing notifications tests
enable notifications app
Fix retarget problem after accept / decline the share

Fix deduplication logic and add tests for it

Fix icon url for non-root ownCloud servers

Code style fixes and adjust acceptance test

Remove summary when the filelist is destroyed
only source file if its availiable

notifications do show users display name, fix expectations in tests
@phil-davis
Copy link
Contributor

I made the same changes in a new commit, rebased and pushed again. All is good with acceptance tests.

@PVince81 PVince81 merged commit b9bfa6c into master May 30, 2018
@PVince81 PVince81 deleted the accept-user-share branch May 30, 2018 21:10
@PVince81
Copy link
Contributor Author

🎉 fantastic work, guys ! 🎉

@jvillafanez please backport to stable10

@phil-davis
Copy link
Contributor

Backport stable10 #31613

@lock
Copy link

lock bot commented Jul 31, 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 Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.