aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-08-06 14:41:33 +0200
committerGeorg Ehrke <developer@georgehrke.com>2019-08-15 15:41:27 +0200
commit3d86537dc922083427a283e84d726d416f9ec95c (patch)
tree7fc0d8d287c360829afd3c102695dd4efbd8209a /apps/dav
parent01a4644cad99c8502f15a7f62f72f4e040670024 (diff)
downloadnextcloud-server-3d86537dc922083427a283e84d726d416f9ec95c.tar.gz
nextcloud-server-3d86537dc922083427a283e84d726d416f9ec95c.zip
Early first stage implementation of the groupset
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/Connector/Sabre/Principal.php56
1 files changed, 54 insertions, 2 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php
index 9a0cd3b5210..cc8e9c7accb 100644
--- a/apps/dav/lib/Connector/Sabre/Principal.php
+++ b/apps/dav/lib/Connector/Sabre/Principal.php
@@ -35,6 +35,7 @@
namespace OCA\DAV\Connector\Sabre;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
+use OCA\DAV\CalDAV\Proxy\Proxy;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
@@ -228,8 +229,59 @@ class Principal implements BackendInterface {
* @throws Exception
*/
public function setGroupMemberSet($principal, array $members) {
- $a = 'b';
- throw new Exception('Setting members of the group is not supported yet');
+ list($prefix, $target) = \Sabre\Uri\split($principal);
+
+ if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') {
+ throw new Exception('Setting members of the group is not supported yet');
+ }
+
+ $permission = ProxyMapper::PERMISSION_READ;
+ if ($target === 'calendar-proxy-write') {
+ $permission |= ProxyMapper::PERMISSION_WRITE;
+ }
+
+ list($prefix, $owner) = \Sabre\Uri\split($prefix);
+ $proxies = $this->proxyMapper->getProxiesOf($owner);
+
+ foreach ($members as $member) {
+ list($prefix, $name) = \Sabre\Uri\split($member);
+
+ if ($prefix !== $this->principalPrefix) {
+ throw new Exception('Invalid member group prefix: ' . $prefix);
+ }
+
+ $user = $this->userManager->get($name);
+ if ($user === null) {
+ throw new Exception('Invalid member: ' . $name);
+ }
+
+ $found = false;
+ foreach ($proxies as $proxy) {
+ if ($proxy->getProxyId() === $user->getUID()) {
+ $found = true;
+ $proxy->setPermissions($proxy->getPermissions() | $permission);
+ $this->proxyMapper->update($proxy);
+
+ $proxies = array_filter($proxies, function(Proxy $p) use ($proxy) {
+ return $p->getId() !== $proxy->getId();
+ });
+ break;
+ }
+ }
+
+ if ($found === false) {
+ $proxy = new Proxy();
+ $proxy->setOwnerId($owner);
+ $proxy->setProxyId($user->getUID());
+ $proxy->setPermissions($permission);
+ $this->proxyMapper->insert($proxy);
+ }
+ }
+
+ // Delete all remaining proxies
+ foreach ($proxies as $proxy) {
+ $this->proxyMapper->delete($proxy);
+ }
}
/**