-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
lib/private/Share20/Manager.php
Outdated
@@ -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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to DI
tests/lib/Share20/ManagerTest.php
Outdated
@@ -231,7 +232,26 @@ public function testDelete($shareType, $sharedWith) { | |||
->method('post') | |||
->with($hookListnerExpectsPost); | |||
|
|||
$calledBeforeEvent = []; | |||
\OC::$server->getEventDispatcher()->addListener('share.beforedelete', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
.
Note that expected events are "share.afterDelete" and "share.afterCreate", note the case-sensitive. The "share.afterCreate" event is still missing. |
0bafe2b
to
30b1178
Compare
@jvillafanez I have added event |
30b1178
to
7b19884
Compare
Not really getting the cause for drone failure. |
7b19884
to
ff554ba
Compare
Got the issue #30930 (comment). The drone was failing because of duplicate event "share.beforeCreate" and "share.afterCreate", at :
Removed the |
ff554ba
to
09df813
Compare
Updated this PR, by moving the |
09df813
to
403a046
Compare
403a046
to
13f93ee
Compare
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnedeed comment
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 |
13f93ee
to
8fdcf74
Compare
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>
8fdcf74
to
294bc9e
Compare
@@ -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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@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. |
Backported PR: #31026 |
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. |
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
Checklist: