@@ -50,43 +50,43 @@ discard block |
||
50 | 50 | * @param Exception|Error $e |
51 | 51 | */ |
52 | 52 | function handleException($e) { |
53 | - $request = \OC::$server->getRequest(); |
|
54 | - // in case the request content type is text/xml - we assume it's a WebDAV request |
|
55 | - $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); |
|
56 | - if ($isXmlContentType === 0) { |
|
57 | - // fire up a simple server to properly process the exception |
|
58 | - $server = new Server(); |
|
59 | - if (!($e instanceof RemoteException)) { |
|
60 | - // we shall not log on RemoteException |
|
61 | - $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
|
62 | - } |
|
63 | - $server->on('beforeMethod:*', function () use ($e) { |
|
64 | - if ($e instanceof RemoteException) { |
|
65 | - switch ($e->getCode()) { |
|
66 | - case 503: |
|
67 | - throw new ServiceUnavailable($e->getMessage()); |
|
68 | - case 404: |
|
69 | - throw new \Sabre\DAV\Exception\NotFound($e->getMessage()); |
|
70 | - } |
|
71 | - } |
|
72 | - $class = get_class($e); |
|
73 | - $msg = $e->getMessage(); |
|
74 | - throw new ServiceUnavailable("$class: $msg"); |
|
75 | - }); |
|
76 | - $server->exec(); |
|
77 | - } else { |
|
78 | - $statusCode = 500; |
|
79 | - if ($e instanceof \OC\ServiceUnavailableException) { |
|
80 | - $statusCode = 503; |
|
81 | - } |
|
82 | - if ($e instanceof RemoteException) { |
|
83 | - // we shall not log on RemoteException |
|
84 | - OC_Template::printErrorPage($e->getMessage(), '', $e->getCode()); |
|
85 | - } else { |
|
86 | - \OC::$server->getLogger()->logException($e, ['app' => 'remote']); |
|
87 | - OC_Template::printExceptionErrorPage($e, $statusCode); |
|
88 | - } |
|
89 | - } |
|
53 | + $request = \OC::$server->getRequest(); |
|
54 | + // in case the request content type is text/xml - we assume it's a WebDAV request |
|
55 | + $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); |
|
56 | + if ($isXmlContentType === 0) { |
|
57 | + // fire up a simple server to properly process the exception |
|
58 | + $server = new Server(); |
|
59 | + if (!($e instanceof RemoteException)) { |
|
60 | + // we shall not log on RemoteException |
|
61 | + $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
|
62 | + } |
|
63 | + $server->on('beforeMethod:*', function () use ($e) { |
|
64 | + if ($e instanceof RemoteException) { |
|
65 | + switch ($e->getCode()) { |
|
66 | + case 503: |
|
67 | + throw new ServiceUnavailable($e->getMessage()); |
|
68 | + case 404: |
|
69 | + throw new \Sabre\DAV\Exception\NotFound($e->getMessage()); |
|
70 | + } |
|
71 | + } |
|
72 | + $class = get_class($e); |
|
73 | + $msg = $e->getMessage(); |
|
74 | + throw new ServiceUnavailable("$class: $msg"); |
|
75 | + }); |
|
76 | + $server->exec(); |
|
77 | + } else { |
|
78 | + $statusCode = 500; |
|
79 | + if ($e instanceof \OC\ServiceUnavailableException) { |
|
80 | + $statusCode = 503; |
|
81 | + } |
|
82 | + if ($e instanceof RemoteException) { |
|
83 | + // we shall not log on RemoteException |
|
84 | + OC_Template::printErrorPage($e->getMessage(), '', $e->getCode()); |
|
85 | + } else { |
|
86 | + \OC::$server->getLogger()->logException($e, ['app' => 'remote']); |
|
87 | + OC_Template::printExceptionErrorPage($e, $statusCode); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,80 +94,80 @@ discard block |
||
94 | 94 | * @return string |
95 | 95 | */ |
96 | 96 | function resolveService($service) { |
97 | - $services = [ |
|
98 | - 'webdav' => 'dav/appinfo/v1/webdav.php', |
|
99 | - 'dav' => 'dav/appinfo/v2/remote.php', |
|
100 | - 'caldav' => 'dav/appinfo/v1/caldav.php', |
|
101 | - 'calendar' => 'dav/appinfo/v1/caldav.php', |
|
102 | - 'carddav' => 'dav/appinfo/v1/carddav.php', |
|
103 | - 'contacts' => 'dav/appinfo/v1/carddav.php', |
|
104 | - 'files' => 'dav/appinfo/v1/webdav.php', |
|
105 | - 'direct' => 'dav/appinfo/v2/direct.php', |
|
106 | - ]; |
|
107 | - if (isset($services[$service])) { |
|
108 | - return $services[$service]; |
|
109 | - } |
|
110 | - |
|
111 | - return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
97 | + $services = [ |
|
98 | + 'webdav' => 'dav/appinfo/v1/webdav.php', |
|
99 | + 'dav' => 'dav/appinfo/v2/remote.php', |
|
100 | + 'caldav' => 'dav/appinfo/v1/caldav.php', |
|
101 | + 'calendar' => 'dav/appinfo/v1/caldav.php', |
|
102 | + 'carddav' => 'dav/appinfo/v1/carddav.php', |
|
103 | + 'contacts' => 'dav/appinfo/v1/carddav.php', |
|
104 | + 'files' => 'dav/appinfo/v1/webdav.php', |
|
105 | + 'direct' => 'dav/appinfo/v2/direct.php', |
|
106 | + ]; |
|
107 | + if (isset($services[$service])) { |
|
108 | + return $services[$service]; |
|
109 | + } |
|
110 | + |
|
111 | + return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | try { |
115 | - require_once __DIR__ . '/lib/base.php'; |
|
116 | - |
|
117 | - // All resources served via the DAV endpoint should have the strictest possible |
|
118 | - // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
|
119 | - // this policy with a softer one if debug mode is enabled. |
|
120 | - header("Content-Security-Policy: default-src 'none';"); |
|
121 | - |
|
122 | - if (\OCP\Util::needUpgrade()) { |
|
123 | - // since the behavior of apps or remotes are unpredictable during |
|
124 | - // an upgrade, return a 503 directly |
|
125 | - throw new RemoteException('Service unavailable', 503); |
|
126 | - } |
|
127 | - |
|
128 | - $request = \OC::$server->getRequest(); |
|
129 | - $pathInfo = $request->getPathInfo(); |
|
130 | - if ($pathInfo === false || $pathInfo === '') { |
|
131 | - throw new RemoteException('Path not found', 404); |
|
132 | - } |
|
133 | - if (!$pos = strpos($pathInfo, '/', 1)) { |
|
134 | - $pos = strlen($pathInfo); |
|
135 | - } |
|
136 | - $service=substr($pathInfo, 1, $pos-1); |
|
137 | - |
|
138 | - $file = resolveService($service); |
|
139 | - |
|
140 | - if(is_null($file)) { |
|
141 | - throw new RemoteException('Path not found', 404); |
|
142 | - } |
|
143 | - |
|
144 | - $file=ltrim($file, '/'); |
|
145 | - |
|
146 | - $parts=explode('/', $file, 2); |
|
147 | - $app=$parts[0]; |
|
148 | - |
|
149 | - // Load all required applications |
|
150 | - \OC::$REQUESTEDAPP = $app; |
|
151 | - OC_App::loadApps(['authentication']); |
|
152 | - OC_App::loadApps(['filesystem', 'logging']); |
|
153 | - |
|
154 | - switch ($app) { |
|
155 | - case 'core': |
|
156 | - $file = OC::$SERVERROOT .'/'. $file; |
|
157 | - break; |
|
158 | - default: |
|
159 | - if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
160 | - throw new RemoteException('App not installed: ' . $app); |
|
161 | - } |
|
162 | - OC_App::loadApp($app); |
|
163 | - $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
164 | - break; |
|
165 | - } |
|
166 | - $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
167 | - require_once $file; |
|
115 | + require_once __DIR__ . '/lib/base.php'; |
|
116 | + |
|
117 | + // All resources served via the DAV endpoint should have the strictest possible |
|
118 | + // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
|
119 | + // this policy with a softer one if debug mode is enabled. |
|
120 | + header("Content-Security-Policy: default-src 'none';"); |
|
121 | + |
|
122 | + if (\OCP\Util::needUpgrade()) { |
|
123 | + // since the behavior of apps or remotes are unpredictable during |
|
124 | + // an upgrade, return a 503 directly |
|
125 | + throw new RemoteException('Service unavailable', 503); |
|
126 | + } |
|
127 | + |
|
128 | + $request = \OC::$server->getRequest(); |
|
129 | + $pathInfo = $request->getPathInfo(); |
|
130 | + if ($pathInfo === false || $pathInfo === '') { |
|
131 | + throw new RemoteException('Path not found', 404); |
|
132 | + } |
|
133 | + if (!$pos = strpos($pathInfo, '/', 1)) { |
|
134 | + $pos = strlen($pathInfo); |
|
135 | + } |
|
136 | + $service=substr($pathInfo, 1, $pos-1); |
|
137 | + |
|
138 | + $file = resolveService($service); |
|
139 | + |
|
140 | + if(is_null($file)) { |
|
141 | + throw new RemoteException('Path not found', 404); |
|
142 | + } |
|
143 | + |
|
144 | + $file=ltrim($file, '/'); |
|
145 | + |
|
146 | + $parts=explode('/', $file, 2); |
|
147 | + $app=$parts[0]; |
|
148 | + |
|
149 | + // Load all required applications |
|
150 | + \OC::$REQUESTEDAPP = $app; |
|
151 | + OC_App::loadApps(['authentication']); |
|
152 | + OC_App::loadApps(['filesystem', 'logging']); |
|
153 | + |
|
154 | + switch ($app) { |
|
155 | + case 'core': |
|
156 | + $file = OC::$SERVERROOT .'/'. $file; |
|
157 | + break; |
|
158 | + default: |
|
159 | + if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
160 | + throw new RemoteException('App not installed: ' . $app); |
|
161 | + } |
|
162 | + OC_App::loadApp($app); |
|
163 | + $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
164 | + break; |
|
165 | + } |
|
166 | + $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
167 | + require_once $file; |
|
168 | 168 | |
169 | 169 | } catch (Exception $ex) { |
170 | - handleException($ex); |
|
170 | + handleException($ex); |
|
171 | 171 | } catch (Error $e) { |
172 | - handleException($e); |
|
172 | + handleException($e); |
|
173 | 173 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | */ |
34 | 34 | |
35 | -require_once __DIR__ . '/lib/versioncheck.php'; |
|
35 | +require_once __DIR__.'/lib/versioncheck.php'; |
|
36 | 36 | |
37 | 37 | use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin; |
38 | 38 | use Sabre\DAV\Exception\ServiceUnavailable; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | // we shall not log on RemoteException |
61 | 61 | $server->addPlugin(new ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); |
62 | 62 | } |
63 | - $server->on('beforeMethod:*', function () use ($e) { |
|
63 | + $server->on('beforeMethod:*', function() use ($e) { |
|
64 | 64 | if ($e instanceof RemoteException) { |
65 | 65 | switch ($e->getCode()) { |
66 | 66 | case 503: |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | return $services[$service]; |
109 | 109 | } |
110 | 110 | |
111 | - return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service); |
|
111 | + return \OC::$server->getConfig()->getAppValue('core', 'remote_'.$service); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | try { |
115 | - require_once __DIR__ . '/lib/base.php'; |
|
115 | + require_once __DIR__.'/lib/base.php'; |
|
116 | 116 | |
117 | 117 | // All resources served via the DAV endpoint should have the strictest possible |
118 | 118 | // policy. Exempted from this is the SabreDAV browser plugin which overwrites |
@@ -133,18 +133,18 @@ discard block |
||
133 | 133 | if (!$pos = strpos($pathInfo, '/', 1)) { |
134 | 134 | $pos = strlen($pathInfo); |
135 | 135 | } |
136 | - $service=substr($pathInfo, 1, $pos-1); |
|
136 | + $service = substr($pathInfo, 1, $pos - 1); |
|
137 | 137 | |
138 | 138 | $file = resolveService($service); |
139 | 139 | |
140 | - if(is_null($file)) { |
|
140 | + if (is_null($file)) { |
|
141 | 141 | throw new RemoteException('Path not found', 404); |
142 | 142 | } |
143 | 143 | |
144 | - $file=ltrim($file, '/'); |
|
144 | + $file = ltrim($file, '/'); |
|
145 | 145 | |
146 | - $parts=explode('/', $file, 2); |
|
147 | - $app=$parts[0]; |
|
146 | + $parts = explode('/', $file, 2); |
|
147 | + $app = $parts[0]; |
|
148 | 148 | |
149 | 149 | // Load all required applications |
150 | 150 | \OC::$REQUESTEDAPP = $app; |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | |
154 | 154 | switch ($app) { |
155 | 155 | case 'core': |
156 | - $file = OC::$SERVERROOT .'/'. $file; |
|
156 | + $file = OC::$SERVERROOT.'/'.$file; |
|
157 | 157 | break; |
158 | 158 | default: |
159 | 159 | if (!\OC::$server->getAppManager()->isInstalled($app)) { |
160 | - throw new RemoteException('App not installed: ' . $app); |
|
160 | + throw new RemoteException('App not installed: '.$app); |
|
161 | 161 | } |
162 | 162 | OC_App::loadApp($app); |
163 | - $file = OC_App::getAppPath($app) .'/'. $parts[1]; |
|
163 | + $file = OC_App::getAppPath($app).'/'.$parts[1]; |
|
164 | 164 | break; |
165 | 165 | } |
166 | - $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/'; |
|
166 | + $baseuri = OC::$WEBROOT.'/remote.php/'.$service.'/'; |
|
167 | 167 | require_once $file; |
168 | 168 | |
169 | 169 | } catch (Exception $ex) { |
@@ -35,270 +35,270 @@ |
||
35 | 35 | use Sabre\DAV\PropPatch; |
36 | 36 | |
37 | 37 | class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { |
38 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
39 | 39 | |
40 | - const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
41 | - const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
42 | - const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
43 | - const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
44 | - const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
45 | - const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
46 | - const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
47 | - const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
40 | + const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
41 | + const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
42 | + const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
43 | + const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
44 | + const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
45 | + const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
46 | + const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
47 | + const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
48 | 48 | |
49 | - /** @var IComment */ |
|
50 | - public $comment; |
|
49 | + /** @var IComment */ |
|
50 | + public $comment; |
|
51 | 51 | |
52 | - /** @var ICommentsManager */ |
|
53 | - protected $commentsManager; |
|
52 | + /** @var ICommentsManager */ |
|
53 | + protected $commentsManager; |
|
54 | 54 | |
55 | - /** @var ILogger */ |
|
56 | - protected $logger; |
|
55 | + /** @var ILogger */ |
|
56 | + protected $logger; |
|
57 | 57 | |
58 | - /** @var array list of properties with key being their name and value their setter */ |
|
59 | - protected $properties = []; |
|
58 | + /** @var array list of properties with key being their name and value their setter */ |
|
59 | + protected $properties = []; |
|
60 | 60 | |
61 | - /** @var IUserManager */ |
|
62 | - protected $userManager; |
|
61 | + /** @var IUserManager */ |
|
62 | + protected $userManager; |
|
63 | 63 | |
64 | - /** @var IUserSession */ |
|
65 | - protected $userSession; |
|
64 | + /** @var IUserSession */ |
|
65 | + protected $userSession; |
|
66 | 66 | |
67 | - /** |
|
68 | - * CommentNode constructor. |
|
69 | - * |
|
70 | - * @param ICommentsManager $commentsManager |
|
71 | - * @param IComment $comment |
|
72 | - * @param IUserManager $userManager |
|
73 | - * @param IUserSession $userSession |
|
74 | - * @param ILogger $logger |
|
75 | - */ |
|
76 | - public function __construct( |
|
77 | - ICommentsManager $commentsManager, |
|
78 | - IComment $comment, |
|
79 | - IUserManager $userManager, |
|
80 | - IUserSession $userSession, |
|
81 | - ILogger $logger |
|
82 | - ) { |
|
83 | - $this->commentsManager = $commentsManager; |
|
84 | - $this->comment = $comment; |
|
85 | - $this->logger = $logger; |
|
67 | + /** |
|
68 | + * CommentNode constructor. |
|
69 | + * |
|
70 | + * @param ICommentsManager $commentsManager |
|
71 | + * @param IComment $comment |
|
72 | + * @param IUserManager $userManager |
|
73 | + * @param IUserSession $userSession |
|
74 | + * @param ILogger $logger |
|
75 | + */ |
|
76 | + public function __construct( |
|
77 | + ICommentsManager $commentsManager, |
|
78 | + IComment $comment, |
|
79 | + IUserManager $userManager, |
|
80 | + IUserSession $userSession, |
|
81 | + ILogger $logger |
|
82 | + ) { |
|
83 | + $this->commentsManager = $commentsManager; |
|
84 | + $this->comment = $comment; |
|
85 | + $this->logger = $logger; |
|
86 | 86 | |
87 | - $methods = get_class_methods($this->comment); |
|
88 | - $methods = array_filter($methods, function ($name) { |
|
89 | - return strpos($name, 'get') === 0; |
|
90 | - }); |
|
91 | - foreach($methods as $getter) { |
|
92 | - if($getter === 'getMentions') { |
|
93 | - continue; // special treatment |
|
94 | - } |
|
95 | - $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
96 | - $this->properties[$name] = $getter; |
|
97 | - } |
|
98 | - $this->userManager = $userManager; |
|
99 | - $this->userSession = $userSession; |
|
100 | - } |
|
87 | + $methods = get_class_methods($this->comment); |
|
88 | + $methods = array_filter($methods, function ($name) { |
|
89 | + return strpos($name, 'get') === 0; |
|
90 | + }); |
|
91 | + foreach($methods as $getter) { |
|
92 | + if($getter === 'getMentions') { |
|
93 | + continue; // special treatment |
|
94 | + } |
|
95 | + $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
96 | + $this->properties[$name] = $getter; |
|
97 | + } |
|
98 | + $this->userManager = $userManager; |
|
99 | + $this->userSession = $userSession; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * returns a list of all possible property names |
|
104 | - * |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - static public function getPropertyNames() { |
|
108 | - return [ |
|
109 | - '{http://owncloud.org/ns}id', |
|
110 | - '{http://owncloud.org/ns}parentId', |
|
111 | - '{http://owncloud.org/ns}topmostParentId', |
|
112 | - '{http://owncloud.org/ns}childrenCount', |
|
113 | - '{http://owncloud.org/ns}verb', |
|
114 | - '{http://owncloud.org/ns}actorType', |
|
115 | - '{http://owncloud.org/ns}actorId', |
|
116 | - '{http://owncloud.org/ns}creationDateTime', |
|
117 | - '{http://owncloud.org/ns}latestChildDateTime', |
|
118 | - '{http://owncloud.org/ns}objectType', |
|
119 | - '{http://owncloud.org/ns}objectId', |
|
120 | - // re-used property names are defined as constants |
|
121 | - self::PROPERTY_NAME_MESSAGE, |
|
122 | - self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
123 | - self::PROPERTY_NAME_UNREAD, |
|
124 | - self::PROPERTY_NAME_MENTIONS, |
|
125 | - self::PROPERTY_NAME_MENTION, |
|
126 | - self::PROPERTY_NAME_MENTION_TYPE, |
|
127 | - self::PROPERTY_NAME_MENTION_ID, |
|
128 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
129 | - ]; |
|
130 | - } |
|
102 | + /** |
|
103 | + * returns a list of all possible property names |
|
104 | + * |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + static public function getPropertyNames() { |
|
108 | + return [ |
|
109 | + '{http://owncloud.org/ns}id', |
|
110 | + '{http://owncloud.org/ns}parentId', |
|
111 | + '{http://owncloud.org/ns}topmostParentId', |
|
112 | + '{http://owncloud.org/ns}childrenCount', |
|
113 | + '{http://owncloud.org/ns}verb', |
|
114 | + '{http://owncloud.org/ns}actorType', |
|
115 | + '{http://owncloud.org/ns}actorId', |
|
116 | + '{http://owncloud.org/ns}creationDateTime', |
|
117 | + '{http://owncloud.org/ns}latestChildDateTime', |
|
118 | + '{http://owncloud.org/ns}objectType', |
|
119 | + '{http://owncloud.org/ns}objectId', |
|
120 | + // re-used property names are defined as constants |
|
121 | + self::PROPERTY_NAME_MESSAGE, |
|
122 | + self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
123 | + self::PROPERTY_NAME_UNREAD, |
|
124 | + self::PROPERTY_NAME_MENTIONS, |
|
125 | + self::PROPERTY_NAME_MENTION, |
|
126 | + self::PROPERTY_NAME_MENTION_TYPE, |
|
127 | + self::PROPERTY_NAME_MENTION_ID, |
|
128 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
129 | + ]; |
|
130 | + } |
|
131 | 131 | |
132 | - protected function checkWriteAccessOnComment() { |
|
133 | - $user = $this->userSession->getUser(); |
|
134 | - if($this->comment->getActorType() !== 'users' |
|
135 | - || is_null($user) |
|
136 | - || $this->comment->getActorId() !== $user->getUID() |
|
137 | - ) { |
|
138 | - throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
139 | - } |
|
140 | - } |
|
132 | + protected function checkWriteAccessOnComment() { |
|
133 | + $user = $this->userSession->getUser(); |
|
134 | + if($this->comment->getActorType() !== 'users' |
|
135 | + || is_null($user) |
|
136 | + || $this->comment->getActorId() !== $user->getUID() |
|
137 | + ) { |
|
138 | + throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
139 | + } |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Deleted the current node |
|
144 | - * |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - function delete() { |
|
148 | - $this->checkWriteAccessOnComment(); |
|
149 | - $this->commentsManager->delete($this->comment->getId()); |
|
150 | - } |
|
142 | + /** |
|
143 | + * Deleted the current node |
|
144 | + * |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + function delete() { |
|
148 | + $this->checkWriteAccessOnComment(); |
|
149 | + $this->commentsManager->delete($this->comment->getId()); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Returns the name of the node. |
|
154 | - * |
|
155 | - * This is used to generate the url. |
|
156 | - * |
|
157 | - * @return string |
|
158 | - */ |
|
159 | - function getName() { |
|
160 | - return $this->comment->getId(); |
|
161 | - } |
|
152 | + /** |
|
153 | + * Returns the name of the node. |
|
154 | + * |
|
155 | + * This is used to generate the url. |
|
156 | + * |
|
157 | + * @return string |
|
158 | + */ |
|
159 | + function getName() { |
|
160 | + return $this->comment->getId(); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Renames the node |
|
165 | - * |
|
166 | - * @param string $name The new name |
|
167 | - * @throws MethodNotAllowed |
|
168 | - */ |
|
169 | - function setName($name) { |
|
170 | - throw new MethodNotAllowed(); |
|
171 | - } |
|
163 | + /** |
|
164 | + * Renames the node |
|
165 | + * |
|
166 | + * @param string $name The new name |
|
167 | + * @throws MethodNotAllowed |
|
168 | + */ |
|
169 | + function setName($name) { |
|
170 | + throw new MethodNotAllowed(); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Returns the last modification time, as a unix timestamp |
|
175 | - * |
|
176 | - * @return int |
|
177 | - */ |
|
178 | - function getLastModified() { |
|
179 | - return null; |
|
180 | - } |
|
173 | + /** |
|
174 | + * Returns the last modification time, as a unix timestamp |
|
175 | + * |
|
176 | + * @return int |
|
177 | + */ |
|
178 | + function getLastModified() { |
|
179 | + return null; |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * update the comment's message |
|
184 | - * |
|
185 | - * @param $propertyValue |
|
186 | - * @return bool |
|
187 | - * @throws BadRequest |
|
188 | - * @throws \Exception |
|
189 | - */ |
|
190 | - public function updateComment($propertyValue) { |
|
191 | - $this->checkWriteAccessOnComment(); |
|
192 | - try { |
|
193 | - $this->comment->setMessage($propertyValue); |
|
194 | - $this->commentsManager->save($this->comment); |
|
195 | - return true; |
|
196 | - } catch (\Exception $e) { |
|
197 | - $this->logger->logException($e, ['app' => 'dav/comments']); |
|
198 | - if($e instanceof MessageTooLongException) { |
|
199 | - $msg = 'Message exceeds allowed character limit of '; |
|
200 | - throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
201 | - } |
|
202 | - throw $e; |
|
203 | - } |
|
204 | - } |
|
182 | + /** |
|
183 | + * update the comment's message |
|
184 | + * |
|
185 | + * @param $propertyValue |
|
186 | + * @return bool |
|
187 | + * @throws BadRequest |
|
188 | + * @throws \Exception |
|
189 | + */ |
|
190 | + public function updateComment($propertyValue) { |
|
191 | + $this->checkWriteAccessOnComment(); |
|
192 | + try { |
|
193 | + $this->comment->setMessage($propertyValue); |
|
194 | + $this->commentsManager->save($this->comment); |
|
195 | + return true; |
|
196 | + } catch (\Exception $e) { |
|
197 | + $this->logger->logException($e, ['app' => 'dav/comments']); |
|
198 | + if($e instanceof MessageTooLongException) { |
|
199 | + $msg = 'Message exceeds allowed character limit of '; |
|
200 | + throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
201 | + } |
|
202 | + throw $e; |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Updates properties on this node. |
|
208 | - * |
|
209 | - * This method received a PropPatch object, which contains all the |
|
210 | - * information about the update. |
|
211 | - * |
|
212 | - * To update specific properties, call the 'handle' method on this object. |
|
213 | - * Read the PropPatch documentation for more information. |
|
214 | - * |
|
215 | - * @param PropPatch $propPatch |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - function propPatch(PropPatch $propPatch) { |
|
219 | - // other properties than 'message' are read only |
|
220 | - $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
221 | - } |
|
206 | + /** |
|
207 | + * Updates properties on this node. |
|
208 | + * |
|
209 | + * This method received a PropPatch object, which contains all the |
|
210 | + * information about the update. |
|
211 | + * |
|
212 | + * To update specific properties, call the 'handle' method on this object. |
|
213 | + * Read the PropPatch documentation for more information. |
|
214 | + * |
|
215 | + * @param PropPatch $propPatch |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + function propPatch(PropPatch $propPatch) { |
|
219 | + // other properties than 'message' are read only |
|
220 | + $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * Returns a list of properties for this nodes. |
|
225 | - * |
|
226 | - * The properties list is a list of propertynames the client requested, |
|
227 | - * encoded in clark-notation {xmlnamespace}tagname |
|
228 | - * |
|
229 | - * If the array is empty, it means 'all properties' were requested. |
|
230 | - * |
|
231 | - * Note that it's fine to liberally give properties back, instead of |
|
232 | - * conforming to the list of requested properties. |
|
233 | - * The Server class will filter out the extra. |
|
234 | - * |
|
235 | - * @param array $properties |
|
236 | - * @return array |
|
237 | - */ |
|
238 | - function getProperties($properties) { |
|
239 | - $properties = array_keys($this->properties); |
|
223 | + /** |
|
224 | + * Returns a list of properties for this nodes. |
|
225 | + * |
|
226 | + * The properties list is a list of propertynames the client requested, |
|
227 | + * encoded in clark-notation {xmlnamespace}tagname |
|
228 | + * |
|
229 | + * If the array is empty, it means 'all properties' were requested. |
|
230 | + * |
|
231 | + * Note that it's fine to liberally give properties back, instead of |
|
232 | + * conforming to the list of requested properties. |
|
233 | + * The Server class will filter out the extra. |
|
234 | + * |
|
235 | + * @param array $properties |
|
236 | + * @return array |
|
237 | + */ |
|
238 | + function getProperties($properties) { |
|
239 | + $properties = array_keys($this->properties); |
|
240 | 240 | |
241 | - $result = []; |
|
242 | - foreach($properties as $property) { |
|
243 | - $getter = $this->properties[$property]; |
|
244 | - if(method_exists($this->comment, $getter)) { |
|
245 | - $result[$property] = $this->comment->$getter(); |
|
246 | - } |
|
247 | - } |
|
241 | + $result = []; |
|
242 | + foreach($properties as $property) { |
|
243 | + $getter = $this->properties[$property]; |
|
244 | + if(method_exists($this->comment, $getter)) { |
|
245 | + $result[$property] = $this->comment->$getter(); |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - if($this->comment->getActorType() === 'users') { |
|
250 | - $user = $this->userManager->get($this->comment->getActorId()); |
|
251 | - $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
252 | - $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
253 | - } |
|
249 | + if($this->comment->getActorType() === 'users') { |
|
250 | + $user = $this->userManager->get($this->comment->getActorId()); |
|
251 | + $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
252 | + $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
253 | + } |
|
254 | 254 | |
255 | - $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
255 | + $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
256 | 256 | |
257 | - $unread = null; |
|
258 | - $user = $this->userSession->getUser(); |
|
259 | - if(!is_null($user)) { |
|
260 | - $readUntil = $this->commentsManager->getReadMark( |
|
261 | - $this->comment->getObjectType(), |
|
262 | - $this->comment->getObjectId(), |
|
263 | - $user |
|
264 | - ); |
|
265 | - if(is_null($readUntil)) { |
|
266 | - $unread = 'true'; |
|
267 | - } else { |
|
268 | - $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
269 | - // re-format for output |
|
270 | - $unread = $unread ? 'true' : 'false'; |
|
271 | - } |
|
272 | - } |
|
273 | - $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
257 | + $unread = null; |
|
258 | + $user = $this->userSession->getUser(); |
|
259 | + if(!is_null($user)) { |
|
260 | + $readUntil = $this->commentsManager->getReadMark( |
|
261 | + $this->comment->getObjectType(), |
|
262 | + $this->comment->getObjectId(), |
|
263 | + $user |
|
264 | + ); |
|
265 | + if(is_null($readUntil)) { |
|
266 | + $unread = 'true'; |
|
267 | + } else { |
|
268 | + $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
269 | + // re-format for output |
|
270 | + $unread = $unread ? 'true' : 'false'; |
|
271 | + } |
|
272 | + } |
|
273 | + $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
274 | 274 | |
275 | - return $result; |
|
276 | - } |
|
275 | + return $result; |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * transforms a mentions array as returned from IComment->getMentions to an |
|
280 | - * array with DAV-compatible structure that can be assigned to the |
|
281 | - * PROPERTY_NAME_MENTION property. |
|
282 | - * |
|
283 | - * @return array |
|
284 | - */ |
|
285 | - protected function composeMentionsPropertyValue() { |
|
286 | - return array_map(function ($mention) { |
|
287 | - try { |
|
288 | - $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
289 | - } catch (\OutOfBoundsException $e) { |
|
290 | - $this->logger->logException($e); |
|
291 | - // No displayname, upon client's discretion what to display. |
|
292 | - $displayName = ''; |
|
293 | - } |
|
278 | + /** |
|
279 | + * transforms a mentions array as returned from IComment->getMentions to an |
|
280 | + * array with DAV-compatible structure that can be assigned to the |
|
281 | + * PROPERTY_NAME_MENTION property. |
|
282 | + * |
|
283 | + * @return array |
|
284 | + */ |
|
285 | + protected function composeMentionsPropertyValue() { |
|
286 | + return array_map(function ($mention) { |
|
287 | + try { |
|
288 | + $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
289 | + } catch (\OutOfBoundsException $e) { |
|
290 | + $this->logger->logException($e); |
|
291 | + // No displayname, upon client's discretion what to display. |
|
292 | + $displayName = ''; |
|
293 | + } |
|
294 | 294 | |
295 | - return [ |
|
296 | - self::PROPERTY_NAME_MENTION => [ |
|
297 | - self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
298 | - self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
299 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
300 | - ] |
|
301 | - ]; |
|
302 | - }, $this->comment->getMentions()); |
|
303 | - } |
|
295 | + return [ |
|
296 | + self::PROPERTY_NAME_MENTION => [ |
|
297 | + self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
298 | + self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
299 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
300 | + ] |
|
301 | + ]; |
|
302 | + }, $this->comment->getMentions()); |
|
303 | + } |
|
304 | 304 | } |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | $this->logger = $logger; |
86 | 86 | |
87 | 87 | $methods = get_class_methods($this->comment); |
88 | - $methods = array_filter($methods, function ($name) { |
|
88 | + $methods = array_filter($methods, function($name) { |
|
89 | 89 | return strpos($name, 'get') === 0; |
90 | 90 | }); |
91 | - foreach($methods as $getter) { |
|
92 | - if($getter === 'getMentions') { |
|
93 | - continue; // special treatment |
|
91 | + foreach ($methods as $getter) { |
|
92 | + if ($getter === 'getMentions') { |
|
93 | + continue; // special treatment |
|
94 | 94 | } |
95 | - $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
95 | + $name = '{'.self::NS_OWNCLOUD.'}'.lcfirst(substr($getter, 3)); |
|
96 | 96 | $this->properties[$name] = $getter; |
97 | 97 | } |
98 | 98 | $this->userManager = $userManager; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | protected function checkWriteAccessOnComment() { |
133 | 133 | $user = $this->userSession->getUser(); |
134 | - if($this->comment->getActorType() !== 'users' |
|
134 | + if ($this->comment->getActorType() !== 'users' |
|
135 | 135 | || is_null($user) |
136 | 136 | || $this->comment->getActorId() !== $user->getUID() |
137 | 137 | ) { |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | return true; |
196 | 196 | } catch (\Exception $e) { |
197 | 197 | $this->logger->logException($e, ['app' => 'dav/comments']); |
198 | - if($e instanceof MessageTooLongException) { |
|
198 | + if ($e instanceof MessageTooLongException) { |
|
199 | 199 | $msg = 'Message exceeds allowed character limit of '; |
200 | - throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
200 | + throw new BadRequest($msg.IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
201 | 201 | } |
202 | 202 | throw $e; |
203 | 203 | } |
@@ -239,14 +239,14 @@ discard block |
||
239 | 239 | $properties = array_keys($this->properties); |
240 | 240 | |
241 | 241 | $result = []; |
242 | - foreach($properties as $property) { |
|
242 | + foreach ($properties as $property) { |
|
243 | 243 | $getter = $this->properties[$property]; |
244 | - if(method_exists($this->comment, $getter)) { |
|
244 | + if (method_exists($this->comment, $getter)) { |
|
245 | 245 | $result[$property] = $this->comment->$getter(); |
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
249 | - if($this->comment->getActorType() === 'users') { |
|
249 | + if ($this->comment->getActorType() === 'users') { |
|
250 | 250 | $user = $this->userManager->get($this->comment->getActorId()); |
251 | 251 | $displayName = is_null($user) ? null : $user->getDisplayName(); |
252 | 252 | $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
@@ -255,14 +255,14 @@ discard block |
||
255 | 255 | $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
256 | 256 | |
257 | 257 | $unread = null; |
258 | - $user = $this->userSession->getUser(); |
|
259 | - if(!is_null($user)) { |
|
258 | + $user = $this->userSession->getUser(); |
|
259 | + if (!is_null($user)) { |
|
260 | 260 | $readUntil = $this->commentsManager->getReadMark( |
261 | 261 | $this->comment->getObjectType(), |
262 | 262 | $this->comment->getObjectId(), |
263 | 263 | $user |
264 | 264 | ); |
265 | - if(is_null($readUntil)) { |
|
265 | + if (is_null($readUntil)) { |
|
266 | 266 | $unread = 'true'; |
267 | 267 | } else { |
268 | 268 | $unread = $this->comment->getCreationDateTime() > $readUntil; |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return array |
284 | 284 | */ |
285 | 285 | protected function composeMentionsPropertyValue() { |
286 | - return array_map(function ($mention) { |
|
286 | + return array_map(function($mention) { |
|
287 | 287 | try { |
288 | 288 | $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
289 | 289 | } catch (\OutOfBoundsException $e) { |
@@ -39,136 +39,136 @@ |
||
39 | 39 | */ |
40 | 40 | class SystemTagsObjectTypeCollection implements ICollection { |
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - private $objectType; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var ISystemTagManager |
|
49 | - */ |
|
50 | - private $tagManager; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var ISystemTagObjectMapper |
|
54 | - */ |
|
55 | - private $tagMapper; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var IGroupManager |
|
59 | - */ |
|
60 | - private $groupManager; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var IUserSession |
|
64 | - */ |
|
65 | - private $userSession; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var \Closure |
|
69 | - **/ |
|
70 | - protected $childExistsFunction; |
|
71 | - |
|
72 | - /** |
|
73 | - * Constructor |
|
74 | - * |
|
75 | - * @param string $objectType object type |
|
76 | - * @param ISystemTagManager $tagManager |
|
77 | - * @param ISystemTagObjectMapper $tagMapper |
|
78 | - * @param IUserSession $userSession |
|
79 | - * @param IGroupManager $groupManager |
|
80 | - * @param \Closure $childExistsFunction |
|
81 | - */ |
|
82 | - public function __construct( |
|
83 | - $objectType, |
|
84 | - ISystemTagManager $tagManager, |
|
85 | - ISystemTagObjectMapper $tagMapper, |
|
86 | - IUserSession $userSession, |
|
87 | - IGroupManager $groupManager, |
|
88 | - \Closure $childExistsFunction |
|
89 | - ) { |
|
90 | - $this->tagManager = $tagManager; |
|
91 | - $this->tagMapper = $tagMapper; |
|
92 | - $this->objectType = $objectType; |
|
93 | - $this->userSession = $userSession; |
|
94 | - $this->groupManager = $groupManager; |
|
95 | - $this->childExistsFunction = $childExistsFunction; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $name |
|
100 | - * @param resource|string $data Initial payload |
|
101 | - * @return null|string |
|
102 | - * @throws Forbidden |
|
103 | - */ |
|
104 | - function createFile($name, $data = null) { |
|
105 | - throw new Forbidden('Permission denied to create nodes'); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $name |
|
110 | - * @throws Forbidden |
|
111 | - */ |
|
112 | - function createDirectory($name) { |
|
113 | - throw new Forbidden('Permission denied to create collections'); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @param string $objectId |
|
118 | - * @return SystemTagsObjectMappingCollection |
|
119 | - * @throws NotFound |
|
120 | - */ |
|
121 | - function getChild($objectId) { |
|
122 | - // make sure the object exists and is reachable |
|
123 | - if(!$this->childExists($objectId)) { |
|
124 | - throw new NotFound('Entity does not exist or is not available'); |
|
125 | - } |
|
126 | - return new SystemTagsObjectMappingCollection( |
|
127 | - $objectId, |
|
128 | - $this->objectType, |
|
129 | - $this->userSession->getUser(), |
|
130 | - $this->tagManager, |
|
131 | - $this->tagMapper |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - function getChildren() { |
|
136 | - // do not list object ids |
|
137 | - throw new MethodNotAllowed(); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Checks if a child-node with the specified name exists |
|
142 | - * |
|
143 | - * @param string $name |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - function childExists($name) { |
|
147 | - return call_user_func($this->childExistsFunction, $name); |
|
148 | - } |
|
149 | - |
|
150 | - function delete() { |
|
151 | - throw new Forbidden('Permission denied to delete this collection'); |
|
152 | - } |
|
153 | - |
|
154 | - function getName() { |
|
155 | - return $this->objectType; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param string $name |
|
160 | - * @throws Forbidden |
|
161 | - */ |
|
162 | - function setName($name) { |
|
163 | - throw new Forbidden('Permission denied to rename this collection'); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Returns the last modification time, as a unix timestamp |
|
168 | - * |
|
169 | - * @return int |
|
170 | - */ |
|
171 | - function getLastModified() { |
|
172 | - return null; |
|
173 | - } |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + private $objectType; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var ISystemTagManager |
|
49 | + */ |
|
50 | + private $tagManager; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var ISystemTagObjectMapper |
|
54 | + */ |
|
55 | + private $tagMapper; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var IGroupManager |
|
59 | + */ |
|
60 | + private $groupManager; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var IUserSession |
|
64 | + */ |
|
65 | + private $userSession; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var \Closure |
|
69 | + **/ |
|
70 | + protected $childExistsFunction; |
|
71 | + |
|
72 | + /** |
|
73 | + * Constructor |
|
74 | + * |
|
75 | + * @param string $objectType object type |
|
76 | + * @param ISystemTagManager $tagManager |
|
77 | + * @param ISystemTagObjectMapper $tagMapper |
|
78 | + * @param IUserSession $userSession |
|
79 | + * @param IGroupManager $groupManager |
|
80 | + * @param \Closure $childExistsFunction |
|
81 | + */ |
|
82 | + public function __construct( |
|
83 | + $objectType, |
|
84 | + ISystemTagManager $tagManager, |
|
85 | + ISystemTagObjectMapper $tagMapper, |
|
86 | + IUserSession $userSession, |
|
87 | + IGroupManager $groupManager, |
|
88 | + \Closure $childExistsFunction |
|
89 | + ) { |
|
90 | + $this->tagManager = $tagManager; |
|
91 | + $this->tagMapper = $tagMapper; |
|
92 | + $this->objectType = $objectType; |
|
93 | + $this->userSession = $userSession; |
|
94 | + $this->groupManager = $groupManager; |
|
95 | + $this->childExistsFunction = $childExistsFunction; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $name |
|
100 | + * @param resource|string $data Initial payload |
|
101 | + * @return null|string |
|
102 | + * @throws Forbidden |
|
103 | + */ |
|
104 | + function createFile($name, $data = null) { |
|
105 | + throw new Forbidden('Permission denied to create nodes'); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $name |
|
110 | + * @throws Forbidden |
|
111 | + */ |
|
112 | + function createDirectory($name) { |
|
113 | + throw new Forbidden('Permission denied to create collections'); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @param string $objectId |
|
118 | + * @return SystemTagsObjectMappingCollection |
|
119 | + * @throws NotFound |
|
120 | + */ |
|
121 | + function getChild($objectId) { |
|
122 | + // make sure the object exists and is reachable |
|
123 | + if(!$this->childExists($objectId)) { |
|
124 | + throw new NotFound('Entity does not exist or is not available'); |
|
125 | + } |
|
126 | + return new SystemTagsObjectMappingCollection( |
|
127 | + $objectId, |
|
128 | + $this->objectType, |
|
129 | + $this->userSession->getUser(), |
|
130 | + $this->tagManager, |
|
131 | + $this->tagMapper |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + function getChildren() { |
|
136 | + // do not list object ids |
|
137 | + throw new MethodNotAllowed(); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Checks if a child-node with the specified name exists |
|
142 | + * |
|
143 | + * @param string $name |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + function childExists($name) { |
|
147 | + return call_user_func($this->childExistsFunction, $name); |
|
148 | + } |
|
149 | + |
|
150 | + function delete() { |
|
151 | + throw new Forbidden('Permission denied to delete this collection'); |
|
152 | + } |
|
153 | + |
|
154 | + function getName() { |
|
155 | + return $this->objectType; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param string $name |
|
160 | + * @throws Forbidden |
|
161 | + */ |
|
162 | + function setName($name) { |
|
163 | + throw new Forbidden('Permission denied to rename this collection'); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Returns the last modification time, as a unix timestamp |
|
168 | + * |
|
169 | + * @return int |
|
170 | + */ |
|
171 | + function getLastModified() { |
|
172 | + return null; |
|
173 | + } |
|
174 | 174 | } |
@@ -41,169 +41,169 @@ |
||
41 | 41 | */ |
42 | 42 | class SystemTagsObjectMappingCollection implements ICollection { |
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $objectId; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - private $objectType; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var ISystemTagManager |
|
56 | - */ |
|
57 | - private $tagManager; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var ISystemTagObjectMapper |
|
61 | - */ |
|
62 | - private $tagMapper; |
|
63 | - |
|
64 | - /** |
|
65 | - * User |
|
66 | - * |
|
67 | - * @var IUser |
|
68 | - */ |
|
69 | - private $user; |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Constructor |
|
74 | - * |
|
75 | - * @param string $objectId object id |
|
76 | - * @param string $objectType object type |
|
77 | - * @param IUser $user user |
|
78 | - * @param ISystemTagManager $tagManager tag manager |
|
79 | - * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - $objectId, |
|
83 | - $objectType, |
|
84 | - IUser $user, |
|
85 | - ISystemTagManager $tagManager, |
|
86 | - ISystemTagObjectMapper $tagMapper |
|
87 | - ) { |
|
88 | - $this->tagManager = $tagManager; |
|
89 | - $this->tagMapper = $tagMapper; |
|
90 | - $this->objectId = $objectId; |
|
91 | - $this->objectType = $objectType; |
|
92 | - $this->user = $user; |
|
93 | - } |
|
94 | - |
|
95 | - function createFile($tagId, $data = null) { |
|
96 | - try { |
|
97 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
98 | - $tag = current($tags); |
|
99 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
100 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
101 | - } |
|
102 | - if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
103 | - throw new Forbidden('No permission to assign tag ' . $tagId); |
|
104 | - } |
|
105 | - |
|
106 | - $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
107 | - } catch (TagNotFoundException $e) { |
|
108 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - function createDirectory($name) { |
|
113 | - throw new Forbidden('Permission denied to create collections'); |
|
114 | - } |
|
115 | - |
|
116 | - function getChild($tagId) { |
|
117 | - try { |
|
118 | - if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
119 | - $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
120 | - $tag = current($tag); |
|
121 | - if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
122 | - return $this->makeNode($tag); |
|
123 | - } |
|
124 | - } |
|
125 | - throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
126 | - } catch (\InvalidArgumentException $e) { |
|
127 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
128 | - } catch (TagNotFoundException $e) { |
|
129 | - throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - function getChildren() { |
|
134 | - $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
135 | - if (empty($tagIds)) { |
|
136 | - return []; |
|
137 | - } |
|
138 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
139 | - |
|
140 | - // filter out non-visible tags |
|
141 | - $tags = array_filter($tags, function ($tag) { |
|
142 | - return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
143 | - }); |
|
144 | - |
|
145 | - return array_values(array_map(function ($tag) { |
|
146 | - return $this->makeNode($tag); |
|
147 | - }, $tags)); |
|
148 | - } |
|
149 | - |
|
150 | - function childExists($tagId) { |
|
151 | - try { |
|
152 | - $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true); |
|
153 | - |
|
154 | - if ($result) { |
|
155 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
156 | - $tag = current($tags); |
|
157 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
158 | - return false; |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - return $result; |
|
163 | - } catch (\InvalidArgumentException $e) { |
|
164 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
165 | - } catch (TagNotFoundException $e) { |
|
166 | - return false; |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - function delete() { |
|
171 | - throw new Forbidden('Permission denied to delete this collection'); |
|
172 | - } |
|
173 | - |
|
174 | - function getName() { |
|
175 | - return $this->objectId; |
|
176 | - } |
|
177 | - |
|
178 | - function setName($name) { |
|
179 | - throw new Forbidden('Permission denied to rename this collection'); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Returns the last modification time, as a unix timestamp |
|
184 | - * |
|
185 | - * @return int |
|
186 | - */ |
|
187 | - function getLastModified() { |
|
188 | - return null; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Create a sabre node for the mapping of the |
|
193 | - * given system tag to the collection's object |
|
194 | - * |
|
195 | - * @param ISystemTag $tag |
|
196 | - * |
|
197 | - * @return SystemTagMappingNode |
|
198 | - */ |
|
199 | - private function makeNode(ISystemTag $tag) { |
|
200 | - return new SystemTagMappingNode( |
|
201 | - $tag, |
|
202 | - $this->objectId, |
|
203 | - $this->objectType, |
|
204 | - $this->user, |
|
205 | - $this->tagManager, |
|
206 | - $this->tagMapper |
|
207 | - ); |
|
208 | - } |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $objectId; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + private $objectType; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var ISystemTagManager |
|
56 | + */ |
|
57 | + private $tagManager; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var ISystemTagObjectMapper |
|
61 | + */ |
|
62 | + private $tagMapper; |
|
63 | + |
|
64 | + /** |
|
65 | + * User |
|
66 | + * |
|
67 | + * @var IUser |
|
68 | + */ |
|
69 | + private $user; |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Constructor |
|
74 | + * |
|
75 | + * @param string $objectId object id |
|
76 | + * @param string $objectType object type |
|
77 | + * @param IUser $user user |
|
78 | + * @param ISystemTagManager $tagManager tag manager |
|
79 | + * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + $objectId, |
|
83 | + $objectType, |
|
84 | + IUser $user, |
|
85 | + ISystemTagManager $tagManager, |
|
86 | + ISystemTagObjectMapper $tagMapper |
|
87 | + ) { |
|
88 | + $this->tagManager = $tagManager; |
|
89 | + $this->tagMapper = $tagMapper; |
|
90 | + $this->objectId = $objectId; |
|
91 | + $this->objectType = $objectType; |
|
92 | + $this->user = $user; |
|
93 | + } |
|
94 | + |
|
95 | + function createFile($tagId, $data = null) { |
|
96 | + try { |
|
97 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
98 | + $tag = current($tags); |
|
99 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
100 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
101 | + } |
|
102 | + if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
103 | + throw new Forbidden('No permission to assign tag ' . $tagId); |
|
104 | + } |
|
105 | + |
|
106 | + $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
107 | + } catch (TagNotFoundException $e) { |
|
108 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + function createDirectory($name) { |
|
113 | + throw new Forbidden('Permission denied to create collections'); |
|
114 | + } |
|
115 | + |
|
116 | + function getChild($tagId) { |
|
117 | + try { |
|
118 | + if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
119 | + $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
120 | + $tag = current($tag); |
|
121 | + if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
122 | + return $this->makeNode($tag); |
|
123 | + } |
|
124 | + } |
|
125 | + throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
126 | + } catch (\InvalidArgumentException $e) { |
|
127 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
128 | + } catch (TagNotFoundException $e) { |
|
129 | + throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + function getChildren() { |
|
134 | + $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
135 | + if (empty($tagIds)) { |
|
136 | + return []; |
|
137 | + } |
|
138 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
139 | + |
|
140 | + // filter out non-visible tags |
|
141 | + $tags = array_filter($tags, function ($tag) { |
|
142 | + return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
143 | + }); |
|
144 | + |
|
145 | + return array_values(array_map(function ($tag) { |
|
146 | + return $this->makeNode($tag); |
|
147 | + }, $tags)); |
|
148 | + } |
|
149 | + |
|
150 | + function childExists($tagId) { |
|
151 | + try { |
|
152 | + $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true); |
|
153 | + |
|
154 | + if ($result) { |
|
155 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
156 | + $tag = current($tags); |
|
157 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
158 | + return false; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + return $result; |
|
163 | + } catch (\InvalidArgumentException $e) { |
|
164 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
165 | + } catch (TagNotFoundException $e) { |
|
166 | + return false; |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + function delete() { |
|
171 | + throw new Forbidden('Permission denied to delete this collection'); |
|
172 | + } |
|
173 | + |
|
174 | + function getName() { |
|
175 | + return $this->objectId; |
|
176 | + } |
|
177 | + |
|
178 | + function setName($name) { |
|
179 | + throw new Forbidden('Permission denied to rename this collection'); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Returns the last modification time, as a unix timestamp |
|
184 | + * |
|
185 | + * @return int |
|
186 | + */ |
|
187 | + function getLastModified() { |
|
188 | + return null; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Create a sabre node for the mapping of the |
|
193 | + * given system tag to the collection's object |
|
194 | + * |
|
195 | + * @param ISystemTag $tag |
|
196 | + * |
|
197 | + * @return SystemTagMappingNode |
|
198 | + */ |
|
199 | + private function makeNode(ISystemTag $tag) { |
|
200 | + return new SystemTagMappingNode( |
|
201 | + $tag, |
|
202 | + $this->objectId, |
|
203 | + $this->objectType, |
|
204 | + $this->user, |
|
205 | + $this->tagManager, |
|
206 | + $this->tagMapper |
|
207 | + ); |
|
208 | + } |
|
209 | 209 | } |
@@ -29,59 +29,59 @@ |
||
29 | 29 | |
30 | 30 | class ShareRequest implements XmlDeserializable { |
31 | 31 | |
32 | - public $set = []; |
|
32 | + public $set = []; |
|
33 | 33 | |
34 | - public $remove = []; |
|
34 | + public $remove = []; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor |
|
38 | - * |
|
39 | - * @param array $set |
|
40 | - * @param array $remove |
|
41 | - */ |
|
42 | - function __construct(array $set, array $remove) { |
|
36 | + /** |
|
37 | + * Constructor |
|
38 | + * |
|
39 | + * @param array $set |
|
40 | + * @param array $remove |
|
41 | + */ |
|
42 | + function __construct(array $set, array $remove) { |
|
43 | 43 | |
44 | - $this->set = $set; |
|
45 | - $this->remove = $remove; |
|
44 | + $this->set = $set; |
|
45 | + $this->remove = $remove; |
|
46 | 46 | |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - static function xmlDeserialize(Reader $reader) { |
|
49 | + static function xmlDeserialize(Reader $reader) { |
|
50 | 50 | |
51 | - $elements = $reader->parseInnerTree([ |
|
52 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
53 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
54 | - ]); |
|
51 | + $elements = $reader->parseInnerTree([ |
|
52 | + '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
53 | + '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
54 | + ]); |
|
55 | 55 | |
56 | - $set = []; |
|
57 | - $remove = []; |
|
56 | + $set = []; |
|
57 | + $remove = []; |
|
58 | 58 | |
59 | - foreach ($elements as $elem) { |
|
60 | - switch ($elem['name']) { |
|
59 | + foreach ($elements as $elem) { |
|
60 | + switch ($elem['name']) { |
|
61 | 61 | |
62 | - case '{' . Plugin::NS_OWNCLOUD . '}set': |
|
63 | - $sharee = $elem['value']; |
|
62 | + case '{' . Plugin::NS_OWNCLOUD . '}set': |
|
63 | + $sharee = $elem['value']; |
|
64 | 64 | |
65 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
66 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
65 | + $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
66 | + $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
67 | 67 | |
68 | - $set[] = [ |
|
69 | - 'href' => $sharee['{DAV:}href'], |
|
70 | - 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
|
71 | - 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
|
72 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
73 | - ]; |
|
74 | - break; |
|
68 | + $set[] = [ |
|
69 | + 'href' => $sharee['{DAV:}href'], |
|
70 | + 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
|
71 | + 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
|
72 | + 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
73 | + ]; |
|
74 | + break; |
|
75 | 75 | |
76 | - case '{' . Plugin::NS_OWNCLOUD . '}remove': |
|
77 | - $remove[] = $elem['value']['{DAV:}href']; |
|
78 | - break; |
|
76 | + case '{' . Plugin::NS_OWNCLOUD . '}remove': |
|
77 | + $remove[] = $elem['value']['{DAV:}href']; |
|
78 | + break; |
|
79 | 79 | |
80 | - } |
|
81 | - } |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - return new self($set, $remove); |
|
83 | + return new self($set, $remove); |
|
84 | 84 | |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | static function xmlDeserialize(Reader $reader) { |
50 | 50 | |
51 | 51 | $elements = $reader->parseInnerTree([ |
52 | - '{' . Plugin::NS_OWNCLOUD. '}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
53 | - '{' . Plugin::NS_OWNCLOUD . '}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
52 | + '{'.Plugin::NS_OWNCLOUD.'}set' => 'Sabre\\Xml\\Element\\KeyValue', |
|
53 | + '{'.Plugin::NS_OWNCLOUD.'}remove' => 'Sabre\\Xml\\Element\\KeyValue', |
|
54 | 54 | ]); |
55 | 55 | |
56 | 56 | $set = []; |
@@ -59,21 +59,21 @@ discard block |
||
59 | 59 | foreach ($elements as $elem) { |
60 | 60 | switch ($elem['name']) { |
61 | 61 | |
62 | - case '{' . Plugin::NS_OWNCLOUD . '}set': |
|
62 | + case '{'.Plugin::NS_OWNCLOUD.'}set': |
|
63 | 63 | $sharee = $elem['value']; |
64 | 64 | |
65 | - $sumElem = '{' . Plugin::NS_OWNCLOUD . '}summary'; |
|
66 | - $commonName = '{' . Plugin::NS_OWNCLOUD . '}common-name'; |
|
65 | + $sumElem = '{'.Plugin::NS_OWNCLOUD.'}summary'; |
|
66 | + $commonName = '{'.Plugin::NS_OWNCLOUD.'}common-name'; |
|
67 | 67 | |
68 | 68 | $set[] = [ |
69 | 69 | 'href' => $sharee['{DAV:}href'], |
70 | 70 | 'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null, |
71 | 71 | 'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null, |
72 | - 'readOnly' => !array_key_exists('{' . Plugin::NS_OWNCLOUD . '}read-write', $sharee), |
|
72 | + 'readOnly' => !array_key_exists('{'.Plugin::NS_OWNCLOUD.'}read-write', $sharee), |
|
73 | 73 | ]; |
74 | 74 | break; |
75 | 75 | |
76 | - case '{' . Plugin::NS_OWNCLOUD . '}remove': |
|
76 | + case '{'.Plugin::NS_OWNCLOUD.'}remove': |
|
77 | 77 | $remove[] = $elem['value']['{DAV:}href']; |
78 | 78 | break; |
79 | 79 |
@@ -38,167 +38,167 @@ |
||
38 | 38 | |
39 | 39 | class Plugin extends ServerPlugin { |
40 | 40 | |
41 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
42 | - const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
43 | - |
|
44 | - /** @var Auth */ |
|
45 | - private $auth; |
|
46 | - |
|
47 | - /** @var IRequest */ |
|
48 | - private $request; |
|
49 | - |
|
50 | - /** |
|
51 | - * Plugin constructor. |
|
52 | - * |
|
53 | - * @param Auth $authBackEnd |
|
54 | - * @param IRequest $request |
|
55 | - */ |
|
56 | - public function __construct(Auth $authBackEnd, IRequest $request) { |
|
57 | - $this->auth = $authBackEnd; |
|
58 | - $this->request = $request; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Reference to SabreDAV server object. |
|
63 | - * |
|
64 | - * @var \Sabre\DAV\Server |
|
65 | - */ |
|
66 | - protected $server; |
|
67 | - |
|
68 | - /** |
|
69 | - * This method should return a list of server-features. |
|
70 | - * |
|
71 | - * This is for example 'versioning' and is added to the DAV: header |
|
72 | - * in an OPTIONS response. |
|
73 | - * |
|
74 | - * @return string[] |
|
75 | - */ |
|
76 | - function getFeatures() { |
|
77 | - return ['oc-resource-sharing']; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Returns a plugin name. |
|
82 | - * |
|
83 | - * Using this name other plugins will be able to access other plugins |
|
84 | - * using Sabre\DAV\Server::getPlugin |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - function getPluginName() { |
|
89 | - return 'oc-resource-sharing'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * This initializes the plugin. |
|
94 | - * |
|
95 | - * This function is called by Sabre\DAV\Server, after |
|
96 | - * addPlugin is called. |
|
97 | - * |
|
98 | - * This method should set up the required event subscriptions. |
|
99 | - * |
|
100 | - * @param Server $server |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - function initialize(Server $server) { |
|
104 | - $this->server = $server; |
|
105 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
106 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
107 | - |
|
108 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
109 | - $this->server->on('propFind', [$this, 'propFind']); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * We intercept this to handle POST requests on a dav resource. |
|
114 | - * |
|
115 | - * @param RequestInterface $request |
|
116 | - * @param ResponseInterface $response |
|
117 | - * @return null|false |
|
118 | - */ |
|
119 | - function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
120 | - |
|
121 | - $path = $request->getPath(); |
|
122 | - |
|
123 | - // Only handling xml |
|
124 | - $contentType = $request->getHeader('Content-Type'); |
|
125 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
126 | - return; |
|
127 | - |
|
128 | - // Making sure the node exists |
|
129 | - try { |
|
130 | - $node = $this->server->tree->getNodeForPath($path); |
|
131 | - } catch (NotFound $e) { |
|
132 | - return; |
|
133 | - } |
|
134 | - |
|
135 | - $requestBody = $request->getBodyAsString(); |
|
136 | - |
|
137 | - // If this request handler could not deal with this POST request, it |
|
138 | - // will return 'null' and other plugins get a chance to handle the |
|
139 | - // request. |
|
140 | - // |
|
141 | - // However, we already requested the full body. This is a problem, |
|
142 | - // because a body can only be read once. This is why we preemptively |
|
143 | - // re-populated the request body with the existing data. |
|
144 | - $request->setBody($requestBody); |
|
145 | - |
|
146 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
147 | - |
|
148 | - switch ($documentType) { |
|
149 | - |
|
150 | - // Dealing with the 'share' document, which modified invitees on a |
|
151 | - // calendar. |
|
152 | - case '{' . self::NS_OWNCLOUD . '}share': |
|
153 | - |
|
154 | - // We can only deal with IShareableCalendar objects |
|
155 | - if (!$node instanceof IShareable) { |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - $this->server->transactionType = 'post-oc-resource-share'; |
|
160 | - |
|
161 | - // Getting ACL info |
|
162 | - $acl = $this->server->getPlugin('acl'); |
|
163 | - |
|
164 | - // If there's no ACL support, we allow everything |
|
165 | - if ($acl) { |
|
166 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
167 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
168 | - } |
|
169 | - |
|
170 | - $node->updateShares($message->set, $message->remove); |
|
171 | - |
|
172 | - $response->setStatus(200); |
|
173 | - // Adding this because sending a response body may cause issues, |
|
174 | - // and I wanted some type of indicator the response was handled. |
|
175 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
176 | - |
|
177 | - // Breaking the event chain |
|
178 | - return false; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * This event is triggered when properties are requested for a certain |
|
184 | - * node. |
|
185 | - * |
|
186 | - * This allows us to inject any properties early. |
|
187 | - * |
|
188 | - * @param PropFind $propFind |
|
189 | - * @param INode $node |
|
190 | - * @return void |
|
191 | - */ |
|
192 | - function propFind(PropFind $propFind, INode $node) { |
|
193 | - if ($node instanceof IShareable) { |
|
194 | - |
|
195 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
196 | - return new Invite( |
|
197 | - $node->getShares() |
|
198 | - ); |
|
199 | - }); |
|
200 | - |
|
201 | - } |
|
202 | - } |
|
41 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
42 | + const NS_NEXTCLOUD = 'http://nextcloud.com/ns'; |
|
43 | + |
|
44 | + /** @var Auth */ |
|
45 | + private $auth; |
|
46 | + |
|
47 | + /** @var IRequest */ |
|
48 | + private $request; |
|
49 | + |
|
50 | + /** |
|
51 | + * Plugin constructor. |
|
52 | + * |
|
53 | + * @param Auth $authBackEnd |
|
54 | + * @param IRequest $request |
|
55 | + */ |
|
56 | + public function __construct(Auth $authBackEnd, IRequest $request) { |
|
57 | + $this->auth = $authBackEnd; |
|
58 | + $this->request = $request; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Reference to SabreDAV server object. |
|
63 | + * |
|
64 | + * @var \Sabre\DAV\Server |
|
65 | + */ |
|
66 | + protected $server; |
|
67 | + |
|
68 | + /** |
|
69 | + * This method should return a list of server-features. |
|
70 | + * |
|
71 | + * This is for example 'versioning' and is added to the DAV: header |
|
72 | + * in an OPTIONS response. |
|
73 | + * |
|
74 | + * @return string[] |
|
75 | + */ |
|
76 | + function getFeatures() { |
|
77 | + return ['oc-resource-sharing']; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Returns a plugin name. |
|
82 | + * |
|
83 | + * Using this name other plugins will be able to access other plugins |
|
84 | + * using Sabre\DAV\Server::getPlugin |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + function getPluginName() { |
|
89 | + return 'oc-resource-sharing'; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * This initializes the plugin. |
|
94 | + * |
|
95 | + * This function is called by Sabre\DAV\Server, after |
|
96 | + * addPlugin is called. |
|
97 | + * |
|
98 | + * This method should set up the required event subscriptions. |
|
99 | + * |
|
100 | + * @param Server $server |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + function initialize(Server $server) { |
|
104 | + $this->server = $server; |
|
105 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
106 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
107 | + |
|
108 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
109 | + $this->server->on('propFind', [$this, 'propFind']); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * We intercept this to handle POST requests on a dav resource. |
|
114 | + * |
|
115 | + * @param RequestInterface $request |
|
116 | + * @param ResponseInterface $response |
|
117 | + * @return null|false |
|
118 | + */ |
|
119 | + function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
120 | + |
|
121 | + $path = $request->getPath(); |
|
122 | + |
|
123 | + // Only handling xml |
|
124 | + $contentType = $request->getHeader('Content-Type'); |
|
125 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
126 | + return; |
|
127 | + |
|
128 | + // Making sure the node exists |
|
129 | + try { |
|
130 | + $node = $this->server->tree->getNodeForPath($path); |
|
131 | + } catch (NotFound $e) { |
|
132 | + return; |
|
133 | + } |
|
134 | + |
|
135 | + $requestBody = $request->getBodyAsString(); |
|
136 | + |
|
137 | + // If this request handler could not deal with this POST request, it |
|
138 | + // will return 'null' and other plugins get a chance to handle the |
|
139 | + // request. |
|
140 | + // |
|
141 | + // However, we already requested the full body. This is a problem, |
|
142 | + // because a body can only be read once. This is why we preemptively |
|
143 | + // re-populated the request body with the existing data. |
|
144 | + $request->setBody($requestBody); |
|
145 | + |
|
146 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
147 | + |
|
148 | + switch ($documentType) { |
|
149 | + |
|
150 | + // Dealing with the 'share' document, which modified invitees on a |
|
151 | + // calendar. |
|
152 | + case '{' . self::NS_OWNCLOUD . '}share': |
|
153 | + |
|
154 | + // We can only deal with IShareableCalendar objects |
|
155 | + if (!$node instanceof IShareable) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + $this->server->transactionType = 'post-oc-resource-share'; |
|
160 | + |
|
161 | + // Getting ACL info |
|
162 | + $acl = $this->server->getPlugin('acl'); |
|
163 | + |
|
164 | + // If there's no ACL support, we allow everything |
|
165 | + if ($acl) { |
|
166 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
167 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
168 | + } |
|
169 | + |
|
170 | + $node->updateShares($message->set, $message->remove); |
|
171 | + |
|
172 | + $response->setStatus(200); |
|
173 | + // Adding this because sending a response body may cause issues, |
|
174 | + // and I wanted some type of indicator the response was handled. |
|
175 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
176 | + |
|
177 | + // Breaking the event chain |
|
178 | + return false; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * This event is triggered when properties are requested for a certain |
|
184 | + * node. |
|
185 | + * |
|
186 | + * This allows us to inject any properties early. |
|
187 | + * |
|
188 | + * @param PropFind $propFind |
|
189 | + * @param INode $node |
|
190 | + * @return void |
|
191 | + */ |
|
192 | + function propFind(PropFind $propFind, INode $node) { |
|
193 | + if ($node instanceof IShareable) { |
|
194 | + |
|
195 | + $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
196 | + return new Invite( |
|
197 | + $node->getShares() |
|
198 | + ); |
|
199 | + }); |
|
200 | + |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | 204 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function initialize(Server $server) { |
104 | 104 | $this->server = $server; |
105 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = ShareRequest::class; |
|
106 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = Invite::class; |
|
105 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}share'] = ShareRequest::class; |
|
106 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}invite'] = Invite::class; |
|
107 | 107 | |
108 | 108 | $this->server->on('method:POST', [$this, 'httpPost']); |
109 | - $this->server->on('propFind', [$this, 'propFind']); |
|
109 | + $this->server->on('propFind', [$this, 'propFind']); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | // Dealing with the 'share' document, which modified invitees on a |
151 | 151 | // calendar. |
152 | - case '{' . self::NS_OWNCLOUD . '}share': |
|
152 | + case '{'.self::NS_OWNCLOUD.'}share': |
|
153 | 153 | |
154 | 154 | // We can only deal with IShareableCalendar objects |
155 | 155 | if (!$node instanceof IShareable) { |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | function propFind(PropFind $propFind, INode $node) { |
193 | 193 | if ($node instanceof IShareable) { |
194 | 194 | |
195 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function () use ($node) { |
|
195 | + $propFind->handle('{'.Plugin::NS_OWNCLOUD.'}invite', function() use ($node) { |
|
196 | 196 | return new Invite( |
197 | 197 | $node->getShares() |
198 | 198 | ); |
@@ -41,148 +41,148 @@ |
||
41 | 41 | |
42 | 42 | class MoveCalendar extends Command { |
43 | 43 | |
44 | - /** @var IUserManager */ |
|
45 | - private $userManager; |
|
46 | - |
|
47 | - /** @var IGroupManager */ |
|
48 | - private $groupManager; |
|
49 | - |
|
50 | - /** @var IShareManager */ |
|
51 | - private $shareManager; |
|
52 | - |
|
53 | - /** @var IConfig $config */ |
|
54 | - private $config; |
|
55 | - |
|
56 | - /** @var IL10N */ |
|
57 | - private $l10n; |
|
58 | - |
|
59 | - /** @var SymfonyStyle */ |
|
60 | - private $io; |
|
61 | - |
|
62 | - /** @var CalDavBackend */ |
|
63 | - private $calDav; |
|
64 | - |
|
65 | - const URI_USERS = 'principals/users/'; |
|
66 | - |
|
67 | - /** |
|
68 | - * @param IUserManager $userManager |
|
69 | - * @param IGroupManager $groupManager |
|
70 | - * @param IShareManager $shareManager |
|
71 | - * @param IConfig $config |
|
72 | - * @param IL10N $l10n |
|
73 | - * @param CalDavBackend $calDav |
|
74 | - */ |
|
75 | - function __construct( |
|
76 | - IUserManager $userManager, |
|
77 | - IGroupManager $groupManager, |
|
78 | - IShareManager $shareManager, |
|
79 | - IConfig $config, |
|
80 | - IL10N $l10n, |
|
81 | - CalDavBackend $calDav |
|
82 | - ) { |
|
83 | - parent::__construct(); |
|
84 | - $this->userManager = $userManager; |
|
85 | - $this->groupManager = $groupManager; |
|
86 | - $this->shareManager = $shareManager; |
|
87 | - $this->config = $config; |
|
88 | - $this->l10n = $l10n; |
|
89 | - $this->calDav = $calDav; |
|
90 | - } |
|
91 | - |
|
92 | - protected function configure() { |
|
93 | - $this |
|
94 | - ->setName('dav:move-calendar') |
|
95 | - ->setDescription('Move a calendar from an user to another') |
|
96 | - ->addArgument('name', |
|
97 | - InputArgument::REQUIRED, |
|
98 | - 'Name of the calendar to move') |
|
99 | - ->addArgument('sourceuid', |
|
100 | - InputArgument::REQUIRED, |
|
101 | - 'User who currently owns the calendar') |
|
102 | - ->addArgument('destinationuid', |
|
103 | - InputArgument::REQUIRED, |
|
104 | - 'User who will receive the calendar') |
|
105 | - ->addOption('force', 'f', InputOption::VALUE_NONE, "Force the migration by removing existing shares"); |
|
106 | - } |
|
107 | - |
|
108 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
109 | - $userOrigin = $input->getArgument('sourceuid'); |
|
110 | - $userDestination = $input->getArgument('destinationuid'); |
|
111 | - |
|
112 | - $this->io = new SymfonyStyle($input, $output); |
|
113 | - |
|
114 | - if (!$this->userManager->userExists($userOrigin)) { |
|
115 | - throw new \InvalidArgumentException("User <$userOrigin> is unknown."); |
|
116 | - } |
|
117 | - |
|
118 | - if (!$this->userManager->userExists($userDestination)) { |
|
119 | - throw new \InvalidArgumentException("User <$userDestination> is unknown."); |
|
120 | - } |
|
121 | - |
|
122 | - $name = $input->getArgument('name'); |
|
123 | - |
|
124 | - $calendar = $this->calDav->getCalendarByUri(self::URI_USERS . $userOrigin, $name); |
|
125 | - |
|
126 | - if (null === $calendar) { |
|
127 | - throw new \InvalidArgumentException("User <$userOrigin> has no calendar named <$name>. You can run occ dav:list-calendars to list calendars URIs for this user."); |
|
128 | - } |
|
129 | - |
|
130 | - if (null !== $this->calDav->getCalendarByUri(self::URI_USERS . $userDestination, $name)) { |
|
131 | - throw new \InvalidArgumentException("User <$userDestination> already has a calendar named <$name>."); |
|
132 | - } |
|
133 | - |
|
134 | - $this->checkShares($calendar, $userOrigin, $userDestination, $input->getOption('force')); |
|
135 | - |
|
136 | - $this->calDav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination); |
|
137 | - |
|
138 | - $this->io->success("Calendar <$name> was moved from user <$userOrigin> to <$userDestination>"); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Check that moving the calendar won't break shares |
|
143 | - * |
|
144 | - * @param array $calendar |
|
145 | - * @param string $userOrigin |
|
146 | - * @param string $userDestination |
|
147 | - * @param bool $force |
|
148 | - */ |
|
149 | - private function checkShares(array $calendar, string $userOrigin, string $userDestination, bool $force = false) |
|
150 | - { |
|
151 | - $shares = $this->calDav->getShares($calendar['id']); |
|
152 | - foreach ($shares as $share) { |
|
153 | - list(, $prefix, $userOrGroup) = explode('/', $share['href'], 3); |
|
154 | - |
|
155 | - /** |
|
156 | - * Check that user destination is member of the groups which whom the calendar was shared |
|
157 | - * If we ask to force the migration, the share with the group is dropped |
|
158 | - */ |
|
159 | - if ($this->shareManager->shareWithGroupMembersOnly() === true && 'groups' === $prefix && !$this->groupManager->isInGroup($userDestination, $userOrGroup)) { |
|
160 | - if ($force) { |
|
161 | - $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/groups/' . $userOrGroup]); |
|
162 | - } else { |
|
163 | - throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$userOrGroup> with whom the calendar <" . $calendar['uri'] . "> was shared. You may use -f to move the calendar while deleting this share."); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Check that calendar isn't already shared with user destination |
|
169 | - */ |
|
170 | - if ($userOrGroup === $userDestination) { |
|
171 | - if ($force) { |
|
172 | - $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/users/' . $userOrGroup]); |
|
173 | - } else { |
|
174 | - throw new \InvalidArgumentException("The calendar <" . $calendar['uri'] . "> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share."); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - /** |
|
179 | - * Warn that share links have changed if there are shares |
|
180 | - */ |
|
181 | - if (count($shares) > 0) { |
|
182 | - $this->io->note([ |
|
183 | - "Please note that moving calendar " . $calendar['uri'] . " from user <$userOrigin> to <$userDestination> has caused share links to change.", |
|
184 | - "Sharees will need to change \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userOrigin\" to \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userDestination\"" |
|
185 | - ]); |
|
186 | - } |
|
187 | - } |
|
44 | + /** @var IUserManager */ |
|
45 | + private $userManager; |
|
46 | + |
|
47 | + /** @var IGroupManager */ |
|
48 | + private $groupManager; |
|
49 | + |
|
50 | + /** @var IShareManager */ |
|
51 | + private $shareManager; |
|
52 | + |
|
53 | + /** @var IConfig $config */ |
|
54 | + private $config; |
|
55 | + |
|
56 | + /** @var IL10N */ |
|
57 | + private $l10n; |
|
58 | + |
|
59 | + /** @var SymfonyStyle */ |
|
60 | + private $io; |
|
61 | + |
|
62 | + /** @var CalDavBackend */ |
|
63 | + private $calDav; |
|
64 | + |
|
65 | + const URI_USERS = 'principals/users/'; |
|
66 | + |
|
67 | + /** |
|
68 | + * @param IUserManager $userManager |
|
69 | + * @param IGroupManager $groupManager |
|
70 | + * @param IShareManager $shareManager |
|
71 | + * @param IConfig $config |
|
72 | + * @param IL10N $l10n |
|
73 | + * @param CalDavBackend $calDav |
|
74 | + */ |
|
75 | + function __construct( |
|
76 | + IUserManager $userManager, |
|
77 | + IGroupManager $groupManager, |
|
78 | + IShareManager $shareManager, |
|
79 | + IConfig $config, |
|
80 | + IL10N $l10n, |
|
81 | + CalDavBackend $calDav |
|
82 | + ) { |
|
83 | + parent::__construct(); |
|
84 | + $this->userManager = $userManager; |
|
85 | + $this->groupManager = $groupManager; |
|
86 | + $this->shareManager = $shareManager; |
|
87 | + $this->config = $config; |
|
88 | + $this->l10n = $l10n; |
|
89 | + $this->calDav = $calDav; |
|
90 | + } |
|
91 | + |
|
92 | + protected function configure() { |
|
93 | + $this |
|
94 | + ->setName('dav:move-calendar') |
|
95 | + ->setDescription('Move a calendar from an user to another') |
|
96 | + ->addArgument('name', |
|
97 | + InputArgument::REQUIRED, |
|
98 | + 'Name of the calendar to move') |
|
99 | + ->addArgument('sourceuid', |
|
100 | + InputArgument::REQUIRED, |
|
101 | + 'User who currently owns the calendar') |
|
102 | + ->addArgument('destinationuid', |
|
103 | + InputArgument::REQUIRED, |
|
104 | + 'User who will receive the calendar') |
|
105 | + ->addOption('force', 'f', InputOption::VALUE_NONE, "Force the migration by removing existing shares"); |
|
106 | + } |
|
107 | + |
|
108 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
109 | + $userOrigin = $input->getArgument('sourceuid'); |
|
110 | + $userDestination = $input->getArgument('destinationuid'); |
|
111 | + |
|
112 | + $this->io = new SymfonyStyle($input, $output); |
|
113 | + |
|
114 | + if (!$this->userManager->userExists($userOrigin)) { |
|
115 | + throw new \InvalidArgumentException("User <$userOrigin> is unknown."); |
|
116 | + } |
|
117 | + |
|
118 | + if (!$this->userManager->userExists($userDestination)) { |
|
119 | + throw new \InvalidArgumentException("User <$userDestination> is unknown."); |
|
120 | + } |
|
121 | + |
|
122 | + $name = $input->getArgument('name'); |
|
123 | + |
|
124 | + $calendar = $this->calDav->getCalendarByUri(self::URI_USERS . $userOrigin, $name); |
|
125 | + |
|
126 | + if (null === $calendar) { |
|
127 | + throw new \InvalidArgumentException("User <$userOrigin> has no calendar named <$name>. You can run occ dav:list-calendars to list calendars URIs for this user."); |
|
128 | + } |
|
129 | + |
|
130 | + if (null !== $this->calDav->getCalendarByUri(self::URI_USERS . $userDestination, $name)) { |
|
131 | + throw new \InvalidArgumentException("User <$userDestination> already has a calendar named <$name>."); |
|
132 | + } |
|
133 | + |
|
134 | + $this->checkShares($calendar, $userOrigin, $userDestination, $input->getOption('force')); |
|
135 | + |
|
136 | + $this->calDav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination); |
|
137 | + |
|
138 | + $this->io->success("Calendar <$name> was moved from user <$userOrigin> to <$userDestination>"); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Check that moving the calendar won't break shares |
|
143 | + * |
|
144 | + * @param array $calendar |
|
145 | + * @param string $userOrigin |
|
146 | + * @param string $userDestination |
|
147 | + * @param bool $force |
|
148 | + */ |
|
149 | + private function checkShares(array $calendar, string $userOrigin, string $userDestination, bool $force = false) |
|
150 | + { |
|
151 | + $shares = $this->calDav->getShares($calendar['id']); |
|
152 | + foreach ($shares as $share) { |
|
153 | + list(, $prefix, $userOrGroup) = explode('/', $share['href'], 3); |
|
154 | + |
|
155 | + /** |
|
156 | + * Check that user destination is member of the groups which whom the calendar was shared |
|
157 | + * If we ask to force the migration, the share with the group is dropped |
|
158 | + */ |
|
159 | + if ($this->shareManager->shareWithGroupMembersOnly() === true && 'groups' === $prefix && !$this->groupManager->isInGroup($userDestination, $userOrGroup)) { |
|
160 | + if ($force) { |
|
161 | + $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/groups/' . $userOrGroup]); |
|
162 | + } else { |
|
163 | + throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$userOrGroup> with whom the calendar <" . $calendar['uri'] . "> was shared. You may use -f to move the calendar while deleting this share."); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Check that calendar isn't already shared with user destination |
|
169 | + */ |
|
170 | + if ($userOrGroup === $userDestination) { |
|
171 | + if ($force) { |
|
172 | + $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/users/' . $userOrGroup]); |
|
173 | + } else { |
|
174 | + throw new \InvalidArgumentException("The calendar <" . $calendar['uri'] . "> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share."); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + /** |
|
179 | + * Warn that share links have changed if there are shares |
|
180 | + */ |
|
181 | + if (count($shares) > 0) { |
|
182 | + $this->io->note([ |
|
183 | + "Please note that moving calendar " . $calendar['uri'] . " from user <$userOrigin> to <$userDestination> has caused share links to change.", |
|
184 | + "Sharees will need to change \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userOrigin\" to \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userDestination\"" |
|
185 | + ]); |
|
186 | + } |
|
187 | + } |
|
188 | 188 | } |
@@ -121,19 +121,19 @@ discard block |
||
121 | 121 | |
122 | 122 | $name = $input->getArgument('name'); |
123 | 123 | |
124 | - $calendar = $this->calDav->getCalendarByUri(self::URI_USERS . $userOrigin, $name); |
|
124 | + $calendar = $this->calDav->getCalendarByUri(self::URI_USERS.$userOrigin, $name); |
|
125 | 125 | |
126 | 126 | if (null === $calendar) { |
127 | 127 | throw new \InvalidArgumentException("User <$userOrigin> has no calendar named <$name>. You can run occ dav:list-calendars to list calendars URIs for this user."); |
128 | 128 | } |
129 | 129 | |
130 | - if (null !== $this->calDav->getCalendarByUri(self::URI_USERS . $userDestination, $name)) { |
|
130 | + if (null !== $this->calDav->getCalendarByUri(self::URI_USERS.$userDestination, $name)) { |
|
131 | 131 | throw new \InvalidArgumentException("User <$userDestination> already has a calendar named <$name>."); |
132 | 132 | } |
133 | 133 | |
134 | 134 | $this->checkShares($calendar, $userOrigin, $userDestination, $input->getOption('force')); |
135 | 135 | |
136 | - $this->calDav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination); |
|
136 | + $this->calDav->moveCalendar($name, self::URI_USERS.$userOrigin, self::URI_USERS.$userDestination); |
|
137 | 137 | |
138 | 138 | $this->io->success("Calendar <$name> was moved from user <$userOrigin> to <$userDestination>"); |
139 | 139 | } |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | */ |
159 | 159 | if ($this->shareManager->shareWithGroupMembersOnly() === true && 'groups' === $prefix && !$this->groupManager->isInGroup($userDestination, $userOrGroup)) { |
160 | 160 | if ($force) { |
161 | - $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/groups/' . $userOrGroup]); |
|
161 | + $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/groups/'.$userOrGroup]); |
|
162 | 162 | } else { |
163 | - throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$userOrGroup> with whom the calendar <" . $calendar['uri'] . "> was shared. You may use -f to move the calendar while deleting this share."); |
|
163 | + throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$userOrGroup> with whom the calendar <".$calendar['uri']."> was shared. You may use -f to move the calendar while deleting this share."); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | */ |
170 | 170 | if ($userOrGroup === $userDestination) { |
171 | 171 | if ($force) { |
172 | - $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/users/' . $userOrGroup]); |
|
172 | + $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/users/'.$userOrGroup]); |
|
173 | 173 | } else { |
174 | - throw new \InvalidArgumentException("The calendar <" . $calendar['uri'] . "> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share."); |
|
174 | + throw new \InvalidArgumentException("The calendar <".$calendar['uri']."> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share."); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | */ |
181 | 181 | if (count($shares) > 0) { |
182 | 182 | $this->io->note([ |
183 | - "Please note that moving calendar " . $calendar['uri'] . " from user <$userOrigin> to <$userDestination> has caused share links to change.", |
|
184 | - "Sharees will need to change \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userOrigin\" to \"example.com/remote.php/dav/calendars/uid/" . $calendar['uri'] . "_shared_by_$userDestination\"" |
|
183 | + "Please note that moving calendar ".$calendar['uri']." from user <$userOrigin> to <$userDestination> has caused share links to change.", |
|
184 | + "Sharees will need to change \"example.com/remote.php/dav/calendars/uid/".$calendar['uri']."_shared_by_$userOrigin\" to \"example.com/remote.php/dav/calendars/uid/".$calendar['uri']."_shared_by_$userDestination\"" |
|
185 | 185 | ]); |
186 | 186 | } |
187 | 187 | } |
@@ -40,197 +40,197 @@ |
||
40 | 40 | use Sabre\HTTP\ResponseInterface; |
41 | 41 | |
42 | 42 | class PublishPlugin extends ServerPlugin { |
43 | - const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Reference to SabreDAV server object. |
|
47 | - * |
|
48 | - * @var \Sabre\DAV\Server |
|
49 | - */ |
|
50 | - protected $server; |
|
51 | - |
|
52 | - /** |
|
53 | - * Config instance to get instance secret. |
|
54 | - * |
|
55 | - * @var IConfig |
|
56 | - */ |
|
57 | - protected $config; |
|
58 | - |
|
59 | - /** |
|
60 | - * URL Generator for absolute URLs. |
|
61 | - * |
|
62 | - * @var IURLGenerator |
|
63 | - */ |
|
64 | - protected $urlGenerator; |
|
65 | - |
|
66 | - /** |
|
67 | - * PublishPlugin constructor. |
|
68 | - * |
|
69 | - * @param IConfig $config |
|
70 | - * @param IURLGenerator $urlGenerator |
|
71 | - */ |
|
72 | - public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
73 | - $this->config = $config; |
|
74 | - $this->urlGenerator = $urlGenerator; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * This method should return a list of server-features. |
|
79 | - * |
|
80 | - * This is for example 'versioning' and is added to the DAV: header |
|
81 | - * in an OPTIONS response. |
|
82 | - * |
|
83 | - * @return string[] |
|
84 | - */ |
|
85 | - public function getFeatures() { |
|
86 | - // May have to be changed to be detected |
|
87 | - return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns a plugin name. |
|
92 | - * |
|
93 | - * Using this name other plugins will be able to access other plugins |
|
94 | - * using Sabre\DAV\Server::getPlugin |
|
95 | - * |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getPluginName() { |
|
99 | - return 'oc-calendar-publishing'; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * This initializes the plugin. |
|
104 | - * |
|
105 | - * This function is called by Sabre\DAV\Server, after |
|
106 | - * addPlugin is called. |
|
107 | - * |
|
108 | - * This method should set up the required event subscriptions. |
|
109 | - * |
|
110 | - * @param Server $server |
|
111 | - */ |
|
112 | - public function initialize(Server $server) { |
|
113 | - $this->server = $server; |
|
114 | - |
|
115 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
116 | - $this->server->on('propFind', [$this, 'propFind']); |
|
117 | - } |
|
118 | - |
|
119 | - public function propFind(PropFind $propFind, INode $node) { |
|
120 | - if ($node instanceof Calendar) { |
|
121 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
122 | - if ($node->getPublishStatus()) { |
|
123 | - // We return the publish-url only if the calendar is published. |
|
124 | - $token = $node->getPublishStatus(); |
|
125 | - $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
126 | - |
|
127 | - return new Publisher($publishUrl, true); |
|
128 | - } |
|
129 | - }); |
|
130 | - |
|
131 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) { |
|
132 | - $canShare = (!$node->isSubscription() && $node->canWrite()); |
|
133 | - $canPublish = (!$node->isSubscription() && $node->canWrite()); |
|
134 | - |
|
135 | - return new AllowedSharingModes($canShare, $canPublish); |
|
136 | - }); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * We intercept this to handle POST requests on calendars. |
|
142 | - * |
|
143 | - * @param RequestInterface $request |
|
144 | - * @param ResponseInterface $response |
|
145 | - * |
|
146 | - * @return void|bool |
|
147 | - */ |
|
148 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
149 | - $path = $request->getPath(); |
|
150 | - |
|
151 | - // Only handling xml |
|
152 | - $contentType = $request->getHeader('Content-Type'); |
|
153 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
154 | - return; |
|
155 | - } |
|
156 | - |
|
157 | - // Making sure the node exists |
|
158 | - try { |
|
159 | - $node = $this->server->tree->getNodeForPath($path); |
|
160 | - } catch (NotFound $e) { |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - $requestBody = $request->getBodyAsString(); |
|
165 | - |
|
166 | - // If this request handler could not deal with this POST request, it |
|
167 | - // will return 'null' and other plugins get a chance to handle the |
|
168 | - // request. |
|
169 | - // |
|
170 | - // However, we already requested the full body. This is a problem, |
|
171 | - // because a body can only be read once. This is why we preemptively |
|
172 | - // re-populated the request body with the existing data. |
|
173 | - $request->setBody($requestBody); |
|
174 | - |
|
175 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
176 | - |
|
177 | - switch ($documentType) { |
|
178 | - |
|
179 | - case '{'.self::NS_CALENDARSERVER.'}publish-calendar': |
|
180 | - |
|
181 | - // We can only deal with IShareableCalendar objects |
|
182 | - if (!$node instanceof Calendar) { |
|
183 | - return; |
|
184 | - } |
|
185 | - $this->server->transactionType = 'post-publish-calendar'; |
|
186 | - |
|
187 | - // Getting ACL info |
|
188 | - $acl = $this->server->getPlugin('acl'); |
|
189 | - |
|
190 | - // If there's no ACL support, we allow everything |
|
191 | - if ($acl) { |
|
192 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
193 | - } |
|
194 | - |
|
195 | - $node->setPublishStatus(true); |
|
196 | - |
|
197 | - // iCloud sends back the 202, so we will too. |
|
198 | - $response->setStatus(202); |
|
199 | - |
|
200 | - // Adding this because sending a response body may cause issues, |
|
201 | - // and I wanted some type of indicator the response was handled. |
|
202 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
203 | - |
|
204 | - // Breaking the event chain |
|
205 | - return false; |
|
206 | - |
|
207 | - case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar': |
|
208 | - |
|
209 | - // We can only deal with IShareableCalendar objects |
|
210 | - if (!$node instanceof Calendar) { |
|
211 | - return; |
|
212 | - } |
|
213 | - $this->server->transactionType = 'post-unpublish-calendar'; |
|
214 | - |
|
215 | - // Getting ACL info |
|
216 | - $acl = $this->server->getPlugin('acl'); |
|
217 | - |
|
218 | - // If there's no ACL support, we allow everything |
|
219 | - if ($acl) { |
|
220 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
221 | - } |
|
222 | - |
|
223 | - $node->setPublishStatus(false); |
|
224 | - |
|
225 | - $response->setStatus(200); |
|
43 | + const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Reference to SabreDAV server object. |
|
47 | + * |
|
48 | + * @var \Sabre\DAV\Server |
|
49 | + */ |
|
50 | + protected $server; |
|
51 | + |
|
52 | + /** |
|
53 | + * Config instance to get instance secret. |
|
54 | + * |
|
55 | + * @var IConfig |
|
56 | + */ |
|
57 | + protected $config; |
|
58 | + |
|
59 | + /** |
|
60 | + * URL Generator for absolute URLs. |
|
61 | + * |
|
62 | + * @var IURLGenerator |
|
63 | + */ |
|
64 | + protected $urlGenerator; |
|
65 | + |
|
66 | + /** |
|
67 | + * PublishPlugin constructor. |
|
68 | + * |
|
69 | + * @param IConfig $config |
|
70 | + * @param IURLGenerator $urlGenerator |
|
71 | + */ |
|
72 | + public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
73 | + $this->config = $config; |
|
74 | + $this->urlGenerator = $urlGenerator; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * This method should return a list of server-features. |
|
79 | + * |
|
80 | + * This is for example 'versioning' and is added to the DAV: header |
|
81 | + * in an OPTIONS response. |
|
82 | + * |
|
83 | + * @return string[] |
|
84 | + */ |
|
85 | + public function getFeatures() { |
|
86 | + // May have to be changed to be detected |
|
87 | + return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns a plugin name. |
|
92 | + * |
|
93 | + * Using this name other plugins will be able to access other plugins |
|
94 | + * using Sabre\DAV\Server::getPlugin |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getPluginName() { |
|
99 | + return 'oc-calendar-publishing'; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * This initializes the plugin. |
|
104 | + * |
|
105 | + * This function is called by Sabre\DAV\Server, after |
|
106 | + * addPlugin is called. |
|
107 | + * |
|
108 | + * This method should set up the required event subscriptions. |
|
109 | + * |
|
110 | + * @param Server $server |
|
111 | + */ |
|
112 | + public function initialize(Server $server) { |
|
113 | + $this->server = $server; |
|
114 | + |
|
115 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
116 | + $this->server->on('propFind', [$this, 'propFind']); |
|
117 | + } |
|
118 | + |
|
119 | + public function propFind(PropFind $propFind, INode $node) { |
|
120 | + if ($node instanceof Calendar) { |
|
121 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
122 | + if ($node->getPublishStatus()) { |
|
123 | + // We return the publish-url only if the calendar is published. |
|
124 | + $token = $node->getPublishStatus(); |
|
125 | + $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
126 | + |
|
127 | + return new Publisher($publishUrl, true); |
|
128 | + } |
|
129 | + }); |
|
130 | + |
|
131 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function () use ($node) { |
|
132 | + $canShare = (!$node->isSubscription() && $node->canWrite()); |
|
133 | + $canPublish = (!$node->isSubscription() && $node->canWrite()); |
|
134 | + |
|
135 | + return new AllowedSharingModes($canShare, $canPublish); |
|
136 | + }); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * We intercept this to handle POST requests on calendars. |
|
142 | + * |
|
143 | + * @param RequestInterface $request |
|
144 | + * @param ResponseInterface $response |
|
145 | + * |
|
146 | + * @return void|bool |
|
147 | + */ |
|
148 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
149 | + $path = $request->getPath(); |
|
150 | + |
|
151 | + // Only handling xml |
|
152 | + $contentType = $request->getHeader('Content-Type'); |
|
153 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
154 | + return; |
|
155 | + } |
|
156 | + |
|
157 | + // Making sure the node exists |
|
158 | + try { |
|
159 | + $node = $this->server->tree->getNodeForPath($path); |
|
160 | + } catch (NotFound $e) { |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + $requestBody = $request->getBodyAsString(); |
|
165 | + |
|
166 | + // If this request handler could not deal with this POST request, it |
|
167 | + // will return 'null' and other plugins get a chance to handle the |
|
168 | + // request. |
|
169 | + // |
|
170 | + // However, we already requested the full body. This is a problem, |
|
171 | + // because a body can only be read once. This is why we preemptively |
|
172 | + // re-populated the request body with the existing data. |
|
173 | + $request->setBody($requestBody); |
|
174 | + |
|
175 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
176 | + |
|
177 | + switch ($documentType) { |
|
178 | + |
|
179 | + case '{'.self::NS_CALENDARSERVER.'}publish-calendar': |
|
180 | + |
|
181 | + // We can only deal with IShareableCalendar objects |
|
182 | + if (!$node instanceof Calendar) { |
|
183 | + return; |
|
184 | + } |
|
185 | + $this->server->transactionType = 'post-publish-calendar'; |
|
186 | + |
|
187 | + // Getting ACL info |
|
188 | + $acl = $this->server->getPlugin('acl'); |
|
189 | + |
|
190 | + // If there's no ACL support, we allow everything |
|
191 | + if ($acl) { |
|
192 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
193 | + } |
|
194 | + |
|
195 | + $node->setPublishStatus(true); |
|
196 | + |
|
197 | + // iCloud sends back the 202, so we will too. |
|
198 | + $response->setStatus(202); |
|
199 | + |
|
200 | + // Adding this because sending a response body may cause issues, |
|
201 | + // and I wanted some type of indicator the response was handled. |
|
202 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
203 | + |
|
204 | + // Breaking the event chain |
|
205 | + return false; |
|
206 | + |
|
207 | + case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar': |
|
208 | + |
|
209 | + // We can only deal with IShareableCalendar objects |
|
210 | + if (!$node instanceof Calendar) { |
|
211 | + return; |
|
212 | + } |
|
213 | + $this->server->transactionType = 'post-unpublish-calendar'; |
|
214 | + |
|
215 | + // Getting ACL info |
|
216 | + $acl = $this->server->getPlugin('acl'); |
|
217 | + |
|
218 | + // If there's no ACL support, we allow everything |
|
219 | + if ($acl) { |
|
220 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
221 | + } |
|
222 | + |
|
223 | + $node->setPublishStatus(false); |
|
224 | + |
|
225 | + $response->setStatus(200); |
|
226 | 226 | |
227 | - // Adding this because sending a response body may cause issues, |
|
228 | - // and I wanted some type of indicator the response was handled. |
|
229 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
227 | + // Adding this because sending a response body may cause issues, |
|
228 | + // and I wanted some type of indicator the response was handled. |
|
229 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
230 | 230 | |
231 | - // Breaking the event chain |
|
232 | - return false; |
|
231 | + // Breaking the event chain |
|
232 | + return false; |
|
233 | 233 | |
234 | - } |
|
235 | - } |
|
234 | + } |
|
235 | + } |
|
236 | 236 | } |
@@ -41,172 +41,172 @@ |
||
41 | 41 | */ |
42 | 42 | class CachedSubscription extends \Sabre\CalDAV\Calendar { |
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getPrincipalURI():string { |
|
48 | - return $this->calendarInfo['principaluri']; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getACL():array { |
|
55 | - return [ |
|
56 | - [ |
|
57 | - 'privilege' => '{DAV:}read', |
|
58 | - 'principal' => $this->getOwner(), |
|
59 | - 'protected' => true, |
|
60 | - ], |
|
61 | - [ |
|
62 | - 'privilege' => '{DAV:}read', |
|
63 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
64 | - 'protected' => true, |
|
65 | - ], |
|
66 | - [ |
|
67 | - 'privilege' => '{DAV:}read', |
|
68 | - 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
69 | - 'protected' => true, |
|
70 | - ], |
|
71 | - [ |
|
72 | - 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', |
|
73 | - 'principal' => '{DAV:}authenticated', |
|
74 | - 'protected' => true, |
|
75 | - ], |
|
76 | - ]; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getChildACL():array { |
|
83 | - return [ |
|
84 | - [ |
|
85 | - 'privilege' => '{DAV:}read', |
|
86 | - 'principal' => $this->getOwner(), |
|
87 | - 'protected' => true, |
|
88 | - ], |
|
89 | - |
|
90 | - [ |
|
91 | - 'privilege' => '{DAV:}read', |
|
92 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
93 | - 'protected' => true, |
|
94 | - ], |
|
95 | - [ |
|
96 | - 'privilege' => '{DAV:}read', |
|
97 | - 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
98 | - 'protected' => true, |
|
99 | - ], |
|
100 | - |
|
101 | - ]; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @return null|string |
|
106 | - */ |
|
107 | - public function getOwner() { |
|
108 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
109 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
110 | - } |
|
111 | - return parent::getOwner(); |
|
112 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getPrincipalURI():string { |
|
48 | + return $this->calendarInfo['principaluri']; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getACL():array { |
|
55 | + return [ |
|
56 | + [ |
|
57 | + 'privilege' => '{DAV:}read', |
|
58 | + 'principal' => $this->getOwner(), |
|
59 | + 'protected' => true, |
|
60 | + ], |
|
61 | + [ |
|
62 | + 'privilege' => '{DAV:}read', |
|
63 | + 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
64 | + 'protected' => true, |
|
65 | + ], |
|
66 | + [ |
|
67 | + 'privilege' => '{DAV:}read', |
|
68 | + 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
69 | + 'protected' => true, |
|
70 | + ], |
|
71 | + [ |
|
72 | + 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', |
|
73 | + 'principal' => '{DAV:}authenticated', |
|
74 | + 'protected' => true, |
|
75 | + ], |
|
76 | + ]; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getChildACL():array { |
|
83 | + return [ |
|
84 | + [ |
|
85 | + 'privilege' => '{DAV:}read', |
|
86 | + 'principal' => $this->getOwner(), |
|
87 | + 'protected' => true, |
|
88 | + ], |
|
89 | + |
|
90 | + [ |
|
91 | + 'privilege' => '{DAV:}read', |
|
92 | + 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
93 | + 'protected' => true, |
|
94 | + ], |
|
95 | + [ |
|
96 | + 'privilege' => '{DAV:}read', |
|
97 | + 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
98 | + 'protected' => true, |
|
99 | + ], |
|
100 | + |
|
101 | + ]; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @return null|string |
|
106 | + */ |
|
107 | + public function getOwner() { |
|
108 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
109 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
110 | + } |
|
111 | + return parent::getOwner(); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | - public function delete() { |
|
116 | - $this->caldavBackend->deleteSubscription($this->calendarInfo['id']); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param PropPatch $propPatch |
|
121 | - */ |
|
122 | - public function propPatch(PropPatch $propPatch) { |
|
123 | - $this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $name |
|
128 | - * @return CalendarObject|\Sabre\CalDAV\ICalendarObject |
|
129 | - * @throws NotFound |
|
130 | - */ |
|
131 | - public function getChild($name) { |
|
132 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
133 | - if (!$obj) { |
|
134 | - throw new NotFound('Calendar object not found'); |
|
135 | - } |
|
136 | - |
|
137 | - $obj['acl'] = $this->getChildACL(); |
|
138 | - return new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
139 | - |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - public function getChildren():array { |
|
146 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
147 | - |
|
148 | - $children = []; |
|
149 | - foreach($objs as $obj) { |
|
150 | - $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
151 | - } |
|
152 | - |
|
153 | - return $children; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @param array $paths |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - public function getMultipleChildren(array $paths):array { |
|
161 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
162 | - |
|
163 | - $children = []; |
|
164 | - foreach($objs as $obj) { |
|
165 | - $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
166 | - } |
|
167 | - |
|
168 | - return $children; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $name |
|
173 | - * @param null $calendarData |
|
174 | - * @return null|string|void |
|
175 | - * @throws MethodNotAllowed |
|
176 | - */ |
|
177 | - public function createFile($name, $calendarData = null) { |
|
178 | - throw new MethodNotAllowed('Creating objects in cached subscription is not allowed'); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $name |
|
183 | - * @return bool |
|
184 | - */ |
|
185 | - public function childExists($name):bool { |
|
186 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
187 | - if (!$obj) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - return true; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param array $filters |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - public function calendarQuery(array $filters):array { |
|
199 | - return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @inheritDoc |
|
204 | - */ |
|
205 | - public function getChanges($syncToken, $syncLevel, $limit = null) { |
|
206 | - if (!$syncToken && $limit) { |
|
207 | - throw new UnsupportedLimitOnInitialSyncException(); |
|
208 | - } |
|
209 | - |
|
210 | - return parent::getChanges($syncToken, $syncLevel, $limit); |
|
211 | - } |
|
115 | + public function delete() { |
|
116 | + $this->caldavBackend->deleteSubscription($this->calendarInfo['id']); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param PropPatch $propPatch |
|
121 | + */ |
|
122 | + public function propPatch(PropPatch $propPatch) { |
|
123 | + $this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $name |
|
128 | + * @return CalendarObject|\Sabre\CalDAV\ICalendarObject |
|
129 | + * @throws NotFound |
|
130 | + */ |
|
131 | + public function getChild($name) { |
|
132 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
133 | + if (!$obj) { |
|
134 | + throw new NotFound('Calendar object not found'); |
|
135 | + } |
|
136 | + |
|
137 | + $obj['acl'] = $this->getChildACL(); |
|
138 | + return new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
139 | + |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + public function getChildren():array { |
|
146 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
147 | + |
|
148 | + $children = []; |
|
149 | + foreach($objs as $obj) { |
|
150 | + $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
151 | + } |
|
152 | + |
|
153 | + return $children; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @param array $paths |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + public function getMultipleChildren(array $paths):array { |
|
161 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
162 | + |
|
163 | + $children = []; |
|
164 | + foreach($objs as $obj) { |
|
165 | + $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
166 | + } |
|
167 | + |
|
168 | + return $children; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $name |
|
173 | + * @param null $calendarData |
|
174 | + * @return null|string|void |
|
175 | + * @throws MethodNotAllowed |
|
176 | + */ |
|
177 | + public function createFile($name, $calendarData = null) { |
|
178 | + throw new MethodNotAllowed('Creating objects in cached subscription is not allowed'); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $name |
|
183 | + * @return bool |
|
184 | + */ |
|
185 | + public function childExists($name):bool { |
|
186 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
187 | + if (!$obj) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + return true; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param array $filters |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + public function calendarQuery(array $filters):array { |
|
199 | + return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @inheritDoc |
|
204 | + */ |
|
205 | + public function getChanges($syncToken, $syncLevel, $limit = null) { |
|
206 | + if (!$syncToken && $limit) { |
|
207 | + throw new UnsupportedLimitOnInitialSyncException(); |
|
208 | + } |
|
209 | + |
|
210 | + return parent::getChanges($syncToken, $syncLevel, $limit); |
|
211 | + } |
|
212 | 212 | } |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | ], |
61 | 61 | [ |
62 | 62 | 'privilege' => '{DAV:}read', |
63 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
63 | + 'principal' => $this->getOwner().'/calendar-proxy-write', |
|
64 | 64 | 'protected' => true, |
65 | 65 | ], |
66 | 66 | [ |
67 | 67 | 'privilege' => '{DAV:}read', |
68 | - 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
68 | + 'principal' => $this->getOwner().'/calendar-proxy-read', |
|
69 | 69 | 'protected' => true, |
70 | 70 | ], |
71 | 71 | [ |
72 | - 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', |
|
72 | + 'privilege' => '{'.Plugin::NS_CALDAV.'}read-free-busy', |
|
73 | 73 | 'principal' => '{DAV:}authenticated', |
74 | 74 | 'protected' => true, |
75 | 75 | ], |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | |
90 | 90 | [ |
91 | 91 | 'privilege' => '{DAV:}read', |
92 | - 'principal' => $this->getOwner() . '/calendar-proxy-write', |
|
92 | + 'principal' => $this->getOwner().'/calendar-proxy-write', |
|
93 | 93 | 'protected' => true, |
94 | 94 | ], |
95 | 95 | [ |
96 | 96 | 'privilege' => '{DAV:}read', |
97 | - 'principal' => $this->getOwner() . '/calendar-proxy-read', |
|
97 | + 'principal' => $this->getOwner().'/calendar-proxy-read', |
|
98 | 98 | 'protected' => true, |
99 | 99 | ], |
100 | 100 | |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
147 | 147 | |
148 | 148 | $children = []; |
149 | - foreach($objs as $obj) { |
|
149 | + foreach ($objs as $obj) { |
|
150 | 150 | $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
151 | 151 | } |
152 | 152 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION); |
162 | 162 | |
163 | 163 | $children = []; |
164 | - foreach($objs as $obj) { |
|
164 | + foreach ($objs as $obj) { |
|
165 | 165 | $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj); |
166 | 166 | } |
167 | 167 |