Example #1
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $l = Util::getL10N('activity', $userLang);
         $l->forceLanguage($userLang);
         $this->helper->setL10n($l);
         $this->helper->setUser($user);
         $description = (string) $l->t('Personal activity feed for %s', $user);
         $activities = $this->data->read($this->helper, $this->settings, 0, self::DEFAULT_PAGE_SIZE, 'all', $user);
     } catch (\UnexpectedValueException $e) {
         $l = Util::getL10N('activity');
         $description = (string) $l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subjectformatted' => ['full' => $description]]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
Example #2
0
 /**
  * Send an event to the notifications of a user
  *
  * @param IEvent $event
  * @return null
  */
 public function receive(IEvent $event)
 {
     $selfAction = $event->getAffectedUser() === $event->getAuthor();
     $streamSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'stream', $event->getType());
     $emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType());
     $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false;
     $types = $this->data->getNotificationTypes($this->l10nFactory->get('activity'));
     $typeData = $types[$event->getType()];
     // User is not the author or wants to see their own actions
     $createStream = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self');
     // User can not control the setting
     $createStream = $createStream || is_array($typeData) && isset($typeData['methods']) && !in_array(IExtension::METHOD_STREAM, $typeData['methods']);
     // Add activity to stream
     if ($streamSetting && $createStream) {
         $this->data->send($event);
     }
     // User is not the author or wants to see their own actions
     $createEmail = !$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail');
     // User can not control the setting
     $createEmail = $createEmail || is_array($typeData) && isset($typeData['methods']) && !in_array(IExtension::METHOD_MAIL, $typeData['methods']);
     // Add activity to mail queue
     if ($emailSetting && $createEmail) {
         $latestSend = $event->getTimestamp() + $emailSetting;
         $this->data->storeMail($event, $latestSend);
     }
 }
 public function tearDown()
 {
     parent::tearDown();
     $data = new Data($this->getMock('\\OCP\\Activity\\IManager'));
     $data->deleteActivities(array('type' => 'test'));
     $query = \OCP\DB::prepare("DELETE FROM `*PREFIX*activity_mq` WHERE `amq_type` = 'test'");
     $query->execute();
 }
Example #4
0
 protected function deleteUser(Data $data, $uid)
 {
     $data->deleteActivities(array('affecteduser' => $uid));
     $user = \OC::$server->getUserManager()->get($uid);
     if ($user) {
         $user->delete();
     }
 }
 protected function tearDown()
 {
     $data = new Data($this->getMock('\\OCP\\Activity\\IManager'), \OC::$server->getDatabaseConnection(), $this->getMock('\\OCP\\IUserSession'));
     $data->deleteActivities(array('type' => 'test'));
     $query = \OC::$server->getDatabaseConnection()->prepare("DELETE FROM `*PREFIX*activity_mq` WHERE `amq_type` = 'test'");
     $query->execute();
     parent::tearDown();
 }
Example #6
0
 protected function tearDown()
 {
     $data = new Data($this->getMock('\\OCP\\Activity\\IManager'));
     $data->deleteActivities(array('affecteduser' => 'activity-api-user1'));
     \OC_User::deleteUser('activity-api-user1');
     $data->deleteActivities(array('affecteduser' => 'activity-api-user2'));
     \OC_User::deleteUser('activity-api-user2');
     $data->deleteActivities(array('type' => 'test'));
     \OC::$WEBROOT = $this->originalWEBROOT;
     parent::tearDown();
 }
Example #7
0
 /**
  * Get a list with enabled notification types for a user
  *
  * @param string	$user	Name of the user
  * @param string	$method	Should be one of 'stream' or 'email'
  * @return array
  */
 public function getNotificationTypes($user, $method)
 {
     $l = Util::getL10N('activity');
     $types = $this->data->getNotificationTypes($l);
     $notificationTypes = array();
     foreach ($types as $type => $desc) {
         if ($this->getUserSetting($user, $method, $type)) {
             $notificationTypes[] = $type;
         }
     }
     return $notificationTypes;
 }
Example #8
0
 /**
  * Send an event to the notifications of a user
  *
  * @param IEvent $event
  * @return null
  */
 public function receive(IEvent $event)
 {
     $selfAction = $event->getAffectedUser() === $event->getAuthor();
     $streamSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'stream', $event->getType());
     $emailSetting = $this->userSettings->getUserSetting($event->getAffectedUser(), 'email', $event->getType());
     $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'batchtime') : false;
     // Add activity to stream
     if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'self'))) {
         $this->data->send($event);
     }
     // Add activity to mail queue
     if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($event->getAffectedUser(), 'setting', 'selfemail'))) {
         $latestSend = $event->getTimestamp() + $emailSetting;
         $this->data->storeMail($event, $latestSend);
     }
 }
Example #9
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function show()
 {
     try {
         $user = $this->activityManager->getCurrentUserId();
         $userLang = $this->config->getUserValue($user, 'core', 'lang');
         // Overwrite user and language in the helper
         $this->l = $this->l10nFactory->get('activity', $userLang);
         $parser = new PlainTextParser($this->l);
         $this->helper->setL10n($this->l);
         $this->helper->setUser($user);
         $description = (string) $this->l->t('Personal activity feed for %s', $user);
         $response = $this->data->get($this->helper, $this->settings, $user, 0, self::DEFAULT_PAGE_SIZE, 'desc', 'all');
         $data = $response['data'];
         $activities = [];
         foreach ($data as $activity) {
             $activity['subject_prepared'] = $parser->parseMessage($activity['subject_prepared']);
             $activity['message_prepared'] = $parser->parseMessage($activity['message_prepared']);
             $activities[] = $activity;
         }
     } catch (\UnexpectedValueException $e) {
         $this->l = $this->l10nFactory->get('activity');
         $description = (string) $this->l->t('Your feed URL is invalid');
         $activities = [['activity_id' => -1, 'timestamp' => time(), 'subject' => true, 'subject_prepared' => $description]];
     }
     $response = new TemplateResponse('activity', 'rss', ['rssLang' => $this->l->getLanguageCode(), 'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'), 'rssPubDate' => date('r'), 'description' => $description, 'activities' => $activities], '');
     if ($this->request->getHeader('accept') !== null && stristr($this->request->getHeader('accept'), 'application/rss+xml')) {
         $response->addHeader('Content-Type', 'application/rss+xml');
     } else {
         $response->addHeader('Content-Type', 'text/xml; charset=UTF-8');
     }
     return $response;
 }
Example #10
0
 /**
  * @dataProvider dataSend
  *
  * @param string $actionUser
  * @param string $affectedUser
  */
 public function testSend($actionUser, $affectedUser, $expectedAuthor, $expectedAffected, $expectedActivity)
 {
     $mockSession = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock();
     if ($actionUser !== '') {
         $mockUser = $this->getMockBuilder('\\OCP\\IUser')->disableOriginalConstructor()->getMock();
         $mockUser->expects($this->any())->method('getUID')->willReturn($actionUser);
         $mockSession->expects($this->any())->method('getUser')->willReturn($mockUser);
     } else {
         $mockSession->expects($this->any())->method('getUser')->willReturn(null);
     }
     $this->overwriteService('UserSession', $mockSession);
     $this->deleteTestActivities();
     $this->assertSame($expectedActivity, Data::send('test', 'subject', [], '', [], '', '', $affectedUser, 'type', IExtension::PRIORITY_MEDIUM));
     $connection = \OC::$server->getDatabaseConnection();
     $query = $connection->prepare('SELECT `user`, `affecteduser` FROM `*PREFIX*activity` WHERE `app` = ? ORDER BY `activity_id` DESC');
     $query->execute(['test']);
     $row = $query->fetch();
     if ($expectedActivity) {
         $this->assertEquals(['user' => $expectedAuthor, 'affecteduser' => $expectedAffected], $row);
     } else {
         $this->assertFalse($row);
     }
     $this->deleteTestActivities();
     $this->restoreService('UserSession');
 }
