summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-01-15 12:38:40 +0100
committerBackportbot <backportbot-noreply@rullzer.com>2020-01-15 23:12:09 +0000
commit90f5e066c35243c2c5e6346b895b2d842ff72661 (patch)
treec7bbc96b10be7bd86e220dd88817365e153ad318 /apps
parentbcb8ce3e07416a6395b4ec3ef9c72216fcf73caf (diff)
downloadnextcloud-server-90f5e066c35243c2c5e6346b895b2d842ff72661.tar.gz
nextcloud-server-90f5e066c35243c2c5e6346b895b2d842ff72661.zip
Listen to the right even for auto share accept
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php39
1 files changed, 30 insertions, 9 deletions
diff --git a/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php
index ba46d722850..f8ce4353c13 100644
--- a/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php
+++ b/apps/files_sharing/lib/Listener/UserShareAcceptanceListener.php
@@ -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);
}
}