@@ -39,169 +39,169 @@ |
||
39 | 39 | */ |
40 | 40 | class SystemTagsObjectMappingCollection implements ICollection { |
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - private $objectId; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - private $objectType; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var ISystemTagManager |
|
54 | - */ |
|
55 | - private $tagManager; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var ISystemTagObjectMapper |
|
59 | - */ |
|
60 | - private $tagMapper; |
|
61 | - |
|
62 | - /** |
|
63 | - * User |
|
64 | - * |
|
65 | - * @var IUser |
|
66 | - */ |
|
67 | - private $user; |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Constructor |
|
72 | - * |
|
73 | - * @param string $objectId object id |
|
74 | - * @param string $objectType object type |
|
75 | - * @param IUser $user user |
|
76 | - * @param ISystemTagManager $tagManager tag manager |
|
77 | - * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
78 | - */ |
|
79 | - public function __construct( |
|
80 | - $objectId, |
|
81 | - $objectType, |
|
82 | - IUser $user, |
|
83 | - ISystemTagManager $tagManager, |
|
84 | - ISystemTagObjectMapper $tagMapper |
|
85 | - ) { |
|
86 | - $this->tagManager = $tagManager; |
|
87 | - $this->tagMapper = $tagMapper; |
|
88 | - $this->objectId = $objectId; |
|
89 | - $this->objectType = $objectType; |
|
90 | - $this->user = $user; |
|
91 | - } |
|
92 | - |
|
93 | - function createFile($tagId, $data = null) { |
|
94 | - try { |
|
95 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
96 | - $tag = current($tags); |
|
97 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
98 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
99 | - } |
|
100 | - if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
101 | - throw new Forbidden('No permission to assign tag ' . $tagId); |
|
102 | - } |
|
103 | - |
|
104 | - $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
105 | - } catch (TagNotFoundException $e) { |
|
106 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - function createDirectory($name) { |
|
111 | - throw new Forbidden('Permission denied to create collections'); |
|
112 | - } |
|
113 | - |
|
114 | - function getChild($tagId) { |
|
115 | - try { |
|
116 | - if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
117 | - $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
118 | - $tag = current($tag); |
|
119 | - if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
120 | - return $this->makeNode($tag); |
|
121 | - } |
|
122 | - } |
|
123 | - throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
124 | - } catch (\InvalidArgumentException $e) { |
|
125 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
126 | - } catch (TagNotFoundException $e) { |
|
127 | - throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - function getChildren() { |
|
132 | - $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
133 | - if (empty($tagIds)) { |
|
134 | - return []; |
|
135 | - } |
|
136 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
137 | - |
|
138 | - // filter out non-visible tags |
|
139 | - $tags = array_filter($tags, function($tag) { |
|
140 | - return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
141 | - }); |
|
142 | - |
|
143 | - return array_values(array_map(function($tag) { |
|
144 | - return $this->makeNode($tag); |
|
145 | - }, $tags)); |
|
146 | - } |
|
147 | - |
|
148 | - function childExists($tagId) { |
|
149 | - try { |
|
150 | - $result = ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)); |
|
151 | - |
|
152 | - if ($result) { |
|
153 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
154 | - $tag = current($tags); |
|
155 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
156 | - return false; |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - return $result; |
|
161 | - } catch (\InvalidArgumentException $e) { |
|
162 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
163 | - } catch (TagNotFoundException $e) { |
|
164 | - return false; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - function delete() { |
|
169 | - throw new Forbidden('Permission denied to delete this collection'); |
|
170 | - } |
|
171 | - |
|
172 | - function getName() { |
|
173 | - return $this->objectId; |
|
174 | - } |
|
175 | - |
|
176 | - function setName($name) { |
|
177 | - throw new Forbidden('Permission denied to rename this collection'); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns the last modification time, as a unix timestamp |
|
182 | - * |
|
183 | - * @return int |
|
184 | - */ |
|
185 | - function getLastModified() { |
|
186 | - return null; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Create a sabre node for the mapping of the |
|
191 | - * given system tag to the collection's object |
|
192 | - * |
|
193 | - * @param ISystemTag $tag |
|
194 | - * |
|
195 | - * @return SystemTagMappingNode |
|
196 | - */ |
|
197 | - private function makeNode(ISystemTag $tag) { |
|
198 | - return new SystemTagMappingNode( |
|
199 | - $tag, |
|
200 | - $this->objectId, |
|
201 | - $this->objectType, |
|
202 | - $this->user, |
|
203 | - $this->tagManager, |
|
204 | - $this->tagMapper |
|
205 | - ); |
|
206 | - } |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + private $objectId; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + private $objectType; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var ISystemTagManager |
|
54 | + */ |
|
55 | + private $tagManager; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var ISystemTagObjectMapper |
|
59 | + */ |
|
60 | + private $tagMapper; |
|
61 | + |
|
62 | + /** |
|
63 | + * User |
|
64 | + * |
|
65 | + * @var IUser |
|
66 | + */ |
|
67 | + private $user; |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Constructor |
|
72 | + * |
|
73 | + * @param string $objectId object id |
|
74 | + * @param string $objectType object type |
|
75 | + * @param IUser $user user |
|
76 | + * @param ISystemTagManager $tagManager tag manager |
|
77 | + * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
78 | + */ |
|
79 | + public function __construct( |
|
80 | + $objectId, |
|
81 | + $objectType, |
|
82 | + IUser $user, |
|
83 | + ISystemTagManager $tagManager, |
|
84 | + ISystemTagObjectMapper $tagMapper |
|
85 | + ) { |
|
86 | + $this->tagManager = $tagManager; |
|
87 | + $this->tagMapper = $tagMapper; |
|
88 | + $this->objectId = $objectId; |
|
89 | + $this->objectType = $objectType; |
|
90 | + $this->user = $user; |
|
91 | + } |
|
92 | + |
|
93 | + function createFile($tagId, $data = null) { |
|
94 | + try { |
|
95 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
96 | + $tag = current($tags); |
|
97 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
98 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
99 | + } |
|
100 | + if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
101 | + throw new Forbidden('No permission to assign tag ' . $tagId); |
|
102 | + } |
|
103 | + |
|
104 | + $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
105 | + } catch (TagNotFoundException $e) { |
|
106 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + function createDirectory($name) { |
|
111 | + throw new Forbidden('Permission denied to create collections'); |
|
112 | + } |
|
113 | + |
|
114 | + function getChild($tagId) { |
|
115 | + try { |
|
116 | + if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
117 | + $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
118 | + $tag = current($tag); |
|
119 | + if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
120 | + return $this->makeNode($tag); |
|
121 | + } |
|
122 | + } |
|
123 | + throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
124 | + } catch (\InvalidArgumentException $e) { |
|
125 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
126 | + } catch (TagNotFoundException $e) { |
|
127 | + throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + function getChildren() { |
|
132 | + $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
133 | + if (empty($tagIds)) { |
|
134 | + return []; |
|
135 | + } |
|
136 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
137 | + |
|
138 | + // filter out non-visible tags |
|
139 | + $tags = array_filter($tags, function($tag) { |
|
140 | + return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
141 | + }); |
|
142 | + |
|
143 | + return array_values(array_map(function($tag) { |
|
144 | + return $this->makeNode($tag); |
|
145 | + }, $tags)); |
|
146 | + } |
|
147 | + |
|
148 | + function childExists($tagId) { |
|
149 | + try { |
|
150 | + $result = ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)); |
|
151 | + |
|
152 | + if ($result) { |
|
153 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
154 | + $tag = current($tags); |
|
155 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
156 | + return false; |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + return $result; |
|
161 | + } catch (\InvalidArgumentException $e) { |
|
162 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
163 | + } catch (TagNotFoundException $e) { |
|
164 | + return false; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + function delete() { |
|
169 | + throw new Forbidden('Permission denied to delete this collection'); |
|
170 | + } |
|
171 | + |
|
172 | + function getName() { |
|
173 | + return $this->objectId; |
|
174 | + } |
|
175 | + |
|
176 | + function setName($name) { |
|
177 | + throw new Forbidden('Permission denied to rename this collection'); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns the last modification time, as a unix timestamp |
|
182 | + * |
|
183 | + * @return int |
|
184 | + */ |
|
185 | + function getLastModified() { |
|
186 | + return null; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Create a sabre node for the mapping of the |
|
191 | + * given system tag to the collection's object |
|
192 | + * |
|
193 | + * @param ISystemTag $tag |
|
194 | + * |
|
195 | + * @return SystemTagMappingNode |
|
196 | + */ |
|
197 | + private function makeNode(ISystemTag $tag) { |
|
198 | + return new SystemTagMappingNode( |
|
199 | + $tag, |
|
200 | + $this->objectId, |
|
201 | + $this->objectType, |
|
202 | + $this->user, |
|
203 | + $this->tagManager, |
|
204 | + $this->tagMapper |
|
205 | + ); |
|
206 | + } |
|
207 | 207 | } |
@@ -36,59 +36,59 @@ |
||
36 | 36 | |
37 | 37 | class SystemTagsRelationsCollection extends SimpleCollection { |
38 | 38 | |
39 | - /** |
|
40 | - * SystemTagsRelationsCollection constructor. |
|
41 | - * |
|
42 | - * @param ISystemTagManager $tagManager |
|
43 | - * @param ISystemTagObjectMapper $tagMapper |
|
44 | - * @param IUserSession $userSession |
|
45 | - * @param IGroupManager $groupManager |
|
46 | - * @param EventDispatcherInterface $dispatcher |
|
47 | - */ |
|
48 | - public function __construct( |
|
49 | - ISystemTagManager $tagManager, |
|
50 | - ISystemTagObjectMapper $tagMapper, |
|
51 | - IUserSession $userSession, |
|
52 | - IGroupManager $groupManager, |
|
53 | - EventDispatcherInterface $dispatcher |
|
54 | - ) { |
|
55 | - $children = [ |
|
56 | - new SystemTagsObjectTypeCollection( |
|
57 | - 'files', |
|
58 | - $tagManager, |
|
59 | - $tagMapper, |
|
60 | - $userSession, |
|
61 | - $groupManager, |
|
62 | - function($name) { |
|
63 | - $nodes = \OC::$server->getUserFolder()->getById(intval($name)); |
|
64 | - return !empty($nodes); |
|
65 | - } |
|
66 | - ), |
|
67 | - ]; |
|
39 | + /** |
|
40 | + * SystemTagsRelationsCollection constructor. |
|
41 | + * |
|
42 | + * @param ISystemTagManager $tagManager |
|
43 | + * @param ISystemTagObjectMapper $tagMapper |
|
44 | + * @param IUserSession $userSession |
|
45 | + * @param IGroupManager $groupManager |
|
46 | + * @param EventDispatcherInterface $dispatcher |
|
47 | + */ |
|
48 | + public function __construct( |
|
49 | + ISystemTagManager $tagManager, |
|
50 | + ISystemTagObjectMapper $tagMapper, |
|
51 | + IUserSession $userSession, |
|
52 | + IGroupManager $groupManager, |
|
53 | + EventDispatcherInterface $dispatcher |
|
54 | + ) { |
|
55 | + $children = [ |
|
56 | + new SystemTagsObjectTypeCollection( |
|
57 | + 'files', |
|
58 | + $tagManager, |
|
59 | + $tagMapper, |
|
60 | + $userSession, |
|
61 | + $groupManager, |
|
62 | + function($name) { |
|
63 | + $nodes = \OC::$server->getUserFolder()->getById(intval($name)); |
|
64 | + return !empty($nodes); |
|
65 | + } |
|
66 | + ), |
|
67 | + ]; |
|
68 | 68 | |
69 | - $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
70 | - $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
69 | + $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY); |
|
70 | + $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event); |
|
71 | 71 | |
72 | - foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
73 | - $children[] = new SystemTagsObjectTypeCollection( |
|
74 | - $entity, |
|
75 | - $tagManager, |
|
76 | - $tagMapper, |
|
77 | - $userSession, |
|
78 | - $groupManager, |
|
79 | - $entityExistsFunction |
|
80 | - ); |
|
81 | - } |
|
72 | + foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
73 | + $children[] = new SystemTagsObjectTypeCollection( |
|
74 | + $entity, |
|
75 | + $tagManager, |
|
76 | + $tagMapper, |
|
77 | + $userSession, |
|
78 | + $groupManager, |
|
79 | + $entityExistsFunction |
|
80 | + ); |
|
81 | + } |
|
82 | 82 | |
83 | - parent::__construct('root', $children); |
|
84 | - } |
|
83 | + parent::__construct('root', $children); |
|
84 | + } |
|
85 | 85 | |
86 | - function getName() { |
|
87 | - return 'systemtags-relations'; |
|
88 | - } |
|
86 | + function getName() { |
|
87 | + return 'systemtags-relations'; |
|
88 | + } |
|
89 | 89 | |
90 | - function setName($name) { |
|
91 | - throw new Forbidden('Permission denied to rename this collection'); |
|
92 | - } |
|
90 | + function setName($name) { |
|
91 | + throw new Forbidden('Permission denied to rename this collection'); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
@@ -35,17 +35,17 @@ discard block |
||
35 | 35 | use Sabre\CardDAV\Plugin; |
36 | 36 | |
37 | 37 | $authBackend = new Auth( |
38 | - \OC::$server->getSession(), |
|
39 | - \OC::$server->getUserSession(), |
|
40 | - \OC::$server->getRequest(), |
|
41 | - \OC::$server->getTwoFactorAuthManager(), |
|
42 | - \OC::$server->getBruteForceThrottler(), |
|
43 | - 'principals/' |
|
38 | + \OC::$server->getSession(), |
|
39 | + \OC::$server->getUserSession(), |
|
40 | + \OC::$server->getRequest(), |
|
41 | + \OC::$server->getTwoFactorAuthManager(), |
|
42 | + \OC::$server->getBruteForceThrottler(), |
|
43 | + 'principals/' |
|
44 | 44 | ); |
45 | 45 | $principalBackend = new Principal( |
46 | - \OC::$server->getUserManager(), |
|
47 | - \OC::$server->getGroupManager(), |
|
48 | - 'principals/' |
|
46 | + \OC::$server->getUserManager(), |
|
47 | + \OC::$server->getGroupManager(), |
|
48 | + 'principals/' |
|
49 | 49 | ); |
50 | 50 | $db = \OC::$server->getDatabaseConnection(); |
51 | 51 | $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager()); |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
61 | 61 | |
62 | 62 | $nodes = array( |
63 | - $principalCollection, |
|
64 | - $addressBookRoot, |
|
63 | + $principalCollection, |
|
64 | + $addressBookRoot, |
|
65 | 65 | ); |
66 | 66 | |
67 | 67 | // Fire up server |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | $server->addPlugin(new LegacyDAVACL()); |
78 | 78 | if ($debugging) { |
79 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
79 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | use OCA\DAV\Connector\Sabre\Principal; |
34 | 34 | |
35 | 35 | $authBackend = new Auth( |
36 | - \OC::$server->getSession(), |
|
37 | - \OC::$server->getUserSession(), |
|
38 | - \OC::$server->getRequest(), |
|
39 | - \OC::$server->getTwoFactorAuthManager(), |
|
40 | - \OC::$server->getBruteForceThrottler(), |
|
41 | - 'principals/' |
|
36 | + \OC::$server->getSession(), |
|
37 | + \OC::$server->getUserSession(), |
|
38 | + \OC::$server->getRequest(), |
|
39 | + \OC::$server->getTwoFactorAuthManager(), |
|
40 | + \OC::$server->getBruteForceThrottler(), |
|
41 | + 'principals/' |
|
42 | 42 | ); |
43 | 43 | $principalBackend = new Principal( |
44 | - \OC::$server->getUserManager(), |
|
45 | - \OC::$server->getGroupManager(), |
|
46 | - 'principals/' |
|
44 | + \OC::$server->getUserManager(), |
|
45 | + \OC::$server->getGroupManager(), |
|
46 | + 'principals/' |
|
47 | 47 | ); |
48 | 48 | $db = \OC::$server->getDatabaseConnection(); |
49 | 49 | $userManager = \OC::$server->getUserManager(); |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
62 | 62 | |
63 | 63 | $nodes = array( |
64 | - $principalCollection, |
|
65 | - $addressBookRoot, |
|
64 | + $principalCollection, |
|
65 | + $addressBookRoot, |
|
66 | 66 | ); |
67 | 67 | |
68 | 68 | // Fire up server |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $server->addPlugin(new LegacyDAVACL()); |
80 | 80 | if ($debugging) { |
81 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
81 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
@@ -38,20 +38,20 @@ discard block |
||
38 | 38 | |
39 | 39 | // Backends |
40 | 40 | $authBackend = new OCA\DAV\Connector\PublicAuth( |
41 | - \OC::$server->getRequest(), |
|
42 | - \OC::$server->getShareManager(), |
|
43 | - \OC::$server->getSession() |
|
41 | + \OC::$server->getRequest(), |
|
42 | + \OC::$server->getShareManager(), |
|
43 | + \OC::$server->getSession() |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( |
47 | - \OC::$server->getConfig(), |
|
48 | - \OC::$server->getLogger(), |
|
49 | - \OC::$server->getDatabaseConnection(), |
|
50 | - \OC::$server->getUserSession(), |
|
51 | - \OC::$server->getMountManager(), |
|
52 | - \OC::$server->getTagManager(), |
|
53 | - \OC::$server->getRequest(), |
|
54 | - \OC::$server->getPreviewManager() |
|
47 | + \OC::$server->getConfig(), |
|
48 | + \OC::$server->getLogger(), |
|
49 | + \OC::$server->getDatabaseConnection(), |
|
50 | + \OC::$server->getUserSession(), |
|
51 | + \OC::$server->getMountManager(), |
|
52 | + \OC::$server->getTagManager(), |
|
53 | + \OC::$server->getRequest(), |
|
54 | + \OC::$server->getPreviewManager() |
|
55 | 55 | ); |
56 | 56 | |
57 | 57 | $requestUri = \OC::$server->getRequest()->getRequestUri(); |
@@ -60,41 +60,41 @@ discard block |
||
60 | 60 | $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); |
61 | 61 | |
62 | 62 | $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
63 | - $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
|
64 | - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
65 | - $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); |
|
66 | - if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { |
|
67 | - // this is what is thrown when trying to access a non-existing share |
|
68 | - throw new \Sabre\DAV\Exception\NotAuthenticated(); |
|
69 | - } |
|
70 | - |
|
71 | - $share = $authBackend->getShare(); |
|
72 | - $owner = $share->getShareOwner(); |
|
73 | - $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; |
|
74 | - $fileId = $share->getNodeId(); |
|
75 | - |
|
76 | - // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
|
77 | - $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
78 | - \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
79 | - return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE)); |
|
80 | - }); |
|
81 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
|
82 | - |
|
83 | - OC_Util::setupFS($owner); |
|
84 | - $ownerView = \OC\Files\Filesystem::getView(); |
|
85 | - $path = $ownerView->getPath($fileId); |
|
86 | - $fileInfo = $ownerView->getFileInfo($path); |
|
87 | - $linkCheckPlugin->setFileInfo($fileInfo); |
|
88 | - |
|
89 | - // If not readble (files_drop) enable the filesdrop plugin |
|
90 | - if (!$isReadable) { |
|
91 | - $filesDropPlugin->enable(); |
|
92 | - } |
|
93 | - |
|
94 | - $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); |
|
95 | - $filesDropPlugin->setView($view); |
|
96 | - |
|
97 | - return $view; |
|
63 | + $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
|
64 | + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
65 | + $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); |
|
66 | + if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { |
|
67 | + // this is what is thrown when trying to access a non-existing share |
|
68 | + throw new \Sabre\DAV\Exception\NotAuthenticated(); |
|
69 | + } |
|
70 | + |
|
71 | + $share = $authBackend->getShare(); |
|
72 | + $owner = $share->getShareOwner(); |
|
73 | + $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; |
|
74 | + $fileId = $share->getNodeId(); |
|
75 | + |
|
76 | + // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
|
77 | + $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
78 | + \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
79 | + return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE)); |
|
80 | + }); |
|
81 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
|
82 | + |
|
83 | + OC_Util::setupFS($owner); |
|
84 | + $ownerView = \OC\Files\Filesystem::getView(); |
|
85 | + $path = $ownerView->getPath($fileId); |
|
86 | + $fileInfo = $ownerView->getFileInfo($path); |
|
87 | + $linkCheckPlugin->setFileInfo($fileInfo); |
|
88 | + |
|
89 | + // If not readble (files_drop) enable the filesdrop plugin |
|
90 | + if (!$isReadable) { |
|
91 | + $filesDropPlugin->enable(); |
|
92 | + } |
|
93 | + |
|
94 | + $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); |
|
95 | + $filesDropPlugin->setView($view); |
|
96 | + |
|
97 | + return $view; |
|
98 | 98 | }); |
99 | 99 | |
100 | 100 | $server->addPlugin($linkCheckPlugin); |
@@ -30,27 +30,27 @@ |
||
30 | 30 | $app->registerHooks(); |
31 | 31 | |
32 | 32 | \OC::$server->registerService('CardDAVSyncService', function() use ($app) { |
33 | - return $app->getSyncService(); |
|
33 | + return $app->getSyncService(); |
|
34 | 34 | }); |
35 | 35 | |
36 | 36 | $eventDispatcher = \OC::$server->getEventDispatcher(); |
37 | 37 | |
38 | 38 | $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', |
39 | - function(GenericEvent $event) use ($app) { |
|
40 | - /** @var CardDavBackend $cardDavBackend */ |
|
41 | - $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
42 | - $addressBookUri = $event->getSubject(); |
|
43 | - $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
44 | - if (!is_null($addressBook)) { |
|
45 | - $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
46 | - } |
|
47 | - } |
|
39 | + function(GenericEvent $event) use ($app) { |
|
40 | + /** @var CardDavBackend $cardDavBackend */ |
|
41 | + $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
42 | + $addressBookUri = $event->getSubject(); |
|
43 | + $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
44 | + if (!is_null($addressBook)) { |
|
45 | + $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | ); |
49 | 49 | |
50 | 50 | $cm = \OC::$server->getContactsManager(); |
51 | 51 | $cm->register(function() use ($cm, $app) { |
52 | - $user = \OC::$server->getUserSession()->getUser(); |
|
53 | - if (!is_null($user)) { |
|
54 | - $app->setupContactsProvider($cm, $user->getUID()); |
|
55 | - } |
|
52 | + $user = \OC::$server->getUserSession()->getUser(); |
|
53 | + if (!is_null($user)) { |
|
54 | + $app->setupContactsProvider($cm, $user->getUID()); |
|
55 | + } |
|
56 | 56 | }); |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | require '../../../../3rdparty/autoload.php'; |
24 | 24 | |
25 | 25 | if ($argc !== 6) { |
26 | - echo "Invalid number of arguments" . PHP_EOL; |
|
27 | - exit; |
|
26 | + echo "Invalid number of arguments" . PHP_EOL; |
|
27 | + exit; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | * @return mixed |
34 | 34 | */ |
35 | 35 | function request($client, $method, $uploadUrl, $data = null, $headers = []) { |
36 | - echo "$method $uploadUrl ... "; |
|
37 | - $t0 = microtime(true); |
|
38 | - $result = $client->request($method, $uploadUrl, $data, $headers); |
|
39 | - $t1 = microtime(true); |
|
40 | - echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL; |
|
41 | - if (!in_array($result['statusCode'], [200, 201])) { |
|
42 | - echo $result['body'] . PHP_EOL; |
|
43 | - } |
|
44 | - return $result; |
|
36 | + echo "$method $uploadUrl ... "; |
|
37 | + $t0 = microtime(true); |
|
38 | + $result = $client->request($method, $uploadUrl, $data, $headers); |
|
39 | + $t1 = microtime(true); |
|
40 | + echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL; |
|
41 | + if (!in_array($result['statusCode'], [200, 201])) { |
|
42 | + echo $result['body'] . PHP_EOL; |
|
43 | + } |
|
44 | + return $result; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $baseUri = $argv[1]; |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | $chunkSize = $argv[5] * 1024 * 1024; |
52 | 52 | |
53 | 53 | $client = new \Sabre\DAV\Client([ |
54 | - 'baseUri' => $baseUri, |
|
55 | - 'userName' => $userName, |
|
56 | - 'password' => $password |
|
54 | + 'baseUri' => $baseUri, |
|
55 | + 'userName' => $userName, |
|
56 | + 'password' => $password |
|
57 | 57 | ]); |
58 | 58 | |
59 | 59 | $transfer = uniqid('transfer', true); |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | |
67 | 67 | $index = 0; |
68 | 68 | while(!feof($stream)) { |
69 | - request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize)); |
|
70 | - $index++; |
|
69 | + request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize)); |
|
70 | + $index++; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $destination = pathinfo($file, PATHINFO_BASENAME); |
74 | 74 | //echo "Moving $uploadUrl/.file to it's final destination $baseUri/files/$userName/$destination" . PHP_EOL; |
75 | 75 | request($client, 'MOVE', "$uploadUrl/.file", null, [ |
76 | - 'Destination' => "$baseUri/files/$userName/$destination" |
|
76 | + 'Destination' => "$baseUri/files/$userName/$destination" |
|
77 | 77 | ]); |
@@ -30,52 +30,52 @@ |
||
30 | 30 | * @package OCA\Admin_Audit\Actions |
31 | 31 | */ |
32 | 32 | class UserManagement extends Action { |
33 | - /** |
|
34 | - * Log creation of users |
|
35 | - * |
|
36 | - * @param array $params |
|
37 | - */ |
|
38 | - public function create(array $params) { |
|
39 | - $this->log( |
|
40 | - 'User created: "%s"', |
|
41 | - $params, |
|
42 | - [ |
|
43 | - 'uid', |
|
44 | - ] |
|
45 | - ); |
|
46 | - } |
|
33 | + /** |
|
34 | + * Log creation of users |
|
35 | + * |
|
36 | + * @param array $params |
|
37 | + */ |
|
38 | + public function create(array $params) { |
|
39 | + $this->log( |
|
40 | + 'User created: "%s"', |
|
41 | + $params, |
|
42 | + [ |
|
43 | + 'uid', |
|
44 | + ] |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Log deletion of users |
|
50 | - * |
|
51 | - * @param array $params |
|
52 | - */ |
|
53 | - public function delete(array $params) { |
|
54 | - $this->log( |
|
55 | - 'User deleted: "%s"', |
|
56 | - $params, |
|
57 | - [ |
|
58 | - 'uid', |
|
59 | - ] |
|
60 | - ); |
|
61 | - } |
|
48 | + /** |
|
49 | + * Log deletion of users |
|
50 | + * |
|
51 | + * @param array $params |
|
52 | + */ |
|
53 | + public function delete(array $params) { |
|
54 | + $this->log( |
|
55 | + 'User deleted: "%s"', |
|
56 | + $params, |
|
57 | + [ |
|
58 | + 'uid', |
|
59 | + ] |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Logs changing of the user scope |
|
65 | - * |
|
66 | - * @param IUser $user |
|
67 | - */ |
|
68 | - public function setPassword(IUser $user) { |
|
69 | - if($user->getBackendClassName() === 'Database') { |
|
70 | - $this->log( |
|
71 | - 'Password of user "%s" has been changed', |
|
72 | - [ |
|
73 | - 'user' => $user->getUID(), |
|
74 | - ], |
|
75 | - [ |
|
76 | - 'user', |
|
77 | - ] |
|
78 | - ); |
|
79 | - } |
|
80 | - } |
|
63 | + /** |
|
64 | + * Logs changing of the user scope |
|
65 | + * |
|
66 | + * @param IUser $user |
|
67 | + */ |
|
68 | + public function setPassword(IUser $user) { |
|
69 | + if($user->getBackendClassName() === 'Database') { |
|
70 | + $this->log( |
|
71 | + 'Password of user "%s" has been changed', |
|
72 | + [ |
|
73 | + 'user' => $user->getUID(), |
|
74 | + ], |
|
75 | + [ |
|
76 | + 'user', |
|
77 | + ] |
|
78 | + ); |
|
79 | + } |
|
80 | + } |
|
81 | 81 | } |
@@ -25,64 +25,64 @@ |
||
25 | 25 | use OCP\ILogger; |
26 | 26 | |
27 | 27 | class Action { |
28 | - /** @var ILogger */ |
|
29 | - private $logger; |
|
28 | + /** @var ILogger */ |
|
29 | + private $logger; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param ILogger $logger |
|
33 | - */ |
|
34 | - public function __construct(ILogger $logger) { |
|
35 | - $this->logger = $logger; |
|
36 | - } |
|
31 | + /** |
|
32 | + * @param ILogger $logger |
|
33 | + */ |
|
34 | + public function __construct(ILogger $logger) { |
|
35 | + $this->logger = $logger; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Log a single action with a log level of info |
|
40 | - * |
|
41 | - * @param string $text |
|
42 | - * @param array $params |
|
43 | - * @param array $elements |
|
44 | - * @param bool $obfuscateParameters |
|
45 | - */ |
|
46 | - public function log($text, |
|
47 | - array $params, |
|
48 | - array $elements, |
|
49 | - $obfuscateParameters = false) { |
|
50 | - foreach($elements as $element) { |
|
51 | - if(!isset($params[$element])) { |
|
52 | - if ($obfuscateParameters) { |
|
53 | - $this->logger->critical( |
|
54 | - '$params["'.$element.'"] was missing.', |
|
55 | - ['app' => 'admin_audit'] |
|
56 | - ); |
|
57 | - } else { |
|
58 | - $this->logger->critical( |
|
59 | - sprintf( |
|
60 | - '$params["'.$element.'"] was missing. Transferred value: %s', |
|
61 | - print_r($params, true) |
|
62 | - ), |
|
63 | - ['app' => 'admin_audit'] |
|
64 | - ); |
|
65 | - } |
|
66 | - return; |
|
67 | - } |
|
68 | - } |
|
38 | + /** |
|
39 | + * Log a single action with a log level of info |
|
40 | + * |
|
41 | + * @param string $text |
|
42 | + * @param array $params |
|
43 | + * @param array $elements |
|
44 | + * @param bool $obfuscateParameters |
|
45 | + */ |
|
46 | + public function log($text, |
|
47 | + array $params, |
|
48 | + array $elements, |
|
49 | + $obfuscateParameters = false) { |
|
50 | + foreach($elements as $element) { |
|
51 | + if(!isset($params[$element])) { |
|
52 | + if ($obfuscateParameters) { |
|
53 | + $this->logger->critical( |
|
54 | + '$params["'.$element.'"] was missing.', |
|
55 | + ['app' => 'admin_audit'] |
|
56 | + ); |
|
57 | + } else { |
|
58 | + $this->logger->critical( |
|
59 | + sprintf( |
|
60 | + '$params["'.$element.'"] was missing. Transferred value: %s', |
|
61 | + print_r($params, true) |
|
62 | + ), |
|
63 | + ['app' => 'admin_audit'] |
|
64 | + ); |
|
65 | + } |
|
66 | + return; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - $replaceArray = []; |
|
71 | - foreach($elements as $element) { |
|
72 | - if($params[$element] instanceof \DateTime) { |
|
73 | - $params[$element] = $params[$element]->format('Y-m-d H:i:s'); |
|
74 | - } |
|
75 | - $replaceArray[] = $params[$element]; |
|
76 | - } |
|
70 | + $replaceArray = []; |
|
71 | + foreach($elements as $element) { |
|
72 | + if($params[$element] instanceof \DateTime) { |
|
73 | + $params[$element] = $params[$element]->format('Y-m-d H:i:s'); |
|
74 | + } |
|
75 | + $replaceArray[] = $params[$element]; |
|
76 | + } |
|
77 | 77 | |
78 | - $this->logger->info( |
|
79 | - vsprintf( |
|
80 | - $text, |
|
81 | - $replaceArray |
|
82 | - ), |
|
83 | - [ |
|
84 | - 'app' => 'admin_audit' |
|
85 | - ] |
|
86 | - ); |
|
87 | - } |
|
78 | + $this->logger->info( |
|
79 | + vsprintf( |
|
80 | + $text, |
|
81 | + $replaceArray |
|
82 | + ), |
|
83 | + [ |
|
84 | + 'app' => 'admin_audit' |
|
85 | + ] |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | } |