]> source.dussan.org Git - nextcloud-server.git/commitdiff
Listen to the right even for auto share accept 18910/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 15 Jan 2020 11:38:40 +0000 (12:38 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 15 Jan 2020 22:10:21 +0000 (23:10 +0100)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php

index ba46d722850b6ea4e4c84d6ef7634cfa9b155e97..f8ce4353c130f2803924946abfe4c5986ac3e1a7 100644 (file)
@@ -29,8 +29,10 @@ namespace OCA\Files_Sharing\Listener;
 use OCP\EventDispatcher\Event;
 use OCP\EventDispatcher\IEventListener;
 use OCP\IConfig;
-use OCP\Share\Events\SharedEvent;
+use OCP\IGroupManager;
+use OCP\Share\Events\ShareCreatedEvent;
 use OCP\Share\IManager;
+use OCP\Share\IShare;
 
 class UserShareAcceptanceListener implements IEventListener {
 
@@ -38,23 +40,42 @@ class UserShareAcceptanceListener implements IEventListener {
        private $config;
        /** @var IManager */
        private $shareManager;
-       /** @var string */
-       private $userId;
+       /** @var IGroupManager */
+       private $groupManager;
 
-       public function __construct(IConfig $config, IManager $shareManager, string $userId) {
+       public function __construct(IConfig $config, IManager $shareManager, IGroupManager $groupManager) {
                $this->config = $config;
                $this->shareManager = $shareManager;
-               $this->userId = $userId;
+               $this->groupManager = $groupManager;
        }
 
        public function handle(Event $event): void {
-               if (!($event instanceof SharedEvent)) {
+               if (!($event instanceof ShareCreatedEvent)) {
                        return;
                }
 
-               if ($this->config->getUserValue($this->userId, 'files_sharing','default_accept','no') === 'yes') {
-                       $share = $event->getShare();
-                       $this->shareManager->acceptShare($share, $this->userId);
+               $share = $event->getShare();
+
+               if ($share->getShareType() === IShare::TYPE_USER) {
+                       $this->handleAutoAccept($share, $share->getSharedWith());
+               } else if ($share->getShareType() === IShare::TYPE_GROUP) {
+                       $group = $this->groupManager->get($share->getSharedWith());
+
+                       if ($group === null) {
+                               return;
+                       }
+
+                       $users = $group->getUsers();
+                       foreach ($users as $user) {
+                               $this->handleAutoAccept($share, $user->getUID());
+                       }
+               }
+
+       }
+
+       private function handleAutoAccept(IShare $share, string $userId) {
+               if ($this->config->getUserValue($userId, 'files_sharing','default_accept','no') === 'yes') {
+                       $this->shareManager->acceptShare($share, $userId);
                }
        }