Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33f75c41 authored by Nivesh Krishna's avatar Nivesh Krishna
Browse files

Merge branch 'revert-1b19dcf5' into 'nc21'

Revert "Merge branch 'create-activity' into 'nc21'"

See merge request e/infra/selfhost/nextcloud-apps/ecloud-drop-account!13
parents 1b19dcf5 15394f9f
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
    <description><![CDATA[in /e/ cloud self-hosting setup, nextcloud accounts are linked to mail accounts and some other things. This app sets the mail, quota and storage of the user upon creation. 
    It also completes the account deletion by cleaning other parts of the /e/ cloud setup to ensure no more data is retained when a user requests an account deletion.
    This app uses the UserDeletedEvent to invoke scripts in the docker-welcome container of /e/ cloud setup]]></description>
    <version>1.3.0</version>
    <version>1.2.0</version>
    <licence>agpl</licence>
    <author mail="dev@e.email" homepage="https://gitlab.e.foundation/">Akhil Potukuchi</author>
    <namespace>EcloudAccounts</namespace>
+2 −38
Original line number Diff line number Diff line
@@ -11,8 +11,6 @@ use OCP\EventDispatcher\IEventListener;
use OCP\IConfig;
use OCP\ILogger;
use OCP\User\Events\UserDeletedEvent;
use OCP\Activity\IManager;
use OCP\IGroupManager;

require_once 'curl.class.php';

@@ -21,15 +19,11 @@ class UserDeletedListener implements IEventListener

    private $logger;
    private $config;
    private $activityManager;
    private $groupManager;

    public function __construct(ILogger $logger, IConfig $config, IManager $activityManager, IGroupManager $groupManager)
    public function __construct(ILogger $logger, IConfig $config)
    {
        $this->logger = $logger;
        $this->config = $config;
        $this->activityManager = $activityManager;
        $this->groupManager = $groupManager;
    }

    public function handle(Event $event): void
@@ -45,36 +39,6 @@ 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(Application::APP_ID)
                    ->setType('account_deletion')
                    ->setObject('user', 0, $username)
                    ->setAuthor($username)
                    ->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) {
            $this->logger->error('There has been an issue while creating and publishing activity for user deletion');
            $this->logger->logException($e, ['app' => Application::APP_ID]);
        }

    }

    /**
@@ -87,7 +51,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
     */
    private function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret)
    public function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret)
    {

        $postDeleteUrl = "https://" . $welcomeDomain . "/postDelete.php";