@@ -49,132 +49,132 @@ |
||
49 | 49 | use Sabre\DAV\SimpleCollection; |
50 | 50 | |
51 | 51 | class RootCollection extends SimpleCollection { |
52 | - public function __construct() { |
|
53 | - $config = \OC::$server->getConfig(); |
|
54 | - $l10n = \OC::$server->getL10N('dav'); |
|
55 | - $random = \OC::$server->getSecureRandom(); |
|
56 | - $logger = \OC::$server->getLogger(); |
|
57 | - $userManager = \OC::$server->getUserManager(); |
|
58 | - $userSession = \OC::$server->getUserSession(); |
|
59 | - $groupManager = \OC::$server->getGroupManager(); |
|
60 | - $shareManager = \OC::$server->getShareManager(); |
|
61 | - $db = \OC::$server->getDatabaseConnection(); |
|
62 | - $dispatcher = \OC::$server->get(IEventDispatcher::class); |
|
63 | - $legacyDispatcher = \OC::$server->getEventDispatcher(); |
|
64 | - $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
65 | - |
|
66 | - $userPrincipalBackend = new Principal( |
|
67 | - $userManager, |
|
68 | - $groupManager, |
|
69 | - $shareManager, |
|
70 | - \OC::$server->getUserSession(), |
|
71 | - \OC::$server->getAppManager(), |
|
72 | - $proxyMapper, |
|
73 | - \OC::$server->getConfig() |
|
74 | - ); |
|
75 | - $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config); |
|
76 | - $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
77 | - $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
78 | - // as soon as debug mode is enabled we allow listing of principals |
|
79 | - $disableListing = !$config->getSystemValue('debug', false); |
|
80 | - |
|
81 | - // setup the first level of the dav tree |
|
82 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
83 | - $userPrincipals->disableListing = $disableListing; |
|
84 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
85 | - $groupPrincipals->disableListing = $disableListing; |
|
86 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
87 | - $systemPrincipals->disableListing = $disableListing; |
|
88 | - $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
89 | - $calendarResourcePrincipals->disableListing = $disableListing; |
|
90 | - $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
91 | - $calendarRoomPrincipals->disableListing = $disableListing; |
|
92 | - |
|
93 | - |
|
94 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
95 | - $filesCollection->disableListing = $disableListing; |
|
96 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); |
|
97 | - $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
98 | - $userCalendarRoot->disableListing = $disableListing; |
|
99 | - |
|
100 | - $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); |
|
101 | - $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
102 | - $resourceCalendarRoot->disableListing = $disableListing; |
|
103 | - $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); |
|
104 | - $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
105 | - $roomCalendarRoot->disableListing = $disableListing; |
|
106 | - |
|
107 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
108 | - $publicCalendarRoot->disableListing = $disableListing; |
|
109 | - |
|
110 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
111 | - \OC::$server->getSystemTagManager(), |
|
112 | - \OC::$server->getUserSession(), |
|
113 | - $groupManager |
|
114 | - ); |
|
115 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
116 | - \OC::$server->getSystemTagManager(), |
|
117 | - \OC::$server->getSystemTagObjectMapper(), |
|
118 | - \OC::$server->getUserSession(), |
|
119 | - $groupManager, |
|
120 | - \OC::$server->getEventDispatcher() |
|
121 | - ); |
|
122 | - $commentsCollection = new Comments\RootCollection( |
|
123 | - \OC::$server->getCommentsManager(), |
|
124 | - $userManager, |
|
125 | - \OC::$server->getUserSession(), |
|
126 | - \OC::$server->getEventDispatcher(), |
|
127 | - \OC::$server->getLogger() |
|
128 | - ); |
|
129 | - |
|
130 | - $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); |
|
131 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher); |
|
132 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users'); |
|
133 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
134 | - |
|
135 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher); |
|
136 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system'); |
|
137 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
138 | - |
|
139 | - $uploadCollection = new Upload\RootCollection( |
|
140 | - $userPrincipalBackend, |
|
141 | - 'principals/users', |
|
142 | - \OC::$server->query(CleanupService::class)); |
|
143 | - $uploadCollection->disableListing = $disableListing; |
|
144 | - |
|
145 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
146 | - $avatarCollection->disableListing = $disableListing; |
|
147 | - |
|
148 | - $appleProvisioning = new AppleProvisioningNode( |
|
149 | - \OC::$server->query(ITimeFactory::class)); |
|
150 | - |
|
151 | - $children = [ |
|
152 | - new SimpleCollection('principals', [ |
|
153 | - $userPrincipals, |
|
154 | - $groupPrincipals, |
|
155 | - $systemPrincipals, |
|
156 | - $calendarResourcePrincipals, |
|
157 | - $calendarRoomPrincipals]), |
|
158 | - $filesCollection, |
|
159 | - $userCalendarRoot, |
|
160 | - new SimpleCollection('system-calendars', [ |
|
161 | - $resourceCalendarRoot, |
|
162 | - $roomCalendarRoot, |
|
163 | - ]), |
|
164 | - $publicCalendarRoot, |
|
165 | - new SimpleCollection('addressbooks', [ |
|
166 | - $usersAddressBookRoot, |
|
167 | - $systemAddressBookRoot]), |
|
168 | - $systemTagCollection, |
|
169 | - $systemTagRelationsCollection, |
|
170 | - $commentsCollection, |
|
171 | - $uploadCollection, |
|
172 | - $avatarCollection, |
|
173 | - new SimpleCollection('provisioning', [ |
|
174 | - $appleProvisioning |
|
175 | - ]) |
|
176 | - ]; |
|
177 | - |
|
178 | - parent::__construct('root', $children); |
|
179 | - } |
|
52 | + public function __construct() { |
|
53 | + $config = \OC::$server->getConfig(); |
|
54 | + $l10n = \OC::$server->getL10N('dav'); |
|
55 | + $random = \OC::$server->getSecureRandom(); |
|
56 | + $logger = \OC::$server->getLogger(); |
|
57 | + $userManager = \OC::$server->getUserManager(); |
|
58 | + $userSession = \OC::$server->getUserSession(); |
|
59 | + $groupManager = \OC::$server->getGroupManager(); |
|
60 | + $shareManager = \OC::$server->getShareManager(); |
|
61 | + $db = \OC::$server->getDatabaseConnection(); |
|
62 | + $dispatcher = \OC::$server->get(IEventDispatcher::class); |
|
63 | + $legacyDispatcher = \OC::$server->getEventDispatcher(); |
|
64 | + $proxyMapper = \OC::$server->query(ProxyMapper::class); |
|
65 | + |
|
66 | + $userPrincipalBackend = new Principal( |
|
67 | + $userManager, |
|
68 | + $groupManager, |
|
69 | + $shareManager, |
|
70 | + \OC::$server->getUserSession(), |
|
71 | + \OC::$server->getAppManager(), |
|
72 | + $proxyMapper, |
|
73 | + \OC::$server->getConfig() |
|
74 | + ); |
|
75 | + $groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config); |
|
76 | + $calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
77 | + $calendarRoomPrincipalBackend = new RoomPrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper); |
|
78 | + // as soon as debug mode is enabled we allow listing of principals |
|
79 | + $disableListing = !$config->getSystemValue('debug', false); |
|
80 | + |
|
81 | + // setup the first level of the dav tree |
|
82 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
83 | + $userPrincipals->disableListing = $disableListing; |
|
84 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
85 | + $groupPrincipals->disableListing = $disableListing; |
|
86 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
87 | + $systemPrincipals->disableListing = $disableListing; |
|
88 | + $calendarResourcePrincipals = new Collection($calendarResourcePrincipalBackend, 'principals/calendar-resources'); |
|
89 | + $calendarResourcePrincipals->disableListing = $disableListing; |
|
90 | + $calendarRoomPrincipals = new Collection($calendarRoomPrincipalBackend, 'principals/calendar-rooms'); |
|
91 | + $calendarRoomPrincipals->disableListing = $disableListing; |
|
92 | + |
|
93 | + |
|
94 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
95 | + $filesCollection->disableListing = $disableListing; |
|
96 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); |
|
97 | + $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
98 | + $userCalendarRoot->disableListing = $disableListing; |
|
99 | + |
|
100 | + $resourceCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); |
|
101 | + $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources'); |
|
102 | + $resourceCalendarRoot->disableListing = $disableListing; |
|
103 | + $roomCalendarCaldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $random, $logger, $dispatcher, $legacyDispatcher); |
|
104 | + $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $roomCalendarCaldavBackend, 'principals/calendar-rooms'); |
|
105 | + $roomCalendarRoot->disableListing = $disableListing; |
|
106 | + |
|
107 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config); |
|
108 | + $publicCalendarRoot->disableListing = $disableListing; |
|
109 | + |
|
110 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
111 | + \OC::$server->getSystemTagManager(), |
|
112 | + \OC::$server->getUserSession(), |
|
113 | + $groupManager |
|
114 | + ); |
|
115 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
116 | + \OC::$server->getSystemTagManager(), |
|
117 | + \OC::$server->getSystemTagObjectMapper(), |
|
118 | + \OC::$server->getUserSession(), |
|
119 | + $groupManager, |
|
120 | + \OC::$server->getEventDispatcher() |
|
121 | + ); |
|
122 | + $commentsCollection = new Comments\RootCollection( |
|
123 | + \OC::$server->getCommentsManager(), |
|
124 | + $userManager, |
|
125 | + \OC::$server->getUserSession(), |
|
126 | + \OC::$server->getEventDispatcher(), |
|
127 | + \OC::$server->getLogger() |
|
128 | + ); |
|
129 | + |
|
130 | + $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); |
|
131 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher); |
|
132 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, $pluginManager, 'principals/users'); |
|
133 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
134 | + |
|
135 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $userManager, $groupManager, $dispatcher, $legacyDispatcher); |
|
136 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, $pluginManager, 'principals/system'); |
|
137 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
138 | + |
|
139 | + $uploadCollection = new Upload\RootCollection( |
|
140 | + $userPrincipalBackend, |
|
141 | + 'principals/users', |
|
142 | + \OC::$server->query(CleanupService::class)); |
|
143 | + $uploadCollection->disableListing = $disableListing; |
|
144 | + |
|
145 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
146 | + $avatarCollection->disableListing = $disableListing; |
|
147 | + |
|
148 | + $appleProvisioning = new AppleProvisioningNode( |
|
149 | + \OC::$server->query(ITimeFactory::class)); |
|
150 | + |
|
151 | + $children = [ |
|
152 | + new SimpleCollection('principals', [ |
|
153 | + $userPrincipals, |
|
154 | + $groupPrincipals, |
|
155 | + $systemPrincipals, |
|
156 | + $calendarResourcePrincipals, |
|
157 | + $calendarRoomPrincipals]), |
|
158 | + $filesCollection, |
|
159 | + $userCalendarRoot, |
|
160 | + new SimpleCollection('system-calendars', [ |
|
161 | + $resourceCalendarRoot, |
|
162 | + $roomCalendarRoot, |
|
163 | + ]), |
|
164 | + $publicCalendarRoot, |
|
165 | + new SimpleCollection('addressbooks', [ |
|
166 | + $usersAddressBookRoot, |
|
167 | + $systemAddressBookRoot]), |
|
168 | + $systemTagCollection, |
|
169 | + $systemTagRelationsCollection, |
|
170 | + $commentsCollection, |
|
171 | + $uploadCollection, |
|
172 | + $avatarCollection, |
|
173 | + new SimpleCollection('provisioning', [ |
|
174 | + $appleProvisioning |
|
175 | + ]) |
|
176 | + ]; |
|
177 | + |
|
178 | + parent::__construct('root', $children); |
|
179 | + } |
|
180 | 180 | } |
@@ -52,485 +52,485 @@ |
||
52 | 52 | |
53 | 53 | class Principal implements BackendInterface { |
54 | 54 | |
55 | - /** @var IUserManager */ |
|
56 | - private $userManager; |
|
57 | - |
|
58 | - /** @var IGroupManager */ |
|
59 | - private $groupManager; |
|
60 | - |
|
61 | - /** @var IShareManager */ |
|
62 | - private $shareManager; |
|
63 | - |
|
64 | - /** @var IUserSession */ |
|
65 | - private $userSession; |
|
66 | - |
|
67 | - /** @var IAppManager */ |
|
68 | - private $appManager; |
|
69 | - |
|
70 | - /** @var string */ |
|
71 | - private $principalPrefix; |
|
72 | - |
|
73 | - /** @var bool */ |
|
74 | - private $hasGroups; |
|
75 | - |
|
76 | - /** @var bool */ |
|
77 | - private $hasCircles; |
|
78 | - |
|
79 | - /** @var ProxyMapper */ |
|
80 | - private $proxyMapper; |
|
81 | - |
|
82 | - /** @var IConfig */ |
|
83 | - private $config; |
|
84 | - |
|
85 | - /** |
|
86 | - * Principal constructor. |
|
87 | - * |
|
88 | - * @param IUserManager $userManager |
|
89 | - * @param IGroupManager $groupManager |
|
90 | - * @param IShareManager $shareManager |
|
91 | - * @param IUserSession $userSession |
|
92 | - * @param IAppManager $appManager |
|
93 | - * @param ProxyMapper $proxyMapper |
|
94 | - * @param IConfig $config |
|
95 | - * @param string $principalPrefix |
|
96 | - */ |
|
97 | - public function __construct(IUserManager $userManager, |
|
98 | - IGroupManager $groupManager, |
|
99 | - IShareManager $shareManager, |
|
100 | - IUserSession $userSession, |
|
101 | - IAppManager $appManager, |
|
102 | - ProxyMapper $proxyMapper, |
|
103 | - IConfig $config, |
|
104 | - string $principalPrefix = 'principals/users/') { |
|
105 | - $this->userManager = $userManager; |
|
106 | - $this->groupManager = $groupManager; |
|
107 | - $this->shareManager = $shareManager; |
|
108 | - $this->userSession = $userSession; |
|
109 | - $this->appManager = $appManager; |
|
110 | - $this->principalPrefix = trim($principalPrefix, '/'); |
|
111 | - $this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/'); |
|
112 | - $this->proxyMapper = $proxyMapper; |
|
113 | - $this->config = $config; |
|
114 | - } |
|
115 | - |
|
116 | - use PrincipalProxyTrait { |
|
117 | - getGroupMembership as protected traitGetGroupMembership; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Returns a list of principals based on a prefix. |
|
122 | - * |
|
123 | - * This prefix will often contain something like 'principals'. You are only |
|
124 | - * expected to return principals that are in this base path. |
|
125 | - * |
|
126 | - * You are expected to return at least a 'uri' for every user, you can |
|
127 | - * return any additional properties if you wish so. Common properties are: |
|
128 | - * {DAV:}displayname |
|
129 | - * |
|
130 | - * @param string $prefixPath |
|
131 | - * @return string[] |
|
132 | - */ |
|
133 | - public function getPrincipalsByPrefix($prefixPath) { |
|
134 | - $principals = []; |
|
135 | - |
|
136 | - if ($prefixPath === $this->principalPrefix) { |
|
137 | - foreach ($this->userManager->search('') as $user) { |
|
138 | - $principals[] = $this->userToPrincipal($user); |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - return $principals; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Returns a specific principal, specified by it's path. |
|
147 | - * The returned structure should be the exact same as from |
|
148 | - * getPrincipalsByPrefix. |
|
149 | - * |
|
150 | - * @param string $path |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function getPrincipalByPath($path) { |
|
154 | - list($prefix, $name) = \Sabre\Uri\split($path); |
|
155 | - |
|
156 | - if ($name === 'calendar-proxy-write' || $name === 'calendar-proxy-read') { |
|
157 | - list($prefix2, $name2) = \Sabre\Uri\split($prefix); |
|
158 | - |
|
159 | - if ($prefix2 === $this->principalPrefix) { |
|
160 | - $user = $this->userManager->get($name2); |
|
161 | - |
|
162 | - if ($user !== null) { |
|
163 | - return [ |
|
164 | - 'uri' => 'principals/users/' . $user->getUID() . '/' . $name, |
|
165 | - ]; |
|
166 | - } |
|
167 | - return null; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - if ($prefix === $this->principalPrefix) { |
|
172 | - // Depending on where it is called, it may happen that this function |
|
173 | - // is called either with a urlencoded version of the name or with a non-urlencoded one. |
|
174 | - // The urldecode function replaces %## and +, both of which are forbidden in usernames. |
|
175 | - // Hence there can be no ambiguity here and it is safe to call urldecode on all usernames |
|
176 | - $user = $this->userManager->get(urldecode($name)); |
|
177 | - |
|
178 | - if ($user !== null) { |
|
179 | - return $this->userToPrincipal($user); |
|
180 | - } |
|
181 | - } elseif ($prefix === 'principals/circles') { |
|
182 | - if ($this->userSession->getUser() !== null) { |
|
183 | - return $this->circleToPrincipal($name); |
|
184 | - } |
|
185 | - } |
|
186 | - return null; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Returns the list of groups a principal is a member of |
|
191 | - * |
|
192 | - * @param string $principal |
|
193 | - * @param bool $needGroups |
|
194 | - * @return array |
|
195 | - * @throws Exception |
|
196 | - */ |
|
197 | - public function getGroupMembership($principal, $needGroups = false) { |
|
198 | - list($prefix, $name) = \Sabre\Uri\split($principal); |
|
199 | - |
|
200 | - if ($prefix !== $this->principalPrefix) { |
|
201 | - return []; |
|
202 | - } |
|
203 | - |
|
204 | - $user = $this->userManager->get($name); |
|
205 | - if (!$user) { |
|
206 | - throw new Exception('Principal not found'); |
|
207 | - } |
|
208 | - |
|
209 | - $groups = []; |
|
210 | - |
|
211 | - if ($this->hasGroups || $needGroups) { |
|
212 | - $userGroups = $this->groupManager->getUserGroups($user); |
|
213 | - foreach ($userGroups as $userGroup) { |
|
214 | - $groups[] = 'principals/groups/' . urlencode($userGroup->getGID()); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - $groups = array_unique(array_merge( |
|
219 | - $groups, |
|
220 | - $this->traitGetGroupMembership($principal, $needGroups) |
|
221 | - )); |
|
222 | - |
|
223 | - return $groups; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @param string $path |
|
228 | - * @param PropPatch $propPatch |
|
229 | - * @return int |
|
230 | - */ |
|
231 | - public function updatePrincipal($path, PropPatch $propPatch) { |
|
232 | - return 0; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Search user principals |
|
237 | - * |
|
238 | - * @param array $searchProperties |
|
239 | - * @param string $test |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - protected function searchUserPrincipals(array $searchProperties, $test = 'allof') { |
|
243 | - $results = []; |
|
244 | - |
|
245 | - // If sharing is disabled, return the empty array |
|
246 | - $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
247 | - if (!$shareAPIEnabled) { |
|
248 | - return []; |
|
249 | - } |
|
250 | - |
|
251 | - $allowEnumeration = $this->shareManager->allowEnumeration(); |
|
252 | - $limitEnumeration = $this->shareManager->limitEnumerationToGroups(); |
|
253 | - |
|
254 | - // If sharing is restricted to group members only, |
|
255 | - // return only members that have groups in common |
|
256 | - $restrictGroups = false; |
|
257 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
258 | - $user = $this->userSession->getUser(); |
|
259 | - if (!$user) { |
|
260 | - return []; |
|
261 | - } |
|
262 | - |
|
263 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
264 | - } |
|
265 | - |
|
266 | - $currentUserGroups = []; |
|
267 | - if ($limitEnumeration) { |
|
268 | - $currentUser = $this->userSession->getUser(); |
|
269 | - if ($currentUser) { |
|
270 | - $currentUserGroups = $this->groupManager->getUserGroupIds($currentUser); |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - $searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
275 | - if ($searchLimit <= 0) { |
|
276 | - $searchLimit = null; |
|
277 | - } |
|
278 | - foreach ($searchProperties as $prop => $value) { |
|
279 | - switch ($prop) { |
|
280 | - case '{http://sabredav.org/ns}email-address': |
|
281 | - $users = $this->userManager->getByEmail($value); |
|
282 | - |
|
283 | - if (!$allowEnumeration) { |
|
284 | - $users = \array_filter($users, static function (IUser $user) use ($value) { |
|
285 | - return $user->getEMailAddress() === $value; |
|
286 | - }); |
|
287 | - } |
|
288 | - |
|
289 | - if ($limitEnumeration) { |
|
290 | - $users = \array_filter($users, function (IUser $user) use ($currentUserGroups, $value) { |
|
291 | - return !empty(array_intersect( |
|
292 | - $this->groupManager->getUserGroupIds($user), |
|
293 | - $currentUserGroups |
|
294 | - )) || $user->getEMailAddress() === $value; |
|
295 | - }); |
|
296 | - } |
|
297 | - |
|
298 | - $results[] = array_reduce($users, function (array $carry, IUser $user) use ($restrictGroups) { |
|
299 | - // is sharing restricted to groups only? |
|
300 | - if ($restrictGroups !== false) { |
|
301 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
302 | - if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
303 | - return $carry; |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
308 | - return $carry; |
|
309 | - }, []); |
|
310 | - break; |
|
311 | - |
|
312 | - case '{DAV:}displayname': |
|
313 | - $users = $this->userManager->searchDisplayName($value, $searchLimit); |
|
314 | - |
|
315 | - if (!$allowEnumeration) { |
|
316 | - $users = \array_filter($users, static function (IUser $user) use ($value) { |
|
317 | - return $user->getDisplayName() === $value; |
|
318 | - }); |
|
319 | - } |
|
320 | - |
|
321 | - if ($limitEnumeration) { |
|
322 | - $users = \array_filter($users, function (IUser $user) use ($currentUserGroups, $value) { |
|
323 | - return !empty(array_intersect( |
|
324 | - $this->groupManager->getUserGroupIds($user), |
|
325 | - $currentUserGroups |
|
326 | - )) || $user->getDisplayName() === $value; |
|
327 | - }); |
|
328 | - } |
|
329 | - |
|
330 | - $results[] = array_reduce($users, function (array $carry, IUser $user) use ($restrictGroups) { |
|
331 | - // is sharing restricted to groups only? |
|
332 | - if ($restrictGroups !== false) { |
|
333 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
334 | - if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
335 | - return $carry; |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
340 | - return $carry; |
|
341 | - }, []); |
|
342 | - break; |
|
343 | - |
|
344 | - case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
345 | - // If you add support for more search properties that qualify as a user-address, |
|
346 | - // please also add them to the array below |
|
347 | - $results[] = $this->searchUserPrincipals([ |
|
348 | - // In theory this should also search for principal:principals/users/... |
|
349 | - // but that's used internally only anyway and i don't know of any client querying that |
|
350 | - '{http://sabredav.org/ns}email-address' => $value, |
|
351 | - ], 'anyof'); |
|
352 | - break; |
|
353 | - |
|
354 | - default: |
|
355 | - $results[] = []; |
|
356 | - break; |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - // results is an array of arrays, so this is not the first search result |
|
361 | - // but the results of the first searchProperty |
|
362 | - if (count($results) === 1) { |
|
363 | - return $results[0]; |
|
364 | - } |
|
365 | - |
|
366 | - switch ($test) { |
|
367 | - case 'anyof': |
|
368 | - return array_values(array_unique(array_merge(...$results))); |
|
369 | - |
|
370 | - case 'allof': |
|
371 | - default: |
|
372 | - return array_values(array_intersect(...$results)); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * @param string $prefixPath |
|
378 | - * @param array $searchProperties |
|
379 | - * @param string $test |
|
380 | - * @return array |
|
381 | - */ |
|
382 | - public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
383 | - if (count($searchProperties) === 0) { |
|
384 | - return []; |
|
385 | - } |
|
386 | - |
|
387 | - switch ($prefixPath) { |
|
388 | - case 'principals/users': |
|
389 | - return $this->searchUserPrincipals($searchProperties, $test); |
|
390 | - |
|
391 | - default: |
|
392 | - return []; |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @param string $uri |
|
398 | - * @param string $principalPrefix |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function findByUri($uri, $principalPrefix) { |
|
402 | - // If sharing is disabled, return the empty array |
|
403 | - $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
404 | - if (!$shareAPIEnabled) { |
|
405 | - return null; |
|
406 | - } |
|
407 | - |
|
408 | - // If sharing is restricted to group members only, |
|
409 | - // return only members that have groups in common |
|
410 | - $restrictGroups = false; |
|
411 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
412 | - $user = $this->userSession->getUser(); |
|
413 | - if (!$user) { |
|
414 | - return null; |
|
415 | - } |
|
416 | - |
|
417 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
418 | - } |
|
419 | - |
|
420 | - if (strpos($uri, 'mailto:') === 0) { |
|
421 | - if ($principalPrefix === 'principals/users') { |
|
422 | - $users = $this->userManager->getByEmail(substr($uri, 7)); |
|
423 | - if (count($users) !== 1) { |
|
424 | - return null; |
|
425 | - } |
|
426 | - $user = $users[0]; |
|
427 | - |
|
428 | - if ($restrictGroups !== false) { |
|
429 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
430 | - if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
431 | - return null; |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - return $this->principalPrefix . '/' . $user->getUID(); |
|
436 | - } |
|
437 | - } |
|
438 | - if (substr($uri, 0, 10) === 'principal:') { |
|
439 | - $principal = substr($uri, 10); |
|
440 | - $principal = $this->getPrincipalByPath($principal); |
|
441 | - if ($principal !== null) { |
|
442 | - return $principal['uri']; |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - return null; |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * @param IUser $user |
|
451 | - * @return array |
|
452 | - */ |
|
453 | - protected function userToPrincipal($user) { |
|
454 | - $userId = $user->getUID(); |
|
455 | - $displayName = $user->getDisplayName(); |
|
456 | - $principal = [ |
|
457 | - 'uri' => $this->principalPrefix . '/' . $userId, |
|
458 | - '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
459 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
460 | - ]; |
|
461 | - |
|
462 | - $email = $user->getEMailAddress(); |
|
463 | - if (!empty($email)) { |
|
464 | - $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
465 | - } |
|
466 | - |
|
467 | - return $principal; |
|
468 | - } |
|
469 | - |
|
470 | - public function getPrincipalPrefix() { |
|
471 | - return $this->principalPrefix; |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * @param string $circleUniqueId |
|
476 | - * @return array|null |
|
477 | - */ |
|
478 | - protected function circleToPrincipal($circleUniqueId) { |
|
479 | - if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
480 | - return null; |
|
481 | - } |
|
482 | - |
|
483 | - try { |
|
484 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId, true); |
|
485 | - } catch (QueryException $ex) { |
|
486 | - return null; |
|
487 | - } catch (CircleDoesNotExistException $ex) { |
|
488 | - return null; |
|
489 | - } |
|
490 | - |
|
491 | - if (!$circle) { |
|
492 | - return null; |
|
493 | - } |
|
494 | - |
|
495 | - $principal = [ |
|
496 | - 'uri' => 'principals/circles/' . $circleUniqueId, |
|
497 | - '{DAV:}displayname' => $circle->getName(), |
|
498 | - ]; |
|
499 | - |
|
500 | - return $principal; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Returns the list of circles a principal is a member of |
|
505 | - * |
|
506 | - * @param string $principal |
|
507 | - * @return array |
|
508 | - * @throws Exception |
|
509 | - * @throws \OCP\AppFramework\QueryException |
|
510 | - * @suppress PhanUndeclaredClassMethod |
|
511 | - */ |
|
512 | - public function getCircleMembership($principal):array { |
|
513 | - if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
514 | - return []; |
|
515 | - } |
|
516 | - |
|
517 | - list($prefix, $name) = \Sabre\Uri\split($principal); |
|
518 | - if ($this->hasCircles && $prefix === $this->principalPrefix) { |
|
519 | - $user = $this->userManager->get($name); |
|
520 | - if (!$user) { |
|
521 | - throw new Exception('Principal not found'); |
|
522 | - } |
|
523 | - |
|
524 | - $circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true); |
|
525 | - |
|
526 | - $circles = array_map(function ($circle) { |
|
527 | - /** @var \OCA\Circles\Model\Circle $circle */ |
|
528 | - return 'principals/circles/' . urlencode($circle->getUniqueId()); |
|
529 | - }, $circles); |
|
530 | - |
|
531 | - return $circles; |
|
532 | - } |
|
533 | - |
|
534 | - return []; |
|
535 | - } |
|
55 | + /** @var IUserManager */ |
|
56 | + private $userManager; |
|
57 | + |
|
58 | + /** @var IGroupManager */ |
|
59 | + private $groupManager; |
|
60 | + |
|
61 | + /** @var IShareManager */ |
|
62 | + private $shareManager; |
|
63 | + |
|
64 | + /** @var IUserSession */ |
|
65 | + private $userSession; |
|
66 | + |
|
67 | + /** @var IAppManager */ |
|
68 | + private $appManager; |
|
69 | + |
|
70 | + /** @var string */ |
|
71 | + private $principalPrefix; |
|
72 | + |
|
73 | + /** @var bool */ |
|
74 | + private $hasGroups; |
|
75 | + |
|
76 | + /** @var bool */ |
|
77 | + private $hasCircles; |
|
78 | + |
|
79 | + /** @var ProxyMapper */ |
|
80 | + private $proxyMapper; |
|
81 | + |
|
82 | + /** @var IConfig */ |
|
83 | + private $config; |
|
84 | + |
|
85 | + /** |
|
86 | + * Principal constructor. |
|
87 | + * |
|
88 | + * @param IUserManager $userManager |
|
89 | + * @param IGroupManager $groupManager |
|
90 | + * @param IShareManager $shareManager |
|
91 | + * @param IUserSession $userSession |
|
92 | + * @param IAppManager $appManager |
|
93 | + * @param ProxyMapper $proxyMapper |
|
94 | + * @param IConfig $config |
|
95 | + * @param string $principalPrefix |
|
96 | + */ |
|
97 | + public function __construct(IUserManager $userManager, |
|
98 | + IGroupManager $groupManager, |
|
99 | + IShareManager $shareManager, |
|
100 | + IUserSession $userSession, |
|
101 | + IAppManager $appManager, |
|
102 | + ProxyMapper $proxyMapper, |
|
103 | + IConfig $config, |
|
104 | + string $principalPrefix = 'principals/users/') { |
|
105 | + $this->userManager = $userManager; |
|
106 | + $this->groupManager = $groupManager; |
|
107 | + $this->shareManager = $shareManager; |
|
108 | + $this->userSession = $userSession; |
|
109 | + $this->appManager = $appManager; |
|
110 | + $this->principalPrefix = trim($principalPrefix, '/'); |
|
111 | + $this->hasGroups = $this->hasCircles = ($principalPrefix === 'principals/users/'); |
|
112 | + $this->proxyMapper = $proxyMapper; |
|
113 | + $this->config = $config; |
|
114 | + } |
|
115 | + |
|
116 | + use PrincipalProxyTrait { |
|
117 | + getGroupMembership as protected traitGetGroupMembership; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Returns a list of principals based on a prefix. |
|
122 | + * |
|
123 | + * This prefix will often contain something like 'principals'. You are only |
|
124 | + * expected to return principals that are in this base path. |
|
125 | + * |
|
126 | + * You are expected to return at least a 'uri' for every user, you can |
|
127 | + * return any additional properties if you wish so. Common properties are: |
|
128 | + * {DAV:}displayname |
|
129 | + * |
|
130 | + * @param string $prefixPath |
|
131 | + * @return string[] |
|
132 | + */ |
|
133 | + public function getPrincipalsByPrefix($prefixPath) { |
|
134 | + $principals = []; |
|
135 | + |
|
136 | + if ($prefixPath === $this->principalPrefix) { |
|
137 | + foreach ($this->userManager->search('') as $user) { |
|
138 | + $principals[] = $this->userToPrincipal($user); |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + return $principals; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Returns a specific principal, specified by it's path. |
|
147 | + * The returned structure should be the exact same as from |
|
148 | + * getPrincipalsByPrefix. |
|
149 | + * |
|
150 | + * @param string $path |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function getPrincipalByPath($path) { |
|
154 | + list($prefix, $name) = \Sabre\Uri\split($path); |
|
155 | + |
|
156 | + if ($name === 'calendar-proxy-write' || $name === 'calendar-proxy-read') { |
|
157 | + list($prefix2, $name2) = \Sabre\Uri\split($prefix); |
|
158 | + |
|
159 | + if ($prefix2 === $this->principalPrefix) { |
|
160 | + $user = $this->userManager->get($name2); |
|
161 | + |
|
162 | + if ($user !== null) { |
|
163 | + return [ |
|
164 | + 'uri' => 'principals/users/' . $user->getUID() . '/' . $name, |
|
165 | + ]; |
|
166 | + } |
|
167 | + return null; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + if ($prefix === $this->principalPrefix) { |
|
172 | + // Depending on where it is called, it may happen that this function |
|
173 | + // is called either with a urlencoded version of the name or with a non-urlencoded one. |
|
174 | + // The urldecode function replaces %## and +, both of which are forbidden in usernames. |
|
175 | + // Hence there can be no ambiguity here and it is safe to call urldecode on all usernames |
|
176 | + $user = $this->userManager->get(urldecode($name)); |
|
177 | + |
|
178 | + if ($user !== null) { |
|
179 | + return $this->userToPrincipal($user); |
|
180 | + } |
|
181 | + } elseif ($prefix === 'principals/circles') { |
|
182 | + if ($this->userSession->getUser() !== null) { |
|
183 | + return $this->circleToPrincipal($name); |
|
184 | + } |
|
185 | + } |
|
186 | + return null; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Returns the list of groups a principal is a member of |
|
191 | + * |
|
192 | + * @param string $principal |
|
193 | + * @param bool $needGroups |
|
194 | + * @return array |
|
195 | + * @throws Exception |
|
196 | + */ |
|
197 | + public function getGroupMembership($principal, $needGroups = false) { |
|
198 | + list($prefix, $name) = \Sabre\Uri\split($principal); |
|
199 | + |
|
200 | + if ($prefix !== $this->principalPrefix) { |
|
201 | + return []; |
|
202 | + } |
|
203 | + |
|
204 | + $user = $this->userManager->get($name); |
|
205 | + if (!$user) { |
|
206 | + throw new Exception('Principal not found'); |
|
207 | + } |
|
208 | + |
|
209 | + $groups = []; |
|
210 | + |
|
211 | + if ($this->hasGroups || $needGroups) { |
|
212 | + $userGroups = $this->groupManager->getUserGroups($user); |
|
213 | + foreach ($userGroups as $userGroup) { |
|
214 | + $groups[] = 'principals/groups/' . urlencode($userGroup->getGID()); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + $groups = array_unique(array_merge( |
|
219 | + $groups, |
|
220 | + $this->traitGetGroupMembership($principal, $needGroups) |
|
221 | + )); |
|
222 | + |
|
223 | + return $groups; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @param string $path |
|
228 | + * @param PropPatch $propPatch |
|
229 | + * @return int |
|
230 | + */ |
|
231 | + public function updatePrincipal($path, PropPatch $propPatch) { |
|
232 | + return 0; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Search user principals |
|
237 | + * |
|
238 | + * @param array $searchProperties |
|
239 | + * @param string $test |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + protected function searchUserPrincipals(array $searchProperties, $test = 'allof') { |
|
243 | + $results = []; |
|
244 | + |
|
245 | + // If sharing is disabled, return the empty array |
|
246 | + $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
247 | + if (!$shareAPIEnabled) { |
|
248 | + return []; |
|
249 | + } |
|
250 | + |
|
251 | + $allowEnumeration = $this->shareManager->allowEnumeration(); |
|
252 | + $limitEnumeration = $this->shareManager->limitEnumerationToGroups(); |
|
253 | + |
|
254 | + // If sharing is restricted to group members only, |
|
255 | + // return only members that have groups in common |
|
256 | + $restrictGroups = false; |
|
257 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
258 | + $user = $this->userSession->getUser(); |
|
259 | + if (!$user) { |
|
260 | + return []; |
|
261 | + } |
|
262 | + |
|
263 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
264 | + } |
|
265 | + |
|
266 | + $currentUserGroups = []; |
|
267 | + if ($limitEnumeration) { |
|
268 | + $currentUser = $this->userSession->getUser(); |
|
269 | + if ($currentUser) { |
|
270 | + $currentUserGroups = $this->groupManager->getUserGroupIds($currentUser); |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + $searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
275 | + if ($searchLimit <= 0) { |
|
276 | + $searchLimit = null; |
|
277 | + } |
|
278 | + foreach ($searchProperties as $prop => $value) { |
|
279 | + switch ($prop) { |
|
280 | + case '{http://sabredav.org/ns}email-address': |
|
281 | + $users = $this->userManager->getByEmail($value); |
|
282 | + |
|
283 | + if (!$allowEnumeration) { |
|
284 | + $users = \array_filter($users, static function (IUser $user) use ($value) { |
|
285 | + return $user->getEMailAddress() === $value; |
|
286 | + }); |
|
287 | + } |
|
288 | + |
|
289 | + if ($limitEnumeration) { |
|
290 | + $users = \array_filter($users, function (IUser $user) use ($currentUserGroups, $value) { |
|
291 | + return !empty(array_intersect( |
|
292 | + $this->groupManager->getUserGroupIds($user), |
|
293 | + $currentUserGroups |
|
294 | + )) || $user->getEMailAddress() === $value; |
|
295 | + }); |
|
296 | + } |
|
297 | + |
|
298 | + $results[] = array_reduce($users, function (array $carry, IUser $user) use ($restrictGroups) { |
|
299 | + // is sharing restricted to groups only? |
|
300 | + if ($restrictGroups !== false) { |
|
301 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
302 | + if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
303 | + return $carry; |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
308 | + return $carry; |
|
309 | + }, []); |
|
310 | + break; |
|
311 | + |
|
312 | + case '{DAV:}displayname': |
|
313 | + $users = $this->userManager->searchDisplayName($value, $searchLimit); |
|
314 | + |
|
315 | + if (!$allowEnumeration) { |
|
316 | + $users = \array_filter($users, static function (IUser $user) use ($value) { |
|
317 | + return $user->getDisplayName() === $value; |
|
318 | + }); |
|
319 | + } |
|
320 | + |
|
321 | + if ($limitEnumeration) { |
|
322 | + $users = \array_filter($users, function (IUser $user) use ($currentUserGroups, $value) { |
|
323 | + return !empty(array_intersect( |
|
324 | + $this->groupManager->getUserGroupIds($user), |
|
325 | + $currentUserGroups |
|
326 | + )) || $user->getDisplayName() === $value; |
|
327 | + }); |
|
328 | + } |
|
329 | + |
|
330 | + $results[] = array_reduce($users, function (array $carry, IUser $user) use ($restrictGroups) { |
|
331 | + // is sharing restricted to groups only? |
|
332 | + if ($restrictGroups !== false) { |
|
333 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
334 | + if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
335 | + return $carry; |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
340 | + return $carry; |
|
341 | + }, []); |
|
342 | + break; |
|
343 | + |
|
344 | + case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
345 | + // If you add support for more search properties that qualify as a user-address, |
|
346 | + // please also add them to the array below |
|
347 | + $results[] = $this->searchUserPrincipals([ |
|
348 | + // In theory this should also search for principal:principals/users/... |
|
349 | + // but that's used internally only anyway and i don't know of any client querying that |
|
350 | + '{http://sabredav.org/ns}email-address' => $value, |
|
351 | + ], 'anyof'); |
|
352 | + break; |
|
353 | + |
|
354 | + default: |
|
355 | + $results[] = []; |
|
356 | + break; |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + // results is an array of arrays, so this is not the first search result |
|
361 | + // but the results of the first searchProperty |
|
362 | + if (count($results) === 1) { |
|
363 | + return $results[0]; |
|
364 | + } |
|
365 | + |
|
366 | + switch ($test) { |
|
367 | + case 'anyof': |
|
368 | + return array_values(array_unique(array_merge(...$results))); |
|
369 | + |
|
370 | + case 'allof': |
|
371 | + default: |
|
372 | + return array_values(array_intersect(...$results)); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * @param string $prefixPath |
|
378 | + * @param array $searchProperties |
|
379 | + * @param string $test |
|
380 | + * @return array |
|
381 | + */ |
|
382 | + public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
383 | + if (count($searchProperties) === 0) { |
|
384 | + return []; |
|
385 | + } |
|
386 | + |
|
387 | + switch ($prefixPath) { |
|
388 | + case 'principals/users': |
|
389 | + return $this->searchUserPrincipals($searchProperties, $test); |
|
390 | + |
|
391 | + default: |
|
392 | + return []; |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @param string $uri |
|
398 | + * @param string $principalPrefix |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function findByUri($uri, $principalPrefix) { |
|
402 | + // If sharing is disabled, return the empty array |
|
403 | + $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
404 | + if (!$shareAPIEnabled) { |
|
405 | + return null; |
|
406 | + } |
|
407 | + |
|
408 | + // If sharing is restricted to group members only, |
|
409 | + // return only members that have groups in common |
|
410 | + $restrictGroups = false; |
|
411 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
412 | + $user = $this->userSession->getUser(); |
|
413 | + if (!$user) { |
|
414 | + return null; |
|
415 | + } |
|
416 | + |
|
417 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
418 | + } |
|
419 | + |
|
420 | + if (strpos($uri, 'mailto:') === 0) { |
|
421 | + if ($principalPrefix === 'principals/users') { |
|
422 | + $users = $this->userManager->getByEmail(substr($uri, 7)); |
|
423 | + if (count($users) !== 1) { |
|
424 | + return null; |
|
425 | + } |
|
426 | + $user = $users[0]; |
|
427 | + |
|
428 | + if ($restrictGroups !== false) { |
|
429 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
430 | + if (count(array_intersect($userGroups, $restrictGroups)) === 0) { |
|
431 | + return null; |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + return $this->principalPrefix . '/' . $user->getUID(); |
|
436 | + } |
|
437 | + } |
|
438 | + if (substr($uri, 0, 10) === 'principal:') { |
|
439 | + $principal = substr($uri, 10); |
|
440 | + $principal = $this->getPrincipalByPath($principal); |
|
441 | + if ($principal !== null) { |
|
442 | + return $principal['uri']; |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + return null; |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * @param IUser $user |
|
451 | + * @return array |
|
452 | + */ |
|
453 | + protected function userToPrincipal($user) { |
|
454 | + $userId = $user->getUID(); |
|
455 | + $displayName = $user->getDisplayName(); |
|
456 | + $principal = [ |
|
457 | + 'uri' => $this->principalPrefix . '/' . $userId, |
|
458 | + '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
459 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
460 | + ]; |
|
461 | + |
|
462 | + $email = $user->getEMailAddress(); |
|
463 | + if (!empty($email)) { |
|
464 | + $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
465 | + } |
|
466 | + |
|
467 | + return $principal; |
|
468 | + } |
|
469 | + |
|
470 | + public function getPrincipalPrefix() { |
|
471 | + return $this->principalPrefix; |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * @param string $circleUniqueId |
|
476 | + * @return array|null |
|
477 | + */ |
|
478 | + protected function circleToPrincipal($circleUniqueId) { |
|
479 | + if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
480 | + return null; |
|
481 | + } |
|
482 | + |
|
483 | + try { |
|
484 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleUniqueId, true); |
|
485 | + } catch (QueryException $ex) { |
|
486 | + return null; |
|
487 | + } catch (CircleDoesNotExistException $ex) { |
|
488 | + return null; |
|
489 | + } |
|
490 | + |
|
491 | + if (!$circle) { |
|
492 | + return null; |
|
493 | + } |
|
494 | + |
|
495 | + $principal = [ |
|
496 | + 'uri' => 'principals/circles/' . $circleUniqueId, |
|
497 | + '{DAV:}displayname' => $circle->getName(), |
|
498 | + ]; |
|
499 | + |
|
500 | + return $principal; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Returns the list of circles a principal is a member of |
|
505 | + * |
|
506 | + * @param string $principal |
|
507 | + * @return array |
|
508 | + * @throws Exception |
|
509 | + * @throws \OCP\AppFramework\QueryException |
|
510 | + * @suppress PhanUndeclaredClassMethod |
|
511 | + */ |
|
512 | + public function getCircleMembership($principal):array { |
|
513 | + if (!$this->appManager->isEnabledForUser('circles') || !class_exists('\OCA\Circles\Api\v1\Circles')) { |
|
514 | + return []; |
|
515 | + } |
|
516 | + |
|
517 | + list($prefix, $name) = \Sabre\Uri\split($principal); |
|
518 | + if ($this->hasCircles && $prefix === $this->principalPrefix) { |
|
519 | + $user = $this->userManager->get($name); |
|
520 | + if (!$user) { |
|
521 | + throw new Exception('Principal not found'); |
|
522 | + } |
|
523 | + |
|
524 | + $circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true); |
|
525 | + |
|
526 | + $circles = array_map(function ($circle) { |
|
527 | + /** @var \OCA\Circles\Model\Circle $circle */ |
|
528 | + return 'principals/circles/' . urlencode($circle->getUniqueId()); |
|
529 | + }, $circles); |
|
530 | + |
|
531 | + return $circles; |
|
532 | + } |
|
533 | + |
|
534 | + return []; |
|
535 | + } |
|
536 | 536 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | if ($user !== null) { |
163 | 163 | return [ |
164 | - 'uri' => 'principals/users/' . $user->getUID() . '/' . $name, |
|
164 | + 'uri' => 'principals/users/'.$user->getUID().'/'.$name, |
|
165 | 165 | ]; |
166 | 166 | } |
167 | 167 | return null; |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | if ($this->hasGroups || $needGroups) { |
212 | 212 | $userGroups = $this->groupManager->getUserGroups($user); |
213 | 213 | foreach ($userGroups as $userGroup) { |
214 | - $groups[] = 'principals/groups/' . urlencode($userGroup->getGID()); |
|
214 | + $groups[] = 'principals/groups/'.urlencode($userGroup->getGID()); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | $users = $this->userManager->getByEmail($value); |
282 | 282 | |
283 | 283 | if (!$allowEnumeration) { |
284 | - $users = \array_filter($users, static function (IUser $user) use ($value) { |
|
284 | + $users = \array_filter($users, static function(IUser $user) use ($value) { |
|
285 | 285 | return $user->getEMailAddress() === $value; |
286 | 286 | }); |
287 | 287 | } |
288 | 288 | |
289 | 289 | if ($limitEnumeration) { |
290 | - $users = \array_filter($users, function (IUser $user) use ($currentUserGroups, $value) { |
|
290 | + $users = \array_filter($users, function(IUser $user) use ($currentUserGroups, $value) { |
|
291 | 291 | return !empty(array_intersect( |
292 | 292 | $this->groupManager->getUserGroupIds($user), |
293 | 293 | $currentUserGroups |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | }); |
296 | 296 | } |
297 | 297 | |
298 | - $results[] = array_reduce($users, function (array $carry, IUser $user) use ($restrictGroups) { |
|
298 | + $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) { |
|
299 | 299 | // is sharing restricted to groups only? |
300 | 300 | if ($restrictGroups !== false) { |
301 | 301 | $userGroups = $this->groupManager->getUserGroupIds($user); |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
307 | + $carry[] = $this->principalPrefix.'/'.$user->getUID(); |
|
308 | 308 | return $carry; |
309 | 309 | }, []); |
310 | 310 | break; |
@@ -313,13 +313,13 @@ discard block |
||
313 | 313 | $users = $this->userManager->searchDisplayName($value, $searchLimit); |
314 | 314 | |
315 | 315 | if (!$allowEnumeration) { |
316 | - $users = \array_filter($users, static function (IUser $user) use ($value) { |
|
316 | + $users = \array_filter($users, static function(IUser $user) use ($value) { |
|
317 | 317 | return $user->getDisplayName() === $value; |
318 | 318 | }); |
319 | 319 | } |
320 | 320 | |
321 | 321 | if ($limitEnumeration) { |
322 | - $users = \array_filter($users, function (IUser $user) use ($currentUserGroups, $value) { |
|
322 | + $users = \array_filter($users, function(IUser $user) use ($currentUserGroups, $value) { |
|
323 | 323 | return !empty(array_intersect( |
324 | 324 | $this->groupManager->getUserGroupIds($user), |
325 | 325 | $currentUserGroups |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | }); |
328 | 328 | } |
329 | 329 | |
330 | - $results[] = array_reduce($users, function (array $carry, IUser $user) use ($restrictGroups) { |
|
330 | + $results[] = array_reduce($users, function(array $carry, IUser $user) use ($restrictGroups) { |
|
331 | 331 | // is sharing restricted to groups only? |
332 | 332 | if ($restrictGroups !== false) { |
333 | 333 | $userGroups = $this->groupManager->getUserGroupIds($user); |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | - $carry[] = $this->principalPrefix . '/' . $user->getUID(); |
|
339 | + $carry[] = $this->principalPrefix.'/'.$user->getUID(); |
|
340 | 340 | return $carry; |
341 | 341 | }, []); |
342 | 342 | break; |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | - return $this->principalPrefix . '/' . $user->getUID(); |
|
435 | + return $this->principalPrefix.'/'.$user->getUID(); |
|
436 | 436 | } |
437 | 437 | } |
438 | 438 | if (substr($uri, 0, 10) === 'principal:') { |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | $userId = $user->getUID(); |
455 | 455 | $displayName = $user->getDisplayName(); |
456 | 456 | $principal = [ |
457 | - 'uri' => $this->principalPrefix . '/' . $userId, |
|
457 | + 'uri' => $this->principalPrefix.'/'.$userId, |
|
458 | 458 | '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
459 | 459 | '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
460 | 460 | ]; |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | } |
494 | 494 | |
495 | 495 | $principal = [ |
496 | - 'uri' => 'principals/circles/' . $circleUniqueId, |
|
496 | + 'uri' => 'principals/circles/'.$circleUniqueId, |
|
497 | 497 | '{DAV:}displayname' => $circle->getName(), |
498 | 498 | ]; |
499 | 499 | |
@@ -523,9 +523,9 @@ discard block |
||
523 | 523 | |
524 | 524 | $circles = \OCA\Circles\Api\v1\Circles::joinedCircles($name, true); |
525 | 525 | |
526 | - $circles = array_map(function ($circle) { |
|
526 | + $circles = array_map(function($circle) { |
|
527 | 527 | /** @var \OCA\Circles\Model\Circle $circle */ |
528 | - return 'principals/circles/' . urlencode($circle->getUniqueId()); |
|
528 | + return 'principals/circles/'.urlencode($circle->getUniqueId()); |
|
529 | 529 | }, $circles); |
530 | 530 | |
531 | 531 | return $circles; |
@@ -39,304 +39,304 @@ |
||
39 | 39 | use Sabre\DAVACL\PrincipalBackend\BackendInterface; |
40 | 40 | |
41 | 41 | class GroupPrincipalBackend implements BackendInterface { |
42 | - public const PRINCIPAL_PREFIX = 'principals/groups'; |
|
43 | - |
|
44 | - /** @var IGroupManager */ |
|
45 | - private $groupManager; |
|
46 | - |
|
47 | - /** @var IUserSession */ |
|
48 | - private $userSession; |
|
49 | - |
|
50 | - /** @var IShareManager */ |
|
51 | - private $shareManager; |
|
52 | - /** @var IConfig */ |
|
53 | - private $config; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param IGroupManager $IGroupManager |
|
57 | - * @param IUserSession $userSession |
|
58 | - * @param IShareManager $shareManager |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - IGroupManager $IGroupManager, |
|
62 | - IUserSession $userSession, |
|
63 | - IShareManager $shareManager, |
|
64 | - IConfig $config |
|
65 | - ) { |
|
66 | - $this->groupManager = $IGroupManager; |
|
67 | - $this->userSession = $userSession; |
|
68 | - $this->shareManager = $shareManager; |
|
69 | - $this->config = $config; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Returns a list of principals based on a prefix. |
|
74 | - * |
|
75 | - * This prefix will often contain something like 'principals'. You are only |
|
76 | - * expected to return principals that are in this base path. |
|
77 | - * |
|
78 | - * You are expected to return at least a 'uri' for every user, you can |
|
79 | - * return any additional properties if you wish so. Common properties are: |
|
80 | - * {DAV:}displayname |
|
81 | - * |
|
82 | - * @param string $prefixPath |
|
83 | - * @return string[] |
|
84 | - */ |
|
85 | - public function getPrincipalsByPrefix($prefixPath) { |
|
86 | - $principals = []; |
|
87 | - |
|
88 | - if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
89 | - foreach ($this->groupManager->search('') as $user) { |
|
90 | - $principals[] = $this->groupToPrincipal($user); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - return $principals; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Returns a specific principal, specified by it's path. |
|
99 | - * The returned structure should be the exact same as from |
|
100 | - * getPrincipalsByPrefix. |
|
101 | - * |
|
102 | - * @param string $path |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function getPrincipalByPath($path) { |
|
106 | - $elements = explode('/', $path, 3); |
|
107 | - if ($elements[0] !== 'principals') { |
|
108 | - return null; |
|
109 | - } |
|
110 | - if ($elements[1] !== 'groups') { |
|
111 | - return null; |
|
112 | - } |
|
113 | - $name = urldecode($elements[2]); |
|
114 | - $group = $this->groupManager->get($name); |
|
115 | - |
|
116 | - if (!is_null($group)) { |
|
117 | - return $this->groupToPrincipal($group); |
|
118 | - } |
|
119 | - |
|
120 | - return null; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns the list of members for a group-principal |
|
125 | - * |
|
126 | - * @param string $principal |
|
127 | - * @return string[] |
|
128 | - * @throws Exception |
|
129 | - */ |
|
130 | - public function getGroupMemberSet($principal) { |
|
131 | - $elements = explode('/', $principal); |
|
132 | - if ($elements[0] !== 'principals') { |
|
133 | - return []; |
|
134 | - } |
|
135 | - if ($elements[1] !== 'groups') { |
|
136 | - return []; |
|
137 | - } |
|
138 | - $name = $elements[2]; |
|
139 | - $group = $this->groupManager->get($name); |
|
140 | - |
|
141 | - if (is_null($group)) { |
|
142 | - return []; |
|
143 | - } |
|
144 | - |
|
145 | - return array_map(function ($user) { |
|
146 | - return $this->userToPrincipal($user); |
|
147 | - }, $group->getUsers()); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Returns the list of groups a principal is a member of |
|
152 | - * |
|
153 | - * @param string $principal |
|
154 | - * @return array |
|
155 | - * @throws Exception |
|
156 | - */ |
|
157 | - public function getGroupMembership($principal) { |
|
158 | - return []; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Updates the list of group members for a group principal. |
|
163 | - * |
|
164 | - * The principals should be passed as a list of uri's. |
|
165 | - * |
|
166 | - * @param string $principal |
|
167 | - * @param string[] $members |
|
168 | - * @throws Exception |
|
169 | - */ |
|
170 | - public function setGroupMemberSet($principal, array $members) { |
|
171 | - throw new Exception('Setting members of the group is not supported yet'); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param string $path |
|
176 | - * @param PropPatch $propPatch |
|
177 | - * @return int |
|
178 | - */ |
|
179 | - public function updatePrincipal($path, PropPatch $propPatch) { |
|
180 | - return 0; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @param string $prefixPath |
|
185 | - * @param array $searchProperties |
|
186 | - * @param string $test |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
190 | - $results = []; |
|
191 | - |
|
192 | - if (\count($searchProperties) === 0) { |
|
193 | - return []; |
|
194 | - } |
|
195 | - if ($prefixPath !== self::PRINCIPAL_PREFIX) { |
|
196 | - return []; |
|
197 | - } |
|
198 | - // If sharing is disabled, return the empty array |
|
199 | - $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
200 | - if (!$shareAPIEnabled) { |
|
201 | - return []; |
|
202 | - } |
|
203 | - |
|
204 | - // If sharing is restricted to group members only, |
|
205 | - // return only members that have groups in common |
|
206 | - $restrictGroups = false; |
|
207 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
208 | - $user = $this->userSession->getUser(); |
|
209 | - if (!$user) { |
|
210 | - return []; |
|
211 | - } |
|
212 | - |
|
213 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
214 | - } |
|
215 | - |
|
216 | - $searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
217 | - if ($searchLimit <= 0) { |
|
218 | - $searchLimit = null; |
|
219 | - } |
|
220 | - foreach ($searchProperties as $prop => $value) { |
|
221 | - switch ($prop) { |
|
222 | - case '{DAV:}displayname': |
|
223 | - $groups = $this->groupManager->search($value, $searchLimit); |
|
224 | - |
|
225 | - $results[] = array_reduce($groups, function (array $carry, IGroup $group) use ($restrictGroups) { |
|
226 | - $gid = $group->getGID(); |
|
227 | - // is sharing restricted to groups only? |
|
228 | - if ($restrictGroups !== false) { |
|
229 | - if (!\in_array($gid, $restrictGroups, true)) { |
|
230 | - return $carry; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - $carry[] = self::PRINCIPAL_PREFIX . '/' . $gid; |
|
235 | - return $carry; |
|
236 | - }, []); |
|
237 | - break; |
|
238 | - |
|
239 | - case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
240 | - // If you add support for more search properties that qualify as a user-address, |
|
241 | - // please also add them to the array below |
|
242 | - $results[] = $this->searchPrincipals(self::PRINCIPAL_PREFIX, [ |
|
243 | - ], 'anyof'); |
|
244 | - break; |
|
245 | - |
|
246 | - default: |
|
247 | - $results[] = []; |
|
248 | - break; |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // results is an array of arrays, so this is not the first search result |
|
253 | - // but the results of the first searchProperty |
|
254 | - if (count($results) === 1) { |
|
255 | - return $results[0]; |
|
256 | - } |
|
257 | - |
|
258 | - switch ($test) { |
|
259 | - case 'anyof': |
|
260 | - return array_values(array_unique(array_merge(...$results))); |
|
261 | - |
|
262 | - case 'allof': |
|
263 | - default: |
|
264 | - return array_values(array_intersect(...$results)); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @param string $uri |
|
270 | - * @param string $principalPrefix |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - public function findByUri($uri, $principalPrefix) { |
|
274 | - // If sharing is disabled, return the empty array |
|
275 | - $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
276 | - if (!$shareAPIEnabled) { |
|
277 | - return null; |
|
278 | - } |
|
279 | - |
|
280 | - // If sharing is restricted to group members only, |
|
281 | - // return only members that have groups in common |
|
282 | - $restrictGroups = false; |
|
283 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
284 | - $user = $this->userSession->getUser(); |
|
285 | - if (!$user) { |
|
286 | - return null; |
|
287 | - } |
|
288 | - |
|
289 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
290 | - } |
|
291 | - |
|
292 | - if (strpos($uri, 'principal:principals/groups/') === 0) { |
|
293 | - $name = urlencode(substr($uri, 28)); |
|
294 | - if ($restrictGroups !== false && !\in_array($name, $restrictGroups, true)) { |
|
295 | - return null; |
|
296 | - } |
|
297 | - |
|
298 | - return substr($uri, 10); |
|
299 | - } |
|
300 | - |
|
301 | - return null; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @param IGroup $group |
|
306 | - * @return array |
|
307 | - */ |
|
308 | - protected function groupToPrincipal($group) { |
|
309 | - $groupId = $group->getGID(); |
|
310 | - // getDisplayName returns UID if none |
|
311 | - $displayName = $group->getDisplayName(); |
|
312 | - |
|
313 | - return [ |
|
314 | - 'uri' => 'principals/groups/' . urlencode($groupId), |
|
315 | - '{DAV:}displayname' => $displayName, |
|
316 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'GROUP', |
|
317 | - ]; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * @param IUser $user |
|
322 | - * @return array |
|
323 | - */ |
|
324 | - protected function userToPrincipal($user) { |
|
325 | - $userId = $user->getUID(); |
|
326 | - // getDisplayName returns UID if none |
|
327 | - $displayName = $user->getDisplayName(); |
|
328 | - |
|
329 | - $principal = [ |
|
330 | - 'uri' => 'principals/users/' . $userId, |
|
331 | - '{DAV:}displayname' => $displayName, |
|
332 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
333 | - ]; |
|
334 | - |
|
335 | - $email = $user->getEMailAddress(); |
|
336 | - if (!empty($email)) { |
|
337 | - $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
338 | - } |
|
339 | - |
|
340 | - return $principal; |
|
341 | - } |
|
42 | + public const PRINCIPAL_PREFIX = 'principals/groups'; |
|
43 | + |
|
44 | + /** @var IGroupManager */ |
|
45 | + private $groupManager; |
|
46 | + |
|
47 | + /** @var IUserSession */ |
|
48 | + private $userSession; |
|
49 | + |
|
50 | + /** @var IShareManager */ |
|
51 | + private $shareManager; |
|
52 | + /** @var IConfig */ |
|
53 | + private $config; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param IGroupManager $IGroupManager |
|
57 | + * @param IUserSession $userSession |
|
58 | + * @param IShareManager $shareManager |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + IGroupManager $IGroupManager, |
|
62 | + IUserSession $userSession, |
|
63 | + IShareManager $shareManager, |
|
64 | + IConfig $config |
|
65 | + ) { |
|
66 | + $this->groupManager = $IGroupManager; |
|
67 | + $this->userSession = $userSession; |
|
68 | + $this->shareManager = $shareManager; |
|
69 | + $this->config = $config; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Returns a list of principals based on a prefix. |
|
74 | + * |
|
75 | + * This prefix will often contain something like 'principals'. You are only |
|
76 | + * expected to return principals that are in this base path. |
|
77 | + * |
|
78 | + * You are expected to return at least a 'uri' for every user, you can |
|
79 | + * return any additional properties if you wish so. Common properties are: |
|
80 | + * {DAV:}displayname |
|
81 | + * |
|
82 | + * @param string $prefixPath |
|
83 | + * @return string[] |
|
84 | + */ |
|
85 | + public function getPrincipalsByPrefix($prefixPath) { |
|
86 | + $principals = []; |
|
87 | + |
|
88 | + if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
89 | + foreach ($this->groupManager->search('') as $user) { |
|
90 | + $principals[] = $this->groupToPrincipal($user); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + return $principals; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Returns a specific principal, specified by it's path. |
|
99 | + * The returned structure should be the exact same as from |
|
100 | + * getPrincipalsByPrefix. |
|
101 | + * |
|
102 | + * @param string $path |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function getPrincipalByPath($path) { |
|
106 | + $elements = explode('/', $path, 3); |
|
107 | + if ($elements[0] !== 'principals') { |
|
108 | + return null; |
|
109 | + } |
|
110 | + if ($elements[1] !== 'groups') { |
|
111 | + return null; |
|
112 | + } |
|
113 | + $name = urldecode($elements[2]); |
|
114 | + $group = $this->groupManager->get($name); |
|
115 | + |
|
116 | + if (!is_null($group)) { |
|
117 | + return $this->groupToPrincipal($group); |
|
118 | + } |
|
119 | + |
|
120 | + return null; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns the list of members for a group-principal |
|
125 | + * |
|
126 | + * @param string $principal |
|
127 | + * @return string[] |
|
128 | + * @throws Exception |
|
129 | + */ |
|
130 | + public function getGroupMemberSet($principal) { |
|
131 | + $elements = explode('/', $principal); |
|
132 | + if ($elements[0] !== 'principals') { |
|
133 | + return []; |
|
134 | + } |
|
135 | + if ($elements[1] !== 'groups') { |
|
136 | + return []; |
|
137 | + } |
|
138 | + $name = $elements[2]; |
|
139 | + $group = $this->groupManager->get($name); |
|
140 | + |
|
141 | + if (is_null($group)) { |
|
142 | + return []; |
|
143 | + } |
|
144 | + |
|
145 | + return array_map(function ($user) { |
|
146 | + return $this->userToPrincipal($user); |
|
147 | + }, $group->getUsers()); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Returns the list of groups a principal is a member of |
|
152 | + * |
|
153 | + * @param string $principal |
|
154 | + * @return array |
|
155 | + * @throws Exception |
|
156 | + */ |
|
157 | + public function getGroupMembership($principal) { |
|
158 | + return []; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Updates the list of group members for a group principal. |
|
163 | + * |
|
164 | + * The principals should be passed as a list of uri's. |
|
165 | + * |
|
166 | + * @param string $principal |
|
167 | + * @param string[] $members |
|
168 | + * @throws Exception |
|
169 | + */ |
|
170 | + public function setGroupMemberSet($principal, array $members) { |
|
171 | + throw new Exception('Setting members of the group is not supported yet'); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param string $path |
|
176 | + * @param PropPatch $propPatch |
|
177 | + * @return int |
|
178 | + */ |
|
179 | + public function updatePrincipal($path, PropPatch $propPatch) { |
|
180 | + return 0; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @param string $prefixPath |
|
185 | + * @param array $searchProperties |
|
186 | + * @param string $test |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
190 | + $results = []; |
|
191 | + |
|
192 | + if (\count($searchProperties) === 0) { |
|
193 | + return []; |
|
194 | + } |
|
195 | + if ($prefixPath !== self::PRINCIPAL_PREFIX) { |
|
196 | + return []; |
|
197 | + } |
|
198 | + // If sharing is disabled, return the empty array |
|
199 | + $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
200 | + if (!$shareAPIEnabled) { |
|
201 | + return []; |
|
202 | + } |
|
203 | + |
|
204 | + // If sharing is restricted to group members only, |
|
205 | + // return only members that have groups in common |
|
206 | + $restrictGroups = false; |
|
207 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
208 | + $user = $this->userSession->getUser(); |
|
209 | + if (!$user) { |
|
210 | + return []; |
|
211 | + } |
|
212 | + |
|
213 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
214 | + } |
|
215 | + |
|
216 | + $searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
217 | + if ($searchLimit <= 0) { |
|
218 | + $searchLimit = null; |
|
219 | + } |
|
220 | + foreach ($searchProperties as $prop => $value) { |
|
221 | + switch ($prop) { |
|
222 | + case '{DAV:}displayname': |
|
223 | + $groups = $this->groupManager->search($value, $searchLimit); |
|
224 | + |
|
225 | + $results[] = array_reduce($groups, function (array $carry, IGroup $group) use ($restrictGroups) { |
|
226 | + $gid = $group->getGID(); |
|
227 | + // is sharing restricted to groups only? |
|
228 | + if ($restrictGroups !== false) { |
|
229 | + if (!\in_array($gid, $restrictGroups, true)) { |
|
230 | + return $carry; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + $carry[] = self::PRINCIPAL_PREFIX . '/' . $gid; |
|
235 | + return $carry; |
|
236 | + }, []); |
|
237 | + break; |
|
238 | + |
|
239 | + case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
240 | + // If you add support for more search properties that qualify as a user-address, |
|
241 | + // please also add them to the array below |
|
242 | + $results[] = $this->searchPrincipals(self::PRINCIPAL_PREFIX, [ |
|
243 | + ], 'anyof'); |
|
244 | + break; |
|
245 | + |
|
246 | + default: |
|
247 | + $results[] = []; |
|
248 | + break; |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // results is an array of arrays, so this is not the first search result |
|
253 | + // but the results of the first searchProperty |
|
254 | + if (count($results) === 1) { |
|
255 | + return $results[0]; |
|
256 | + } |
|
257 | + |
|
258 | + switch ($test) { |
|
259 | + case 'anyof': |
|
260 | + return array_values(array_unique(array_merge(...$results))); |
|
261 | + |
|
262 | + case 'allof': |
|
263 | + default: |
|
264 | + return array_values(array_intersect(...$results)); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @param string $uri |
|
270 | + * @param string $principalPrefix |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + public function findByUri($uri, $principalPrefix) { |
|
274 | + // If sharing is disabled, return the empty array |
|
275 | + $shareAPIEnabled = $this->shareManager->shareApiEnabled(); |
|
276 | + if (!$shareAPIEnabled) { |
|
277 | + return null; |
|
278 | + } |
|
279 | + |
|
280 | + // If sharing is restricted to group members only, |
|
281 | + // return only members that have groups in common |
|
282 | + $restrictGroups = false; |
|
283 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
284 | + $user = $this->userSession->getUser(); |
|
285 | + if (!$user) { |
|
286 | + return null; |
|
287 | + } |
|
288 | + |
|
289 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
290 | + } |
|
291 | + |
|
292 | + if (strpos($uri, 'principal:principals/groups/') === 0) { |
|
293 | + $name = urlencode(substr($uri, 28)); |
|
294 | + if ($restrictGroups !== false && !\in_array($name, $restrictGroups, true)) { |
|
295 | + return null; |
|
296 | + } |
|
297 | + |
|
298 | + return substr($uri, 10); |
|
299 | + } |
|
300 | + |
|
301 | + return null; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @param IGroup $group |
|
306 | + * @return array |
|
307 | + */ |
|
308 | + protected function groupToPrincipal($group) { |
|
309 | + $groupId = $group->getGID(); |
|
310 | + // getDisplayName returns UID if none |
|
311 | + $displayName = $group->getDisplayName(); |
|
312 | + |
|
313 | + return [ |
|
314 | + 'uri' => 'principals/groups/' . urlencode($groupId), |
|
315 | + '{DAV:}displayname' => $displayName, |
|
316 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'GROUP', |
|
317 | + ]; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * @param IUser $user |
|
322 | + * @return array |
|
323 | + */ |
|
324 | + protected function userToPrincipal($user) { |
|
325 | + $userId = $user->getUID(); |
|
326 | + // getDisplayName returns UID if none |
|
327 | + $displayName = $user->getDisplayName(); |
|
328 | + |
|
329 | + $principal = [ |
|
330 | + 'uri' => 'principals/users/' . $userId, |
|
331 | + '{DAV:}displayname' => $displayName, |
|
332 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
333 | + ]; |
|
334 | + |
|
335 | + $email = $user->getEMailAddress(); |
|
336 | + if (!empty($email)) { |
|
337 | + $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
338 | + } |
|
339 | + |
|
340 | + return $principal; |
|
341 | + } |
|
342 | 342 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return array |
104 | 104 | */ |
105 | 105 | public function getPrincipalByPath($path) { |
106 | - $elements = explode('/', $path, 3); |
|
106 | + $elements = explode('/', $path, 3); |
|
107 | 107 | if ($elements[0] !== 'principals') { |
108 | 108 | return null; |
109 | 109 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | return []; |
143 | 143 | } |
144 | 144 | |
145 | - return array_map(function ($user) { |
|
145 | + return array_map(function($user) { |
|
146 | 146 | return $this->userToPrincipal($user); |
147 | 147 | }, $group->getUsers()); |
148 | 148 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | case '{DAV:}displayname': |
223 | 223 | $groups = $this->groupManager->search($value, $searchLimit); |
224 | 224 | |
225 | - $results[] = array_reduce($groups, function (array $carry, IGroup $group) use ($restrictGroups) { |
|
225 | + $results[] = array_reduce($groups, function(array $carry, IGroup $group) use ($restrictGroups) { |
|
226 | 226 | $gid = $group->getGID(); |
227 | 227 | // is sharing restricted to groups only? |
228 | 228 | if ($restrictGroups !== false) { |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | - $carry[] = self::PRINCIPAL_PREFIX . '/' . $gid; |
|
234 | + $carry[] = self::PRINCIPAL_PREFIX.'/'.$gid; |
|
235 | 235 | return $carry; |
236 | 236 | }, []); |
237 | 237 | break; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | $displayName = $group->getDisplayName(); |
312 | 312 | |
313 | 313 | return [ |
314 | - 'uri' => 'principals/groups/' . urlencode($groupId), |
|
314 | + 'uri' => 'principals/groups/'.urlencode($groupId), |
|
315 | 315 | '{DAV:}displayname' => $displayName, |
316 | 316 | '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'GROUP', |
317 | 317 | ]; |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $displayName = $user->getDisplayName(); |
328 | 328 | |
329 | 329 | $principal = [ |
330 | - 'uri' => 'principals/users/' . $userId, |
|
330 | + 'uri' => 'principals/users/'.$userId, |
|
331 | 331 | '{DAV:}displayname' => $displayName, |
332 | 332 | '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
333 | 333 | ]; |
@@ -56,383 +56,383 @@ |
||
56 | 56 | |
57 | 57 | class ShareesAPIController extends OCSController { |
58 | 58 | |
59 | - /** @var string */ |
|
60 | - protected $userId; |
|
61 | - |
|
62 | - /** @var IConfig */ |
|
63 | - protected $config; |
|
64 | - |
|
65 | - /** @var IURLGenerator */ |
|
66 | - protected $urlGenerator; |
|
67 | - |
|
68 | - /** @var IManager */ |
|
69 | - protected $shareManager; |
|
70 | - |
|
71 | - /** @var int */ |
|
72 | - protected $offset = 0; |
|
73 | - |
|
74 | - /** @var int */ |
|
75 | - protected $limit = 10; |
|
76 | - |
|
77 | - /** @var array */ |
|
78 | - protected $result = [ |
|
79 | - 'exact' => [ |
|
80 | - 'users' => [], |
|
81 | - 'groups' => [], |
|
82 | - 'remotes' => [], |
|
83 | - 'remote_groups' => [], |
|
84 | - 'emails' => [], |
|
85 | - 'circles' => [], |
|
86 | - 'rooms' => [], |
|
87 | - 'deck' => [], |
|
88 | - ], |
|
89 | - 'users' => [], |
|
90 | - 'groups' => [], |
|
91 | - 'remotes' => [], |
|
92 | - 'remote_groups' => [], |
|
93 | - 'emails' => [], |
|
94 | - 'lookup' => [], |
|
95 | - 'circles' => [], |
|
96 | - 'rooms' => [], |
|
97 | - 'deck' => [], |
|
98 | - 'lookupEnabled' => false, |
|
99 | - ]; |
|
100 | - |
|
101 | - protected $reachedEndFor = []; |
|
102 | - /** @var ISearch */ |
|
103 | - private $collaboratorSearch; |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $UserId |
|
107 | - * @param string $appName |
|
108 | - * @param IRequest $request |
|
109 | - * @param IConfig $config |
|
110 | - * @param IURLGenerator $urlGenerator |
|
111 | - * @param IManager $shareManager |
|
112 | - * @param ISearch $collaboratorSearch |
|
113 | - */ |
|
114 | - public function __construct( |
|
115 | - $UserId, |
|
116 | - string $appName, |
|
117 | - IRequest $request, |
|
118 | - IConfig $config, |
|
119 | - IURLGenerator $urlGenerator, |
|
120 | - IManager $shareManager, |
|
121 | - ISearch $collaboratorSearch |
|
122 | - ) { |
|
123 | - parent::__construct($appName, $request); |
|
124 | - $this->userId = $UserId; |
|
125 | - $this->config = $config; |
|
126 | - $this->urlGenerator = $urlGenerator; |
|
127 | - $this->shareManager = $shareManager; |
|
128 | - $this->collaboratorSearch = $collaboratorSearch; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @NoAdminRequired |
|
133 | - * |
|
134 | - * @param string $search |
|
135 | - * @param string $itemType |
|
136 | - * @param int $page |
|
137 | - * @param int $perPage |
|
138 | - * @param int|int[] $shareType |
|
139 | - * @param bool $lookup |
|
140 | - * @return DataResponse |
|
141 | - * @throws OCSBadRequestException |
|
142 | - */ |
|
143 | - public function search(string $search = '', string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = true): DataResponse { |
|
144 | - |
|
145 | - // only search for string larger than a given threshold |
|
146 | - $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
147 | - if (strlen($search) < $threshold) { |
|
148 | - return new DataResponse($this->result); |
|
149 | - } |
|
150 | - |
|
151 | - // never return more than the max. number of results configured in the config.php |
|
152 | - $maxResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
153 | - if ($maxResults > 0) { |
|
154 | - $perPage = min($perPage, $maxResults); |
|
155 | - } |
|
156 | - if ($perPage <= 0) { |
|
157 | - throw new OCSBadRequestException('Invalid perPage argument'); |
|
158 | - } |
|
159 | - if ($page <= 0) { |
|
160 | - throw new OCSBadRequestException('Invalid page'); |
|
161 | - } |
|
162 | - |
|
163 | - $shareTypes = [ |
|
164 | - IShare::TYPE_USER, |
|
165 | - ]; |
|
166 | - |
|
167 | - if ($itemType === null) { |
|
168 | - throw new OCSBadRequestException('Missing itemType'); |
|
169 | - } elseif ($itemType === 'file' || $itemType === 'folder') { |
|
170 | - if ($this->shareManager->allowGroupSharing()) { |
|
171 | - $shareTypes[] = IShare::TYPE_GROUP; |
|
172 | - } |
|
173 | - |
|
174 | - if ($this->isRemoteSharingAllowed($itemType)) { |
|
175 | - $shareTypes[] = IShare::TYPE_REMOTE; |
|
176 | - } |
|
177 | - |
|
178 | - if ($this->isRemoteGroupSharingAllowed($itemType)) { |
|
179 | - $shareTypes[] = IShare::TYPE_REMOTE_GROUP; |
|
180 | - } |
|
181 | - |
|
182 | - if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
183 | - $shareTypes[] = IShare::TYPE_EMAIL; |
|
184 | - } |
|
185 | - |
|
186 | - if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) { |
|
187 | - $shareTypes[] = IShare::TYPE_ROOM; |
|
188 | - } |
|
189 | - |
|
190 | - if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) { |
|
191 | - $shareTypes[] = IShare::TYPE_DECK; |
|
192 | - } |
|
193 | - } else { |
|
194 | - $shareTypes[] = IShare::TYPE_GROUP; |
|
195 | - $shareTypes[] = IShare::TYPE_EMAIL; |
|
196 | - } |
|
197 | - |
|
198 | - // FIXME: DI |
|
199 | - if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
200 | - $shareTypes[] = IShare::TYPE_CIRCLE; |
|
201 | - } |
|
202 | - |
|
203 | - if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) { |
|
204 | - $shareTypes[] = IShare::TYPE_DECK; |
|
205 | - } |
|
206 | - |
|
207 | - if ($shareType !== null && is_array($shareType)) { |
|
208 | - $shareTypes = array_intersect($shareTypes, $shareType); |
|
209 | - } elseif (is_numeric($shareType)) { |
|
210 | - $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
211 | - } |
|
212 | - sort($shareTypes); |
|
213 | - |
|
214 | - $this->limit = (int) $perPage; |
|
215 | - $this->offset = $perPage * ($page - 1); |
|
216 | - |
|
217 | - // In global scale mode we always search the loogup server |
|
218 | - if ($this->config->getSystemValueBool('gs.enabled', false)) { |
|
219 | - $lookup = true; |
|
220 | - $this->result['lookupEnabled'] = true; |
|
221 | - } else { |
|
222 | - $this->result['lookupEnabled'] = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes'; |
|
223 | - } |
|
224 | - |
|
225 | - list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset); |
|
226 | - |
|
227 | - // extra treatment for 'exact' subarray, with a single merge expected keys might be lost |
|
228 | - if (isset($result['exact'])) { |
|
229 | - $result['exact'] = array_merge($this->result['exact'], $result['exact']); |
|
230 | - } |
|
231 | - $this->result = array_merge($this->result, $result); |
|
232 | - $response = new DataResponse($this->result); |
|
233 | - |
|
234 | - if ($hasMoreResults) { |
|
235 | - $response->addHeader('Link', $this->getPaginationLink($page, [ |
|
236 | - 'search' => $search, |
|
237 | - 'itemType' => $itemType, |
|
238 | - 'shareType' => $shareTypes, |
|
239 | - 'perPage' => $perPage, |
|
240 | - ])); |
|
241 | - } |
|
242 | - |
|
243 | - return $response; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @param string $user |
|
248 | - * @param int $shareType |
|
249 | - * |
|
250 | - * @return Generator<array<string>> |
|
251 | - */ |
|
252 | - private function getAllShareesByType(string $user, int $shareType): Generator { |
|
253 | - $offset = 0; |
|
254 | - $pageSize = 50; |
|
255 | - |
|
256 | - while (count($page = $this->shareManager->getSharesBy( |
|
257 | - $user, |
|
258 | - $shareType, |
|
259 | - null, |
|
260 | - false, |
|
261 | - $pageSize, |
|
262 | - $offset |
|
263 | - ))) { |
|
264 | - foreach ($page as $share) { |
|
265 | - yield [$share->getSharedWith(), $share->getSharedWithDisplayName() ?? $share->getSharedWith()]; |
|
266 | - } |
|
267 | - |
|
268 | - $offset += $pageSize; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - private function sortShareesByFrequency(array $sharees): array { |
|
273 | - usort($sharees, function (array $s1, array $s2) { |
|
274 | - return $s2['count'] - $s1['count']; |
|
275 | - }); |
|
276 | - return $sharees; |
|
277 | - } |
|
278 | - |
|
279 | - private $searchResultTypeMap = [ |
|
280 | - IShare::TYPE_USER => 'users', |
|
281 | - IShare::TYPE_GROUP => 'groups', |
|
282 | - IShare::TYPE_REMOTE => 'remotes', |
|
283 | - IShare::TYPE_REMOTE_GROUP => 'remote_groups', |
|
284 | - IShare::TYPE_EMAIL => 'emails', |
|
285 | - ]; |
|
286 | - |
|
287 | - private function getAllSharees(string $user, array $shareTypes): ISearchResult { |
|
288 | - $result = []; |
|
289 | - foreach ($shareTypes as $shareType) { |
|
290 | - $sharees = $this->getAllShareesByType($user, $shareType); |
|
291 | - $shareTypeResults = []; |
|
292 | - foreach ($sharees as list($sharee, $displayname)) { |
|
293 | - if (!isset($this->searchResultTypeMap[$shareType])) { |
|
294 | - continue; |
|
295 | - } |
|
296 | - |
|
297 | - if (!isset($shareTypeResults[$sharee])) { |
|
298 | - $shareTypeResults[$sharee] = [ |
|
299 | - 'count' => 1, |
|
300 | - 'label' => $displayname, |
|
301 | - 'value' => [ |
|
302 | - 'shareType' => $shareType, |
|
303 | - 'shareWith' => $sharee, |
|
304 | - ], |
|
305 | - ]; |
|
306 | - } else { |
|
307 | - $shareTypeResults[$sharee]['count']++; |
|
308 | - } |
|
309 | - } |
|
310 | - $result = array_merge($result, array_values($shareTypeResults)); |
|
311 | - } |
|
312 | - |
|
313 | - $top5 = array_slice( |
|
314 | - $this->sortShareesByFrequency($result), |
|
315 | - 0, |
|
316 | - 5 |
|
317 | - ); |
|
318 | - |
|
319 | - $searchResult = new SearchResult(); |
|
320 | - foreach ($this->searchResultTypeMap as $int => $str) { |
|
321 | - $searchResult->addResultSet(new SearchResultType($str), [], []); |
|
322 | - foreach ($top5 as $x) { |
|
323 | - if ($x['value']['shareType'] === $int) { |
|
324 | - $searchResult->addResultSet(new SearchResultType($str), [], [$x]); |
|
325 | - } |
|
326 | - } |
|
327 | - } |
|
328 | - return $searchResult; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @NoAdminRequired |
|
333 | - * |
|
334 | - * @param string $itemType |
|
335 | - * @return DataResponse |
|
336 | - * @throws OCSBadRequestException |
|
337 | - */ |
|
338 | - public function findRecommended(string $itemType = null, $shareType = null): DataResponse { |
|
339 | - $shareTypes = [ |
|
340 | - IShare::TYPE_USER, |
|
341 | - ]; |
|
342 | - |
|
343 | - if ($itemType === null) { |
|
344 | - throw new OCSBadRequestException('Missing itemType'); |
|
345 | - } elseif ($itemType === 'file' || $itemType === 'folder') { |
|
346 | - if ($this->shareManager->allowGroupSharing()) { |
|
347 | - $shareTypes[] = IShare::TYPE_GROUP; |
|
348 | - } |
|
349 | - |
|
350 | - if ($this->isRemoteSharingAllowed($itemType)) { |
|
351 | - $shareTypes[] = IShare::TYPE_REMOTE; |
|
352 | - } |
|
353 | - |
|
354 | - if ($this->isRemoteGroupSharingAllowed($itemType)) { |
|
355 | - $shareTypes[] = IShare::TYPE_REMOTE_GROUP; |
|
356 | - } |
|
357 | - |
|
358 | - if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
359 | - $shareTypes[] = IShare::TYPE_EMAIL; |
|
360 | - } |
|
361 | - |
|
362 | - if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) { |
|
363 | - $shareTypes[] = IShare::TYPE_ROOM; |
|
364 | - } |
|
365 | - } else { |
|
366 | - $shareTypes[] = IShare::TYPE_GROUP; |
|
367 | - $shareTypes[] = IShare::TYPE_EMAIL; |
|
368 | - } |
|
369 | - |
|
370 | - // FIXME: DI |
|
371 | - if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
372 | - $shareTypes[] = IShare::TYPE_CIRCLE; |
|
373 | - } |
|
374 | - |
|
375 | - if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { |
|
376 | - $shareTypes = array_intersect($shareTypes, $_GET['shareType']); |
|
377 | - sort($shareTypes); |
|
378 | - } elseif (is_numeric($shareType)) { |
|
379 | - $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
380 | - sort($shareTypes); |
|
381 | - } |
|
382 | - |
|
383 | - return new DataResponse( |
|
384 | - $this->getAllSharees($this->userId, $shareTypes)->asArray() |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Method to get out the static call for better testing |
|
390 | - * |
|
391 | - * @param string $itemType |
|
392 | - * @return bool |
|
393 | - */ |
|
394 | - protected function isRemoteSharingAllowed(string $itemType): bool { |
|
395 | - try { |
|
396 | - // FIXME: static foo makes unit testing unnecessarily difficult |
|
397 | - $backend = \OC\Share\Share::getBackend($itemType); |
|
398 | - return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE); |
|
399 | - } catch (\Exception $e) { |
|
400 | - return false; |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - protected function isRemoteGroupSharingAllowed(string $itemType): bool { |
|
405 | - try { |
|
406 | - // FIXME: static foo makes unit testing unnecessarily difficult |
|
407 | - $backend = \OC\Share\Share::getBackend($itemType); |
|
408 | - return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE_GROUP); |
|
409 | - } catch (\Exception $e) { |
|
410 | - return false; |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * Generates a bunch of pagination links for the current page |
|
417 | - * |
|
418 | - * @param int $page Current page |
|
419 | - * @param array $params Parameters for the URL |
|
420 | - * @return string |
|
421 | - */ |
|
422 | - protected function getPaginationLink(int $page, array $params): string { |
|
423 | - if ($this->isV2()) { |
|
424 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
425 | - } else { |
|
426 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
427 | - } |
|
428 | - $params['page'] = $page + 1; |
|
429 | - return '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * @return bool |
|
434 | - */ |
|
435 | - protected function isV2(): bool { |
|
436 | - return $this->request->getScriptName() === '/ocs/v2.php'; |
|
437 | - } |
|
59 | + /** @var string */ |
|
60 | + protected $userId; |
|
61 | + |
|
62 | + /** @var IConfig */ |
|
63 | + protected $config; |
|
64 | + |
|
65 | + /** @var IURLGenerator */ |
|
66 | + protected $urlGenerator; |
|
67 | + |
|
68 | + /** @var IManager */ |
|
69 | + protected $shareManager; |
|
70 | + |
|
71 | + /** @var int */ |
|
72 | + protected $offset = 0; |
|
73 | + |
|
74 | + /** @var int */ |
|
75 | + protected $limit = 10; |
|
76 | + |
|
77 | + /** @var array */ |
|
78 | + protected $result = [ |
|
79 | + 'exact' => [ |
|
80 | + 'users' => [], |
|
81 | + 'groups' => [], |
|
82 | + 'remotes' => [], |
|
83 | + 'remote_groups' => [], |
|
84 | + 'emails' => [], |
|
85 | + 'circles' => [], |
|
86 | + 'rooms' => [], |
|
87 | + 'deck' => [], |
|
88 | + ], |
|
89 | + 'users' => [], |
|
90 | + 'groups' => [], |
|
91 | + 'remotes' => [], |
|
92 | + 'remote_groups' => [], |
|
93 | + 'emails' => [], |
|
94 | + 'lookup' => [], |
|
95 | + 'circles' => [], |
|
96 | + 'rooms' => [], |
|
97 | + 'deck' => [], |
|
98 | + 'lookupEnabled' => false, |
|
99 | + ]; |
|
100 | + |
|
101 | + protected $reachedEndFor = []; |
|
102 | + /** @var ISearch */ |
|
103 | + private $collaboratorSearch; |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $UserId |
|
107 | + * @param string $appName |
|
108 | + * @param IRequest $request |
|
109 | + * @param IConfig $config |
|
110 | + * @param IURLGenerator $urlGenerator |
|
111 | + * @param IManager $shareManager |
|
112 | + * @param ISearch $collaboratorSearch |
|
113 | + */ |
|
114 | + public function __construct( |
|
115 | + $UserId, |
|
116 | + string $appName, |
|
117 | + IRequest $request, |
|
118 | + IConfig $config, |
|
119 | + IURLGenerator $urlGenerator, |
|
120 | + IManager $shareManager, |
|
121 | + ISearch $collaboratorSearch |
|
122 | + ) { |
|
123 | + parent::__construct($appName, $request); |
|
124 | + $this->userId = $UserId; |
|
125 | + $this->config = $config; |
|
126 | + $this->urlGenerator = $urlGenerator; |
|
127 | + $this->shareManager = $shareManager; |
|
128 | + $this->collaboratorSearch = $collaboratorSearch; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @NoAdminRequired |
|
133 | + * |
|
134 | + * @param string $search |
|
135 | + * @param string $itemType |
|
136 | + * @param int $page |
|
137 | + * @param int $perPage |
|
138 | + * @param int|int[] $shareType |
|
139 | + * @param bool $lookup |
|
140 | + * @return DataResponse |
|
141 | + * @throws OCSBadRequestException |
|
142 | + */ |
|
143 | + public function search(string $search = '', string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = true): DataResponse { |
|
144 | + |
|
145 | + // only search for string larger than a given threshold |
|
146 | + $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
147 | + if (strlen($search) < $threshold) { |
|
148 | + return new DataResponse($this->result); |
|
149 | + } |
|
150 | + |
|
151 | + // never return more than the max. number of results configured in the config.php |
|
152 | + $maxResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
153 | + if ($maxResults > 0) { |
|
154 | + $perPage = min($perPage, $maxResults); |
|
155 | + } |
|
156 | + if ($perPage <= 0) { |
|
157 | + throw new OCSBadRequestException('Invalid perPage argument'); |
|
158 | + } |
|
159 | + if ($page <= 0) { |
|
160 | + throw new OCSBadRequestException('Invalid page'); |
|
161 | + } |
|
162 | + |
|
163 | + $shareTypes = [ |
|
164 | + IShare::TYPE_USER, |
|
165 | + ]; |
|
166 | + |
|
167 | + if ($itemType === null) { |
|
168 | + throw new OCSBadRequestException('Missing itemType'); |
|
169 | + } elseif ($itemType === 'file' || $itemType === 'folder') { |
|
170 | + if ($this->shareManager->allowGroupSharing()) { |
|
171 | + $shareTypes[] = IShare::TYPE_GROUP; |
|
172 | + } |
|
173 | + |
|
174 | + if ($this->isRemoteSharingAllowed($itemType)) { |
|
175 | + $shareTypes[] = IShare::TYPE_REMOTE; |
|
176 | + } |
|
177 | + |
|
178 | + if ($this->isRemoteGroupSharingAllowed($itemType)) { |
|
179 | + $shareTypes[] = IShare::TYPE_REMOTE_GROUP; |
|
180 | + } |
|
181 | + |
|
182 | + if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
183 | + $shareTypes[] = IShare::TYPE_EMAIL; |
|
184 | + } |
|
185 | + |
|
186 | + if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) { |
|
187 | + $shareTypes[] = IShare::TYPE_ROOM; |
|
188 | + } |
|
189 | + |
|
190 | + if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) { |
|
191 | + $shareTypes[] = IShare::TYPE_DECK; |
|
192 | + } |
|
193 | + } else { |
|
194 | + $shareTypes[] = IShare::TYPE_GROUP; |
|
195 | + $shareTypes[] = IShare::TYPE_EMAIL; |
|
196 | + } |
|
197 | + |
|
198 | + // FIXME: DI |
|
199 | + if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
200 | + $shareTypes[] = IShare::TYPE_CIRCLE; |
|
201 | + } |
|
202 | + |
|
203 | + if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) { |
|
204 | + $shareTypes[] = IShare::TYPE_DECK; |
|
205 | + } |
|
206 | + |
|
207 | + if ($shareType !== null && is_array($shareType)) { |
|
208 | + $shareTypes = array_intersect($shareTypes, $shareType); |
|
209 | + } elseif (is_numeric($shareType)) { |
|
210 | + $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
211 | + } |
|
212 | + sort($shareTypes); |
|
213 | + |
|
214 | + $this->limit = (int) $perPage; |
|
215 | + $this->offset = $perPage * ($page - 1); |
|
216 | + |
|
217 | + // In global scale mode we always search the loogup server |
|
218 | + if ($this->config->getSystemValueBool('gs.enabled', false)) { |
|
219 | + $lookup = true; |
|
220 | + $this->result['lookupEnabled'] = true; |
|
221 | + } else { |
|
222 | + $this->result['lookupEnabled'] = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes'; |
|
223 | + } |
|
224 | + |
|
225 | + list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset); |
|
226 | + |
|
227 | + // extra treatment for 'exact' subarray, with a single merge expected keys might be lost |
|
228 | + if (isset($result['exact'])) { |
|
229 | + $result['exact'] = array_merge($this->result['exact'], $result['exact']); |
|
230 | + } |
|
231 | + $this->result = array_merge($this->result, $result); |
|
232 | + $response = new DataResponse($this->result); |
|
233 | + |
|
234 | + if ($hasMoreResults) { |
|
235 | + $response->addHeader('Link', $this->getPaginationLink($page, [ |
|
236 | + 'search' => $search, |
|
237 | + 'itemType' => $itemType, |
|
238 | + 'shareType' => $shareTypes, |
|
239 | + 'perPage' => $perPage, |
|
240 | + ])); |
|
241 | + } |
|
242 | + |
|
243 | + return $response; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @param string $user |
|
248 | + * @param int $shareType |
|
249 | + * |
|
250 | + * @return Generator<array<string>> |
|
251 | + */ |
|
252 | + private function getAllShareesByType(string $user, int $shareType): Generator { |
|
253 | + $offset = 0; |
|
254 | + $pageSize = 50; |
|
255 | + |
|
256 | + while (count($page = $this->shareManager->getSharesBy( |
|
257 | + $user, |
|
258 | + $shareType, |
|
259 | + null, |
|
260 | + false, |
|
261 | + $pageSize, |
|
262 | + $offset |
|
263 | + ))) { |
|
264 | + foreach ($page as $share) { |
|
265 | + yield [$share->getSharedWith(), $share->getSharedWithDisplayName() ?? $share->getSharedWith()]; |
|
266 | + } |
|
267 | + |
|
268 | + $offset += $pageSize; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + private function sortShareesByFrequency(array $sharees): array { |
|
273 | + usort($sharees, function (array $s1, array $s2) { |
|
274 | + return $s2['count'] - $s1['count']; |
|
275 | + }); |
|
276 | + return $sharees; |
|
277 | + } |
|
278 | + |
|
279 | + private $searchResultTypeMap = [ |
|
280 | + IShare::TYPE_USER => 'users', |
|
281 | + IShare::TYPE_GROUP => 'groups', |
|
282 | + IShare::TYPE_REMOTE => 'remotes', |
|
283 | + IShare::TYPE_REMOTE_GROUP => 'remote_groups', |
|
284 | + IShare::TYPE_EMAIL => 'emails', |
|
285 | + ]; |
|
286 | + |
|
287 | + private function getAllSharees(string $user, array $shareTypes): ISearchResult { |
|
288 | + $result = []; |
|
289 | + foreach ($shareTypes as $shareType) { |
|
290 | + $sharees = $this->getAllShareesByType($user, $shareType); |
|
291 | + $shareTypeResults = []; |
|
292 | + foreach ($sharees as list($sharee, $displayname)) { |
|
293 | + if (!isset($this->searchResultTypeMap[$shareType])) { |
|
294 | + continue; |
|
295 | + } |
|
296 | + |
|
297 | + if (!isset($shareTypeResults[$sharee])) { |
|
298 | + $shareTypeResults[$sharee] = [ |
|
299 | + 'count' => 1, |
|
300 | + 'label' => $displayname, |
|
301 | + 'value' => [ |
|
302 | + 'shareType' => $shareType, |
|
303 | + 'shareWith' => $sharee, |
|
304 | + ], |
|
305 | + ]; |
|
306 | + } else { |
|
307 | + $shareTypeResults[$sharee]['count']++; |
|
308 | + } |
|
309 | + } |
|
310 | + $result = array_merge($result, array_values($shareTypeResults)); |
|
311 | + } |
|
312 | + |
|
313 | + $top5 = array_slice( |
|
314 | + $this->sortShareesByFrequency($result), |
|
315 | + 0, |
|
316 | + 5 |
|
317 | + ); |
|
318 | + |
|
319 | + $searchResult = new SearchResult(); |
|
320 | + foreach ($this->searchResultTypeMap as $int => $str) { |
|
321 | + $searchResult->addResultSet(new SearchResultType($str), [], []); |
|
322 | + foreach ($top5 as $x) { |
|
323 | + if ($x['value']['shareType'] === $int) { |
|
324 | + $searchResult->addResultSet(new SearchResultType($str), [], [$x]); |
|
325 | + } |
|
326 | + } |
|
327 | + } |
|
328 | + return $searchResult; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @NoAdminRequired |
|
333 | + * |
|
334 | + * @param string $itemType |
|
335 | + * @return DataResponse |
|
336 | + * @throws OCSBadRequestException |
|
337 | + */ |
|
338 | + public function findRecommended(string $itemType = null, $shareType = null): DataResponse { |
|
339 | + $shareTypes = [ |
|
340 | + IShare::TYPE_USER, |
|
341 | + ]; |
|
342 | + |
|
343 | + if ($itemType === null) { |
|
344 | + throw new OCSBadRequestException('Missing itemType'); |
|
345 | + } elseif ($itemType === 'file' || $itemType === 'folder') { |
|
346 | + if ($this->shareManager->allowGroupSharing()) { |
|
347 | + $shareTypes[] = IShare::TYPE_GROUP; |
|
348 | + } |
|
349 | + |
|
350 | + if ($this->isRemoteSharingAllowed($itemType)) { |
|
351 | + $shareTypes[] = IShare::TYPE_REMOTE; |
|
352 | + } |
|
353 | + |
|
354 | + if ($this->isRemoteGroupSharingAllowed($itemType)) { |
|
355 | + $shareTypes[] = IShare::TYPE_REMOTE_GROUP; |
|
356 | + } |
|
357 | + |
|
358 | + if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) { |
|
359 | + $shareTypes[] = IShare::TYPE_EMAIL; |
|
360 | + } |
|
361 | + |
|
362 | + if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) { |
|
363 | + $shareTypes[] = IShare::TYPE_ROOM; |
|
364 | + } |
|
365 | + } else { |
|
366 | + $shareTypes[] = IShare::TYPE_GROUP; |
|
367 | + $shareTypes[] = IShare::TYPE_EMAIL; |
|
368 | + } |
|
369 | + |
|
370 | + // FIXME: DI |
|
371 | + if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
372 | + $shareTypes[] = IShare::TYPE_CIRCLE; |
|
373 | + } |
|
374 | + |
|
375 | + if (isset($_GET['shareType']) && is_array($_GET['shareType'])) { |
|
376 | + $shareTypes = array_intersect($shareTypes, $_GET['shareType']); |
|
377 | + sort($shareTypes); |
|
378 | + } elseif (is_numeric($shareType)) { |
|
379 | + $shareTypes = array_intersect($shareTypes, [(int) $shareType]); |
|
380 | + sort($shareTypes); |
|
381 | + } |
|
382 | + |
|
383 | + return new DataResponse( |
|
384 | + $this->getAllSharees($this->userId, $shareTypes)->asArray() |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Method to get out the static call for better testing |
|
390 | + * |
|
391 | + * @param string $itemType |
|
392 | + * @return bool |
|
393 | + */ |
|
394 | + protected function isRemoteSharingAllowed(string $itemType): bool { |
|
395 | + try { |
|
396 | + // FIXME: static foo makes unit testing unnecessarily difficult |
|
397 | + $backend = \OC\Share\Share::getBackend($itemType); |
|
398 | + return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE); |
|
399 | + } catch (\Exception $e) { |
|
400 | + return false; |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + protected function isRemoteGroupSharingAllowed(string $itemType): bool { |
|
405 | + try { |
|
406 | + // FIXME: static foo makes unit testing unnecessarily difficult |
|
407 | + $backend = \OC\Share\Share::getBackend($itemType); |
|
408 | + return $backend->isShareTypeAllowed(IShare::TYPE_REMOTE_GROUP); |
|
409 | + } catch (\Exception $e) { |
|
410 | + return false; |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * Generates a bunch of pagination links for the current page |
|
417 | + * |
|
418 | + * @param int $page Current page |
|
419 | + * @param array $params Parameters for the URL |
|
420 | + * @return string |
|
421 | + */ |
|
422 | + protected function getPaginationLink(int $page, array $params): string { |
|
423 | + if ($this->isV2()) { |
|
424 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
425 | + } else { |
|
426 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
427 | + } |
|
428 | + $params['page'] = $page + 1; |
|
429 | + return '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * @return bool |
|
434 | + */ |
|
435 | + protected function isV2(): bool { |
|
436 | + return $this->request->getScriptName() === '/ocs/v2.php'; |
|
437 | + } |
|
438 | 438 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function search(string $search = '', string $itemType = null, int $page = 1, int $perPage = 200, $shareType = null, bool $lookup = true): DataResponse { |
144 | 144 | |
145 | 145 | // only search for string larger than a given threshold |
146 | - $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
146 | + $threshold = (int) $this->config->getSystemValue('sharing.minSearchStringLength', 0); |
|
147 | 147 | if (strlen($search) < $threshold) { |
148 | 148 | return new DataResponse($this->result); |
149 | 149 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | private function sortShareesByFrequency(array $sharees): array { |
273 | - usort($sharees, function (array $s1, array $s2) { |
|
273 | + usort($sharees, function(array $s1, array $s2) { |
|
274 | 274 | return $s2['count'] - $s1['count']; |
275 | 275 | }); |
276 | 276 | return $sharees; |
@@ -421,12 +421,12 @@ discard block |
||
421 | 421 | */ |
422 | 422 | protected function getPaginationLink(int $page, array $params): string { |
423 | 423 | if ($this->isV2()) { |
424 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
424 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees').'?'; |
|
425 | 425 | } else { |
426 | - $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?'; |
|
426 | + $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees').'?'; |
|
427 | 427 | } |
428 | 428 | $params['page'] = $page + 1; |
429 | - return '<' . $url . http_build_query($params) . '>; rel="next"'; |
|
429 | + return '<'.$url.http_build_query($params).'>; rel="next"'; |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -34,90 +34,90 @@ |
||
34 | 34 | |
35 | 35 | class Manager { |
36 | 36 | |
37 | - /** @var ContactsStore */ |
|
38 | - private $store; |
|
37 | + /** @var ContactsStore */ |
|
38 | + private $store; |
|
39 | 39 | |
40 | - /** @var ActionProviderStore */ |
|
41 | - private $actionProviderStore; |
|
40 | + /** @var ActionProviderStore */ |
|
41 | + private $actionProviderStore; |
|
42 | 42 | |
43 | - /** @var IAppManager */ |
|
44 | - private $appManager; |
|
43 | + /** @var IAppManager */ |
|
44 | + private $appManager; |
|
45 | 45 | |
46 | - /** @var IConfig */ |
|
47 | - private $config; |
|
46 | + /** @var IConfig */ |
|
47 | + private $config; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param ContactsStore $store |
|
51 | - * @param ActionProviderStore $actionProviderStore |
|
52 | - * @param IAppManager $appManager |
|
53 | - */ |
|
54 | - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
55 | - $this->store = $store; |
|
56 | - $this->actionProviderStore = $actionProviderStore; |
|
57 | - $this->appManager = $appManager; |
|
58 | - $this->config = $config; |
|
59 | - } |
|
49 | + /** |
|
50 | + * @param ContactsStore $store |
|
51 | + * @param ActionProviderStore $actionProviderStore |
|
52 | + * @param IAppManager $appManager |
|
53 | + */ |
|
54 | + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
55 | + $this->store = $store; |
|
56 | + $this->actionProviderStore = $actionProviderStore; |
|
57 | + $this->appManager = $appManager; |
|
58 | + $this->config = $config; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param IUser $user |
|
63 | - * @param string $filter |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function getEntries(IUser $user, $filter) { |
|
67 | - $maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)); |
|
68 | - $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
69 | - $topEntries = []; |
|
70 | - if (strlen($filter) >= $minSearchStringLength) { |
|
71 | - $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
61 | + /** |
|
62 | + * @param IUser $user |
|
63 | + * @param string $filter |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function getEntries(IUser $user, $filter) { |
|
67 | + $maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)); |
|
68 | + $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
69 | + $topEntries = []; |
|
70 | + if (strlen($filter) >= $minSearchStringLength) { |
|
71 | + $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
72 | 72 | |
73 | - $sortedEntries = $this->sortEntries($entries); |
|
74 | - $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
75 | - $this->processEntries($topEntries, $user); |
|
76 | - } |
|
73 | + $sortedEntries = $this->sortEntries($entries); |
|
74 | + $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
75 | + $this->processEntries($topEntries, $user); |
|
76 | + } |
|
77 | 77 | |
78 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
79 | - return [ |
|
80 | - 'contacts' => $topEntries, |
|
81 | - 'contactsAppEnabled' => $contactsEnabled, |
|
82 | - ]; |
|
83 | - } |
|
78 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
79 | + return [ |
|
80 | + 'contacts' => $topEntries, |
|
81 | + 'contactsAppEnabled' => $contactsEnabled, |
|
82 | + ]; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param IUser $user |
|
87 | - * @param integer $shareType |
|
88 | - * @param string $shareWith |
|
89 | - * @return IEntry |
|
90 | - */ |
|
91 | - public function findOne(IUser $user, $shareType, $shareWith) { |
|
92 | - $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
93 | - if ($entry) { |
|
94 | - $this->processEntries([$entry], $user); |
|
95 | - } |
|
85 | + /** |
|
86 | + * @param IUser $user |
|
87 | + * @param integer $shareType |
|
88 | + * @param string $shareWith |
|
89 | + * @return IEntry |
|
90 | + */ |
|
91 | + public function findOne(IUser $user, $shareType, $shareWith) { |
|
92 | + $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
93 | + if ($entry) { |
|
94 | + $this->processEntries([$entry], $user); |
|
95 | + } |
|
96 | 96 | |
97 | - return $entry; |
|
98 | - } |
|
97 | + return $entry; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param IEntry[] $entries |
|
102 | - * @return IEntry[] |
|
103 | - */ |
|
104 | - private function sortEntries(array $entries) { |
|
105 | - usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
106 | - return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
107 | - }); |
|
108 | - return $entries; |
|
109 | - } |
|
100 | + /** |
|
101 | + * @param IEntry[] $entries |
|
102 | + * @return IEntry[] |
|
103 | + */ |
|
104 | + private function sortEntries(array $entries) { |
|
105 | + usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
106 | + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
107 | + }); |
|
108 | + return $entries; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @param IEntry[] $entries |
|
113 | - * @param IUser $user |
|
114 | - */ |
|
115 | - private function processEntries(array $entries, IUser $user) { |
|
116 | - $providers = $this->actionProviderStore->getProviders($user); |
|
117 | - foreach ($entries as $entry) { |
|
118 | - foreach ($providers as $provider) { |
|
119 | - $provider->process($entry); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
111 | + /** |
|
112 | + * @param IEntry[] $entries |
|
113 | + * @param IUser $user |
|
114 | + */ |
|
115 | + private function processEntries(array $entries, IUser $user) { |
|
116 | + $providers = $this->actionProviderStore->getProviders($user); |
|
117 | + foreach ($entries as $entry) { |
|
118 | + foreach ($providers as $provider) { |
|
119 | + $provider->process($entry); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |
@@ -46,277 +46,277 @@ |
||
46 | 46 | |
47 | 47 | class JSConfigHelper { |
48 | 48 | |
49 | - /** @var IL10N */ |
|
50 | - private $l; |
|
51 | - |
|
52 | - /** @var Defaults */ |
|
53 | - private $defaults; |
|
54 | - |
|
55 | - /** @var IAppManager */ |
|
56 | - private $appManager; |
|
57 | - |
|
58 | - /** @var ISession */ |
|
59 | - private $session; |
|
60 | - |
|
61 | - /** @var IUser|null */ |
|
62 | - private $currentUser; |
|
63 | - |
|
64 | - /** @var IConfig */ |
|
65 | - private $config; |
|
66 | - |
|
67 | - /** @var IGroupManager */ |
|
68 | - private $groupManager; |
|
69 | - |
|
70 | - /** @var IniGetWrapper */ |
|
71 | - private $iniWrapper; |
|
72 | - |
|
73 | - /** @var IURLGenerator */ |
|
74 | - private $urlGenerator; |
|
75 | - |
|
76 | - /** @var CapabilitiesManager */ |
|
77 | - private $capabilitiesManager; |
|
78 | - |
|
79 | - /** @var IInitialStateService */ |
|
80 | - private $initialStateService; |
|
81 | - |
|
82 | - /** @var array user back-ends excluded from password verification */ |
|
83 | - private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
84 | - |
|
85 | - /** |
|
86 | - * @param IL10N $l |
|
87 | - * @param Defaults $defaults |
|
88 | - * @param IAppManager $appManager |
|
89 | - * @param ISession $session |
|
90 | - * @param IUser|null $currentUser |
|
91 | - * @param IConfig $config |
|
92 | - * @param IGroupManager $groupManager |
|
93 | - * @param IniGetWrapper $iniWrapper |
|
94 | - * @param IURLGenerator $urlGenerator |
|
95 | - * @param CapabilitiesManager $capabilitiesManager |
|
96 | - */ |
|
97 | - public function __construct(IL10N $l, |
|
98 | - Defaults $defaults, |
|
99 | - IAppManager $appManager, |
|
100 | - ISession $session, |
|
101 | - $currentUser, |
|
102 | - IConfig $config, |
|
103 | - IGroupManager $groupManager, |
|
104 | - IniGetWrapper $iniWrapper, |
|
105 | - IURLGenerator $urlGenerator, |
|
106 | - CapabilitiesManager $capabilitiesManager, |
|
107 | - IInitialStateService $initialStateService) { |
|
108 | - $this->l = $l; |
|
109 | - $this->defaults = $defaults; |
|
110 | - $this->appManager = $appManager; |
|
111 | - $this->session = $session; |
|
112 | - $this->currentUser = $currentUser; |
|
113 | - $this->config = $config; |
|
114 | - $this->groupManager = $groupManager; |
|
115 | - $this->iniWrapper = $iniWrapper; |
|
116 | - $this->urlGenerator = $urlGenerator; |
|
117 | - $this->capabilitiesManager = $capabilitiesManager; |
|
118 | - $this->initialStateService = $initialStateService; |
|
119 | - } |
|
120 | - |
|
121 | - public function getConfig() { |
|
122 | - $userBackendAllowsPasswordConfirmation = true; |
|
123 | - if ($this->currentUser !== null) { |
|
124 | - $uid = $this->currentUser->getUID(); |
|
125 | - |
|
126 | - $backend = $this->currentUser->getBackend(); |
|
127 | - if ($backend instanceof IPasswordConfirmationBackend) { |
|
128 | - $userBackendAllowsPasswordConfirmation = $backend->canConfirmPassword($uid); |
|
129 | - } elseif (isset($this->excludedUserBackEnds[$this->currentUser->getBackendClassName()])) { |
|
130 | - $userBackendAllowsPasswordConfirmation = false; |
|
131 | - } |
|
132 | - } else { |
|
133 | - $uid = null; |
|
134 | - } |
|
135 | - |
|
136 | - // Get the config |
|
137 | - $apps_paths = []; |
|
138 | - |
|
139 | - if ($this->currentUser === null) { |
|
140 | - $apps = $this->appManager->getInstalledApps(); |
|
141 | - } else { |
|
142 | - $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
143 | - } |
|
144 | - |
|
145 | - foreach ($apps as $app) { |
|
146 | - $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
151 | - $enableLinkPasswordByDefault = $enableLinkPasswordByDefault === 'yes'; |
|
152 | - $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
153 | - $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
154 | - if ($defaultExpireDateEnabled) { |
|
155 | - $defaultExpireDate = (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
156 | - $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
157 | - } |
|
158 | - $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
159 | - |
|
160 | - $defaultInternalExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
161 | - $defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null; |
|
162 | - if ($defaultInternalExpireDateEnabled) { |
|
163 | - $defaultInternalExpireDate = (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
164 | - $defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
165 | - } |
|
166 | - |
|
167 | - $countOfDataLocation = 0; |
|
168 | - $dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
169 | - if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
170 | - $dataLocation = false; |
|
171 | - } |
|
172 | - |
|
173 | - if ($this->currentUser instanceof IUser) { |
|
174 | - $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
175 | - if (!is_int($lastConfirmTimestamp)) { |
|
176 | - $lastConfirmTimestamp = 0; |
|
177 | - } |
|
178 | - } else { |
|
179 | - $lastConfirmTimestamp = 0; |
|
180 | - } |
|
181 | - |
|
182 | - $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
183 | - |
|
184 | - $config = [ |
|
185 | - 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
186 | - 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
187 | - 'auto_logout' => $this->config->getSystemValue('auto_logout', false), |
|
188 | - 'version' => implode('.', \OCP\Util::getVersion()), |
|
189 | - 'versionstring' => \OC_Util::getVersionString(), |
|
190 | - 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
191 | - 'lost_password_link' => $this->config->getSystemValue('lost_password_link', null), |
|
192 | - 'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true', |
|
193 | - 'sharing.maxAutocompleteResults' => max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)), |
|
194 | - 'sharing.minSearchStringLength' => $this->config->getSystemValueInt('sharing.minSearchStringLength', 0), |
|
195 | - 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
196 | - ]; |
|
197 | - |
|
198 | - $array = [ |
|
199 | - "_oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
200 | - "_oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
201 | - "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', |
|
202 | - "oc_dataURL" => is_string($dataLocation) ? "\"" . $dataLocation . "\"" : 'false', |
|
203 | - "_oc_webroot" => "\"" . \OC::$WEBROOT . "\"", |
|
204 | - "_oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
205 | - "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
206 | - 'nc_lastLogin' => $lastConfirmTimestamp, |
|
207 | - 'nc_pageLoad' => time(), |
|
208 | - "dayNames" => json_encode([ |
|
209 | - (string)$this->l->t('Sunday'), |
|
210 | - (string)$this->l->t('Monday'), |
|
211 | - (string)$this->l->t('Tuesday'), |
|
212 | - (string)$this->l->t('Wednesday'), |
|
213 | - (string)$this->l->t('Thursday'), |
|
214 | - (string)$this->l->t('Friday'), |
|
215 | - (string)$this->l->t('Saturday') |
|
216 | - ]), |
|
217 | - "dayNamesShort" => json_encode([ |
|
218 | - (string)$this->l->t('Sun.'), |
|
219 | - (string)$this->l->t('Mon.'), |
|
220 | - (string)$this->l->t('Tue.'), |
|
221 | - (string)$this->l->t('Wed.'), |
|
222 | - (string)$this->l->t('Thu.'), |
|
223 | - (string)$this->l->t('Fri.'), |
|
224 | - (string)$this->l->t('Sat.') |
|
225 | - ]), |
|
226 | - "dayNamesMin" => json_encode([ |
|
227 | - (string)$this->l->t('Su'), |
|
228 | - (string)$this->l->t('Mo'), |
|
229 | - (string)$this->l->t('Tu'), |
|
230 | - (string)$this->l->t('We'), |
|
231 | - (string)$this->l->t('Th'), |
|
232 | - (string)$this->l->t('Fr'), |
|
233 | - (string)$this->l->t('Sa') |
|
234 | - ]), |
|
235 | - "monthNames" => json_encode([ |
|
236 | - (string)$this->l->t('January'), |
|
237 | - (string)$this->l->t('February'), |
|
238 | - (string)$this->l->t('March'), |
|
239 | - (string)$this->l->t('April'), |
|
240 | - (string)$this->l->t('May'), |
|
241 | - (string)$this->l->t('June'), |
|
242 | - (string)$this->l->t('July'), |
|
243 | - (string)$this->l->t('August'), |
|
244 | - (string)$this->l->t('September'), |
|
245 | - (string)$this->l->t('October'), |
|
246 | - (string)$this->l->t('November'), |
|
247 | - (string)$this->l->t('December') |
|
248 | - ]), |
|
249 | - "monthNamesShort" => json_encode([ |
|
250 | - (string)$this->l->t('Jan.'), |
|
251 | - (string)$this->l->t('Feb.'), |
|
252 | - (string)$this->l->t('Mar.'), |
|
253 | - (string)$this->l->t('Apr.'), |
|
254 | - (string)$this->l->t('May.'), |
|
255 | - (string)$this->l->t('Jun.'), |
|
256 | - (string)$this->l->t('Jul.'), |
|
257 | - (string)$this->l->t('Aug.'), |
|
258 | - (string)$this->l->t('Sep.'), |
|
259 | - (string)$this->l->t('Oct.'), |
|
260 | - (string)$this->l->t('Nov.'), |
|
261 | - (string)$this->l->t('Dec.') |
|
262 | - ]), |
|
263 | - "firstDay" => json_encode($this->l->l('firstday', null)), |
|
264 | - "_oc_config" => json_encode($config), |
|
265 | - "oc_appconfig" => json_encode([ |
|
266 | - 'core' => [ |
|
267 | - 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
268 | - 'defaultExpireDate' => $defaultExpireDate, |
|
269 | - 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
270 | - 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
271 | - 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
272 | - 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
273 | - 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
274 | - 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
275 | - 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
276 | - 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(), |
|
277 | - 'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled, |
|
278 | - 'defaultInternalExpireDate' => $defaultInternalExpireDate, |
|
279 | - 'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced, |
|
280 | - ] |
|
281 | - ]), |
|
282 | - "_theme" => json_encode([ |
|
283 | - 'entity' => $this->defaults->getEntity(), |
|
284 | - 'name' => $this->defaults->getName(), |
|
285 | - 'title' => $this->defaults->getTitle(), |
|
286 | - 'baseUrl' => $this->defaults->getBaseUrl(), |
|
287 | - 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
288 | - 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
289 | - 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
290 | - 'slogan' => $this->defaults->getSlogan(), |
|
291 | - 'logoClaim' => '', |
|
292 | - 'shortFooter' => $this->defaults->getShortFooter(), |
|
293 | - 'longFooter' => $this->defaults->getLongFooter(), |
|
294 | - 'folder' => \OC_Util::getTheme(), |
|
295 | - ]), |
|
296 | - ]; |
|
297 | - |
|
298 | - if ($this->currentUser !== null) { |
|
299 | - $array['oc_userconfig'] = json_encode([ |
|
300 | - 'avatar' => [ |
|
301 | - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
302 | - 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', |
|
303 | - ] |
|
304 | - ]); |
|
305 | - } |
|
306 | - |
|
307 | - $this->initialStateService->provideInitialState('core', 'config', $config); |
|
308 | - $this->initialStateService->provideInitialState('core', 'capabilities', $capabilities); |
|
309 | - |
|
310 | - // Allow hooks to modify the output values |
|
311 | - \OC_Hook::emit('\OCP\Config', 'js', ['array' => &$array]); |
|
312 | - |
|
313 | - $result = ''; |
|
314 | - |
|
315 | - // Echo it |
|
316 | - foreach ($array as $setting => $value) { |
|
317 | - $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
318 | - } |
|
319 | - |
|
320 | - return $result; |
|
321 | - } |
|
49 | + /** @var IL10N */ |
|
50 | + private $l; |
|
51 | + |
|
52 | + /** @var Defaults */ |
|
53 | + private $defaults; |
|
54 | + |
|
55 | + /** @var IAppManager */ |
|
56 | + private $appManager; |
|
57 | + |
|
58 | + /** @var ISession */ |
|
59 | + private $session; |
|
60 | + |
|
61 | + /** @var IUser|null */ |
|
62 | + private $currentUser; |
|
63 | + |
|
64 | + /** @var IConfig */ |
|
65 | + private $config; |
|
66 | + |
|
67 | + /** @var IGroupManager */ |
|
68 | + private $groupManager; |
|
69 | + |
|
70 | + /** @var IniGetWrapper */ |
|
71 | + private $iniWrapper; |
|
72 | + |
|
73 | + /** @var IURLGenerator */ |
|
74 | + private $urlGenerator; |
|
75 | + |
|
76 | + /** @var CapabilitiesManager */ |
|
77 | + private $capabilitiesManager; |
|
78 | + |
|
79 | + /** @var IInitialStateService */ |
|
80 | + private $initialStateService; |
|
81 | + |
|
82 | + /** @var array user back-ends excluded from password verification */ |
|
83 | + private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
84 | + |
|
85 | + /** |
|
86 | + * @param IL10N $l |
|
87 | + * @param Defaults $defaults |
|
88 | + * @param IAppManager $appManager |
|
89 | + * @param ISession $session |
|
90 | + * @param IUser|null $currentUser |
|
91 | + * @param IConfig $config |
|
92 | + * @param IGroupManager $groupManager |
|
93 | + * @param IniGetWrapper $iniWrapper |
|
94 | + * @param IURLGenerator $urlGenerator |
|
95 | + * @param CapabilitiesManager $capabilitiesManager |
|
96 | + */ |
|
97 | + public function __construct(IL10N $l, |
|
98 | + Defaults $defaults, |
|
99 | + IAppManager $appManager, |
|
100 | + ISession $session, |
|
101 | + $currentUser, |
|
102 | + IConfig $config, |
|
103 | + IGroupManager $groupManager, |
|
104 | + IniGetWrapper $iniWrapper, |
|
105 | + IURLGenerator $urlGenerator, |
|
106 | + CapabilitiesManager $capabilitiesManager, |
|
107 | + IInitialStateService $initialStateService) { |
|
108 | + $this->l = $l; |
|
109 | + $this->defaults = $defaults; |
|
110 | + $this->appManager = $appManager; |
|
111 | + $this->session = $session; |
|
112 | + $this->currentUser = $currentUser; |
|
113 | + $this->config = $config; |
|
114 | + $this->groupManager = $groupManager; |
|
115 | + $this->iniWrapper = $iniWrapper; |
|
116 | + $this->urlGenerator = $urlGenerator; |
|
117 | + $this->capabilitiesManager = $capabilitiesManager; |
|
118 | + $this->initialStateService = $initialStateService; |
|
119 | + } |
|
120 | + |
|
121 | + public function getConfig() { |
|
122 | + $userBackendAllowsPasswordConfirmation = true; |
|
123 | + if ($this->currentUser !== null) { |
|
124 | + $uid = $this->currentUser->getUID(); |
|
125 | + |
|
126 | + $backend = $this->currentUser->getBackend(); |
|
127 | + if ($backend instanceof IPasswordConfirmationBackend) { |
|
128 | + $userBackendAllowsPasswordConfirmation = $backend->canConfirmPassword($uid); |
|
129 | + } elseif (isset($this->excludedUserBackEnds[$this->currentUser->getBackendClassName()])) { |
|
130 | + $userBackendAllowsPasswordConfirmation = false; |
|
131 | + } |
|
132 | + } else { |
|
133 | + $uid = null; |
|
134 | + } |
|
135 | + |
|
136 | + // Get the config |
|
137 | + $apps_paths = []; |
|
138 | + |
|
139 | + if ($this->currentUser === null) { |
|
140 | + $apps = $this->appManager->getInstalledApps(); |
|
141 | + } else { |
|
142 | + $apps = $this->appManager->getEnabledAppsForUser($this->currentUser); |
|
143 | + } |
|
144 | + |
|
145 | + foreach ($apps as $app) { |
|
146 | + $apps_paths[$app] = \OC_App::getAppWebPath($app); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + $enableLinkPasswordByDefault = $this->config->getAppValue('core', 'shareapi_enable_link_password_by_default', 'no'); |
|
151 | + $enableLinkPasswordByDefault = $enableLinkPasswordByDefault === 'yes'; |
|
152 | + $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
153 | + $defaultExpireDate = $enforceDefaultExpireDate = null; |
|
154 | + if ($defaultExpireDateEnabled) { |
|
155 | + $defaultExpireDate = (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
156 | + $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
157 | + } |
|
158 | + $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
|
159 | + |
|
160 | + $defaultInternalExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
|
161 | + $defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null; |
|
162 | + if ($defaultInternalExpireDateEnabled) { |
|
163 | + $defaultInternalExpireDate = (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
164 | + $defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
|
165 | + } |
|
166 | + |
|
167 | + $countOfDataLocation = 0; |
|
168 | + $dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
169 | + if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
|
170 | + $dataLocation = false; |
|
171 | + } |
|
172 | + |
|
173 | + if ($this->currentUser instanceof IUser) { |
|
174 | + $lastConfirmTimestamp = $this->session->get('last-password-confirm'); |
|
175 | + if (!is_int($lastConfirmTimestamp)) { |
|
176 | + $lastConfirmTimestamp = 0; |
|
177 | + } |
|
178 | + } else { |
|
179 | + $lastConfirmTimestamp = 0; |
|
180 | + } |
|
181 | + |
|
182 | + $capabilities = $this->capabilitiesManager->getCapabilities(); |
|
183 | + |
|
184 | + $config = [ |
|
185 | + 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), |
|
186 | + 'session_keepalive' => $this->config->getSystemValue('session_keepalive', true), |
|
187 | + 'auto_logout' => $this->config->getSystemValue('auto_logout', false), |
|
188 | + 'version' => implode('.', \OCP\Util::getVersion()), |
|
189 | + 'versionstring' => \OC_Util::getVersionString(), |
|
190 | + 'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value |
|
191 | + 'lost_password_link' => $this->config->getSystemValue('lost_password_link', null), |
|
192 | + 'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true', |
|
193 | + 'sharing.maxAutocompleteResults' => max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)), |
|
194 | + 'sharing.minSearchStringLength' => $this->config->getSystemValueInt('sharing.minSearchStringLength', 0), |
|
195 | + 'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX, |
|
196 | + ]; |
|
197 | + |
|
198 | + $array = [ |
|
199 | + "_oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
|
200 | + "_oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
|
201 | + "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', |
|
202 | + "oc_dataURL" => is_string($dataLocation) ? "\"" . $dataLocation . "\"" : 'false', |
|
203 | + "_oc_webroot" => "\"" . \OC::$WEBROOT . "\"", |
|
204 | + "_oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
|
205 | + "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
|
206 | + 'nc_lastLogin' => $lastConfirmTimestamp, |
|
207 | + 'nc_pageLoad' => time(), |
|
208 | + "dayNames" => json_encode([ |
|
209 | + (string)$this->l->t('Sunday'), |
|
210 | + (string)$this->l->t('Monday'), |
|
211 | + (string)$this->l->t('Tuesday'), |
|
212 | + (string)$this->l->t('Wednesday'), |
|
213 | + (string)$this->l->t('Thursday'), |
|
214 | + (string)$this->l->t('Friday'), |
|
215 | + (string)$this->l->t('Saturday') |
|
216 | + ]), |
|
217 | + "dayNamesShort" => json_encode([ |
|
218 | + (string)$this->l->t('Sun.'), |
|
219 | + (string)$this->l->t('Mon.'), |
|
220 | + (string)$this->l->t('Tue.'), |
|
221 | + (string)$this->l->t('Wed.'), |
|
222 | + (string)$this->l->t('Thu.'), |
|
223 | + (string)$this->l->t('Fri.'), |
|
224 | + (string)$this->l->t('Sat.') |
|
225 | + ]), |
|
226 | + "dayNamesMin" => json_encode([ |
|
227 | + (string)$this->l->t('Su'), |
|
228 | + (string)$this->l->t('Mo'), |
|
229 | + (string)$this->l->t('Tu'), |
|
230 | + (string)$this->l->t('We'), |
|
231 | + (string)$this->l->t('Th'), |
|
232 | + (string)$this->l->t('Fr'), |
|
233 | + (string)$this->l->t('Sa') |
|
234 | + ]), |
|
235 | + "monthNames" => json_encode([ |
|
236 | + (string)$this->l->t('January'), |
|
237 | + (string)$this->l->t('February'), |
|
238 | + (string)$this->l->t('March'), |
|
239 | + (string)$this->l->t('April'), |
|
240 | + (string)$this->l->t('May'), |
|
241 | + (string)$this->l->t('June'), |
|
242 | + (string)$this->l->t('July'), |
|
243 | + (string)$this->l->t('August'), |
|
244 | + (string)$this->l->t('September'), |
|
245 | + (string)$this->l->t('October'), |
|
246 | + (string)$this->l->t('November'), |
|
247 | + (string)$this->l->t('December') |
|
248 | + ]), |
|
249 | + "monthNamesShort" => json_encode([ |
|
250 | + (string)$this->l->t('Jan.'), |
|
251 | + (string)$this->l->t('Feb.'), |
|
252 | + (string)$this->l->t('Mar.'), |
|
253 | + (string)$this->l->t('Apr.'), |
|
254 | + (string)$this->l->t('May.'), |
|
255 | + (string)$this->l->t('Jun.'), |
|
256 | + (string)$this->l->t('Jul.'), |
|
257 | + (string)$this->l->t('Aug.'), |
|
258 | + (string)$this->l->t('Sep.'), |
|
259 | + (string)$this->l->t('Oct.'), |
|
260 | + (string)$this->l->t('Nov.'), |
|
261 | + (string)$this->l->t('Dec.') |
|
262 | + ]), |
|
263 | + "firstDay" => json_encode($this->l->l('firstday', null)), |
|
264 | + "_oc_config" => json_encode($config), |
|
265 | + "oc_appconfig" => json_encode([ |
|
266 | + 'core' => [ |
|
267 | + 'defaultExpireDateEnabled' => $defaultExpireDateEnabled, |
|
268 | + 'defaultExpireDate' => $defaultExpireDate, |
|
269 | + 'defaultExpireDateEnforced' => $enforceDefaultExpireDate, |
|
270 | + 'enforcePasswordForPublicLink' => \OCP\Util::isPublicLinkPasswordRequired(), |
|
271 | + 'enableLinkPasswordByDefault' => $enableLinkPasswordByDefault, |
|
272 | + 'sharingDisabledForUser' => \OCP\Util::isSharingDisabledForUser(), |
|
273 | + 'resharingAllowed' => \OC\Share\Share::isResharingAllowed(), |
|
274 | + 'remoteShareAllowed' => $outgoingServer2serverShareEnabled, |
|
275 | + 'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'), |
|
276 | + 'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(), |
|
277 | + 'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled, |
|
278 | + 'defaultInternalExpireDate' => $defaultInternalExpireDate, |
|
279 | + 'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced, |
|
280 | + ] |
|
281 | + ]), |
|
282 | + "_theme" => json_encode([ |
|
283 | + 'entity' => $this->defaults->getEntity(), |
|
284 | + 'name' => $this->defaults->getName(), |
|
285 | + 'title' => $this->defaults->getTitle(), |
|
286 | + 'baseUrl' => $this->defaults->getBaseUrl(), |
|
287 | + 'syncClientUrl' => $this->defaults->getSyncClientUrl(), |
|
288 | + 'docBaseUrl' => $this->defaults->getDocBaseUrl(), |
|
289 | + 'docPlaceholderUrl' => $this->defaults->buildDocLinkToKey('PLACEHOLDER'), |
|
290 | + 'slogan' => $this->defaults->getSlogan(), |
|
291 | + 'logoClaim' => '', |
|
292 | + 'shortFooter' => $this->defaults->getShortFooter(), |
|
293 | + 'longFooter' => $this->defaults->getLongFooter(), |
|
294 | + 'folder' => \OC_Util::getTheme(), |
|
295 | + ]), |
|
296 | + ]; |
|
297 | + |
|
298 | + if ($this->currentUser !== null) { |
|
299 | + $array['oc_userconfig'] = json_encode([ |
|
300 | + 'avatar' => [ |
|
301 | + 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
302 | + 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', |
|
303 | + ] |
|
304 | + ]); |
|
305 | + } |
|
306 | + |
|
307 | + $this->initialStateService->provideInitialState('core', 'config', $config); |
|
308 | + $this->initialStateService->provideInitialState('core', 'capabilities', $capabilities); |
|
309 | + |
|
310 | + // Allow hooks to modify the output values |
|
311 | + \OC_Hook::emit('\OCP\Config', 'js', ['array' => &$array]); |
|
312 | + |
|
313 | + $result = ''; |
|
314 | + |
|
315 | + // Echo it |
|
316 | + foreach ($array as $setting => $value) { |
|
317 | + $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
318 | + } |
|
319 | + |
|
320 | + return $result; |
|
321 | + } |
|
322 | 322 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $defaultExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
153 | 153 | $defaultExpireDate = $enforceDefaultExpireDate = null; |
154 | 154 | if ($defaultExpireDateEnabled) { |
155 | - $defaultExpireDate = (int)$this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
155 | + $defaultExpireDate = (int) $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
156 | 156 | $enforceDefaultExpireDate = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
157 | 157 | } |
158 | 158 | $outgoingServer2serverShareEnabled = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes'; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | $defaultInternalExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes'; |
161 | 161 | $defaultInternalExpireDate = $defaultInternalExpireDateEnforced = null; |
162 | 162 | if ($defaultInternalExpireDateEnabled) { |
163 | - $defaultInternalExpireDate = (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
163 | + $defaultInternalExpireDate = (int) $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'); |
|
164 | 164 | $defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes'; |
165 | 165 | } |
166 | 166 | |
167 | 167 | $countOfDataLocation = 0; |
168 | - $dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
168 | + $dataLocation = str_replace(\OC::$SERVERROOT.'/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation); |
|
169 | 169 | if ($countOfDataLocation !== 1 || !$this->groupManager->isAdmin($uid)) { |
170 | 170 | $dataLocation = false; |
171 | 171 | } |
@@ -199,66 +199,66 @@ discard block |
||
199 | 199 | "_oc_debug" => $this->config->getSystemValue('debug', false) ? 'true' : 'false', |
200 | 200 | "_oc_isadmin" => $this->groupManager->isAdmin($uid) ? 'true' : 'false', |
201 | 201 | "backendAllowsPasswordConfirmation" => $userBackendAllowsPasswordConfirmation ? 'true' : 'false', |
202 | - "oc_dataURL" => is_string($dataLocation) ? "\"" . $dataLocation . "\"" : 'false', |
|
203 | - "_oc_webroot" => "\"" . \OC::$WEBROOT . "\"", |
|
202 | + "oc_dataURL" => is_string($dataLocation) ? "\"".$dataLocation."\"" : 'false', |
|
203 | + "_oc_webroot" => "\"".\OC::$WEBROOT."\"", |
|
204 | 204 | "_oc_appswebroots" => str_replace('\\/', '/', json_encode($apps_paths)), // Ugly unescape slashes waiting for better solution |
205 | 205 | "datepickerFormatDate" => json_encode($this->l->l('jsdate', null)), |
206 | 206 | 'nc_lastLogin' => $lastConfirmTimestamp, |
207 | 207 | 'nc_pageLoad' => time(), |
208 | 208 | "dayNames" => json_encode([ |
209 | - (string)$this->l->t('Sunday'), |
|
210 | - (string)$this->l->t('Monday'), |
|
211 | - (string)$this->l->t('Tuesday'), |
|
212 | - (string)$this->l->t('Wednesday'), |
|
213 | - (string)$this->l->t('Thursday'), |
|
214 | - (string)$this->l->t('Friday'), |
|
215 | - (string)$this->l->t('Saturday') |
|
209 | + (string) $this->l->t('Sunday'), |
|
210 | + (string) $this->l->t('Monday'), |
|
211 | + (string) $this->l->t('Tuesday'), |
|
212 | + (string) $this->l->t('Wednesday'), |
|
213 | + (string) $this->l->t('Thursday'), |
|
214 | + (string) $this->l->t('Friday'), |
|
215 | + (string) $this->l->t('Saturday') |
|
216 | 216 | ]), |
217 | 217 | "dayNamesShort" => json_encode([ |
218 | - (string)$this->l->t('Sun.'), |
|
219 | - (string)$this->l->t('Mon.'), |
|
220 | - (string)$this->l->t('Tue.'), |
|
221 | - (string)$this->l->t('Wed.'), |
|
222 | - (string)$this->l->t('Thu.'), |
|
223 | - (string)$this->l->t('Fri.'), |
|
224 | - (string)$this->l->t('Sat.') |
|
218 | + (string) $this->l->t('Sun.'), |
|
219 | + (string) $this->l->t('Mon.'), |
|
220 | + (string) $this->l->t('Tue.'), |
|
221 | + (string) $this->l->t('Wed.'), |
|
222 | + (string) $this->l->t('Thu.'), |
|
223 | + (string) $this->l->t('Fri.'), |
|
224 | + (string) $this->l->t('Sat.') |
|
225 | 225 | ]), |
226 | 226 | "dayNamesMin" => json_encode([ |
227 | - (string)$this->l->t('Su'), |
|
228 | - (string)$this->l->t('Mo'), |
|
229 | - (string)$this->l->t('Tu'), |
|
230 | - (string)$this->l->t('We'), |
|
231 | - (string)$this->l->t('Th'), |
|
232 | - (string)$this->l->t('Fr'), |
|
233 | - (string)$this->l->t('Sa') |
|
227 | + (string) $this->l->t('Su'), |
|
228 | + (string) $this->l->t('Mo'), |
|
229 | + (string) $this->l->t('Tu'), |
|
230 | + (string) $this->l->t('We'), |
|
231 | + (string) $this->l->t('Th'), |
|
232 | + (string) $this->l->t('Fr'), |
|
233 | + (string) $this->l->t('Sa') |
|
234 | 234 | ]), |
235 | 235 | "monthNames" => json_encode([ |
236 | - (string)$this->l->t('January'), |
|
237 | - (string)$this->l->t('February'), |
|
238 | - (string)$this->l->t('March'), |
|
239 | - (string)$this->l->t('April'), |
|
240 | - (string)$this->l->t('May'), |
|
241 | - (string)$this->l->t('June'), |
|
242 | - (string)$this->l->t('July'), |
|
243 | - (string)$this->l->t('August'), |
|
244 | - (string)$this->l->t('September'), |
|
245 | - (string)$this->l->t('October'), |
|
246 | - (string)$this->l->t('November'), |
|
247 | - (string)$this->l->t('December') |
|
236 | + (string) $this->l->t('January'), |
|
237 | + (string) $this->l->t('February'), |
|
238 | + (string) $this->l->t('March'), |
|
239 | + (string) $this->l->t('April'), |
|
240 | + (string) $this->l->t('May'), |
|
241 | + (string) $this->l->t('June'), |
|
242 | + (string) $this->l->t('July'), |
|
243 | + (string) $this->l->t('August'), |
|
244 | + (string) $this->l->t('September'), |
|
245 | + (string) $this->l->t('October'), |
|
246 | + (string) $this->l->t('November'), |
|
247 | + (string) $this->l->t('December') |
|
248 | 248 | ]), |
249 | 249 | "monthNamesShort" => json_encode([ |
250 | - (string)$this->l->t('Jan.'), |
|
251 | - (string)$this->l->t('Feb.'), |
|
252 | - (string)$this->l->t('Mar.'), |
|
253 | - (string)$this->l->t('Apr.'), |
|
254 | - (string)$this->l->t('May.'), |
|
255 | - (string)$this->l->t('Jun.'), |
|
256 | - (string)$this->l->t('Jul.'), |
|
257 | - (string)$this->l->t('Aug.'), |
|
258 | - (string)$this->l->t('Sep.'), |
|
259 | - (string)$this->l->t('Oct.'), |
|
260 | - (string)$this->l->t('Nov.'), |
|
261 | - (string)$this->l->t('Dec.') |
|
250 | + (string) $this->l->t('Jan.'), |
|
251 | + (string) $this->l->t('Feb.'), |
|
252 | + (string) $this->l->t('Mar.'), |
|
253 | + (string) $this->l->t('Apr.'), |
|
254 | + (string) $this->l->t('May.'), |
|
255 | + (string) $this->l->t('Jun.'), |
|
256 | + (string) $this->l->t('Jul.'), |
|
257 | + (string) $this->l->t('Aug.'), |
|
258 | + (string) $this->l->t('Sep.'), |
|
259 | + (string) $this->l->t('Oct.'), |
|
260 | + (string) $this->l->t('Nov.'), |
|
261 | + (string) $this->l->t('Dec.') |
|
262 | 262 | ]), |
263 | 263 | "firstDay" => json_encode($this->l->l('firstday', null)), |
264 | 264 | "_oc_config" => json_encode($config), |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | if ($this->currentUser !== null) { |
299 | 299 | $array['oc_userconfig'] = json_encode([ |
300 | 300 | 'avatar' => [ |
301 | - 'version' => (int)$this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
301 | + 'version' => (int) $this->config->getUserValue($uid, 'avatar', 'version', 0), |
|
302 | 302 | 'generated' => $this->config->getUserValue($uid, 'avatar', 'generated', 'true') === 'true', |
303 | 303 | ] |
304 | 304 | ]); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | |
315 | 315 | // Echo it |
316 | 316 | foreach ($array as $setting => $value) { |
317 | - $result .= 'var '. $setting . '='. $value . ';' . PHP_EOL; |
|
317 | + $result .= 'var '.$setting.'='.$value.';'.PHP_EOL; |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | return $result; |
@@ -36,26 +36,26 @@ |
||
36 | 36 | * @since 8.0.0 |
37 | 37 | */ |
38 | 38 | class Constants { |
39 | - /** |
|
40 | - * CRUDS permissions. |
|
41 | - * @since 8.0.0 |
|
42 | - */ |
|
43 | - public const PERMISSION_CREATE = 4; |
|
44 | - public const PERMISSION_READ = 1; |
|
45 | - public const PERMISSION_UPDATE = 2; |
|
46 | - public const PERMISSION_DELETE = 8; |
|
47 | - public const PERMISSION_SHARE = 16; |
|
48 | - public const PERMISSION_ALL = 31; |
|
39 | + /** |
|
40 | + * CRUDS permissions. |
|
41 | + * @since 8.0.0 |
|
42 | + */ |
|
43 | + public const PERMISSION_CREATE = 4; |
|
44 | + public const PERMISSION_READ = 1; |
|
45 | + public const PERMISSION_UPDATE = 2; |
|
46 | + public const PERMISSION_DELETE = 8; |
|
47 | + public const PERMISSION_SHARE = 16; |
|
48 | + public const PERMISSION_ALL = 31; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @since 8.0.0 - Updated in 9.0.0 to allow all POSIX chars since we no |
|
52 | - * longer support windows as server platform. |
|
53 | - */ |
|
54 | - public const FILENAME_INVALID_CHARS = "\\/"; |
|
50 | + /** |
|
51 | + * @since 8.0.0 - Updated in 9.0.0 to allow all POSIX chars since we no |
|
52 | + * longer support windows as server platform. |
|
53 | + */ |
|
54 | + public const FILENAME_INVALID_CHARS = "\\/"; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @since 21.0.0 – default value for autocomplete/search results limit, |
|
58 | - * cf. sharing.maxAutocompleteResults in config.sample.php. |
|
59 | - */ |
|
60 | - public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25; |
|
56 | + /** |
|
57 | + * @since 21.0.0 – default value for autocomplete/search results limit, |
|
58 | + * cf. sharing.maxAutocompleteResults in config.sample.php. |
|
59 | + */ |
|
60 | + public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25; |
|
61 | 61 | } |