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

Clear user notifications from table after they are deleted #221

Merged
merged 1 commit into from
Aug 20, 2018

Conversation

sharidas
Copy link
Contributor

@sharidas sharidas commented Aug 7, 2018

Clear user notifications from table after they are deleted.

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

@sharidas sharidas self-assigned this Aug 7, 2018
@sharidas sharidas added this to the development milestone Aug 7, 2018
@sharidas sharidas force-pushed the clear-notifications-after-user-deleted branch from f10f715 to 4d543ec Compare August 7, 2018 07:53
@codecov-io
Copy link

codecov-io commented Aug 7, 2018

Codecov Report

Merging #221 into master will increase coverage by 0.22%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Flag Coverage Δ Complexity Δ
#phpunit 89.78% <100%> (+0.22%) 137 <3> (+3) ⬆️
Impacted Files Coverage Δ Complexity Δ
lib/Handler.php 99.3% <100%> (+0.02%) 33 <1> (+1) ⬆️
lib/AppInfo/Application.php 91.42% <100%> (+1.77%) 8 <2> (+2) ⬆️
appinfo/app.php 100% <100%> (ø) 0 <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 4452637...b258fea. Read the comment docs.

@sharidas
Copy link
Contributor Author

sharidas commented Aug 7, 2018

@sharidas sharidas force-pushed the clear-notifications-after-user-deleted branch 3 times, most recently from 644c4dc to 437d372 Compare August 8, 2018 07:56
lib/App.php Outdated
* @param string $uid uid of the user
* @since 10.0.10
*/
public function removeUserNotifications($uid) {
Copy link
Member

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'));
Copy link
Member

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

Copy link
Contributor Author

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.

@sharidas sharidas force-pushed the clear-notifications-after-user-deleted branch 2 times, most recently from a07dd21 to 2bf7c7a Compare August 8, 2018 10:38
@@ -23,6 +23,7 @@
namespace OCA\Notifications\Tests\Unit;


use OC\Notification\Notification;
Copy link
Member

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)

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed and updated.

@@ -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');
Copy link
Member

Choose a reason for hiding this comment

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

Use Handler::class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to Handler::class

@@ -60,6 +64,11 @@ public function __construct (array $urlParams = array()) {
});
$container->registerCapability('Capabilities');

$container->getServer()->getEventDispatcher()->addListener('user.afterdelete', function (GenericEvent $event) use ($container) {
Copy link
Member

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.

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 this block to a new method in the new version of the pr.

use OCA\Notifications\Controller\EndpointController;
use OCA\Notifications\Handler;
use OCA\Notifications\App as NotificationApp;
use OCA\Notifications\Mailer\NotificationMailer;
Copy link
Member

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.

Copy link
Contributor Author

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.

@jvillafanez
Copy link
Member

Just some minor changes to keep the code as clean as possible.

@sharidas sharidas force-pushed the clear-notifications-after-user-deleted branch from 2bf7c7a to a369ac6 Compare August 8, 2018 11:18
@PVince81
Copy link
Contributor

PVince81 commented Aug 8, 2018

@sharidas did you try adding tests for the new method in the Application class ?

@sharidas
Copy link
Contributor Author

sharidas commented Aug 8, 2018

did you try adding tests for the new method in the Application class ?

Will update test for Application for new method.

@sharidas sharidas force-pushed the clear-notifications-after-user-deleted branch from a369ac6 to abb1cd3 Compare August 8, 2018 16:46
@sharidas
Copy link
Contributor Author

sharidas commented Aug 8, 2018

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)
Copy link
Member

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? 😕

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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>
@sharidas sharidas force-pushed the clear-notifications-after-user-deleted branch from abb1cd3 to b258fea Compare August 9, 2018 07:30
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 db956fc into master Aug 20, 2018
@PVince81 PVince81 deleted the clear-notifications-after-user-deleted branch August 20, 2018 08:22
@PVince81
Copy link
Contributor

@sharidas please backport to stable10

@sharidas
Copy link
Contributor Author

Backport to stable10 #223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants