]> source.dussan.org Git - gitblit.git/commitdiff
Rewrite fix without the additional List
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Sun, 7 Aug 2022 12:26:16 +0000 (14:26 +0200)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Sun, 7 Aug 2022 12:26:16 +0000 (14:26 +0200)
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.

src/main/java/com/gitblit/models/UserModel.java

index 1d95569f9b85ff8dae0b678b20ce92f3890940df..b0933093d23a996a61a58a4ac40807d096e7da5c 100644 (file)
@@ -110,7 +110,7 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
         * @return the user's list of permissions\r
         */\r
        public List<RegistrantAccessPermission> getRepositoryPermissions() {\r
-               List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();\r
+               List<RegistrantAccessPermission> list = new ArrayList<>();\r
                if (canAdmin()) {\r
                        // user has REWIND access to all repositories\r
                        return list;\r
@@ -135,8 +135,6 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
                Collections.sort(list);\r
 \r
                // include immutable team permissions, being careful to preserve order\r
-               Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>(list);\r
-               ArrayList<RegistrantAccessPermission> arrayList = new ArrayList<RegistrantAccessPermission>(list);\r
                for (TeamModel team : teams) {\r
                        for (RegistrantAccessPermission teamPermission : team.getRepositoryPermissions()) {\r
                                // we can not change an inherited team permission, though we can override\r
@@ -144,22 +142,17 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
                                teamPermission.permissionType = PermissionType.TEAM;\r
                                teamPermission.source = team.name;\r
                                teamPermission.mutable = false;\r
-                if(arrayList.contains(teamPermission) && arrayList.get(arrayList.indexOf(teamPermission)).permissionType != PermissionType.REGEX){\r
-                    //checking either to replace permission in set or not\r
-                    if(teamPermission.permission.compareTo(arrayList.get(arrayList.indexOf(teamPermission)).permission) > 0 ){\r
-                        arrayList.remove(teamPermission);\r
-                        arrayList.add(teamPermission);\r
-                        set.remove(teamPermission);\r
-                        set.add(teamPermission);\r
-                    }\r
-                }\r
-                else{\r
-                    arrayList.add(teamPermission);\r
-                }\r
-                               set.add(teamPermission);\r
+                               int i = list.indexOf(teamPermission);\r
+                               if (i < 0) list.add(teamPermission);\r
+                               else {\r
+                                       RegistrantAccessPermission lp = list.get(i);\r
+                                       if (teamPermission.permission.exceeds(lp.permission)) {\r
+                                               list.set(i, teamPermission);\r
+                                       }\r
+                               }\r
                        }\r
                }\r
-               return new ArrayList<RegistrantAccessPermission>(set);\r
+               return list;\r
        }\r
 \r
        /**\r