@@ -29,19 +29,19 @@ |
||
29 | 29 | use Exception; |
30 | 30 | |
31 | 31 | class FileLocked extends \Sabre\DAV\Exception { |
32 | - public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
33 | - if ($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
34 | - $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
35 | - } |
|
36 | - parent::__construct($message, $code, $previous); |
|
37 | - } |
|
32 | + public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
33 | + if ($previous instanceof \OCP\Files\LockNotAcquiredException) { |
|
34 | + $message = sprintf('Target file %s is locked by another process.', $previous->path); |
|
35 | + } |
|
36 | + parent::__construct($message, $code, $previous); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Returns the HTTP status code for this exception |
|
41 | - * |
|
42 | - * @return int |
|
43 | - */ |
|
44 | - public function getHTTPCode() { |
|
45 | - return 423; |
|
46 | - } |
|
39 | + /** |
|
40 | + * Returns the HTTP status code for this exception |
|
41 | + * |
|
42 | + * @return int |
|
43 | + */ |
|
44 | + public function getHTTPCode() { |
|
45 | + return 423; |
|
46 | + } |
|
47 | 47 | } |
@@ -31,12 +31,12 @@ |
||
31 | 31 | */ |
32 | 32 | class UnsupportedMediaType extends \Sabre\DAV\Exception { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the HTTP status code for this exception |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function getHTTPCode() { |
|
40 | - return 415; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Returns the HTTP status code for this exception |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function getHTTPCode() { |
|
40 | + return 415; |
|
41 | + } |
|
42 | 42 | } |
@@ -31,12 +31,12 @@ |
||
31 | 31 | */ |
32 | 32 | class EntityTooLarge extends \Sabre\DAV\Exception { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns the HTTP status code for this exception |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function getHTTPCode() { |
|
40 | - return 413; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Returns the HTTP status code for this exception |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function getHTTPCode() { |
|
40 | + return 413; |
|
41 | + } |
|
42 | 42 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | return null; |
89 | 89 | } |
90 | 90 | foreach ($tree as $elem) { |
91 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
91 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
92 | 92 | $tags[] = $elem['value']; |
93 | 93 | } |
94 | 94 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function xmlSerialize(Writer $writer) { |
118 | 118 | foreach ($this->tags as $tag) { |
119 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
119 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
@@ -33,89 +33,89 @@ |
||
33 | 33 | * This property contains multiple "tag" elements, each containing a tag name. |
34 | 34 | */ |
35 | 35 | class TagList implements Element { |
36 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * tags |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - private $tags; |
|
38 | + /** |
|
39 | + * tags |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + private $tags; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param array $tags |
|
47 | - */ |
|
48 | - public function __construct(array $tags) { |
|
49 | - $this->tags = $tags; |
|
50 | - } |
|
45 | + /** |
|
46 | + * @param array $tags |
|
47 | + */ |
|
48 | + public function __construct(array $tags) { |
|
49 | + $this->tags = $tags; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Returns the tags |
|
54 | - * |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function getTags() { |
|
58 | - return $this->tags; |
|
59 | - } |
|
52 | + /** |
|
53 | + * Returns the tags |
|
54 | + * |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function getTags() { |
|
58 | + return $this->tags; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * The deserialize method is called during xml parsing. |
|
63 | - * |
|
64 | - * This method is called statictly, this is because in theory this method |
|
65 | - * may be used as a type of constructor, or factory method. |
|
66 | - * |
|
67 | - * Often you want to return an instance of the current class, but you are |
|
68 | - * free to return other data as well. |
|
69 | - * |
|
70 | - * You are responsible for advancing the reader to the next element. Not |
|
71 | - * doing anything will result in a never-ending loop. |
|
72 | - * |
|
73 | - * If you just want to skip parsing for this element altogether, you can |
|
74 | - * just call $reader->next(); |
|
75 | - * |
|
76 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
77 | - * the next element. |
|
78 | - * |
|
79 | - * @param Reader $reader |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public static function xmlDeserialize(Reader $reader) { |
|
83 | - $tags = []; |
|
61 | + /** |
|
62 | + * The deserialize method is called during xml parsing. |
|
63 | + * |
|
64 | + * This method is called statictly, this is because in theory this method |
|
65 | + * may be used as a type of constructor, or factory method. |
|
66 | + * |
|
67 | + * Often you want to return an instance of the current class, but you are |
|
68 | + * free to return other data as well. |
|
69 | + * |
|
70 | + * You are responsible for advancing the reader to the next element. Not |
|
71 | + * doing anything will result in a never-ending loop. |
|
72 | + * |
|
73 | + * If you just want to skip parsing for this element altogether, you can |
|
74 | + * just call $reader->next(); |
|
75 | + * |
|
76 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
77 | + * the next element. |
|
78 | + * |
|
79 | + * @param Reader $reader |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public static function xmlDeserialize(Reader $reader) { |
|
83 | + $tags = []; |
|
84 | 84 | |
85 | - $tree = $reader->parseInnerTree(); |
|
86 | - if ($tree === null) { |
|
87 | - return null; |
|
88 | - } |
|
89 | - foreach ($tree as $elem) { |
|
90 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
91 | - $tags[] = $elem['value']; |
|
92 | - } |
|
93 | - } |
|
94 | - return new self($tags); |
|
95 | - } |
|
85 | + $tree = $reader->parseInnerTree(); |
|
86 | + if ($tree === null) { |
|
87 | + return null; |
|
88 | + } |
|
89 | + foreach ($tree as $elem) { |
|
90 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
91 | + $tags[] = $elem['value']; |
|
92 | + } |
|
93 | + } |
|
94 | + return new self($tags); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * The xmlSerialize method is called during xml writing. |
|
99 | - * |
|
100 | - * Use the $writer argument to write its own xml serialization. |
|
101 | - * |
|
102 | - * An important note: do _not_ create a parent element. Any element |
|
103 | - * implementing XmlSerializble should only ever write what's considered |
|
104 | - * its 'inner xml'. |
|
105 | - * |
|
106 | - * The parent of the current element is responsible for writing a |
|
107 | - * containing element. |
|
108 | - * |
|
109 | - * This allows serializers to be re-used for different element names. |
|
110 | - * |
|
111 | - * If you are opening new elements, you must also close them again. |
|
112 | - * |
|
113 | - * @param Writer $writer |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function xmlSerialize(Writer $writer) { |
|
117 | - foreach ($this->tags as $tag) { |
|
118 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
119 | - } |
|
120 | - } |
|
97 | + /** |
|
98 | + * The xmlSerialize method is called during xml writing. |
|
99 | + * |
|
100 | + * Use the $writer argument to write its own xml serialization. |
|
101 | + * |
|
102 | + * An important note: do _not_ create a parent element. Any element |
|
103 | + * implementing XmlSerializble should only ever write what's considered |
|
104 | + * its 'inner xml'. |
|
105 | + * |
|
106 | + * The parent of the current element is responsible for writing a |
|
107 | + * containing element. |
|
108 | + * |
|
109 | + * This allows serializers to be re-used for different element names. |
|
110 | + * |
|
111 | + * If you are opening new elements, you must also close them again. |
|
112 | + * |
|
113 | + * @param Writer $writer |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function xmlSerialize(Writer $writer) { |
|
117 | + foreach ($this->tags as $tag) { |
|
118 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
119 | + } |
|
120 | + } |
|
121 | 121 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | */ |
65 | 65 | public function xmlSerialize(Writer $writer) { |
66 | 66 | foreach ($this->checksums as $checksum) { |
67 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
67 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}checksum', $checksum); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | } |
@@ -32,37 +32,37 @@ |
||
32 | 32 | * checksum name. |
33 | 33 | */ |
34 | 34 | class ChecksumList implements XmlSerializable { |
35 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** @var string[] of TYPE:CHECKSUM */ |
|
38 | - private array $checksums; |
|
37 | + /** @var string[] of TYPE:CHECKSUM */ |
|
38 | + private array $checksums; |
|
39 | 39 | |
40 | - public function __construct(string $checksum) { |
|
41 | - $this->checksums = explode(',', $checksum); |
|
42 | - } |
|
40 | + public function __construct(string $checksum) { |
|
41 | + $this->checksums = explode(',', $checksum); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * The xmlSerialize method is called during xml writing. |
|
46 | - * |
|
47 | - * Use the $writer argument to write its own xml serialization. |
|
48 | - * |
|
49 | - * An important note: do _not_ create a parent element. Any element |
|
50 | - * implementing XmlSerializble should only ever write what's considered |
|
51 | - * its 'inner xml'. |
|
52 | - * |
|
53 | - * The parent of the current element is responsible for writing a |
|
54 | - * containing element. |
|
55 | - * |
|
56 | - * This allows serializers to be re-used for different element names. |
|
57 | - * |
|
58 | - * If you are opening new elements, you must also close them again. |
|
59 | - * |
|
60 | - * @param Writer $writer |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function xmlSerialize(Writer $writer) { |
|
64 | - foreach ($this->checksums as $checksum) { |
|
65 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
66 | - } |
|
67 | - } |
|
44 | + /** |
|
45 | + * The xmlSerialize method is called during xml writing. |
|
46 | + * |
|
47 | + * Use the $writer argument to write its own xml serialization. |
|
48 | + * |
|
49 | + * An important note: do _not_ create a parent element. Any element |
|
50 | + * implementing XmlSerializble should only ever write what's considered |
|
51 | + * its 'inner xml'. |
|
52 | + * |
|
53 | + * The parent of the current element is responsible for writing a |
|
54 | + * containing element. |
|
55 | + * |
|
56 | + * This allows serializers to be re-used for different element names. |
|
57 | + * |
|
58 | + * If you are opening new elements, you must also close them again. |
|
59 | + * |
|
60 | + * @param Writer $writer |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function xmlSerialize(Writer $writer) { |
|
64 | + foreach ($this->checksums as $checksum) { |
|
65 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | return null; |
72 | 72 | } |
73 | 73 | foreach ($tree as $elem) { |
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
74 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') { |
|
75 | + $shareTypes[] = (int) $elem['value']; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | return new self($shareTypes); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function xmlSerialize(Writer $writer) { |
88 | 88 | foreach ($this->shareTypes as $shareType) { |
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
89 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -32,61 +32,61 @@ |
||
32 | 32 | * This property contains multiple "share-type" elements, each containing a share type. |
33 | 33 | */ |
34 | 34 | class ShareTypeList implements Element { |
35 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Share types |
|
39 | - * |
|
40 | - * @var int[] |
|
41 | - */ |
|
42 | - private $shareTypes; |
|
37 | + /** |
|
38 | + * Share types |
|
39 | + * |
|
40 | + * @var int[] |
|
41 | + */ |
|
42 | + private $shareTypes; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int[] $shareTypes |
|
46 | - */ |
|
47 | - public function __construct($shareTypes) { |
|
48 | - $this->shareTypes = $shareTypes; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param int[] $shareTypes |
|
46 | + */ |
|
47 | + public function __construct($shareTypes) { |
|
48 | + $this->shareTypes = $shareTypes; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the share types |
|
53 | - * |
|
54 | - * @return int[] |
|
55 | - */ |
|
56 | - public function getShareTypes() { |
|
57 | - return $this->shareTypes; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Returns the share types |
|
53 | + * |
|
54 | + * @return int[] |
|
55 | + */ |
|
56 | + public function getShareTypes() { |
|
57 | + return $this->shareTypes; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * The deserialize method is called during xml parsing. |
|
62 | - * |
|
63 | - * @param Reader $reader |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - public static function xmlDeserialize(Reader $reader) { |
|
67 | - $shareTypes = []; |
|
60 | + /** |
|
61 | + * The deserialize method is called during xml parsing. |
|
62 | + * |
|
63 | + * @param Reader $reader |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + public static function xmlDeserialize(Reader $reader) { |
|
67 | + $shareTypes = []; |
|
68 | 68 | |
69 | - $tree = $reader->parseInnerTree(); |
|
70 | - if ($tree === null) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - foreach ($tree as $elem) { |
|
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
76 | - } |
|
77 | - } |
|
78 | - return new self($shareTypes); |
|
79 | - } |
|
69 | + $tree = $reader->parseInnerTree(); |
|
70 | + if ($tree === null) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + foreach ($tree as $elem) { |
|
74 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | + $shareTypes[] = (int)$elem['value']; |
|
76 | + } |
|
77 | + } |
|
78 | + return new self($shareTypes); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * The xmlSerialize method is called during xml writing. |
|
83 | - * |
|
84 | - * @param Writer $writer |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function xmlSerialize(Writer $writer) { |
|
88 | - foreach ($this->shareTypes as $shareType) { |
|
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | - } |
|
91 | - } |
|
81 | + /** |
|
82 | + * The xmlSerialize method is called during xml writing. |
|
83 | + * |
|
84 | + * @param Writer $writer |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function xmlSerialize(Writer $writer) { |
|
88 | + foreach ($this->shareTypes as $shareType) { |
|
89 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | } |
@@ -23,11 +23,11 @@ |
||
23 | 23 | |
24 | 24 | class PublicCalendarObject extends CalendarObject { |
25 | 25 | |
26 | - /** |
|
27 | - * public calendars are always shared |
|
28 | - * @return bool |
|
29 | - */ |
|
30 | - protected function isShared() { |
|
31 | - return true; |
|
32 | - } |
|
26 | + /** |
|
27 | + * public calendars are always shared |
|
28 | + * @return bool |
|
29 | + */ |
|
30 | + protected function isShared() { |
|
31 | + return true; |
|
32 | + } |
|
33 | 33 | } |
@@ -27,17 +27,17 @@ |
||
27 | 27 | |
28 | 28 | class SearchTermFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public static function xmlDeserialize(Reader $reader) { |
|
36 | - $value = $reader->parseInnerTree(); |
|
37 | - if (!is_string($value)) { |
|
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
39 | - } |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public static function xmlDeserialize(Reader $reader) { |
|
36 | + $value = $reader->parseInnerTree(); |
|
37 | + if (!is_string($value)) { |
|
38 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
39 | + } |
|
40 | 40 | |
41 | - return $value; |
|
42 | - } |
|
41 | + return $value; |
|
42 | + } |
|
43 | 43 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | public static function xmlDeserialize(Reader $reader) { |
36 | 36 | $value = $reader->parseInnerTree(); |
37 | 37 | if (!is_string($value)) { |
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
38 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}search-term has illegal value'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return $value; |
@@ -35,144 +35,144 @@ |
||
35 | 35 | |
36 | 36 | class SystemTagsByIdCollection implements ICollection { |
37 | 37 | |
38 | - /** |
|
39 | - * @var ISystemTagManager |
|
40 | - */ |
|
41 | - private $tagManager; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var IGroupManager |
|
45 | - */ |
|
46 | - private $groupManager; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var IUserSession |
|
50 | - */ |
|
51 | - private $userSession; |
|
52 | - |
|
53 | - /** |
|
54 | - * SystemTagsByIdCollection constructor. |
|
55 | - * |
|
56 | - * @param ISystemTagManager $tagManager |
|
57 | - * @param IUserSession $userSession |
|
58 | - * @param IGroupManager $groupManager |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - ISystemTagManager $tagManager, |
|
62 | - IUserSession $userSession, |
|
63 | - IGroupManager $groupManager |
|
64 | - ) { |
|
65 | - $this->tagManager = $tagManager; |
|
66 | - $this->userSession = $userSession; |
|
67 | - $this->groupManager = $groupManager; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns whether the currently logged in user is an administrator |
|
72 | - * |
|
73 | - * @return bool true if the user is an admin |
|
74 | - */ |
|
75 | - private function isAdmin() { |
|
76 | - $user = $this->userSession->getUser(); |
|
77 | - if ($user !== null) { |
|
78 | - return $this->groupManager->isAdmin($user->getUID()); |
|
79 | - } |
|
80 | - return false; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $name |
|
85 | - * @param resource|string $data Initial payload |
|
86 | - * @throws Forbidden |
|
87 | - */ |
|
88 | - public function createFile($name, $data = null) { |
|
89 | - throw new Forbidden('Cannot create tags by id'); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param string $name |
|
94 | - */ |
|
95 | - public function createDirectory($name) { |
|
96 | - throw new Forbidden('Permission denied to create collections'); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $name |
|
101 | - */ |
|
102 | - public function getChild($name) { |
|
103 | - try { |
|
104 | - $tag = $this->tagManager->getTagsByIds([$name]); |
|
105 | - $tag = current($tag); |
|
106 | - if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
107 | - throw new NotFound('Tag with id ' . $name . ' not found'); |
|
108 | - } |
|
109 | - return $this->makeNode($tag); |
|
110 | - } catch (\InvalidArgumentException $e) { |
|
111 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
112 | - } catch (TagNotFoundException $e) { |
|
113 | - throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - public function getChildren() { |
|
118 | - $visibilityFilter = true; |
|
119 | - if ($this->isAdmin()) { |
|
120 | - $visibilityFilter = null; |
|
121 | - } |
|
122 | - |
|
123 | - $tags = $this->tagManager->getAllTags($visibilityFilter); |
|
124 | - return array_map(function ($tag) { |
|
125 | - return $this->makeNode($tag); |
|
126 | - }, $tags); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @param string $name |
|
131 | - */ |
|
132 | - public function childExists($name) { |
|
133 | - try { |
|
134 | - $tag = $this->tagManager->getTagsByIds([$name]); |
|
135 | - $tag = current($tag); |
|
136 | - if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
137 | - return false; |
|
138 | - } |
|
139 | - return true; |
|
140 | - } catch (\InvalidArgumentException $e) { |
|
141 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
142 | - } catch (TagNotFoundException $e) { |
|
143 | - return false; |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - public function delete() { |
|
148 | - throw new Forbidden('Permission denied to delete this collection'); |
|
149 | - } |
|
150 | - |
|
151 | - public function getName() { |
|
152 | - return 'systemtags'; |
|
153 | - } |
|
154 | - |
|
155 | - public function setName($name) { |
|
156 | - throw new Forbidden('Permission denied to rename this collection'); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Returns the last modification time, as a unix timestamp |
|
161 | - * |
|
162 | - * @return int |
|
163 | - */ |
|
164 | - public function getLastModified() { |
|
165 | - return null; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Create a sabre node for the given system tag |
|
170 | - * |
|
171 | - * @param ISystemTag $tag |
|
172 | - * |
|
173 | - * @return SystemTagNode |
|
174 | - */ |
|
175 | - private function makeNode(ISystemTag $tag) { |
|
176 | - return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager); |
|
177 | - } |
|
38 | + /** |
|
39 | + * @var ISystemTagManager |
|
40 | + */ |
|
41 | + private $tagManager; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var IGroupManager |
|
45 | + */ |
|
46 | + private $groupManager; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var IUserSession |
|
50 | + */ |
|
51 | + private $userSession; |
|
52 | + |
|
53 | + /** |
|
54 | + * SystemTagsByIdCollection constructor. |
|
55 | + * |
|
56 | + * @param ISystemTagManager $tagManager |
|
57 | + * @param IUserSession $userSession |
|
58 | + * @param IGroupManager $groupManager |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + ISystemTagManager $tagManager, |
|
62 | + IUserSession $userSession, |
|
63 | + IGroupManager $groupManager |
|
64 | + ) { |
|
65 | + $this->tagManager = $tagManager; |
|
66 | + $this->userSession = $userSession; |
|
67 | + $this->groupManager = $groupManager; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns whether the currently logged in user is an administrator |
|
72 | + * |
|
73 | + * @return bool true if the user is an admin |
|
74 | + */ |
|
75 | + private function isAdmin() { |
|
76 | + $user = $this->userSession->getUser(); |
|
77 | + if ($user !== null) { |
|
78 | + return $this->groupManager->isAdmin($user->getUID()); |
|
79 | + } |
|
80 | + return false; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $name |
|
85 | + * @param resource|string $data Initial payload |
|
86 | + * @throws Forbidden |
|
87 | + */ |
|
88 | + public function createFile($name, $data = null) { |
|
89 | + throw new Forbidden('Cannot create tags by id'); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param string $name |
|
94 | + */ |
|
95 | + public function createDirectory($name) { |
|
96 | + throw new Forbidden('Permission denied to create collections'); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $name |
|
101 | + */ |
|
102 | + public function getChild($name) { |
|
103 | + try { |
|
104 | + $tag = $this->tagManager->getTagsByIds([$name]); |
|
105 | + $tag = current($tag); |
|
106 | + if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
107 | + throw new NotFound('Tag with id ' . $name . ' not found'); |
|
108 | + } |
|
109 | + return $this->makeNode($tag); |
|
110 | + } catch (\InvalidArgumentException $e) { |
|
111 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
112 | + } catch (TagNotFoundException $e) { |
|
113 | + throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + public function getChildren() { |
|
118 | + $visibilityFilter = true; |
|
119 | + if ($this->isAdmin()) { |
|
120 | + $visibilityFilter = null; |
|
121 | + } |
|
122 | + |
|
123 | + $tags = $this->tagManager->getAllTags($visibilityFilter); |
|
124 | + return array_map(function ($tag) { |
|
125 | + return $this->makeNode($tag); |
|
126 | + }, $tags); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @param string $name |
|
131 | + */ |
|
132 | + public function childExists($name) { |
|
133 | + try { |
|
134 | + $tag = $this->tagManager->getTagsByIds([$name]); |
|
135 | + $tag = current($tag); |
|
136 | + if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
|
137 | + return false; |
|
138 | + } |
|
139 | + return true; |
|
140 | + } catch (\InvalidArgumentException $e) { |
|
141 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
142 | + } catch (TagNotFoundException $e) { |
|
143 | + return false; |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + public function delete() { |
|
148 | + throw new Forbidden('Permission denied to delete this collection'); |
|
149 | + } |
|
150 | + |
|
151 | + public function getName() { |
|
152 | + return 'systemtags'; |
|
153 | + } |
|
154 | + |
|
155 | + public function setName($name) { |
|
156 | + throw new Forbidden('Permission denied to rename this collection'); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Returns the last modification time, as a unix timestamp |
|
161 | + * |
|
162 | + * @return int |
|
163 | + */ |
|
164 | + public function getLastModified() { |
|
165 | + return null; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Create a sabre node for the given system tag |
|
170 | + * |
|
171 | + * @param ISystemTag $tag |
|
172 | + * |
|
173 | + * @return SystemTagNode |
|
174 | + */ |
|
175 | + private function makeNode(ISystemTag $tag) { |
|
176 | + return new SystemTagNode($tag, $this->userSession->getUser(), $this->isAdmin(), $this->tagManager); |
|
177 | + } |
|
178 | 178 | } |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | $tag = $this->tagManager->getTagsByIds([$name]); |
105 | 105 | $tag = current($tag); |
106 | 106 | if (!$this->tagManager->canUserSeeTag($tag, $this->userSession->getUser())) { |
107 | - throw new NotFound('Tag with id ' . $name . ' not found'); |
|
107 | + throw new NotFound('Tag with id '.$name.' not found'); |
|
108 | 108 | } |
109 | 109 | return $this->makeNode($tag); |
110 | 110 | } catch (\InvalidArgumentException $e) { |
111 | 111 | throw new BadRequest('Invalid tag id', 0, $e); |
112 | 112 | } catch (TagNotFoundException $e) { |
113 | - throw new NotFound('Tag with id ' . $name . ' not found', 0, $e); |
|
113 | + throw new NotFound('Tag with id '.$name.' not found', 0, $e); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | $tags = $this->tagManager->getAllTags($visibilityFilter); |
124 | - return array_map(function ($tag) { |
|
124 | + return array_map(function($tag) { |
|
125 | 125 | return $this->makeNode($tag); |
126 | 126 | }, $tags); |
127 | 127 | } |