Skip to content

Commit 63d584a

Browse files
committed
use principaluri instead of userid, allowing to add delegates for rooms and things
Signed-off-by: Georg Ehrke <developer@georgehrke.com> !fixup add owner_id and proxy_id as db index, since we use it for querying Signed-off-by: Georg Ehrke <developer@georgehrke.com> !fixup don't add ACL for each individual proxy, just use calendar-proxy groups Signed-off-by: Georg Ehrke <developer@georgehrke.com> !fixup allow delegation of resources / rooms Signed-off-by: Georg Ehrke <developer@georgehrke.com> !fixup fix addIndex call in migration Signed-off-by: Georg Ehrke <developer@georgehrke.com> !fixup fix remaining constructor calls of Principal Signed-off-by: Georg Ehrke <developer@georgehrke.com> !fixup minor fixes and unit tests Signed-off-by: Georg Ehrke <developer@georgehrke.com>
1 parent 3d86537 commit 63d584a

21 files changed

+644
-222
lines changed

apps/dav/appinfo/v1/caldav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
\OC::$server->getGroupManager(),
4747
\OC::$server->getShareManager(),
4848
\OC::$server->getUserSession(),
49-
\OC::$server->getConfig(),
5049
\OC::$server->getAppManager(),
50+
\OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
5151
'principals/'
5252
);
5353
$db = \OC::$server->getDatabaseConnection();

apps/dav/appinfo/v1/carddav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
\OC::$server->getGroupManager(),
4848
\OC::$server->getShareManager(),
4949
\OC::$server->getUserSession(),
50-
\OC::$server->getConfig(),
5150
\OC::$server->getAppManager(),
51+
\OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
5252
'principals/'
5353
);
5454
$db = \OC::$server->getDatabaseConnection();

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
'OCA\\DAV\\SystemTag\\SystemTagsObjectMappingCollection' => $baseDir . '/../lib/SystemTag/SystemTagsObjectMappingCollection.php',
197197
'OCA\\DAV\\SystemTag\\SystemTagsObjectTypeCollection' => $baseDir . '/../lib/SystemTag/SystemTagsObjectTypeCollection.php',
198198
'OCA\\DAV\\SystemTag\\SystemTagsRelationsCollection' => $baseDir . '/../lib/SystemTag/SystemTagsRelationsCollection.php',
199+
'OCA\\DAV\\Traits\\PrincipalProxyTrait' => $baseDir . '/../lib/Traits/PrincipalProxyTrait.php',
199200
'OCA\\DAV\\Upload\\AssemblyStream' => $baseDir . '/../lib/Upload/AssemblyStream.php',
200201
'OCA\\DAV\\Upload\\ChunkingPlugin' => $baseDir . '/../lib/Upload/ChunkingPlugin.php',
201202
'OCA\\DAV\\Upload\\CleanupService' => $baseDir . '/../lib/Upload/CleanupService.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class ComposerStaticInitDAV
211211
'OCA\\DAV\\SystemTag\\SystemTagsObjectMappingCollection' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagsObjectMappingCollection.php',
212212
'OCA\\DAV\\SystemTag\\SystemTagsObjectTypeCollection' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagsObjectTypeCollection.php',
213213
'OCA\\DAV\\SystemTag\\SystemTagsRelationsCollection' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagsRelationsCollection.php',
214+
'OCA\\DAV\\Traits\\PrincipalProxyTrait' => __DIR__ . '/..' . '/../lib/Traits/PrincipalProxyTrait.php',
214215
'OCA\\DAV\\Upload\\AssemblyStream' => __DIR__ . '/..' . '/../lib/Upload/AssemblyStream.php',
215216
'OCA\\DAV\\Upload\\ChunkingPlugin' => __DIR__ . '/..' . '/../lib/Upload/ChunkingPlugin.php',
216217
'OCA\\DAV\\Upload\\CleanupService' => __DIR__ . '/..' . '/../lib/Upload/CleanupService.php',

apps/dav/lib/CalDAV/Calendar.php

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
4747
/** @var IConfig */
4848
private $config;
4949

50-
/** @var ProxyMapper */
51-
private $proxyMapper;
52-
50+
/**
51+
* Calendar constructor.
52+
*
53+
* @param BackendInterface $caldavBackend
54+
* @param $calendarInfo
55+
* @param IL10N $l10n
56+
* @param IConfig $config
57+
*/
5358
public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
5459
parent::__construct($caldavBackend, $calendarInfo);
5560

@@ -62,9 +67,6 @@ public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10
6267
}
6368

6469
$this->config = $config;
65-
66-
// TODO: proper DI
67-
$this->proxyMapper = \OC::$server->query(ProxyMapper::class);
6870
}
6971

7072
/**
@@ -126,29 +128,60 @@ public function getPrincipalURI() {
126128
return $this->calendarInfo['principaluri'];
127129
}
128130

131+
/**
132+
* @return array
133+
*/
129134
public function getACL() {
130135
$acl = [
131136
[
132137
'privilege' => '{DAV:}read',
133138
'principal' => $this->getOwner(),
134139
'protected' => true,
135-
]];
140+
],
141+
[
142+
'privilege' => '{DAV:}read',
143+
'principal' => $this->getOwner() . '/calendar-proxy-write',
144+
'protected' => true,
145+
],
146+
[
147+
'privilege' => '{DAV:}read',
148+
'principal' => $this->getOwner() . '/calendar-proxy-read',
149+
'protected' => true,
150+
],
151+
];
152+
136153
if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
137154
$acl[] = [
138155
'privilege' => '{DAV:}write',
139156
'principal' => $this->getOwner(),
140157
'protected' => true,
141158
];
159+
$acl[] = [
160+
'privilege' => '{DAV:}write',
161+
'principal' => $this->getOwner() . '/calendar-proxy-write',
162+
'protected' => true,
163+
];
142164
} else {
143165
$acl[] = [
144166
'privilege' => '{DAV:}write-properties',
145167
'principal' => $this->getOwner(),
146168
'protected' => true,
147169
];
170+
$acl[] = [
171+
'privilege' => '{DAV:}write-properties',
172+
'principal' => $this->getOwner() . '/calendar-proxy-write',
173+
'protected' => true,
174+
];
148175
}
149176

177+
$acl[] = [
178+
'privilege' => '{DAV:}write-properties',
179+
'principal' => $this->getOwner() . '/calendar-proxy-read',
180+
'protected' => true,
181+
];
182+
150183
if (!$this->isShared()) {
151-
return $this->addProxies($acl);
184+
return $acl;
152185
}
153186

