зеркало из https://github.com/nextcloud/activity.git
Merge the activitydefaults app into activity
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Родитель
a6bdfbd7f3
Коммит
3c99781d9c
|
@ -15,7 +15,7 @@
|
|||
<licence>AGPL</licence>
|
||||
<author>Frank Karlitschek, Joas Schilling</author>
|
||||
<shipped>true</shipped>
|
||||
<version>2.5.0</version>
|
||||
<version>2.5.1</version>
|
||||
<default_enable/>
|
||||
<types>
|
||||
<filesystem/>
|
||||
|
@ -49,6 +49,11 @@
|
|||
</filters>
|
||||
</activity>
|
||||
|
||||
<settings>
|
||||
<admin>OCA\Activity\Settings\Admin</admin>
|
||||
<admin-section>OCA\Activity\Settings\Section</admin-section>
|
||||
</settings>
|
||||
|
||||
<background-jobs>
|
||||
<job>OCA\Activity\BackgroundJob\EmailNotification</job>
|
||||
<job>OCA\Activity\BackgroundJob\ExpireActivities</job>
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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', ''),
|
||||
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
script('activity', 'admin');
|
||||
style('activity', 'settings');
|
||||
print_unescaped($this->inc('settings/form'));
|
|
@ -22,12 +22,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
script('activity', 'settings');
|
||||
style('activity', 'settings');
|
||||
?>
|
||||
|
||||
<form id="activity_notifications" class="section">
|
||||
<h2><?php p($l->t('Activity')); ?></h2>
|
||||
<h2 class="icon-activity"><?php p($l->t('Activity')); ?></h2>
|
||||
|
||||
<table class="grid activitysettings">
|
||||
<thead>
|
||||
<tr>
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
script('activity', 'settings');
|
||||
style('activity', 'settings');
|
||||
print_unescaped($this->inc('settings/form'));
|
Загрузка…
Ссылка в новой задаче