-
Notifications
You must be signed in to change notification settings - Fork 14
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
Clear user notifications from table after they are deleted #221
Conversation
f10f715
to
4d543ec
Compare
Codecov Report
@@ Coverage Diff @@
## master #221 +/- ##
============================================
+ Coverage 89.55% 89.78% +0.22%
- Complexity 134 137 +3
============================================
Files 18 18
Lines 536 548 +12
============================================
+ Hits 480 492 +12
Misses 56 56
Continue to review full report at Codecov.
|
644c4dc
to
437d372
Compare
lib/App.php
Outdated
* @param string $uid uid of the user | ||
* @since 10.0.10 | ||
*/ | ||
public function removeUserNotifications($uid) { |
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.
While I don't have a strong opinion against this, I'd prefer to keep the implementation as close as possible to the interface. If the interface doesn't have this public method, I'd prefer to remove it.
|
||
public function testUserDeleteEvent() { | ||
\OC::$server->getEventDispatcher()->dispatch('user.afterdelete', new GenericEvent(null, ['uid' => 'foo'])); | ||
$this->assertInstanceOf(App::class, $this->container->query('OCA\Notifications\App')); |
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.
Not sure what you're testing here....
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.
Was trying to please the code coverage. I will remove this test, and see if the coverage looks ok.
a07dd21
to
2bf7c7a
Compare
tests/Unit/HandlerTest.php
Outdated
@@ -23,6 +23,7 @@ | |||
namespace OCA\Notifications\Tests\Unit; | |||
|
|||
|
|||
use OC\Notification\Notification; |
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.
Prefer public over private (OCP\Notification\INotification
)
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.
Done
@@ -22,8 +22,10 @@ | |||
|
|||
namespace OCA\Notifications\Tests\Unit\AppInfo; | |||
|
|||
use OCA\Notifications\App; |
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.
It doesn't seem to be used here. The GenericEvent
neither.
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.
Removed and updated.
lib/AppInfo/Application.php
Outdated
@@ -60,6 +64,11 @@ public function __construct (array $urlParams = array()) { | |||
}); | |||
$container->registerCapability('Capabilities'); | |||
|
|||
$container->getServer()->getEventDispatcher()->addListener('user.afterdelete', function (GenericEvent $event) use ($container) { | |||
$handler = $container->query('OCA\Notifications\Handler'); |
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.
Use Handler::class
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.
Updated to Handler::class
lib/AppInfo/Application.php
Outdated
@@ -60,6 +64,11 @@ public function __construct (array $urlParams = array()) { | |||
}); | |||
$container->registerCapability('Capabilities'); | |||
|
|||
$container->getServer()->getEventDispatcher()->addListener('user.afterdelete', function (GenericEvent $event) use ($container) { |
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.
It might be worthy to move this block to another function, similarly to what we have for the setupConsumerAndNotifier
function. Note that you'll need to call the function in the app.php file.
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.
Moved this block to a new method in the new version of the pr.
lib/AppInfo/Application.php
Outdated
use OCA\Notifications\Controller\EndpointController; | ||
use OCA\Notifications\Handler; | ||
use OCA\Notifications\App as NotificationApp; | ||
use OCA\Notifications\Mailer\NotificationMailer; |
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.
Check what of these new classes are being used here.
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.
Removed the unused classes added due to this PR.
Just some minor changes to keep the code as clean as possible. |
2bf7c7a
to
a369ac6
Compare
@sharidas did you try adding tests for the new method in the Application class ? |
Will update test for Application for new method. |
a369ac6
to
abb1cd3
Compare
Added a test to increase coverage. |
@@ -64,4 +69,53 @@ public function dataContainerQuery() { | |||
public function testContainerQuery($service, $expected) { | |||
$this->assertTrue($this->container->query($service) instanceof $expected); | |||
} | |||
|
|||
public function testSetupSymfonyEventListeners() { | |||
$app = $this->getMockBuilder(Application::class) |
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.
Why are you mocking the class you should be testing? 😕
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.
I took this approach, because internally its calling getContainer
.
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.
Since this can't be unittested properly, just test the whole stack: add some notifications in the DB, and trigger the event. Make sure you clean up everything after the test (the listener and the information added in the DB table).
The other option is not to test this method, at least with unittests. Acceptance test should be able to cover the scenario.
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.
Updated the test.. Tried to add a user, then added an entry into the notification table. Deleted the user.. Verified that entry is not there in the table.
Clear user notifications from table after they are deleted. Signed-off-by: Sujith H <sharidasan@owncloud.com>
abb1cd3
to
b258fea
Compare
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 to stable10 |
Backport to stable10 #223 |
Clear user notifications from table after they are deleted.
Signed-off-by: Sujith H sharidasan@owncloud.com