4040use OCP \App \IAppManager ;
4141use OCP \AppFramework \QueryException ;
4242use OCP \IConfig ;
43+ use OCP \IGroup ;
4344use OCP \IGroupManager ;
4445use OCP \IUser ;
4546use OCP \IUserManager ;
@@ -151,6 +152,7 @@ public function getPrincipalsByPrefix($prefixPath) {
151152 */
152153 public function getPrincipalByPath ($ path ) {
153154 list ($ prefix , $ name ) = \Sabre \Uri \split ($ path );
155+ $ decodedName = urldecode ($ name );
154156
155157 if ($ name === 'calendar-proxy-write ' || $ name === 'calendar-proxy-read ' ) {
156158 list ($ prefix2 , $ name2 ) = \Sabre \Uri \split ($ prefix );
@@ -172,14 +174,28 @@ public function getPrincipalByPath($path) {
172174 // is called either with a urlencoded version of the name or with a non-urlencoded one.
173175 // The urldecode function replaces %## and +, both of which are forbidden in usernames.
174176 // Hence there can be no ambiguity here and it is safe to call urldecode on all usernames
175- $ user = $ this ->userManager ->get (urldecode ( $ name ) );
177+ $ user = $ this ->userManager ->get ($ decodedName );
176178
177179 if ($ user !== null ) {
178180 return $ this ->userToPrincipal ($ user );
179181 }
180182 } elseif ($ prefix === 'principals/circles ' ) {
181183 if ($ this ->userSession ->getUser () !== null ) {
182- return $ this ->circleToPrincipal ($ name );
184+ // At the time of writing - 2021-01-19 — a mixed state is possible.
185+ // The second condition can be removed when this is fixed.
186+ return $ this ->circleToPrincipal ($ decodedName )
187+ ?: $ this ->circleToPrincipal ($ name );
188+ }
189+ } elseif ($ prefix === 'principals/groups ' ) {
190+ // At the time of writing - 2021-01-19 — a mixed state is possible.
191+ // The second condition can be removed when this is fixed.
192+ $ group = $ this ->groupManager ->get ($ decodedName )
193+ ?: $ this ->groupManager ->get ($ name );
194+ if ($ group instanceof IGroup) {
195+ return [
196+ 'uri ' => 'principals/groups/ ' . $ name ,
197+ '{DAV:}displayname ' => $ group ->getDisplayName (),
198+ ];
183199 }
184200 }
185201 return null ;
0 commit comments