Add option to configure notification level per board
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -37,6 +37,8 @@ class Board extends RelationalEntity {
|
||||
protected $deletedAt = 0;
|
||||
protected $lastModified = 0;
|
||||
|
||||
protected $settings = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id', 'integer');
|
||||
$this->addType('shared', 'integer');
|
||||
@@ -49,6 +51,7 @@ class Board extends RelationalEntity {
|
||||
$this->addRelation('users');
|
||||
$this->addRelation('permissions');
|
||||
$this->addRelation('stacks');
|
||||
$this->addRelation('settings');
|
||||
$this->addResolvable('owner');
|
||||
$this->shared = -1;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\Activity\ActivityManager;
|
||||
use OCA\Deck\Activity\ChangeSet;
|
||||
use OCA\Deck\AppInfo\Application;
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\AssignedUsersMapper;
|
||||
@@ -37,6 +38,7 @@ use OCA\Deck\Db\StackMapper;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCA\Deck\Db\Board;
|
||||
@@ -52,6 +54,8 @@ class BoardService {
|
||||
private $stackMapper;
|
||||
private $labelMapper;
|
||||
private $aclMapper;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
private $l10n;
|
||||
private $permissionService;
|
||||
private $notificationHelper;
|
||||
@@ -66,9 +70,11 @@ class BoardService {
|
||||
|
||||
private $boardsCache = null;
|
||||
|
||||
|
||||
public function __construct(
|
||||
BoardMapper $boardMapper,
|
||||
StackMapper $stackMapper,
|
||||
IConfig $config,
|
||||
IL10N $l10n,
|
||||
LabelMapper $labelMapper,
|
||||
AclMapper $aclMapper,
|
||||
@@ -85,6 +91,7 @@ class BoardService {
|
||||
$this->boardMapper = $boardMapper;
|
||||
$this->stackMapper = $stackMapper;
|
||||
$this->labelMapper = $labelMapper;
|
||||
$this->config = $config;
|
||||
$this->aclMapper = $aclMapper;
|
||||
$this->l10n = $l10n;
|
||||
$this->permissionService = $permissionService;
|
||||
@@ -151,6 +158,7 @@ class BoardService {
|
||||
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$this->enrichWithBoardSettings($item);
|
||||
$result[$item->getId()] = $item;
|
||||
}
|
||||
$this->boardsCache = $result;
|
||||
@@ -190,6 +198,7 @@ class BoardService {
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$this->enrichWithUsers($board);
|
||||
$this->enrichWithBoardSettings($board);
|
||||
$this->boardsCache[$board->getId()] = $board;
|
||||
return $board;
|
||||
}
|
||||
@@ -476,6 +485,14 @@ class BoardService {
|
||||
return [$edit, $share, $manage];
|
||||
}
|
||||
|
||||
public function enrichWithBoardSettings(Board $board) {
|
||||
$settings = [
|
||||
'notify-due' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED),
|
||||
'calendar' => $this->config->getUserValue($this->userId, Application::APP_ID, 'board:' . $board->getId() . ':calendar', true),
|
||||
];
|
||||
$board->setSettings($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $boardId
|
||||
* @param $type
|
||||
|
||||
@@ -27,12 +27,18 @@ declare(strict_types=1);
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\AppInfo\Application;
|
||||
use OCA\Deck\BadRequestException;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
|
||||
class ConfigService {
|
||||
public const SETTING_BOARD_NOTIFICATION_DUE_OFF = 'off';
|
||||
public const SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED = 'assigned';
|
||||
public const SETTING_BOARD_NOTIFICATION_DUE_ALL = 'all';
|
||||
public const SETTING_BOARD_NOTIFICATION_DUE_DEFAULT = self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
|
||||
|
||||
private $config;
|
||||
private $userId;
|
||||
private $groupManager;
|
||||
@@ -52,9 +58,7 @@ class ConfigService {
|
||||
'calendar' => $this->get('calendar')
|
||||
];
|
||||
if ($this->groupManager->isAdmin($this->userId)) {
|
||||
$data = [
|
||||
'groupLimit' => $this->get('groupLimit'),
|
||||
];
|
||||
$data['groupLimit'] = $this->get('groupLimit');
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@@ -77,7 +81,8 @@ class ConfigService {
|
||||
|
||||
public function set($key, $value) {
|
||||
$result = null;
|
||||
switch ($key) {
|
||||
[$scope, $id] = explode(':', $key, 2);
|
||||
switch ($scope) {
|
||||
case 'groupLimit':
|
||||
if (!$this->groupManager->isAdmin($this->userId)) {
|
||||
throw new NoPermissionException('You must be admin to set the group limit');
|
||||
@@ -88,6 +93,13 @@ class ConfigService {
|
||||
$this->config->setUserValue($this->userId, Application::APP_ID, 'calendar', (int)$value);
|
||||
$result = $value;
|
||||
break;
|
||||
case 'board':
|
||||
[$boardId, $boardConfigKey] = explode(':', $key);
|
||||
if (!in_array($value, [self::SETTING_BOARD_NOTIFICATION_DUE_ALL, self::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED, self::SETTING_BOARD_NOTIFICATION_DUE_OFF], true)) {
|
||||
throw new BadRequestException('Board notification option must be one of: off, assigned, all');
|
||||
}
|
||||
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
|
||||
$result = $value;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user