Merge branch 'master' into enh/cloneStack
This commit is contained in:
@@ -64,6 +64,8 @@ class BoardService {
|
||||
private $eventDispatcher;
|
||||
private $changeHelper;
|
||||
|
||||
private $boardsCache = null;
|
||||
|
||||
public function __construct(
|
||||
BoardMapper $boardMapper,
|
||||
StackMapper $stackMapper,
|
||||
@@ -105,42 +107,55 @@ class BoardService {
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function findAll($since = -1, $details = null) {
|
||||
public function getUserBoards(int $since = -1): array {
|
||||
$userInfo = $this->getBoardPrerequisites();
|
||||
$userBoards = $this->boardMapper->findAllByUser($userInfo['user'], null, null, $since);
|
||||
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups'],null, null, $since);
|
||||
$circleBoards = $this->boardMapper->findAllByCircles($userInfo['user'], null, null, $since);
|
||||
$complete = array_merge($userBoards, $groupBoards, $circleBoards);
|
||||
$mergedBoards = array_merge($userBoards, $groupBoards, $circleBoards);
|
||||
$result = [];
|
||||
/** @var Board $item */
|
||||
foreach ($complete as &$item) {
|
||||
foreach ($mergedBoards as &$item) {
|
||||
if (!array_key_exists($item->getId(), $result)) {
|
||||
$this->boardMapper->mapOwner($item);
|
||||
if ($item->getAcl() !== null) {
|
||||
foreach ($item->getAcl() as &$acl) {
|
||||
$this->boardMapper->mapAcl($acl);
|
||||
}
|
||||
}
|
||||
if ($details !== null) {
|
||||
$this->enrichWithStacks($item);
|
||||
$this->enrichWithLabels($item);
|
||||
$this->enrichWithUsers($item);
|
||||
}
|
||||
$permissions = $this->permissionService->matchPermissions($item);
|
||||
$item->setPermissions([
|
||||
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false,
|
||||
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false,
|
||||
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$result[$item->getId()] = $item;
|
||||
}
|
||||
}
|
||||
return array_values($result);
|
||||
}
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function findAll($since = -1, $details = null) {
|
||||
if ($this->boardsCache) {
|
||||
return $this->boardsCache;
|
||||
}
|
||||
$complete = $this->getUserBoards($since);
|
||||
$result = [];
|
||||
/** @var Board $item */
|
||||
foreach ($complete as &$item) {
|
||||
$this->boardMapper->mapOwner($item);
|
||||
if ($item->getAcl() !== null) {
|
||||
foreach ($item->getAcl() as &$acl) {
|
||||
$this->boardMapper->mapAcl($acl);
|
||||
}
|
||||
}
|
||||
if ($details !== null) {
|
||||
$this->enrichWithStacks($item);
|
||||
$this->enrichWithLabels($item);
|
||||
$this->enrichWithUsers($item);
|
||||
}
|
||||
$permissions = $this->permissionService->matchPermissions($item);
|
||||
$item->setPermissions([
|
||||
'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ] ?? false,
|
||||
'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT] ?? false,
|
||||
'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE] ?? false,
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$result[$item->getId()] = $item;
|
||||
}
|
||||
$this->boardsCache = $result;
|
||||
return array_values($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $boardId
|
||||
@@ -151,6 +166,9 @@ class BoardService {
|
||||
* @throws BadRequestException
|
||||
*/
|
||||
public function find($boardId) {
|
||||
if ($this->boardsCache && isset($this->boardsCache[$boardId])) {
|
||||
return $this->boardsCache[$boardId];
|
||||
}
|
||||
if (is_numeric($boardId) === false) {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
@@ -172,6 +190,7 @@ class BoardService {
|
||||
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE] ?? false
|
||||
]);
|
||||
$this->enrichWithUsers($board);
|
||||
$this->boardsCache[$board->getId()] = $board;
|
||||
return $board;
|
||||
}
|
||||
|
||||
@@ -331,7 +350,7 @@ class BoardService {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
if ($board->getDeletedAt() > 0) {
|
||||
throw new BadRequestException('This board has already been deleted');
|
||||
@@ -360,7 +379,7 @@ class BoardService {
|
||||
throw new BadRequestException('board id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
$board->setDeletedAt(0);
|
||||
$board = $this->boardMapper->update($board);
|
||||
@@ -387,7 +406,7 @@ class BoardService {
|
||||
throw new BadRequestException('id must be a number');
|
||||
}
|
||||
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_READ);
|
||||
$this->permissionService->checkPermission($this->boardMapper, $id, Acl::PERMISSION_MANAGE);
|
||||
$board = $this->find($id);
|
||||
$delete = $this->boardMapper->delete($board);
|
||||
|
||||
|
||||
@@ -116,6 +116,11 @@ class CardService {
|
||||
return $cards;
|
||||
}
|
||||
|
||||
public function search($boardIds, $term) {
|
||||
$cards = $this->cardMapper->search($boardIds, $term);
|
||||
return $cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cardId
|
||||
* @return \OCA\Deck\Db\RelationalEntity
|
||||
@@ -139,6 +144,15 @@ class CardService {
|
||||
return $card;
|
||||
}
|
||||
|
||||
public function findCalendarEntries($boardId) {
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||
$cards = $this->cardMapper->findCalendarEntries($boardId);
|
||||
foreach ($cards as $card) {
|
||||
$this->enrich($card);
|
||||
}
|
||||
return $cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $title
|
||||
* @param $stackId
|
||||
|
||||
129
lib/Service/ConfigService.php
Normal file
129
lib/Service/ConfigService.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace OCA\Deck\Service;
|
||||
|
||||
use OCA\Deck\AppInfo\Application;
|
||||
use OCA\Deck\NoPermissionException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
|
||||
class ConfigService {
|
||||
private $config;
|
||||
private $userId;
|
||||
private $groupManager;
|
||||
|
||||
public function __construct(
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
$userId
|
||||
) {
|
||||
$this->userId = $userId;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getAll(): array {
|
||||
$data = [
|
||||
'calendar' => $this->get('calendar')
|
||||
];
|
||||
if ($this->groupManager->isAdmin($this->userId)) {
|
||||
$data = [
|
||||
'groupLimit' => $this->get('groupLimit'),
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function get($key) {
|
||||
$result = null;
|
||||
switch ($key) {
|
||||
case 'groupLimit':
|
||||
if (!$this->groupManager->isAdmin($this->userId)) {
|
||||
throw new NoPermissionException('You must be admin to get the group limit');
|
||||
}
|
||||
$result = $this->getGroupLimit();
|
||||
break;
|
||||
case 'calendar':
|
||||
$result = (bool)$this->config->getUserValue($this->userId, Application::APP_ID, 'calendar', true);
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function set($key, $value) {
|
||||
$result = null;
|
||||
switch ($key) {
|
||||
case 'groupLimit':
|
||||
if (!$this->groupManager->isAdmin($this->userId)) {
|
||||
throw new NoPermissionException('You must be admin to set the group limit');
|
||||
}
|
||||
$result = $this->setGroupLimit($value);
|
||||
break;
|
||||
case 'calendar':
|
||||
$this->config->setUserValue($this->userId, Application::APP_ID, 'calendar', (int)$value);
|
||||
$result = $value;
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function setGroupLimit($value) {
|
||||
$groups = [];
|
||||
foreach ($value as $group) {
|
||||
$groups[] = $group['id'];
|
||||
}
|
||||
$data = implode(',', $groups);
|
||||
$this->config->setAppValue(Application::APP_ID, 'groupLimit', $data);
|
||||
return $groups;
|
||||
}
|
||||
|
||||
private function getGroupLimitList() {
|
||||
$value = $this->config->getAppValue(Application::APP_ID, 'groupLimit', '');
|
||||
$groups = explode(',', $value);
|
||||
if ($value === '') {
|
||||
return [];
|
||||
}
|
||||
return $groups;
|
||||
}
|
||||
|
||||
private function getGroupLimit() {
|
||||
$groups = $this->getGroupLimitList();
|
||||
$groups = array_map(function ($groupId) {
|
||||
/** @var IGroup $groups */
|
||||
$group = $this->groupManager->get($groupId);
|
||||
if ($group === null) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
'id' => $group->getGID(),
|
||||
'displayname' => $group->getDisplayName(),
|
||||
];
|
||||
}, $groups);
|
||||
return array_filter($groups);
|
||||
}
|
||||
}
|
||||
@@ -162,6 +162,11 @@ class StackService {
|
||||
return $stacks;
|
||||
}
|
||||
|
||||
public function findCalendarEntries($boardId) {
|
||||
$this->permissionService->checkPermission(null, $boardId, Acl::PERMISSION_READ);
|
||||
return $this->stackMapper->findAll($boardId);
|
||||
}
|
||||
|
||||
public function fetchDeleted($boardId) {
|
||||
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
|
||||
$stacks = $this->stackMapper->findDeleted($boardId);
|
||||
|
||||
Reference in New Issue
Block a user