diff options
author | Florian Zschocke <f.zschocke+git@gmail.com> | 2022-08-07 14:26:16 +0200 |
---|---|---|
committer | Florian Zschocke <f.zschocke+git@gmail.com> | 2022-08-07 14:26:16 +0200 |
commit | f2fc9cc57b8b70f5e521e7c56b5ee56db3bab35c (patch) | |
tree | 49806318932d14b3c9ea6bfe81f59d89c8252000 /src/main/java/com/gitblit | |
parent | bf5aa7f42e22547e3ea95ece0b142ac6c9282e52 (diff) | |
download | gitblit-f2fc9cc57b8b70f5e521e7c56b5ee56db3bab35c.tar.gz gitblit-f2fc9cc57b8b70f5e521e7c56b5ee56db3bab35c.zip |
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.
Diffstat (limited to 'src/main/java/com/gitblit')
-rw-r--r-- | src/main/java/com/gitblit/models/UserModel.java | 27 |
1 files 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<UserModel> * @return the user's list of permissions
*/
public List<RegistrantAccessPermission> getRepositoryPermissions() {
- List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
+ List<RegistrantAccessPermission> 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<UserModel> Collections.sort(list);
// include immutable team permissions, being careful to preserve order
- Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>(list);
- ArrayList<RegistrantAccessPermission> arrayList = new ArrayList<RegistrantAccessPermission>(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<UserModel> 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<RegistrantAccessPermission>(set);
+ return list;
}
/**
|