Exemplo n.º 1
0
 protected function shareFileOrFolderWithGroup($shareWith, $fileSource, $itemType, $fileTarget, $shareId)
 {
     // Members of the new group
     $affectedUsers = array();
     // User performing the share
     $this->shareNotificationForSharer('shared_sharing_group_self', $shareWith, $fileSource, $itemType);
     $this->shareNotificationForOriginalOwners($this->currentUser, 'reshared_sharing_group_by', $shareWith, $fileSource, $itemType);
     $usersInGroup = \OCA\Sharing_Group\Data::readGroupUsers($shareWith);
     foreach ($usersInGroup as $user) {
         $affectedUsers[$user] = $fileTarget;
     }
     // Remove the triggering user, we already managed his notifications
     unset($affectedUsers[$this->currentUser]);
     if (empty($affectedUsers)) {
         return;
     }
     $filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'stream', Files_Sharing::TYPE_SHARED);
     $filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'email', Files_Sharing::TYPE_SHARED);
     $affectedUsers = $this->fixPathsForShareExceptions($affectedUsers, $shareId);
     foreach ($affectedUsers as $user => $path) {
         if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) {
             continue;
         }
         $this->addNotificationsForUser($user, 'shared_with_by', array($path, $this->currentUser), $fileSource, $path, $itemType === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0);
     }
 }
Exemplo n.º 2
0
 /**
  * Sharing a file or folder with a group
  * @param array $params The hook params
  */
 protected function shareFileOrFolderWithGroup($params)
 {
     // User performing the share
     $this->shareNotificationForSharer('shared_group_self', $params['shareWith'], $params['fileSource'], $params['itemType']);
     // Members of the new group
     $affectedUsers = array();
     $usersInGroup = \OC_Group::usersInGroup($params['shareWith']);
     foreach ($usersInGroup as $user) {
         $affectedUsers[$user] = $params['fileTarget'];
     }
     // Remove the triggering user, we already managed his notifications
     unset($affectedUsers[$this->currentUser]);
     if (empty($affectedUsers)) {
         return;
     }
     $filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'stream', Files_Sharing::TYPE_SHARED);
     $filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'email', Files_Sharing::TYPE_SHARED);
     // Check when there was a naming conflict and the target is different
     // for some of the users
     $query = $this->connection->executeQuery('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? ', [(int) $params['id']]);
     while ($row = $query->fetch()) {
         $affectedUsers[$row['share_with']] = $row['file_target'];
     }
     foreach ($affectedUsers as $user => $path) {
         if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) {
             continue;
         }
         $this->addNotificationsForUser($user, 'shared_with_by', array($path, $this->currentUser), $path, $params['itemType'] === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0);
     }
 }
Exemplo n.º 3
0
 /**
  * Sharing a file or folder with a group
  * @param array $params The hook params
  */
 protected function shareFileOrFolderWithGroup($params)
 {
     // User performing the share
     $this->shareNotificationForSharer('shared_group_self', $params['shareWith'], $params['fileSource'], $params['itemType']);
     // Members of the new group
     $affectedUsers = array();
     $usersInGroup = \OC_Group::usersInGroup($params['shareWith']);
     foreach ($usersInGroup as $user) {
         $affectedUsers[$user] = $params['fileTarget'];
     }
     // Remove the triggering user, we already managed his notifications
     unset($affectedUsers[$this->currentUser]);
     if (empty($affectedUsers)) {
         return;
     }
     $filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'stream', Data::TYPE_SHARED);
     $filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting($usersInGroup, 'email', Data::TYPE_SHARED);
     // Check when there was a naming conflict and the target is different
     // for some of the users
     $query = \OCP\DB::prepare('SELECT `share_with`, `file_target` FROM `*PREFIX*share` WHERE `parent` = ? ');
     $result = $query->execute(array($params['id']));
     if (\OCP\DB::isError($result)) {
         \OCP\Util::writeLog('OCA\\Activity\\Hooks::shareFileOrFolderWithGroup', \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
     } else {
         while ($row = $result->fetchRow()) {
             $affectedUsers[$row['share_with']] = $row['file_target'];
         }
     }
     foreach ($affectedUsers as $user => $path) {
         if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) {
             continue;
         }
         $this->addNotificationsForUser($user, 'shared_with_by', array($path, $this->currentUser), $path, $params['itemType'] === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0);
     }
 }