Example #11
0
 /**
  * @NoAdminRequired
  *
  * @param int $page
  * @param string $filter
  * @param string $objecttype
  * @param int $objectid
  * @return JSONResponse
  */
 public function fetch($page, $filter = 'all', $objecttype = '', $objectid = 0)
 {
     $pageOffset = $page - 1;
     $filter = $this->data->validateFilter($filter);
     $activities = $this->data->read($this->helper, $this->settings, $pageOffset * self::DEFAULT_PAGE_SIZE, self::DEFAULT_PAGE_SIZE, $filter, '', $objecttype, $objectid);
     $preparedActivities = [];
     foreach ($activities as $activity) {
         if (strpos($activity['subjectformatted']['markup']['trimmed'], '<a ') !== false) {
             // We do not link the subject as we create links for the parameters instead
             $activity['link'] = '';
         }
         $activity['previews'] = [];
         if ($activity['object_type'] === 'files' && !empty($activity['files'])) {
             foreach ($activity['files'] as $objectId => $objectName) {
                 if ((int) $objectId === 0 || $objectName === '') {
                     // No file, no preview
                     continue;
                 }
                 $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $objectId, $objectName);
                 if (sizeof($activity['previews']) >= self::MAX_NUM_THUMBNAILS) {
                     // Don't want to clutter the page, so we stop after a few thumbnails
                     break;
                 }
             }
         } else {
             if ($activity['object_type'] === 'files' && $activity['object_id']) {
                 $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $activity['object_id'], $activity['file']);
             }
         }
         $preparedActivities[] = $activity;
     }
     return new JSONResponse($preparedActivities);
 }
Example #12
0
 /**
  * Delete remaining activities and emails when a user is deleted
  * @param array $params The hook params
  */
 public function deleteUser($params)
 {
     // Delete activity entries
     $this->activityData->deleteActivities(array('affecteduser' => $params['uid']));
     // Delete entries from mail queue
     $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*activity_mq` ' . ' WHERE `amq_affecteduser` = ?');
     $query->execute(array($params['uid']));
 }
Example #13
0
 /**
  * @expectedException \OutOfBoundsException
  * @expectedExceptionMessage Invalid user
  * @expectedExceptionCode 1
  */
 public function testGetNoUser()
 {
     /** @var \OCA\Activity\GroupHelper|\PHPUnit_Framework_MockObject_MockObject $groupHelper */
     $groupHelper = $this->getMockBuilder('OCA\\Activity\\GroupHelper')->disableOriginalConstructor()->getMock();
     /** @var \OCA\Activity\UserSettings|\PHPUnit_Framework_MockObject_MockObject $settings */
     $settings = $this->getMockBuilder('OCA\\Activity\\UserSettings')->disableOriginalConstructor()->getMock();
     $this->data->get($groupHelper, $settings, '', 0, 0, 'asc', '');
 }
Example #14
0
 /**
  * @dataProvider showData
  *
  * @param string $acceptHeader
  * @param string $expectedHeader
  */
 public function testShow($acceptHeader, $expectedHeader)
 {
     $this->mockUserSession('test');
     $this->data->expects($this->any())->method('get')->willReturn(['data' => []]);
     if ($acceptHeader !== null) {
         $this->request->expects($this->any())->method('getHeader')->willReturn($acceptHeader);
     }
     $templateResponse = $this->controller->show();
     $this->assertTrue($templateResponse instanceof TemplateResponse, 'Asserting type of return is \\OCP\\AppFramework\\Http\\TemplateResponse');
     $headers = $templateResponse->getHeaders();
     $this->assertArrayHasKey('Content-Type', $headers);
     $this->assertEquals($expectedHeader, $headers['Content-Type']);
     $renderedResponse = $templateResponse->render();
     $this->assertNotEmpty($renderedResponse);
     $l = Util::getL10N('activity');
     $description = (string) $l->t('Your feed URL is invalid');
     $this->assertNotContains($description, $renderedResponse);
 }
 /**
  * @dataProvider receiveData
  *
  * @param string $type
  * @param string $author
  * @param string $affectedUser
  * @param string $subject
  * @param array|false $expected
  */
 public function testReceiveEmail($type, $author, $affectedUser, $subject, $expected)
 {
     $time = time();
     $consumer = new Consumer($this->data, $this->userSettings);
     $event = \OC::$server->getActivityManager()->generateEvent();
     $event->setApp('test')->setType($type)->setAffectedUser($affectedUser)->setAuthor($author)->setTimestamp($time)->setSubject($subject, ['subjectParam1', 'subjectParam2'])->setMessage('message', ['messageParam1', 'messageParam2'])->setObject('', 0, 'file')->setLink('link');
     if ($expected === false) {
         $this->data->expects($this->never())->method('storeMail');
     } else {
         $this->data->expects($this->once())->method('storeMail')->with($event, $time + 10);
     }
     $consumer->receive($event);
 }
Example #16
0
 /**
  * @dataProvider dataGet
  * @param int $time
  * @param string $objectType
  * @param int $objectId
  * @param array $additionalArgs
  * @param bool $loadPreviews
  * @param int $numGetPreviewCalls
  * @param array $expected
  */
 public function testGet($time, $objectType, $objectId, array $additionalArgs, $loadPreviews, $numGetPreviewCalls, array $expected)
 {
     $controller = $this->getController(['readParameters', 'generateHeaders', 'getPreview']);
     $controller->expects($this->any())->method('generateHeaders')->willReturnArgument(0);
     $controller->expects($this->once())->method('readParameters');
     $controller->expects($this->exactly($numGetPreviewCalls))->method('getPreview')->willReturn(['preview']);
     $this->invokePrivate($controller, 'loadPreviews', [$loadPreviews]);
     $this->data->expects($this->once())->method('get')->willReturn(['data' => [array_merge(['timestamp' => $time, 'object_type' => $objectType, 'object_id' => $objectId], $additionalArgs)], 'headers' => ['X-Activity-First-Known' => 23], 'has_more' => false]);
     /** @var \OC_OCS_Result $result */
     $result = $this->invokePrivate($controller, 'get', [[]]);
     $this->assertInstanceOf('\\OC_OCS_Result', $result);
     $this->assertSame(100, $result->getStatusCode());
     $this->assertSame([$expected], $result->getData());
 }
Example #17
0
 /**
  * Send an event into the activity stream of a user
  *
  * @param string $app The app where this event is associated with
  * @param string $subject A short description of the event
  * @param array  $subjectParams Array with parameters that are filled in the subject
  * @param string $message A longer description of the event
  * @param array  $messageParams Array with parameters that are filled in the message
  * @param string $file The file including path where this event is associated with. (optional)
  * @param string $link A link where this event is associated with (optional)
  * @param string $affectedUser If empty the current user will be used
  * @param string $type Type of the notification
  * @param int    $priority Priority of the notification
  * @return null
  */
 public function receive($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority)
 {
     $selfAction = substr($subject, -5) === '_self';
     $streamSetting = $this->userSettings->getUserSetting($affectedUser, 'stream', $type);
     $emailSetting = $this->userSettings->getUserSetting($affectedUser, 'email', $type);
     $emailSetting = $emailSetting ? $this->userSettings->getUserSetting($affectedUser, 'setting', 'batchtime') : false;
     // Add activity to stream
     if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($affectedUser, 'setting', 'self'))) {
         Data::send($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority);
     }
     // Add activity to mail queue
     if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($affectedUser, 'setting', 'selfemail'))) {
         $latestSend = time() + $emailSetting;
         Data::storeMail($app, $subject, $subjectParams, $affectedUser, $type, $latestSend);
     }
 }
Example #18
0
 /**
  * @param array $parameters
  * @return \OC_OCS_Result
  */
 protected function get(array $parameters)
 {
     try {
         $this->readParameters($parameters);
     } catch (InvalidFilterException $e) {
         return new \OC_OCS_Result(null, Http::STATUS_NOT_FOUND);
     } catch (\OutOfBoundsException $e) {
         return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
     }
     try {
         $response = $this->data->get($this->helper, $this->settings, $this->user, $this->since, $this->limit, $this->sort, $this->filter, $this->objectType, $this->objectId);
     } catch (\OutOfBoundsException $e) {
         // Invalid since argument
         return new \OC_OCS_Result(null, Http::STATUS_FORBIDDEN);
     } catch (\BadMethodCallException $e) {
         // No activity settings enabled
         return new \OC_OCS_Result(null, Http::STATUS_NO_CONTENT);
     }
     $headers = $this->generateHeaders($response['headers'], $response['has_more']);
     if (empty($response['data'])) {
         return new \OC_OCS_Result([], Http::STATUS_NOT_MODIFIED, null, $headers);
     }
     $preparedActivities = [];
     foreach ($response['data'] as $activity) {
         $activity['datetime'] = date('c', $activity['timestamp']);
         unset($activity['timestamp']);
         if ($this->loadPreviews) {
             $activity['previews'] = [];
             if ($activity['object_type'] === 'files' && !empty($activity['files'])) {
                 foreach ($activity['files'] as $objectId => $objectName) {
                     if ((int) $objectId === 0 || $objectName === '') {
                         // No file, no preview
                         continue;
                     }
                     $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $objectId, $objectName);
                 }
             } else {
                 if ($activity['object_type'] === 'files' && $activity['object_id']) {
                     $activity['previews'][] = $this->getPreview($activity['affecteduser'], (int) $activity['object_id'], $activity['file']);
                 }
             }
         }
         $preparedActivities[] = $activity;
     }
     return new \OC_OCS_Result($preparedActivities, 100, null, $headers);
 }
Example #19
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function displayPanel()
 {
     $types = $this->data->getNotificationTypes($this->l10n);
     $activities = array();
     foreach ($types as $type => $desc) {
         $activities[$type] = array('desc' => $desc, 'email' => $this->userSettings->getUserSetting($this->user, 'email', $type), 'stream' => $this->userSettings->getUserSetting($this->user, 'stream', $type));
     }
     $settingBatchTime = UserSettings::EMAIL_SEND_HOURLY;
     if ($this->userSettings->getUserSetting($this->user, 'setting', 'batchtime') == 3600 * 24 * 7) {
         $settingBatchTime = UserSettings::EMAIL_SEND_WEEKLY;
     } else {
         if ($this->userSettings->getUserSetting($this->user, 'setting', 'batchtime') == 3600 * 24) {
             $settingBatchTime = UserSettings::EMAIL_SEND_DAILY;
         }
     }
     return new TemplateResponse('activity', 'personal', ['activities' => $activities, 'activity_email' => $this->config->getUserValue($this->user, 'settings', 'email', ''), 'setting_batchtime' => $settingBatchTime, 'notify_self' => $this->userSettings->getUserSetting($this->user, 'setting', 'self'), 'notify_selfemail' => $this->userSettings->getUserSetting($this->user, 'setting', 'selfemail')], '');
 }
Example #20
0
 /**
  * @brief Registers the filesystem hooks for basic filesystem operations. All other events has to be triggered by the apps.
  */
 public static function getActivities()
 {
     $start = isset($_GET['start']) ? $_GET['start'] : 0;
     $count = isset($_GET['count']) ? $_GET['count'] : 30;
     $data = Data::read($start, $count);
     $activities = array();
     foreach ($data as $d) {
         $activity = array();
         $activity['id'] = $d['activity_id'];
         $activity['subject'] = $d['subject'];
         $activity['message'] = $d['message'];
         $activity['file'] = $d['file'];
         $activity['link'] = $d['link'];
         $activity['date'] = date('c', $d['timestamp']);
         $activities[] = $activity;
     }
     return new OC_OCS_Result($activities);
 }
Example #21
0
 /**
  * Adds the activity and email for a user when the settings require it
  *
  * @param string $user
  * @param string $subject
  * @param array $subjectParams
  * @param string $path
  * @param bool $isFile If the item is a file, we link to the parent directory
  * @param bool $streamSetting
  * @param int $emailSetting
  * @param string $type
  * @param int $priority
  */
 protected function addNotificationsForUser($user, $subject, $subjectParams, $path, $isFile, $streamSetting, $emailSetting, $type = Files_Sharing::TYPE_SHARED, $priority = IExtension::PRIORITY_MEDIUM)
 {
     if (!$streamSetting && !$emailSetting) {
         return;
     }
     $selfAction = $user === $this->currentUser;
     $app = $type === Files_Sharing::TYPE_SHARED ? 'files_sharing' : 'files';
     $link = Util::linkToAbsolute('files', 'index.php', array('dir' => $isFile ? dirname($path) : $path));
     // Add activity to stream
     if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'self'))) {
         $this->activityData->send($app, $subject, $subjectParams, '', array(), $path, $link, $user, $type, $priority);
     }
     // Add activity to mail queue
     if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'selfemail'))) {
         $latestSend = time() + $emailSetting;
         $this->activityData->storeMail($app, $subject, $subjectParams, $user, $type, $latestSend);
     }
 }
Example #22
0
 /**
  * Adds the activity and email for a user when the settings require it
  *
  * @param string $user
  * @param string $subject
  * @param array $subjectParams
  * @param int $fileId
  * @param string $path
  * @param bool $isFile If the item is a file, we link to the parent directory
  * @param bool $streamSetting
  * @param int $emailSetting
  * @param string $type
  */
 protected function addNotificationsForUser($user, $subject, $subjectParams, $fileId, $path, $isFile, $streamSetting, $emailSetting, $type = Files_Sharing::TYPE_SHARED)
 {
     if (!$streamSetting && !$emailSetting) {
         return;
     }
     $selfAction = $user === $this->currentUser;
     $app = $type === Files_Sharing::TYPE_SHARED ? 'files_sharing' : 'files';
     $link = Util::linkToAbsolute('files', 'index.php', array('dir' => $isFile ? dirname($path) : $path));
     $objectType = $fileId ? 'files' : '';
     $event = $this->manager->generateEvent();
     $event->setApp($app)->setType($type)->setAffectedUser($user)->setAuthor($this->currentUser)->setTimestamp(time())->setSubject($subject, $subjectParams)->setObject($objectType, $fileId, $path)->setLink($link);
     // Add activity to stream
     if ($streamSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'self'))) {
         $this->activityData->send($event);
     }
     // Add activity to mail queue
     if ($emailSetting && (!$selfAction || $this->userSettings->getUserSetting($this->currentUser, 'setting', 'selfemail'))) {
         $latestSend = time() + $emailSetting;
         $this->activityData->storeMail($event, $latestSend);
     }
 }
Example #23
0
 /**
  * @dataProvider dataAddNotificationsForUser
  *
  * @param string $user
  * @param string $subject
  * @param array $parameter
  * @param int $fileId
  * @param string $path
  * @param bool $isFile
  * @param bool $stream
  * @param bool $email
  * @param int $type
  * @param bool $selfSetting
  * @param bool $selfEmailSetting
  * @param string $app
  * @param bool $sentStream
  * @param bool $sentEmail
  */
 public function testAddNotificationsForUser($user, $subject, $parameter, $fileId, $path, $isFile, $stream, $email, $type, $selfSetting, $selfEmailSetting, $app, $sentStream, $sentEmail)
 {
     $this->settings->expects($this->any())->method('getUserSetting')->willReturnMap([[$user, 'setting', 'self', $selfSetting], [$user, 'setting', 'selfemail', $selfEmailSetting]]);
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('setApp')->with($app)->willReturnSelf();
     $event->expects($this->once())->method('setType')->with($type)->willReturnSelf();
     $event->expects($this->once())->method('setAffectedUser')->with($user)->willReturnSelf();
     $event->expects($this->once())->method('setAuthor')->with('user')->willReturnSelf();
     $event->expects($this->once())->method('setTimestamp')->willReturnSelf();
     $event->expects($this->once())->method('setSubject')->with($subject, $parameter)->willReturnSelf();
     $event->expects($this->once())->method('setLink')->willReturnSelf();
     if ($fileId) {
         $event->expects($this->once())->method('setObject')->with('files', $fileId, $path)->willReturnSelf();
     } else {
         $event->expects($this->once())->method('setObject')->with('', $fileId, $path)->willReturnSelf();
     }
     $this->activityManager->expects($this->once())->method('generateEvent')->willReturn($event);
     $this->data->expects($sentStream ? $this->once() : $this->never())->method('send')->with($event);
     $this->data->expects($sentEmail ? $this->once() : $this->never())->method('storeMail')->with($event, $this->anything());
     $this->invokePrivate($this->filesHooks, 'addNotificationsForUser', [$user, $subject, $parameter, $fileId, $path, $isFile, $stream, $email, $type]);
 }
Example #24
0
 /**
  * @dataProvider dataSend
  *
  * @param string $actionUser
  * @param string $affectedUser
  * @param string $expectedAuthor
  * @param string $expectedAffected
  * @param bool $expectedActivity
  */
 public function testStoreMail($actionUser, $affectedUser, $expectedAuthor, $expectedAffected, $expectedActivity)
 {
     $mockSession = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock();
     $this->overwriteService('UserSession', $mockSession);
     $this->deleteTestMails();
     $time = time();
     $event = \OC::$server->getActivityManager()->generateEvent();
     $event->setApp('test')->setType('type')->setAffectedUser($affectedUser)->setSubject('subject', [])->setTimestamp($time);
     $this->assertSame($expectedActivity, $this->data->storeMail($event, $time + 10));
     $connection = \OC::$server->getDatabaseConnection();
     $query = $connection->prepare('SELECT `amq_latest_send`, `amq_affecteduser` FROM `*PREFIX*activity_mq` WHERE `amq_appid` = ? ORDER BY `mail_id` DESC');
     $query->execute(['test']);
     $row = $query->fetch();
     if ($expectedActivity) {
         $this->assertEquals(['amq_latest_send' => $time + 10, 'amq_affecteduser' => $expectedAffected], $row);
     } else {
         $this->assertFalse($row);
     }
     $this->deleteTestMails();
     $this->restoreService('UserSession');
 }
Example #25
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @return TemplateResponse
  */
 public function displayPanel()
 {
     $types = $this->data->getNotificationTypes($this->l10n);
     $activities = array();
     foreach ($types as $type => $desc) {
         if (is_array($desc)) {
             $methods = isset($desc['methods']) ? $desc['methods'] : [IExtension::METHOD_STREAM, IExtension::METHOD_MAIL];
             $desc = isset($desc['desc']) ? $desc['desc'] : '';
         } else {
             $methods = [IExtension::METHOD_STREAM, IExtension::METHOD_MAIL];
         }
         $activities[$type] = array('desc' => $desc, IExtension::METHOD_MAIL => $this->userSettings->getUserSetting($this->user, 'email', $type), IExtension::METHOD_STREAM => $this->userSettings->getUserSetting($this->user, 'stream', $type), 'methods' => $methods);
     }
     $settingBatchTime = UserSettings::EMAIL_SEND_HOURLY;
     $currentSetting = (int) $this->userSettings->getUserSetting($this->user, 'setting', 'batchtime');
     if ($currentSetting === 3600 * 24 * 7) {
         $settingBatchTime = UserSettings::EMAIL_SEND_WEEKLY;
     } else {
         if ($currentSetting === 3600 * 24) {
             $settingBatchTime = UserSettings::EMAIL_SEND_DAILY;
         }
     }
     return new TemplateResponse('activity', 'personal', ['activities' => $activities, 'activity_email' => $this->config->getUserValue($this->user, 'settings', 'email', ''), 'setting_batchtime' => $settingBatchTime, 'notify_self' => $this->userSettings->getUserSetting($this->user, 'setting', 'self'), 'notify_selfemail' => $this->userSettings->getUserSetting($this->user, 'setting', 'selfemail'), 'methods' => [IExtension::METHOD_MAIL => $this->l10n->t('Mail'), IExtension::METHOD_STREAM => $this->l10n->t('Stream')]], '');
 }
Example #26
0
 /**
  * Get a list with enabled notification types for a user
  *
  * @param string	$user	Name of the user
  * @param string	$method	Should be one of 'stream' or 'email'
  * @return array
  */
 public static function getNotificationTypes($user, $method)
 {
     $l = \OC_L10N::get('activity');
     $data = new Data(\OC::$server->getActivityManager());
     $types = $data->getNotificationTypes($l);
     $notificationTypes = array();
     foreach ($types as $type => $desc) {
         if (self::getUserSetting($user, $method, $type)) {
             $notificationTypes[] = $type;
         }
     }
     return $notificationTypes;
 }
 /**
  * @dataProvider deleteActivitiesData
  */
 public function testDeleteActivities($condition, $expected)
 {
     $this->assertUserActivities(array('delete', 'otherUser'));
     $this->data->deleteActivities($condition);
     $this->assertUserActivities($expected);
 }
 /**
  * @NoAdminRequired
  *
  * @param int $page
  * @param string $filter
  * @return TemplateResponse
  */
 public function fetch($page, $filter = 'all')
 {
     $pageOffset = $page - 1;
     $filter = $this->data->validateFilter($filter);
     return new TemplateResponse('activity', 'activities.part', ['activity' => $this->data->read($this->helper, $this->settings, $pageOffset * self::DEFAULT_PAGE_SIZE, self::DEFAULT_PAGE_SIZE, $filter)], '');
 }
Example #29
0
 /**
  * @dataProvider validateFilterData
  *
  * @param string $filter
  * @param string $expected
  */
 public function testValidateFilter($filter, $expected)
 {
     $this->assertEquals($expected, $this->data->validateFilter($filter));
 }
Example #30
0
 /**
  * @param $app
  * @param $subject
  * @param $subjectParams
  * @param $message
  * @param $messageParams
  * @param $file
  * @param $link
  * @param $affectedUser
  * @param $type
  * @param $priority
  * @return mixed
  */
 function receive($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority)
 {
     Data::send($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority);
 }