Skip to content

Commit

Permalink
Adding more dispatcher events for the app
Browse files Browse the repository at this point in the history
Adding more dispatcher events to handle:
a) Rename of groups
b) Members leaving groups and
c) Role change of members in the group

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Aug 24, 2017
1 parent 9cc8ec2 commit 497fcec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Dav/GroupMembershipCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ public function updateDisplayName($displayName) {
return 409;
}

$event = new GenericEvent(null, ['oldGroupName' => $this->groupInfo['display_name'],
'newGroupName' => $displayName]);
$this->dispatcher->dispatch('updateGroupName', $event);

$result = $this->groupsHandler->updateGroup(
$this->groupInfo['group_id'],
$this->groupInfo['uri'],
Expand Down
10 changes: 10 additions & 0 deletions lib/Dav/MembershipNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Sabre\DAV\Exception\PreconditionFailed;
use OCA\CustomGroups\Dav\Roles;
use OCA\CustomGroups\Service\MembershipHelper;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Membership node
Expand Down Expand Up @@ -74,6 +75,11 @@ class MembershipNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties {
*/
private $name;

/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
private $dispatcher;

/**
* Constructor
*
Expand All @@ -94,6 +100,7 @@ public function __construct(
$this->memberInfo = $memberInfo;
$this->groupInfo = $groupInfo;
$this->helper = $helper;
$this->dispatcher = \OC::$server->getEventDispatcher();
}

/**
Expand Down Expand Up @@ -131,6 +138,9 @@ public function delete() {
// only notify when the removal was done by another user
$this->helper->notifyUserRemoved($userId, $this->groupInfo, $this->memberInfo);
}

$event = new GenericEvent(null, ['user' => $currentUserId, 'groupName' => $this->groupInfo['display_name']]);
$this->dispatcher->dispatch('leaveGroup', $event);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions lib/Service/MembershipHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace OCA\CustomGroups\Service;

use OCA\CustomGroups\CustomGroupsDatabaseHandler;
use OCA\CustomGroups\Dav\Roles;
use OCP\IUserSession;
use OCP\IUserManager;
use OCP\IGroupManager;
Expand Down Expand Up @@ -315,6 +316,13 @@ public function notifyUserRoleChange($targetUserId, array $groupInfo, array $mem
->setUser($targetUserId)
->setLink($link);
$this->notificationManager->notify($notification);
if($memberInfo['role'] === Roles::BACKEND_ROLE_MEMBER) {
$roleName = "Member";
} elseif ($memberInfo['role'] === Roles::BACKEND_ROLE_ADMIN) {
$roleName = "Group owner";
}
$event = new GenericEvent(null, ['user' => $targetUserId, 'groupName' => $groupInfo['display_name'], 'roleNumber' => $memberInfo['role'], 'roleDisaplayName' => $roleName]);
$this->dispatcher->dispatch('changeRoleInGroup', $event);
}

/**
Expand Down

0 comments on commit 497fcec

Please sign in to comment.