summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-09-06 13:06:21 +0200
committerJoas Schilling <coding@schilljs.com>2019-11-12 17:37:00 +0100
commit8986910a7d6a0bd7ee08bca68f1f5008612e38dc (patch)
tree1a0ecb30f9ea33ed4738746941150476994183a5 /apps
parent520042bbd0512e19717d18705c3b045b2d8400a7 (diff)
downloadnextcloud-server-8986910a7d6a0bd7ee08bca68f1f5008612e38dc.tar.gz
nextcloud-server-8986910a7d6a0bd7ee08bca68f1f5008612e38dc.zip
Add notifications for users that are added to the group
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php6
-rw-r--r--apps/files_sharing/lib/Notification/Listener.php48
2 files changed, 51 insertions, 3 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index 92b3a92d438..5f48088d719 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.php
@@ -43,6 +43,7 @@ use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\Defaults;
use OCP\Federation\ICloudIdManager;
use \OCP\IContainer;
+use OCP\IGroup;
use OCP\IServerContainer;
use OCA\Files_Sharing\Capabilities;
use OCA\Files_Sharing\External\Manager;
@@ -188,5 +189,10 @@ class Application extends App {
$listener = $this->getContainer()->query(Listener::class);
$listener->shareNotification($event);
});
+ $dispatcher->addListener(IGroup::class . '::postAddUser', function(GenericEvent $event) {
+ /** @var Listener $listener */
+ $listener = $this->getContainer()->query(Listener::class);
+ $listener->userAddedToGroup($event);
+ });
}
}
diff --git a/apps/files_sharing/lib/Notification/Listener.php b/apps/files_sharing/lib/Notification/Listener.php
index fd4daca28e7..1f8358dd3b8 100644
--- a/apps/files_sharing/lib/Notification/Listener.php
+++ b/apps/files_sharing/lib/Notification/Listener.php
@@ -25,24 +25,31 @@ declare(strict_types=1);
namespace OCA\Files_Sharing\Notification;
use OC\Share\Share;
+use OCP\IGroup;
use OCP\IGroupManager;
-use OCP\Notification\IManager;
+use OCP\IUser;
+use OCP\Notification\IManager as INotificationManager;
use OCP\Notification\INotification;
+use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\GenericEvent;
class Listener {
- /** @var IManager */
+ /** @var INotificationManager */
protected $notificationManager;
+ /** @var IShareManager */
+ protected $shareManager;
/** @var IGroupManager */
protected $groupManager;
public function __construct(
- IManager $notificationManager,
+ INotificationManager $notificationManager,
+ IShareManager $shareManager,
IGroupManager $groupManager
) {
$this->notificationManager = $notificationManager;
+ $this->shareManager = $shareManager;
$this->groupManager = $groupManager;
}
@@ -75,6 +82,41 @@ class Listener {
}
/**
+ * @param GenericEvent $event
+ */
+ public function userAddedToGroup(GenericEvent $event): void {
+ /** @var IGroup $group */
+ $group = $event->getSubject();
+ /** @var IUser $user */
+ $user = $event->getArgument('user');
+
+ $offset = 0;
+ while (true) {
+ $shares = $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP, null, 50, $offset);
+ if (empty($shares)) {
+ break;
+ }
+
+ foreach ($shares as $share) {
+ if ($share->getSharedWith() !== $group->getGID()) {
+ continue;
+ }
+
+ if ($user->getUID() === $share->getShareOwner() ||
+ $user->getUID() === $share->getSharedBy()) {
+ continue;
+ }
+
+ $notification = $this->instantiateNotification($share);
+ $notification->setSubject('incoming_group_share')
+ ->setUser($user->getUID());
+ $this->notificationManager->notify($notification);
+ }
+ $offset += 50;
+ }
+ }
+
+ /**
* @param IShare $share
* @return INotification
*/