@@ -125,7 +125,7 @@ public RepositoryInfo getRepositoryInfo(UserInfo user, String repoId)
125125 {
126126 if (isReady ())
127127 {
128- return findUserRepository (user .getUserId (), repoId );
128+ return findUserRepository (user .getUserId (), repoId , true );
129129 }
130130 else
131131 return null ;
@@ -203,9 +203,13 @@ private void createRepositoryWithId(String id, String owner, RepositoryInfo info
203203 public RepositoryInfo updateRepository (UserInfo user , String repoId , RepositoryInfo info )
204204 throws RepositoryException
205205 {
206+ final boolean isadmin = (user .getRoles () != null && user .getRoles ().contains ("admin" ));
207+ if (!isadmin && user .isAnonymous ())
208+ return null ; // only admin can modify guest repositories
209+
206210 if (isReady ())
207211 {
208- RepositoryInfo current = findUserRepository (user .getUserId (), repoId );
212+ RepositoryInfo current = findUserRepository (user .getUserId (), repoId , isadmin );
209213 if (current != null )
210214 {
211215 current .updateWith (info );
@@ -267,11 +271,19 @@ private RepositoryInfo findRepository(String uuid)
267271 }
268272 }
269273
270- private RepositoryInfo findUserRepository (String userId , String repoId )
274+ /**
275+ * Finds the user repositor and gets the info.
276+ *
277+ * @param userId the repository user ID
278+ * @param repoId the repository ID
279+ * @param allowAnonymous try to look for anonymous user repository if the user's repository does not exist?
280+ * @return the repository info or {@code null} if it does not exist
281+ */
282+ private RepositoryInfo findUserRepository (String userId , String repoId , boolean allowAnonymous )
271283 {
272284 var info = manager .getRepositoryInfo (userId + SEP + repoId );
273285 //if the repository is not defined for the user, try to find it for anonymous guest
274- if (info == null && !UserInfo .ANONYMOUS_USER .equals (userId ))
286+ if (info == null && allowAnonymous && !UserInfo .ANONYMOUS_USER .equals (userId ))
275287 info = manager .getRepositoryInfo (UserInfo .ANONYMOUS_USER + SEP + repoId );
276288
277289 if (info != null )
0 commit comments