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

Add symfony events for delete and create share #30930

Merged
merged 1 commit into from
Apr 6, 2018

Conversation

sharidas
Copy link
Contributor

Add symfony events for delete share.

Signed-off-by: Sujith H sharidasan@owncloud.com

Description

Adding symfony events for delete share. This was missing in the code base.

Related Issue

Motivation and Context

Adding symfony events for delete share. This was missing in the codebase.

How Has This Been Tested?

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.

@sharidas sharidas added this to the development milestone Mar 26, 2018
@sharidas sharidas self-assigned this Mar 26, 2018
@sharidas sharidas requested a review from PVince81 March 26, 2018 16:59
@codecov
Copy link

codecov bot commented Mar 26, 2018

Codecov Report

Merging #30930 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #30930      +/-   ##
============================================
+ Coverage     62.31%   62.31%   +<.01%     
- Complexity    18208    18371     +163     
============================================
  Files          1142     1142              
  Lines         68190    68194       +4     
  Branches       1232     1232              
============================================
+ Hits          42494    42498       +4     
  Misses        25335    25335              
  Partials        361      361
Flag Coverage Δ Complexity Δ
#javascript 52.04% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 63.49% <100%> (ø) 18371 <0> (+163) ⬆️
Impacted Files Coverage Δ Complexity Δ
apps/files_sharing/lib/API/Share20OCS.php 91.52% <ø> (-0.13%) 152 <0> (ø)
lib/private/Share20/Manager.php 97.01% <100%> (+0.04%) 212 <0> (ø) ⬇️
lib/private/Server.php 85% <100%> (+0.01%) 254 <0> (ø) ⬇️

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 6e2b8aa...294bc9e. Read the comment docs.

@@ -846,6 +846,8 @@ public function deleteShare(\OCP\Share\IShare $share) {
// Emit pre-hook
\OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams);

$beforeEvent = new GenericEvent(null, ['share' => $hookParams, 'shareObject' => $share]);
\OC::$server->getEventDispatcher()->dispatch('share.beforedelete', $beforeEvent);
Copy link
Contributor

Choose a reason for hiding this comment

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

please inject the event dispatcher with DI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to DI

@@ -231,7 +232,26 @@ public function testDelete($shareType, $sharedWith) {
->method('post')
->with($hookListnerExpectsPost);

$calledBeforeEvent = [];
\OC::$server->getEventDispatcher()->addListener('share.beforedelete',
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use a new EventDispatcher from now on: $this->eventDispatcher = new EventDispatcher() because reusing the existing one will pollute the server with events and will eventually cause side effects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used $this->eventDispatcher = new EventDispatcher() instead of \OC::$server->getEventDispatcher().

@PVince81 PVince81 mentioned this pull request Mar 27, 2018
19 tasks
@jvillafanez
Copy link
Member

Note that expected events are "share.afterDelete" and "share.afterCreate", note the case-sensitive. The "share.afterCreate" event is still missing.

@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch 2 times, most recently from 0bafe2b to 30b1178 Compare March 28, 2018 12:54
@sharidas sharidas changed the title Add symfony events for delete share Add symfony events for delete and create share Mar 28, 2018
@sharidas sharidas changed the title Add symfony events for delete and create share Add symfony events for delete and share Mar 28, 2018
@sharidas
Copy link
Contributor Author

@jvillafanez I have added event share.afterCreate.

@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch from 30b1178 to 7b19884 Compare March 29, 2018 06:08
@sharidas
Copy link
Contributor Author

Not really getting the cause for drone failure.
Not able to reproduce the same in my local instance : http://paste.opensuse.org/29265128.

@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch from 7b19884 to ff554ba Compare March 29, 2018 10:58
@sharidas sharidas changed the title Add symfony events for delete and share Add symfony events for delete share Mar 29, 2018
@sharidas
Copy link
Contributor Author

sharidas commented Mar 29, 2018

Got the issue #30930 (comment). The drone was failing because of duplicate event "share.beforeCreate" and "share.afterCreate", at :

Removed the share.beforeCreate and share.afterCreate in this PR.

@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch from ff554ba to 09df813 Compare March 29, 2018 13:19
@sharidas
Copy link
Contributor Author

Updated this PR, by moving the share.afterCreate and share.beforeCreate events to share manager. Have also tried to grab the data from the Share20OCS to Share20/Manager.php.

@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch from 09df813 to 403a046 Compare March 29, 2018 14:28
@sharidas sharidas changed the title Add symfony events for delete share Add symfony events for delete and create share Mar 29, 2018
@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch from 403a046 to 13f93ee Compare March 30, 2018 07:34
@@ -108,7 +108,8 @@ protected function setUp() {
['core', 'shareapi_default_permissions', \OCP\Constants::PERMISSION_ALL, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE]
]));

$this->eventDispatcher = \OC::$server->getEventDispatcher();
//$this->eventDispatcher = \OC::$server->getEventDispatcher();
Copy link
Member

Choose a reason for hiding this comment

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

unnedeed comment

@jvillafanez
Copy link
Member

Taking into account that the events will be thrown by core, I don't know if we should create custom public events instead of using the GenericEvent one.

Other than that, the code looks fine

@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch from 13f93ee to 8fdcf74 Compare April 3, 2018 07:53
@PVince81
Copy link
Contributor

PVince81 commented Apr 3, 2018

I don't know if we should create custom public events instead of using the GenericEvent one.

I'm also undecided here. In many places we already use GenericEvent so let's stick with it when it works.

Add symfony events for delete share.
And move create share to share manager.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
@sharidas sharidas force-pushed the add-symfony-events-for-deleteshare branch from 8fdcf74 to 294bc9e Compare April 3, 2018 18:01
@@ -635,6 +640,9 @@ public function createShare(\OCP\Share\IShare $share) {
];
\OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData);

$beforeEvent = new GenericEvent(null, ['shareData' => $preHookData]);
$this->eventDispatcher->dispatch('share.beforeCreate', $beforeEvent);
Copy link
Contributor

Choose a reason for hiding this comment

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

this would break any listener that was relying on the old formatter pre-hook data.

this is only ok if the beforeCreate change was never released before, else this is an API change

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I see that this event did not exist in 10.0.7.

this makes this change critical for 10.0.8 as we don't want to introduce the old event in 10.0.8 and change it again

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

👍

@PVince81 PVince81 merged commit bedfb50 into master Apr 6, 2018
@PVince81 PVince81 deleted the add-symfony-events-for-deleteshare branch April 6, 2018 10:06
@PVince81
Copy link
Contributor

PVince81 commented Apr 6, 2018

@sharidas please backport, p1-urgent because the current stable10 code would introduce the old hook format and this PR adjusts it to the correct one.

@sharidas
Copy link
Contributor Author

sharidas commented Apr 6, 2018

Backported PR: #31026

@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.

3 participants