154187
if ($this->getOwner() !== parent::getOwner()) {
@@ -180,38 +213,16 @@ public function getACL() {
180213
}
181214

182215
$acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl);
183-
$allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public'];
184-
$acl = array_filter($acl, function($rule) use ($allowedPrincipals) {
216+
$allowedPrincipals = [
217+
$this->getOwner(),
218+
$this->getOwner(). '/calendar-proxy-read',
219+
$this->getOwner(). '/calendar-proxy-write',
220+
parent::getOwner(),
221+
'principals/system/public'
222+
];
223+
return array_filter($acl, function($rule) use ($allowedPrincipals) {
185224
return \in_array($rule['principal'], $allowedPrincipals, true);
186225
});
187-
188-
$acl = $this->addProxies($acl);
189-
190-
return $acl;
191-
}
192-
193-
public function addProxies(array $acl): array {
194-
list($prefix, $name) = \Sabre\Uri\split($this->getOwner());
195-
$proxies = $this->proxyMapper->getProxiesOf($name);
196-
197-
foreach ($proxies as $proxy) {
198-
if ($proxy->getPermissions() & ProxyMapper::PERMISSION_READ) {
199-
$acl[] = [
200-
'privilege' => '{DAV:}read',
201-
'principal' => 'principals/users/' . $proxy->getProxyId(),
202-
'protected' => true,
203-
];
204-
}
205-
if ($proxy->getPermissions() & ProxyMapper::PERMISSION_WRITE) {
206-
$acl[] = [
207-
'privilege' => '{DAV:}write',
208-
'principal' => 'principals/users/' . $proxy->getProxyId(),
209-
'protected' => true,
210-
];
211-
}
212-
}
213-
214-
return $acl;
215226
}
216227

217228
public function getChildACL() {

apps/dav/lib/CalDAV/Proxy/ProxyMapper.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,27 @@
2727
use OCP\AppFramework\Db\QBMapper;
2828
use OCP\IDBConnection;
2929

30+
/**
31+
* Class ProxyMapper
32+
*
33+
* @package OCA\DAV\CalDAV\Proxy
34+
*/
3035
class ProxyMapper extends QBMapper {
3136

3237
const PERMISSION_READ = 1;
3338
const PERMISSION_WRITE = 2;
3439

40+
/**
41+
* ProxyMapper constructor.
42+
*
43+
* @param IDBConnection $db
44+
*/
3545
public function __construct(IDBConnection $db) {
3646
parent::__construct($db, 'dav_cal_proxy', Proxy::class);
3747
}
3848

3949
/**
40-
* @param string $proxyId The userId that can act as a proxy for the resulting calendars
50+
* @param string $proxyId The principal uri that can act as a proxy for the resulting calendars
4151
*
4252
* @return Proxy[]
4353
*/
@@ -52,7 +62,7 @@ public function getProxiesFor(string $proxyId): array {
5262
}
5363

5464
/**
55-
* @param string $ownerId The userId that has the resulting proxies for their calendars
65+
* @param string $ownerId The principal uri that has the resulting proxies for their calendars
5666
*
5767
* @return Proxy[]
5868
*/

apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
namespace OCA\DAV\CalDAV\ResourceBooking;
2424

25+
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
26+
use OCA\DAV\Traits\PrincipalProxyTrait;
2527
use OCP\IDBConnection;
2628
use OCP\IGroupManager;
2729
use OCP\ILogger;
@@ -44,6 +46,9 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
4446
/** @var ILogger */
4547
private $logger;
4648

49+
/** @var ProxyMapper */
50+
private $proxyMapper;
51+
4752
/** @var string */
4853
private $principalPrefix;
4954

@@ -72,20 +77,24 @@ public function __construct(IDBConnection $dbConnection,
7277
IUserSession $userSession,
7378
IGroupManager $groupManager,
7479
ILogger $logger,
80+
ProxyMapper $proxyMapper,
7581
string $principalPrefix,
7682
string $dbPrefix,
7783
string $cuType) {
7884
$this->db = $dbConnection;
7985
$this->userSession = $userSession;
8086
$this->groupManager = $groupManager;
8187
$this->logger = $logger;
88+
$this->proxyMapper = $proxyMapper;
8289
$this->principalPrefix = $principalPrefix;
8390
$this->dbTableName = 'calendar_' . $dbPrefix . 's';
8491
$this->dbMetaDataTableName = $this->dbTableName . '_md';
8592
$this->dbForeignKeyName = $dbPrefix . '_id';
8693
$this->cuType = $cuType;
8794
}
8895

96+
use PrincipalProxyTrait;
97+
8998
/**
9099
* Returns a list of principals based on a prefix.
91100
*
@@ -215,39 +224,6 @@ public function getPrincipalById($id):?array {
215224
return $this->rowToPrincipal($row, $metadata);
216225
}
217226

218-
/**
219-
* Returns the list of members for a group-principal
220-
*
221-
* @param string $principal
222-
* @return string[]
223-
*/
224-
public function getGroupMemberSet($principal) {
225-
return [];
226-
}
227-
228-
/**
229-
* Returns the list of groups a principal is a member of
230-
*
231-
* @param string $principal
232-
* @return array
233-
*/
234-
public function getGroupMembership($principal) {
235-
return [];
236-
}
237-
238-
/**
239-
* Updates the list of group members for a group principal.
240-
*
241-
* The principals should be passed as a list of uri's.
242-
*
243-
* @param string $principal
244-
* @param string[] $members
245-
* @throws Exception
246-
*/
247-
public function setGroupMemberSet($principal, array $members) {
248-
throw new Exception('Setting members of the group is not supported yet');
249-
}
250-
251227
/**
252228
* @param string $path
253229
* @param PropPatch $propPatch

apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,34 @@
2222
*/
2323
namespace OCA\DAV\CalDAV\ResourceBooking;
2424

25+
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
2526
use OCP\IDBConnection;
2627
use OCP\IGroupManager;
2728
use OCP\ILogger;
2829
use OCP\IUserSession;
2930

31+
/**
32+
* Class ResourcePrincipalBackend
33+
*
34+
* @package OCA\DAV\CalDAV\ResourceBooking
35+
*/
3036
class ResourcePrincipalBackend extends AbstractPrincipalBackend {
3137

3238
/**
39+
* ResourcePrincipalBackend constructor.
40+
*
3341
* @param IDBConnection $dbConnection
3442
* @param IUserSession $userSession
3543
* @param IGroupManager $groupManager
3644
* @param ILogger $logger
45+
* @param ProxyMapper $proxyMapper
3746
*/
3847
public function __construct(IDBConnection $dbConnection,
3948
IUserSession $userSession,
4049
IGroupManager $groupManager,
41-
ILogger $logger) {
50+
ILogger $logger,
51+
ProxyMapper $proxyMapper) {
4252
parent::__construct($dbConnection, $userSession, $groupManager, $logger,
43-
'principals/calendar-resources', 'resource', 'RESOURCE');
53+
$proxyMapper, 'principals/calendar-resources', 'resource', 'RESOURCE');
4454
}
4555
}

apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,34 @@
2222
*/
2323
namespace OCA\DAV\CalDAV\ResourceBooking;
2424

25+
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
2526
use OCP\IDBConnection;
2627
use OCP\IGroupManager;
2728
use OCP\ILogger;
2829
use OCP\IUserSession;
2930

31+
/**
32+
* Class RoomPrincipalBackend
33+
*
34+
* @package OCA\DAV\CalDAV\ResourceBooking
35+
*/
3036
class RoomPrincipalBackend extends AbstractPrincipalBackend {
3137

3238
/**
39+
* RoomPrincipalBackend constructor.
40+
*
3341
* @param IDBConnection $dbConnection
3442
* @param IUserSession $userSession
3543
* @param IGroupManager $groupManager
3644
* @param ILogger $logger
45+
* @param ProxyMapper $proxyMapper
3746
*/
3847
public function __construct(IDBConnection $dbConnection,
3948
IUserSession $userSession,
4049
IGroupManager $groupManager,
41-
ILogger $logger) {
50+
ILogger $logger,
51+
ProxyMapper $proxyMapper) {
4252
parent::__construct($dbConnection, $userSession, $groupManager, $logger,
43-
'principals/calendar-rooms', 'room', 'ROOM');
53+
$proxyMapper, 'principals/calendar-rooms', 'room', 'ROOM');
4454
}
4555
}

apps/dav/lib/Command/CreateCalendar.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace OCA\DAV\Command;
2525

2626
use OCA\DAV\CalDAV\CalDavBackend;
27+
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
2728
use OCA\DAV\Connector\Sabre\Principal;
2829
use OCP\IDBConnection;
2930
use OCP\IGroupManager;
@@ -78,8 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output) {
7879
$this->groupManager,
7980
\OC::$server->getShareManager(),
8081
\OC::$server->getUserSession(),
81-
\OC::$server->getConfig(),
82-
\OC::$server->getAppManager()
82+
\OC::$server->getAppManager(),
83+
\OC::$server->query(ProxyMapper::class)
8384
);
8485
$random = \OC::$server->getSecureRandom();
8586
$logger = \OC::$server->getLogger();

0 commit comments

Comments
 (0)