diff --git a/appinfo/info.xml b/appinfo/info.xml
index c6ff2956..087e8c60 100755
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -15,7 +15,7 @@
AGPL
Frank Karlitschek, Joas Schilling
true
- 2.5.0
+ 2.5.1
@@ -49,6 +49,11 @@
+
+ OCA\Activity\Settings\Admin
+ OCA\Activity\Settings\Section
+
+
OCA\Activity\BackgroundJob\EmailNotification
OCA\Activity\BackgroundJob\ExpireActivities
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 76aa403f..08127c21 100755
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -27,6 +27,7 @@ return [
],
'routes' => [
['name' => 'Settings#personal', 'url' => '/settings', 'verb' => 'POST'],
+ ['name' => 'Settings#admin', 'url' => '/settings/admin', 'verb' => 'POST'],
['name' => 'Settings#feed', 'url' => '/settings/feed', 'verb' => 'POST'],
['name' => 'Activities#showList', 'url' => '/', 'verb' => 'GET'],
['name' => 'Feed#show', 'url' => '/rss.php', 'verb' => 'GET'],
diff --git a/js/admin.js b/js/admin.js
new file mode 100644
index 00000000..4caebb65
--- /dev/null
+++ b/js/admin.js
@@ -0,0 +1,29 @@
+$(document).ready(function() {
+ function saveSettings() {
+ OC.msg.startSaving('#activity_notifications_msg');
+ var post = $('#activity_notifications').serialize();
+
+ $.post(OC.generateUrl('/apps/activity/settings/admin'), post, function(response) {
+ OC.msg.finishedSuccess('#activity_notifications_msg', response.data.message);
+ });
+ }
+
+ var $activityNotifications = $('#activity_notifications');
+ $activityNotifications.find('input[type=checkbox]').change(saveSettings);
+
+ $activityNotifications.find('select').change(saveSettings);
+
+ $activityNotifications.find('.activity_select_group').click(function() {
+ var $selectGroup = '#activity_notifications .' + $(this).attr('data-select-group');
+ var $filteredBoxes = $($selectGroup).not(':disabled');
+ var $checkedBoxes = $filteredBoxes.filter(':checked').length;
+
+ $filteredBoxes.prop('checked', true);
+ if ($checkedBoxes === $filteredBoxes.filter(':checked').length) {
+ // All values were already selected, so invert it
+ $filteredBoxes.prop('checked', false);
+ }
+
+ saveSettings();
+ });
+});
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 43e208eb..ad7ab4c5 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -86,6 +86,7 @@ class Application extends App {
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', [FilesHooksStatic::class, 'onLoadFilesAppScripts']);
Util::connectHook('OC_User', 'post_deleteUser', Hooks::class, 'deleteUser');
+ Util::connectHook('OC_User', 'post_login', Hooks::class, 'setDefaultsForUser');
$this->registerFilesActivity();
}
diff --git a/lib/Controller/Settings.php b/lib/Controller/Settings.php
index 34ce52e6..d16b7d75 100644
--- a/lib/Controller/Settings.php
+++ b/lib/Controller/Settings.php
@@ -153,6 +153,66 @@ class Settings extends Controller {
));
}
+ /**
+ * @param int $notify_setting_batchtime
+ * @param bool $notify_setting_self
+ * @param bool $notify_setting_selfemail
+ * @return DataResponse
+ */
+ public function admin(
+ $notify_setting_batchtime = UserSettings::EMAIL_SEND_HOURLY,
+ $notify_setting_self = false,
+ $notify_setting_selfemail = false) {
+
+ $settings = $this->manager->getSettings();
+ foreach ($settings as $setting) {
+ if ($setting->canChangeStream()) {
+ $this->config->setAppValue(
+ 'activity',
+ 'notify_stream_' . $setting->getIdentifier(),
+ (int) $this->request->getParam($setting->getIdentifier() . '_stream', false)
+ );
+ }
+
+ if ($setting->canChangeMail()) {
+ $this->config->setAppValue(
+ 'activity',
+ 'notify_email_' . $setting->getIdentifier(),
+ (int) $this->request->getParam($setting->getIdentifier() . '_email', false)
+ );
+ }
+ }
+
+ $email_batch_time = 3600;
+ if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_DAILY) {
+ $email_batch_time = 3600 * 24;
+ } else if ($notify_setting_batchtime === UserSettings::EMAIL_SEND_WEEKLY) {
+ $email_batch_time = 3600 * 24 * 7;
+ }
+
+ $this->config->setAppValue(
+ 'activity',
+ 'notify_setting_batchtime',
+ $email_batch_time
+ );
+ $this->config->setAppValue(
+ 'activity',
+ 'notify_setting_self',
+ (int) $notify_setting_self
+ );
+ $this->config->setAppValue(
+ 'activity',
+ 'notify_setting_selfemail',
+ (int) $notify_setting_selfemail
+ );
+
+ return new DataResponse(array(
+ 'data' => array(
+ 'message' => (string) $this->l10n->t('Settings have been updated.'),
+ ),
+ ));
+ }
+
/**
* @NoAdminRequired
* @NoCSRFRequired
@@ -200,7 +260,7 @@ class Settings extends Controller {
$settingBatchTime = UserSettings::EMAIL_SEND_DAILY;
}
- return new TemplateResponse('activity', 'personal', [
+ return new TemplateResponse('activity', 'settings/personal', [
'activities' => $activities,
'activity_email' => $this->config->getUserValue($this->user, 'settings', 'email', ''),
diff --git a/lib/Hooks.php b/lib/Hooks.php
index d7222487..ab489e5d 100755
--- a/lib/Hooks.php
+++ b/lib/Hooks.php
@@ -68,4 +68,25 @@ class Hooks {
->setParameter('user', $user);
$queryBuilder->execute();
}
+
+ static public function setDefaultsForUser($params) {
+ $config = \OC::$server->getConfig();
+ if ($config->getUserValue($params['uid'], 'activity','notify_setting_batchtime', null) !== null) {
+ // Already has settings
+ return;
+ }
+
+ foreach ($config->getAppKeys('activity') as $key) {
+ if (strpos($key, 'notify_') !== 0) {
+ continue;
+ }
+
+ $config->setUserValue(
+ $params['uid'],
+ 'activity',
+ $key,
+ $config->getAppValue('activity', $key)
+ );
+ }
+ }
}
diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php
new file mode 100644
index 00000000..9a89c091
--- /dev/null
+++ b/lib/Settings/Admin.php
@@ -0,0 +1,140 @@
+
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 program. If not, see .
+ *
+ */
+
+namespace OCA\Activity\Settings;
+
+use OCA\Activity\UserSettings;
+use OCP\Activity\IExtension;
+use OCP\Activity\IManager;
+use OCP\Activity\ISetting;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\Settings\ISettings;
+
+class Admin implements ISettings {
+
+ /** @var IConfig */
+ protected $config;
+
+ /** @var IL10N */
+ protected $l10n;
+
+ /** @var IManager */
+ protected $manager;
+
+ /** @var UserSettings */
+ protected $userSettings;
+
+ /**
+ * @param IConfig $config
+ * @param IL10N $l10n
+ * @param IManager $manager
+ * @param UserSettings $userSettings
+ */
+ public function __construct(IConfig $config, IL10N $l10n, UserSettings $userSettings, IManager $manager) {
+ $this->config = $config;
+ $this->l10n = $l10n;
+ $this->manager = $manager;
+ $this->userSettings = $userSettings;
+ }
+
+ /**
+ * @return TemplateResponse
+ */
+ public function getForm() {
+ $settings = $this->manager->getSettings();
+ usort($settings, function(ISetting $a, ISetting $b) {
+ if ($a->getPriority() === $b->getPriority()) {
+ return $a->getIdentifier() > $b->getIdentifier();
+ }
+
+ return $a->getPriority() > $b->getPriority();
+ });
+
+ $activities = [];
+ foreach ($settings as $setting) {
+ if (!$setting->canChangeStream() && !$setting->canChangeMail()) {
+ // No setting can be changed => don't display
+ continue;
+ }
+
+ $methods = [];
+ if ($setting->canChangeStream()) {
+ $methods[] = IExtension::METHOD_STREAM;
+ }
+ if ($setting->canChangeMail()) {
+ $methods[] = IExtension::METHOD_MAIL;
+ }
+
+ $identifier = $setting->getIdentifier();
+
+ $activities[$identifier] = array(
+ 'desc' => $setting->getName(),
+ IExtension::METHOD_MAIL => $this->userSettings->getConfigSetting('email', $identifier),
+ IExtension::METHOD_STREAM => $this->userSettings->getConfigSetting('stream', $identifier),
+ 'methods' => $methods,
+ );
+ }
+
+ $settingBatchTime = UserSettings::EMAIL_SEND_HOURLY;
+ $currentSetting = (int) $this->userSettings->getConfigSetting('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', 'settings/admin', [
+ 'activities' => $activities,
+ 'activity_email' => '!empty',
+
+ 'setting_batchtime' => $settingBatchTime,
+
+ 'notify_self' => $this->userSettings->getConfigSetting('setting', 'self'),
+ 'notify_selfemail' => $this->userSettings->getConfigSetting('setting', 'selfemail'),
+
+ 'methods' => [
+ IExtension::METHOD_MAIL => $this->l10n->t('Mail'),
+ IExtension::METHOD_STREAM => $this->l10n->t('Stream'),
+ ],
+ ], 'blank');
+ }
+
+ /**
+ * @return string the section ID, e.g. 'sharing'
+ */
+ public function getSection() {
+ return 'activity';
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the admin section. The forms are arranged in ascending order of the
+ * priority values. It is required to return a value between 0 and 100.
+ *
+ * E.g.: 70
+ */
+ public function getPriority() {
+ return 55;
+ }
+
+}
diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php
new file mode 100644
index 00000000..b4d8ecf7
--- /dev/null
+++ b/lib/Settings/Section.php
@@ -0,0 +1,89 @@
+
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 program. If not, see .
+ *
+ */
+
+namespace OCA\Activity\Settings;
+
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\Settings\IIconSection;
+
+class Section implements IIconSection {
+
+ /** @var IL10N */
+ private $l;
+
+ /** @var IURLGenerator */
+ private $url;
+
+ /**
+ * @param IURLGenerator $url
+ * @param IL10N $l
+ */
+ public function __construct(IURLGenerator $url, IL10N $l) {
+ $this->url = $url;
+ $this->l = $l;
+ }
+
+ /**
+ * returns the relative path to an 16*16 icon describing the section.
+ * e.g. '/core/img/places/files.svg'
+ *
+ * @returns string
+ * @since 12
+ */
+ public function getIcon() {
+ return $this->url->imagePath('activity', 'activity-dark.svg');
+ }
+
+ /**
+ * returns the ID of the section. It is supposed to be a lower case string,
+ * e.g. 'ldap'
+ *
+ * @returns string
+ * @since 9.1
+ */
+ public function getID() {
+ return 'activity';
+ }
+
+ /**
+ * returns the translated name as it should be displayed, e.g. 'LDAP / AD
+ * integration'. Use the L10N service to translate it.
+ *
+ * @return string
+ * @since 9.1
+ */
+ public function getName() {
+ return $this->l->t('Activity');
+ }
+
+ /**
+ * @return int whether the form should be rather on the top or bottom of
+ * the settings navigation. The sections are arranged in ascending order of
+ * the priority values. It is required to return a value between 0 and 99.
+ *
+ * E.g.: 70
+ * @since 9.1
+ */
+ public function getPriority() {
+ return 55;
+ }
+}
diff --git a/lib/UserSettings.php b/lib/UserSettings.php
index 4cc9c278..8ec08585 100644
--- a/lib/UserSettings.php
+++ b/lib/UserSettings.php
@@ -64,7 +64,7 @@ class UserSettings {
* @return bool|int
*/
public function getUserSetting($user, $method, $type) {
- $defaultSetting = $this->getDefaultSetting($method, $type);
+ $defaultSetting = $this->getDefaultFromSetting($method, $type);
if (is_bool($defaultSetting)) {
return (bool) $this->config->getUserValue(
$user,
@@ -82,6 +82,28 @@ class UserSettings {
}
}
+ /**
+ * @param string $method
+ * @param string $type
+ * @return bool|int
+ */
+ public function getConfigSetting($method, $type) {
+ $defaultSetting = $this->getDefaultFromSetting($method, $type);
+ if (is_bool($defaultSetting)) {
+ return (bool) $this->config->getAppValue(
+ 'activity',
+ 'notify_' . $method . '_' . $type,
+ $defaultSetting
+ );
+ } else {
+ return (int) $this->config->getAppValue(
+ 'activity',
+ 'notify_' . $method . '_' . $type,
+ $defaultSetting
+ );
+ }
+ }
+
/**
* Get a good default setting for a preference
*
@@ -89,7 +111,7 @@ class UserSettings {
* @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail'
* @return bool|int
*/
- public function getDefaultSetting($method, $type) {
+ protected function getDefaultFromSetting($method, $type) {
if ($method === 'setting') {
if ($type === 'batchtime') {
return 3600;
@@ -166,12 +188,12 @@ class UserSettings {
// If the setting is enabled by default,
// we add all users that didn't set the preference yet.
- if ($this->getDefaultSetting($method, $type)) {
+ if ($this->getDefaultFromSetting($method, $type)) {
foreach ($users as $user) {
if ($method === 'stream') {
$filteredUsers[$user] = true;
} else {
- $filteredUsers[$user] = $this->getDefaultSetting('setting', 'batchtime');
+ $filteredUsers[$user] = $this->getDefaultFromSetting('setting', 'batchtime');
}
}
}
diff --git a/templates/settings/admin.php b/templates/settings/admin.php
new file mode 100644
index 00000000..6ced8da1
--- /dev/null
+++ b/templates/settings/admin.php
@@ -0,0 +1,23 @@
+
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 program. If not, see .
+ *
+ */
+script('activity', 'admin');
+style('activity', 'settings');
+print_unescaped($this->inc('settings/form'));
diff --git a/templates/personal.php b/templates/settings/form.php
similarity index 97%
rename from templates/personal.php
rename to templates/settings/form.php
index 9b9eb248..9b21b99b 100644
--- a/templates/personal.php
+++ b/templates/settings/form.php
@@ -22,12 +22,11 @@
* along with this program. If not, see .
*
*/
-script('activity', 'settings');
-style('activity', 'settings');
?>