Skip to content

Commit 044706f

Browse files
authored
Merge pull request #5625 from nextcloud/feat/team-provider
feat: Implement a team resource provider
2 parents 2f5a479 + d90d0a5 commit 044706f

5 files changed

Lines changed: 140 additions & 4 deletions

File tree

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

img/deck-current.svg

Lines changed: 8 additions & 0 deletions
Loading

lib/AppInfo/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
use OCA\Deck\Service\PermissionService;
6363
use OCA\Deck\Sharing\DeckShareProvider;
6464
use OCA\Deck\Sharing\Listener;
65+
use OCA\Deck\Teams\DeckTeamResourceProvider;
6566
use OCA\Text\Event\LoadEditor;
6667
use OCP\AppFramework\App;
6768
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -179,6 +180,8 @@ public function register(IRegistrationContext $context): void {
179180

180181
$context->registerNotifierService(Notifier::class);
181182
$context->registerEventListener(LoadAdditionalScriptsEvent::class, ResourceAdditionalScriptsListener::class);
183+
184+
$context->registerTeamResourceProvider(DeckTeamResourceProvider::class);
182185
}
183186

184187
public function registerCommentsEntity(IEventDispatcher $eventDispatcher): void {

lib/Db/BoardMapper.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,51 @@ public function findAllByCircles(string $userId, ?int $limit = null, ?int $offse
400400
return $entries;
401401
}
402402

403+
public function findAllByTeam(string $teamId): array {
404+
$qb = $this->db->getQueryBuilder();
405+
$qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified')
406+
->from('deck_boards', 'b')
407+
->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id'))
408+
->where($qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)))
409+
->andWhere($qb->expr()->eq('acl.participant', $qb->createNamedParameter($teamId, IQueryBuilder::PARAM_STR)));
410+
$entries = $this->findEntities($qb);
411+
foreach ($entries as $entry) {
412+
$entry->setShared(2);
413+
}
414+
return $entries;
415+
}
416+
417+
public function findTeamsForBoard(int $boardId): array {
418+
$qb = $this->db->getQueryBuilder();
419+
$qb->select('acl.participant')
420+
->from('deck_boards', 'b')
421+
->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id'))
422+
->where($qb->expr()->eq('b.id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)))
423+
->andWhere($qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)));
424+
425+
$result = $qb->executeQuery();
426+
return array_map(function ($entry) {
427+
return $entry['participant'];
428+
}, $result->fetchAll());
429+
}
430+
431+
public function isSharedWithTeam(int $boardId, string $teamId): bool {
432+
$qb = $this->db->getQueryBuilder();
433+
$qb->select('b.id', 'title', 'owner', 'color', 'archived', 'deleted_at', 'last_modified')
434+
->from('deck_boards', 'b')
435+
->innerJoin('b', 'deck_board_acl', 'acl', $qb->expr()->eq('b.id', 'acl.board_id'))
436+
->where($qb->expr()->eq('b.id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)))
437+
->andWhere($qb->expr()->eq('acl.type', $qb->createNamedParameter(Acl::PERMISSION_TYPE_CIRCLE, IQueryBuilder::PARAM_INT)))
438+
->andWhere($qb->expr()->eq('acl.participant', $qb->createNamedParameter($teamId, IQueryBuilder::PARAM_STR)));
439+
try {
440+
$this->findEntity($qb);
441+
return true;
442+
} catch (DoesNotExistException $e) {
443+
// Expected return falue
444+
}
445+
return false;
446+
}
447+
403448
public function findAll(): array {
404449
$qb = $this->db->getQueryBuilder();
405450
$qb->select('id')
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\Deck\Teams;
6+
7+
use OCA\Deck\AppInfo\Application;
8+
use OCA\Deck\Db\Board;
9+
use OCA\Deck\Db\BoardMapper;
10+
use OCP\IURLGenerator;
11+
use OCP\Teams\TeamResource;
12+
13+
/**
14+
* @copyright Copyright (c) 2024 Julius Härtl <jus@bitgrid.net>
15+
*
16+
* @author Julius Härtl <jus@bitgrid.net>
17+
*
18+
* @license GNU AGPL version 3 or any later version
19+
*
20+
* This program is free software: you can redistribute it and/or modify
21+
* it under the terms of the GNU Affero General Public License as
22+
* published by the Free Software Foundation, either version 3 of the
23+
* License, or (at your option) any later version.
24+
*
25+
* This program is distributed in the hope that it will be useful,
26+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+
* GNU Affero General Public License for more details.
29+
*
30+
* You should have received a copy of the GNU Affero General Public License
31+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
32+
*/
33+
34+
class DeckTeamResourceProvider implements \OCP\Teams\ITeamResourceProvider {
35+
36+
public function __construct(
37+
private BoardMapper $boardMapper,
38+
private IURLGenerator $urlGenerator,
39+
) {
40+
}
41+
42+
43+
public function getId(): string {
44+
return Application::APP_ID;
45+
}
46+
47+
public function getName(): string {
48+
return 'Deck';
49+
}
50+
51+
public function getIconSvg(): string {
52+
return file_get_contents(__DIR__ . '/../../img/deck-current.svg');
53+
}
54+
55+
public function getSharedWith($teamId): array {
56+
$boards = $this->boardMapper->findAllByTeam($teamId);
57+
return array_map(function (Board $board) {
58+
return new TeamResource(
59+
$this,
60+
(string)$board->getId(),
61+
$board->getTitle(),
62+
$this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#/board/' . $board->getId(),
63+
$this->getBoardBulletIcon($board),
64+
$this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('deck', 'deck-current.svg')),
65+
);
66+
}, $boards);
67+
}
68+
69+
public function isSharedWithTeam(string $teamId, string $resourceId): bool {
70+
return $this->boardMapper->isSharedWithTeam((int)$resourceId, $teamId);
71+
}
72+
73+
public function getTeamsForResource(string $resourceId): array {
74+
return $this->boardMapper->findTeamsForBoard((int)$resourceId);
75+
}
76+
77+
public function getBoardBulletIcon(Board $board): string {
78+
return '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" version="1.1" viewBox="0 0 16 16"><g fill="#' . $board->getColor(). '"><rect ry="15" height="14" width="14" y="1" x="1"/></g></svg>';
79+
}
80+
}

0 commit comments

Comments
 (0)