From 5b6e2f58021f91de44fa3a9884b5ed5392e22ee4 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Apr 2022 01:58:46 +0530 Subject: [PATCH 1/8] create activity when user is deleted --- appinfo/info.xml | 2 +- lib/Listeners/UserDeletedListener.php | 34 +++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index c019ae03..e9d62deb 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,7 +10,7 @@ - 1.1.0 + 1.2.0 agpl Akhil Potukuchi EcloudAccounts diff --git a/lib/Listeners/UserDeletedListener.php b/lib/Listeners/UserDeletedListener.php index 25e98359..419f357d 100644 --- a/lib/Listeners/UserDeletedListener.php +++ b/lib/Listeners/UserDeletedListener.php @@ -11,6 +11,7 @@ use OCP\EventDispatcher\IEventListener; use OCP\IConfig; use OCP\ILogger; use OCP\User\Events\UserDeletedEvent; +use OCP\Activity\IManager; require_once 'curl.class.php'; @@ -19,11 +20,13 @@ class UserDeletedListener implements IEventListener private $logger; private $config; + private $activityManager; - public function __construct(ILogger $logger, IConfig $config) + public function __construct(ILogger $logger, IConfig $config, IManager $activityManager) { $this->logger = $logger; $this->config = $config; + $this->activityManager = $activityManager; } public function handle(Event $event): void @@ -39,8 +42,35 @@ class UserDeletedListener implements IEventListener $this->config->getSystemValue('e_welcome_domain'), $this->config->getSystemValue('e_welcome_secret') ); + + $this->createAndPublishActivity($uid); + } + /** + * Create an activity to record user deletion + * As this will be used for monitoring and sending alerts to admins + * @param $username string + */ + private function createAndPublishActivity(string $username) + { + try { + $event = $this->activityManager->generateEvent(); + $event->setApp('drop_account') + ->setType('account_deletion') + ->setObject('user', 0, $username) + ->setAuthor($username) + ->setSubject('account_self_deletion', ['name' => $username, 'type' => 'account']) + ->setAffectedUser('ncadmin'); + + $this->activityManager->publish($event); + } catch (\Exception $e) { + $this->logger->error('There has been an issue while creating and publishing activity for user deletion'); + $this->logger->logException($e, ['app' => Application::APP_NAME]); + } + + } + /** * Once NC deleted the account, * perform specific ecloud selfhosting actions @@ -51,7 +81,7 @@ class UserDeletedListener implements IEventListener * @param $welcomeSecret string generated at ecloud selfhosting install and added as a custom var in NC's config * @return mixed response of the external endpoint */ - public function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret) + private function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret) { $postDeleteUrl = "https://" . $welcomeDomain . "/postDelete.php"; -- GitLab From e59d0efef64c5443c3adec60e2a37e1e28fdab9c Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Apr 2022 02:05:56 +0530 Subject: [PATCH 2/8] convert tabs to spaces --- lib/Listeners/UserDeletedListener.php | 46 +++++++++++++-------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/Listeners/UserDeletedListener.php b/lib/Listeners/UserDeletedListener.php index 419f357d..e184c01c 100644 --- a/lib/Listeners/UserDeletedListener.php +++ b/lib/Listeners/UserDeletedListener.php @@ -43,33 +43,33 @@ class UserDeletedListener implements IEventListener $this->config->getSystemValue('e_welcome_secret') ); - $this->createAndPublishActivity($uid); + $this->createAndPublishActivity($uid); } - /** - * Create an activity to record user deletion - * As this will be used for monitoring and sending alerts to admins + /** + * Create an activity to record user deletion + * As this will be used for monitoring and sending alerts to admins * @param $username string - */ - private function createAndPublishActivity(string $username) - { - try { - $event = $this->activityManager->generateEvent(); - $event->setApp('drop_account') - ->setType('account_deletion') - ->setObject('user', 0, $username) - ->setAuthor($username) - ->setSubject('account_self_deletion', ['name' => $username, 'type' => 'account']) - ->setAffectedUser('ncadmin'); - - $this->activityManager->publish($event); - } catch (\Exception $e) { - $this->logger->error('There has been an issue while creating and publishing activity for user deletion'); - $this->logger->logException($e, ['app' => Application::APP_NAME]); - } - - } + */ + private function createAndPublishActivity(string $username) + { + try { + $event = $this->activityManager->generateEvent(); + $event->setApp('drop_account') + ->setType('account_deletion') + ->setObject('user', 0, $username) + ->setAuthor($username) + ->setSubject('account_self_deletion', ['name' => $username, 'type' => 'account']) + ->setAffectedUser('ncadmin'); + + $this->activityManager->publish($event); + } catch (\Exception $e) { + $this->logger->error('There has been an issue while creating and publishing activity for user deletion'); + $this->logger->logException($e, ['app' => Application::APP_NAME]); + } + + } /** * Once NC deleted the account, -- GitLab From ffa4223c66f0b4f9d0c0f98657297cd07fd41065 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Apr 2022 14:22:12 +0530 Subject: [PATCH 3/8] fix app name --- lib/Listeners/UserDeletedListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Listeners/UserDeletedListener.php b/lib/Listeners/UserDeletedListener.php index e184c01c..807d341c 100644 --- a/lib/Listeners/UserDeletedListener.php +++ b/lib/Listeners/UserDeletedListener.php @@ -56,7 +56,7 @@ class UserDeletedListener implements IEventListener { try { $event = $this->activityManager->generateEvent(); - $event->setApp('drop_account') + $event->setApp(Application::APP_NAME) ->setType('account_deletion') ->setObject('user', 0, $username) ->setAuthor($username) -- GitLab From a75e500f56ce75de9451a6ceae1c1186f787be7e Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Apr 2022 14:25:42 +0530 Subject: [PATCH 4/8] use APP_ID instead of APP_NAME --- lib/Listeners/UserDeletedListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/UserDeletedListener.php b/lib/Listeners/UserDeletedListener.php index 807d341c..5fca0ba8 100644 --- a/lib/Listeners/UserDeletedListener.php +++ b/lib/Listeners/UserDeletedListener.php @@ -56,7 +56,7 @@ class UserDeletedListener implements IEventListener { try { $event = $this->activityManager->generateEvent(); - $event->setApp(Application::APP_NAME) + $event->setApp(Application::APP_ID) ->setType('account_deletion') ->setObject('user', 0, $username) ->setAuthor($username) @@ -66,7 +66,7 @@ class UserDeletedListener implements IEventListener $this->activityManager->publish($event); } catch (\Exception $e) { $this->logger->error('There has been an issue while creating and publishing activity for user deletion'); - $this->logger->logException($e, ['app' => Application::APP_NAME]); + $this->logger->logException($e, ['app' => Application::APP_ID]); } } -- GitLab From a7ac4307d8c32b6cfde697075a22283e4adaee96 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Apr 2022 18:34:07 +0530 Subject: [PATCH 5/8] setaffecteduser to all admin --- lib/Listeners/UserDeletedListener.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/UserDeletedListener.php b/lib/Listeners/UserDeletedListener.php index 5fca0ba8..50a84a28 100644 --- a/lib/Listeners/UserDeletedListener.php +++ b/lib/Listeners/UserDeletedListener.php @@ -60,8 +60,11 @@ class UserDeletedListener implements IEventListener ->setType('account_deletion') ->setObject('user', 0, $username) ->setAuthor($username) - ->setSubject('account_self_deletion', ['name' => $username, 'type' => 'account']) - ->setAffectedUser('ncadmin'); + ->setSubject('account_self_deletion', ['name' => $username, 'type' => 'account']); + $admins = $this->groupManager->get('admin')->getUsers(); + foreach ($admins as $admin) { + $event->setAffectedUser($admin->getUID()); + } $this->activityManager->publish($event); } catch (\Exception $e) { -- GitLab From 84227b497a46458e17b80c5f1c78d8d06b3c8edf Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Apr 2022 19:01:15 +0530 Subject: [PATCH 6/8] add group manager --- lib/Listeners/UserDeletedListener.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Listeners/UserDeletedListener.php b/lib/Listeners/UserDeletedListener.php index 50a84a28..718e1667 100644 --- a/lib/Listeners/UserDeletedListener.php +++ b/lib/Listeners/UserDeletedListener.php @@ -12,6 +12,7 @@ use OCP\IConfig; use OCP\ILogger; use OCP\User\Events\UserDeletedEvent; use OCP\Activity\IManager; +use OCP\IGroupManager; require_once 'curl.class.php'; @@ -21,12 +22,14 @@ class UserDeletedListener implements IEventListener private $logger; private $config; private $activityManager; + private $groupManager; - public function __construct(ILogger $logger, IConfig $config, IManager $activityManager) + public function __construct(ILogger $logger, IConfig $config, IManager $activityManager, IGroupManager $groupManager) { $this->logger = $logger; $this->config = $config; $this->activityManager = $activityManager; + $this->groupManager = $groupManager; } public function handle(Event $event): void -- GitLab From 70e689012789a4ce6c9fe4010d2f2258418492fa Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Apr 2022 19:22:44 +0530 Subject: [PATCH 7/8] publish event for all admins --- lib/Listeners/UserDeletedListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Listeners/UserDeletedListener.php b/lib/Listeners/UserDeletedListener.php index 718e1667..177d0f78 100644 --- a/lib/Listeners/UserDeletedListener.php +++ b/lib/Listeners/UserDeletedListener.php @@ -67,9 +67,9 @@ class UserDeletedListener implements IEventListener $admins = $this->groupManager->get('admin')->getUsers(); foreach ($admins as $admin) { $event->setAffectedUser($admin->getUID()); + $this->activityManager->publish($event); } - $this->activityManager->publish($event); } catch (\Exception $e) { $this->logger->error('There has been an issue while creating and publishing activity for user deletion'); $this->logger->logException($e, ['app' => Application::APP_ID]); -- GitLab From 2798163909e8fa85a1171029634019184640d64d Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Tue, 26 Apr 2022 11:50:50 +0530 Subject: [PATCH 8/8] update version --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index e9d62deb..558a84c0 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -10,7 +10,7 @@ - 1.2.0 + 1.3.0 agpl Akhil Potukuchi EcloudAccounts -- GitLab