From f2fc9cc57b8b70f5e521e7c56b5ee56db3bab35c Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Sun, 7 Aug 2022 14:26:16 +0200 Subject: [PATCH] Rewrite fix without the additional List This also removes the additional Set. What changes is that the order of the repositories is kept, but the resulting list will have user and team permissions intertwined. --- .../java/com/gitblit/models/UserModel.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/gitblit/models/UserModel.java b/src/main/java/com/gitblit/models/UserModel.java index 1d95569f..b0933093 100644 --- a/src/main/java/com/gitblit/models/UserModel.java +++ b/src/main/java/com/gitblit/models/UserModel.java @@ -110,7 +110,7 @@ public class UserModel implements Principal, Serializable, Comparable * @return the user's list of permissions */ public List getRepositoryPermissions() { - List list = new ArrayList(); + List list = new ArrayList<>(); if (canAdmin()) { // user has REWIND access to all repositories return list; @@ -135,8 +135,6 @@ public class UserModel implements Principal, Serializable, Comparable Collections.sort(list); // include immutable team permissions, being careful to preserve order - Set set = new LinkedHashSet(list); - ArrayList arrayList = new ArrayList(list); for (TeamModel team : teams) { for (RegistrantAccessPermission teamPermission : team.getRepositoryPermissions()) { // we can not change an inherited team permission, though we can override @@ -144,22 +142,17 @@ public class UserModel implements Principal, Serializable, Comparable teamPermission.permissionType = PermissionType.TEAM; teamPermission.source = team.name; teamPermission.mutable = false; - if(arrayList.contains(teamPermission) && arrayList.get(arrayList.indexOf(teamPermission)).permissionType != PermissionType.REGEX){ - //checking either to replace permission in set or not - if(teamPermission.permission.compareTo(arrayList.get(arrayList.indexOf(teamPermission)).permission) > 0 ){ - arrayList.remove(teamPermission); - arrayList.add(teamPermission); - set.remove(teamPermission); - set.add(teamPermission); - } - } - else{ - arrayList.add(teamPermission); - } - set.add(teamPermission); + int i = list.indexOf(teamPermission); + if (i < 0) list.add(teamPermission); + else { + RegistrantAccessPermission lp = list.get(i); + if (teamPermission.permission.exceeds(lp.permission)) { + list.set(i, teamPermission); + } + } } } - return new ArrayList(set); + return list; } /** -- 2.39.5