Skip to content
Snippets Groups Projects
Unverified Commit 3d86537d authored by Roeland Jago Douma's avatar Roeland Jago Douma Committed by Georg Ehrke
Browse files

Early first stage implementation of the groupset

parent 01a4644c
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
namespace OCA\DAV\Connector\Sabre; namespace OCA\DAV\Connector\Sabre;
use OCA\Circles\Exceptions\CircleDoesNotExistException; use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\DAV\CalDAV\Proxy\Proxy;
use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCP\App\IAppManager; use OCP\App\IAppManager;
use OCP\AppFramework\QueryException; use OCP\AppFramework\QueryException;
...@@ -228,8 +229,59 @@ class Principal implements BackendInterface { ...@@ -228,8 +229,59 @@ class Principal implements BackendInterface {
* @throws Exception * @throws Exception
*/ */
public function setGroupMemberSet($principal, array $members) { public function setGroupMemberSet($principal, array $members) {
$a = 'b'; list($prefix, $target) = \Sabre\Uri\split($principal);
throw new Exception('Setting members of the group is not supported yet');
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);
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment