/**
  * Send an email to {$limit} users
  *
  * @param int $limit Number of users we want to send an email to
  * @return int Number of users we sent an email to
  */
 protected function runStep($limit)
 {
     // Get all users which should receive an email
     $affectedUsers = $this->mqHandler->getAffectedUsers($limit);
     if (empty($affectedUsers)) {
         // No users found to notify, mission abort
         return 0;
     }
     $preferences = new \OC\Preferences(\OC_DB::getConnection());
     $userLanguages = $preferences->getValueForUsers('core', 'lang', $affectedUsers);
     $userEmails = $preferences->getValueForUsers('settings', 'email', $affectedUsers);
     // Get all items for these users
     // We don't use time() but "time() - 1" here, so we don't run into
     // runtime issues and delete emails later, which were created in the
     // same second, but were not collected for the emails.
     $sendTime = time() - 1;
     $mailData = $this->mqHandler->getItemsForUsers($affectedUsers, $sendTime);
     // Send Email
     $default_lang = \OC_Config::getValue('default_language', 'en');
     foreach ($mailData as $user => $data) {
         if (!isset($userEmails[$user])) {
             // The user did not setup an email address
             // So we will not send an email :(
             continue;
         }
         $language = isset($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
         $this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $data);
     }
     // Delete all entries we dealt with
     $this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
     return sizeof($affectedUsers);
 }
Exemple #2
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
\OCP\App::checkAppEnabled('activity');
$forceUserLogout = false;
if (!\OCP\User::isLoggedIn()) {
    if (!isset($_GET['token']) || strlen($_GET['token']) !== 30) {
        // Token missing or invalid
        header('HTTP/1.0 404 Not Found');
        exit;
    }
    $preferences = new \OC\Preferences(\OC_DB::getConnection());
    $users = $preferences->getUsersForValue('activity', 'rsstoken', $_GET['token']);
    if (sizeof($users) !== 1) {
        // User not found
        header('HTTP/1.0 404 Not Found');
        exit;
    }
    // Token found login as that user
    \OC_User::setUserId(array_shift($users));
    $forceUserLogout = true;
}
// check if the user has the right permissions.
\OCP\User::checkLoggedIn();
// rss is of content type text/xml
if (isset($_SERVER['HTTP_ACCEPT']) && stristr($_SERVER['HTTP_ACCEPT'], 'application/rss+xml')) {
    header('Content-Type: application/rss+xml');
Exemple #3
0
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*
*/
\OCP\JSON::checkLoggedIn();
\OCP\JSON::checkAppEnabled('activity');
\OCP\JSON::callCheck();
$l = \OCP\Util::getL10N('activity');
$token = $tokenUrl = '';
if ($_POST['enable'] === 'true') {
    // Check for collisions
    $token = \OCP\Util::generateRandomBytes();
    $preferences = new \OC\Preferences(\OC_DB::getConnection());
    $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token);
    while (!empty($conflicts)) {
        $token = \OCP\Util::generateRandomBytes();
        $conflicts = $preferences->getUsersForValue('activity', 'rsstoken', $token);
    }
    $tokenUrl = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('activity.rss', array('token' => $token)));
}
\OCP\Config::setUserValue(\OCP\User::getUser(), 'activity', 'rsstoken', $token);
\OCP\JSON::success(array('data' => array('message' => $l->t('Your settings have been updated.'), 'rsslink' => $tokenUrl)));
Exemple #4
0
 /**
  * Filters the given user array by their notification setting
  *
  * @param array $users
  * @param string $method
  * @param string $type
  * @return array Returns a "username => b:true" Map for method = stream
  *               Returns a "username => i:batchtime" Map for method = email
  */
 public static function filterUsersBySetting($users, $method, $type)
 {
     if (empty($users) || !is_array($users)) {
         return array();
     }
     $preferences = new \OC\Preferences(\OC_DB::getConnection());
     $filteredUsers = array();
     $potentialUsers = $preferences->getValueForUsers('activity', 'notify_' . $method . '_' . $type, $users);
     foreach ($potentialUsers as $user => $value) {
         if ($value) {
             $filteredUsers[$user] = true;
         }
         unset($users[array_search($user, $users)]);
     }
     // Get the batch time setting from the database
     if ($method == 'email') {
         $potentialUsers = $preferences->getValueForUsers('activity', 'notify_setting_batchtime', array_keys($filteredUsers));
         foreach ($potentialUsers as $user => $value) {
             $filteredUsers[$user] = $value;
         }
     }
     if (empty($users)) {
         return $filteredUsers;
     }
     // If the setting is enabled by default,
     // we add all users that didn't set the preference yet.
     if (UserSettings::getDefaultSetting($method, $type)) {
         foreach ($users as $user) {
             if ($method == 'stream') {
                 $filteredUsers[$user] = true;
             } else {
                 $filteredUsers[$user] = self::getDefaultSetting('setting', 'batchtime');
             }
         }
     }
     return $filteredUsers;
 }
Exemple #5
0
 public function testDeleteAppFromAllUsers()
 {
     $connectionMock = $this->getMock('\\OC\\DB\\Connection', array(), array(), '', false);
     $connectionMock->expects($this->once())->method('delete')->with($this->equalTo('*PREFIX*preferences'), $this->equalTo(array('appid' => 'bar')));
     $preferences = new OC\Preferences($connectionMock);
     $preferences->deleteAppFromAllUsers('bar');
 }