Exemplo n.º 4
0
 protected function addNotificationsForFileAction($oldfilePath, $newfilePath, $activityType, $subject)
 {
     // Do not add activities for .part-files
     if (substr($newfilePath, -5) === '.part') {
         return;
     }
     list($filePath, $uidOwner, $fileId) = $this->getSourcePathAndOwner($newfilePath);
     $affectedUsers = $this->getUserPathsFromPath($filePath, $uidOwner);
     $filteredStreamUsers = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'stream', $activityType);
     $filteredEmailUsers = $this->userSettings->filterUsersBySetting(array_keys($affectedUsers), 'email', $activityType);
     foreach ($affectedUsers as $user => $path) {
         if (empty($filteredStreamUsers[$user]) && empty($filteredEmailUsers[$user])) {
             continue;
         }
         if ($user === $this->currentUser) {
             $userSubject = $subject;
             $userParams = array($oldfilePath, $path);
         } else {
             continue;
         }
         $this->addNotificationsForUser($user, $userSubject, $userParams, $fileId, $path, true, !empty($filteredStreamUsers[$this->currentUser]), !empty($filteredEmailUsers[$this->currentUser]) ? $filteredEmailUsers[$this->currentUser] : 0, $activityType);
     }
 }
Exemplo n.º 5
0
 /**
  * @param IUser[] $usersInGroup
  * @param int $fileSource File ID that is being shared
  * @param string $itemType File type that is being shared (file or folder)
  * @param string $fileTarget File path
  * @param int $shareId The Share ID of this share
  */
 protected function addNotificationsForGroupUsers(array $usersInGroup, $fileSource, $itemType, $fileTarget, $shareId)
 {
     $affectedUsers = [];
     foreach ($usersInGroup as $user) {
         $affectedUsers[$user->getUID()] = $fileTarget;
     }
     // Remove the triggering user, we already managed his notifications
     unset($affectedUsers[$this->currentUser]);
     if (empty($affectedUsers)) {
         return;
     }
     $userIds = array_keys($affectedUsers);
     $filteredStreamUsersInGroup = $this->userSettings->filterUsersBySetting($userIds, 'stream', Files_Sharing::TYPE_SHARED);
     $filteredEmailUsersInGroup = $this->userSettings->filterUsersBySetting($userIds, 'email', Files_Sharing::TYPE_SHARED);
     $affectedUsers = $this->fixPathsForShareExceptions($affectedUsers, $shareId);
     foreach ($affectedUsers as $user => $path) {
         if (empty($filteredStreamUsersInGroup[$user]) && empty($filteredEmailUsersInGroup[$user])) {
             continue;
         }
         $this->addNotificationsForUser($user, 'shared_with_by', array($path, $this->currentUser), $fileSource, $path, $itemType === 'file', !empty($filteredStreamUsersInGroup[$user]), !empty($filteredEmailUsersInGroup[$user]) ? $filteredEmailUsersInGroup[$user] : 0);
     }
 }
 /**
  * @dataProvider filterUsersBySettingData
  *
  * @param array $users
  * @param string $method
  * @param string $type
  * @param array $expected
  */
 public function testFilterUsersBySetting($users, $method, $type, $expected)
 {
     $this->config->expects($this->any())->method('getUserValueForUsers')->with($this->anything(), $this->anything(), $this->anything())->willReturnMap([['activity', 'notify_stream_file_created', ['test', 'test6'], ['test6' => '1']], ['activity', 'notify_stream_file_nodefault', ['test', 'test6'], ['test6' => '1']], ['activity', 'notify_stream_type1', ['test', 'test1', 'test2', 'test3', 'test4'], ['test1' => '1', 'test2' => '0', 'test3' => '', 'test4' => '1']], ['activity', 'notify_email_file_created', ['test', 'test6'], ['test6' => '1']], ['activity', 'notify_email_shared', ['test6'], ['test6' => '1']], ['activity', 'notify_email_shared', ['test', 'test6'], ['test6' => '1']], ['activity', 'notify_email_type1', ['test', 'test1', 'test2', 'test3', 'test4', 'test5'], ['test1' => '1', 'test2' => '0', 'test3' => '', 'test4' => '3', 'test5' => '1']], ['activity', 'notify_setting_batchtime', ['test6'], ['test6' => '2700']], ['activity', 'notify_setting_batchtime', ['test', 'test6'], ['test6' => '2700']], ['activity', 'notify_setting_batchtime', ['test1', 'test4', 'test5'], ['test1' => '1', 'test4' => '4']]]);
     $this->assertEquals($expected, $this->userSettings->filterUsersBySetting($users, $method, $type));
 }
Exemplo n.º 7
0
 /**
  * @dataProvider filterUsersBySettingData
  */
 public function testFilterUsersBySetting($users, $method, $type, $expected)
 {
     $this->assertEquals($expected, UserSettings::filterUsersBySetting($users, $method, $type));
 }