@@ -40,143 +40,143 @@ |
||
40 | 40 | */ |
41 | 41 | class SystemTagNode implements \Sabre\DAV\INode { |
42 | 42 | |
43 | - /** |
|
44 | - * @var ISystemTag |
|
45 | - */ |
|
46 | - protected $tag; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var ISystemTagManager |
|
50 | - */ |
|
51 | - protected $tagManager; |
|
52 | - |
|
53 | - /** |
|
54 | - * User |
|
55 | - * |
|
56 | - * @var IUser |
|
57 | - */ |
|
58 | - protected $user; |
|
59 | - |
|
60 | - /** |
|
61 | - * Whether to allow permissions for admins |
|
62 | - * |
|
63 | - * @var bool |
|
64 | - */ |
|
65 | - protected $isAdmin; |
|
66 | - |
|
67 | - /** |
|
68 | - * Sets up the node, expects a full path name |
|
69 | - * |
|
70 | - * @param ISystemTag $tag system tag |
|
71 | - * @param IUser $user user |
|
72 | - * @param bool $isAdmin whether to allow operations for admins |
|
73 | - * @param ISystemTagManager $tagManager tag manager |
|
74 | - */ |
|
75 | - public function __construct(ISystemTag $tag, IUser $user, $isAdmin, ISystemTagManager $tagManager) { |
|
76 | - $this->tag = $tag; |
|
77 | - $this->user = $user; |
|
78 | - $this->isAdmin = $isAdmin; |
|
79 | - $this->tagManager = $tagManager; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns the id of the tag |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function getName() { |
|
88 | - return $this->tag->getId(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns the system tag represented by this node |
|
93 | - * |
|
94 | - * @return ISystemTag system tag |
|
95 | - */ |
|
96 | - public function getSystemTag() { |
|
97 | - return $this->tag; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Renames the node |
|
102 | - * |
|
103 | - * @param string $name The new name |
|
104 | - * |
|
105 | - * @throws MethodNotAllowed not allowed to rename node |
|
106 | - * |
|
107 | - * @return never |
|
108 | - */ |
|
109 | - public function setName($name) { |
|
110 | - throw new MethodNotAllowed(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Update tag |
|
115 | - * |
|
116 | - * @param string $name new tag name |
|
117 | - * @param bool $userVisible user visible |
|
118 | - * @param bool $userAssignable user assignable |
|
119 | - * |
|
120 | - * @throws NotFound whenever the given tag id does not exist |
|
121 | - * @throws Forbidden whenever there is no permission to update said tag |
|
122 | - * @throws Conflict whenever a tag already exists with the given attributes |
|
123 | - */ |
|
124 | - public function update($name, $userVisible, $userAssignable): void { |
|
125 | - try { |
|
126 | - if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
127 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
128 | - } |
|
129 | - if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
130 | - throw new Forbidden('No permission to update tag ' . $this->tag->getId()); |
|
131 | - } |
|
132 | - |
|
133 | - // only admin is able to change permissions, regular users can only rename |
|
134 | - if (!$this->isAdmin) { |
|
135 | - // only renaming is allowed for regular users |
|
136 | - if ($userVisible !== $this->tag->isUserVisible() |
|
137 | - || $userAssignable !== $this->tag->isUserAssignable() |
|
138 | - ) { |
|
139 | - throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId()); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable); |
|
144 | - } catch (TagNotFoundException $e) { |
|
145 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
146 | - } catch (TagAlreadyExistsException $e) { |
|
147 | - throw new Conflict( |
|
148 | - 'Tag with the properties "' . $name . '", ' . |
|
149 | - $userVisible . ', ' . $userAssignable . ' already exists' |
|
150 | - ); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns null, not supported |
|
156 | - * |
|
157 | - * @return null |
|
158 | - */ |
|
159 | - public function getLastModified() { |
|
160 | - return null; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @return void |
|
165 | - */ |
|
166 | - public function delete() { |
|
167 | - try { |
|
168 | - if (!$this->isAdmin) { |
|
169 | - throw new Forbidden('No permission to delete tag ' . $this->tag->getId()); |
|
170 | - } |
|
171 | - |
|
172 | - if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
173 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
174 | - } |
|
175 | - |
|
176 | - $this->tagManager->deleteTags($this->tag->getId()); |
|
177 | - } catch (TagNotFoundException $e) { |
|
178 | - // can happen if concurrent deletion occurred |
|
179 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
180 | - } |
|
181 | - } |
|
43 | + /** |
|
44 | + * @var ISystemTag |
|
45 | + */ |
|
46 | + protected $tag; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var ISystemTagManager |
|
50 | + */ |
|
51 | + protected $tagManager; |
|
52 | + |
|
53 | + /** |
|
54 | + * User |
|
55 | + * |
|
56 | + * @var IUser |
|
57 | + */ |
|
58 | + protected $user; |
|
59 | + |
|
60 | + /** |
|
61 | + * Whether to allow permissions for admins |
|
62 | + * |
|
63 | + * @var bool |
|
64 | + */ |
|
65 | + protected $isAdmin; |
|
66 | + |
|
67 | + /** |
|
68 | + * Sets up the node, expects a full path name |
|
69 | + * |
|
70 | + * @param ISystemTag $tag system tag |
|
71 | + * @param IUser $user user |
|
72 | + * @param bool $isAdmin whether to allow operations for admins |
|
73 | + * @param ISystemTagManager $tagManager tag manager |
|
74 | + */ |
|
75 | + public function __construct(ISystemTag $tag, IUser $user, $isAdmin, ISystemTagManager $tagManager) { |
|
76 | + $this->tag = $tag; |
|
77 | + $this->user = $user; |
|
78 | + $this->isAdmin = $isAdmin; |
|
79 | + $this->tagManager = $tagManager; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns the id of the tag |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function getName() { |
|
88 | + return $this->tag->getId(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns the system tag represented by this node |
|
93 | + * |
|
94 | + * @return ISystemTag system tag |
|
95 | + */ |
|
96 | + public function getSystemTag() { |
|
97 | + return $this->tag; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Renames the node |
|
102 | + * |
|
103 | + * @param string $name The new name |
|
104 | + * |
|
105 | + * @throws MethodNotAllowed not allowed to rename node |
|
106 | + * |
|
107 | + * @return never |
|
108 | + */ |
|
109 | + public function setName($name) { |
|
110 | + throw new MethodNotAllowed(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Update tag |
|
115 | + * |
|
116 | + * @param string $name new tag name |
|
117 | + * @param bool $userVisible user visible |
|
118 | + * @param bool $userAssignable user assignable |
|
119 | + * |
|
120 | + * @throws NotFound whenever the given tag id does not exist |
|
121 | + * @throws Forbidden whenever there is no permission to update said tag |
|
122 | + * @throws Conflict whenever a tag already exists with the given attributes |
|
123 | + */ |
|
124 | + public function update($name, $userVisible, $userAssignable): void { |
|
125 | + try { |
|
126 | + if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
127 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
128 | + } |
|
129 | + if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
|
130 | + throw new Forbidden('No permission to update tag ' . $this->tag->getId()); |
|
131 | + } |
|
132 | + |
|
133 | + // only admin is able to change permissions, regular users can only rename |
|
134 | + if (!$this->isAdmin) { |
|
135 | + // only renaming is allowed for regular users |
|
136 | + if ($userVisible !== $this->tag->isUserVisible() |
|
137 | + || $userAssignable !== $this->tag->isUserAssignable() |
|
138 | + ) { |
|
139 | + throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId()); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable); |
|
144 | + } catch (TagNotFoundException $e) { |
|
145 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
146 | + } catch (TagAlreadyExistsException $e) { |
|
147 | + throw new Conflict( |
|
148 | + 'Tag with the properties "' . $name . '", ' . |
|
149 | + $userVisible . ', ' . $userAssignable . ' already exists' |
|
150 | + ); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns null, not supported |
|
156 | + * |
|
157 | + * @return null |
|
158 | + */ |
|
159 | + public function getLastModified() { |
|
160 | + return null; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @return void |
|
165 | + */ |
|
166 | + public function delete() { |
|
167 | + try { |
|
168 | + if (!$this->isAdmin) { |
|
169 | + throw new Forbidden('No permission to delete tag ' . $this->tag->getId()); |
|
170 | + } |
|
171 | + |
|
172 | + if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
|
173 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
174 | + } |
|
175 | + |
|
176 | + $this->tagManager->deleteTags($this->tag->getId()); |
|
177 | + } catch (TagNotFoundException $e) { |
|
178 | + // can happen if concurrent deletion occurred |
|
179 | + throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
180 | + } |
|
181 | + } |
|
182 | 182 | } |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | public function update($name, $userVisible, $userAssignable): void { |
125 | 125 | try { |
126 | 126 | if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
127 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
127 | + throw new NotFound('Tag with id '.$this->tag->getId().' does not exist'); |
|
128 | 128 | } |
129 | 129 | if (!$this->tagManager->canUserAssignTag($this->tag, $this->user)) { |
130 | - throw new Forbidden('No permission to update tag ' . $this->tag->getId()); |
|
130 | + throw new Forbidden('No permission to update tag '.$this->tag->getId()); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | // only admin is able to change permissions, regular users can only rename |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | if ($userVisible !== $this->tag->isUserVisible() |
137 | 137 | || $userAssignable !== $this->tag->isUserAssignable() |
138 | 138 | ) { |
139 | - throw new Forbidden('No permission to update permissions for tag ' . $this->tag->getId()); |
|
139 | + throw new Forbidden('No permission to update permissions for tag '.$this->tag->getId()); |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | |
143 | 143 | $this->tagManager->updateTag($this->tag->getId(), $name, $userVisible, $userAssignable); |
144 | 144 | } catch (TagNotFoundException $e) { |
145 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' does not exist'); |
|
145 | + throw new NotFound('Tag with id '.$this->tag->getId().' does not exist'); |
|
146 | 146 | } catch (TagAlreadyExistsException $e) { |
147 | 147 | throw new Conflict( |
148 | - 'Tag with the properties "' . $name . '", ' . |
|
149 | - $userVisible . ', ' . $userAssignable . ' already exists' |
|
148 | + 'Tag with the properties "'.$name.'", '. |
|
149 | + $userVisible.', '.$userAssignable.' already exists' |
|
150 | 150 | ); |
151 | 151 | } |
152 | 152 | } |
@@ -166,17 +166,17 @@ discard block |
||
166 | 166 | public function delete() { |
167 | 167 | try { |
168 | 168 | if (!$this->isAdmin) { |
169 | - throw new Forbidden('No permission to delete tag ' . $this->tag->getId()); |
|
169 | + throw new Forbidden('No permission to delete tag '.$this->tag->getId()); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | if (!$this->tagManager->canUserSeeTag($this->tag, $this->user)) { |
173 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found'); |
|
173 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found'); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | $this->tagManager->deleteTags($this->tag->getId()); |
177 | 177 | } catch (TagNotFoundException $e) { |
178 | 178 | // can happen if concurrent deletion occurred |
179 | - throw new NotFound('Tag with id ' . $this->tag->getId() . ' not found', 0, $e); |
|
179 | + throw new NotFound('Tag with id '.$this->tag->getId().' not found', 0, $e); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | } |