This pulls in the rebased branch from PR #1100.pull/1328/merge
@@ -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,7 +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); | |||
for (TeamModel team : teams) { | |||
for (RegistrantAccessPermission teamPermission : team.getRepositoryPermissions()) { | |||
// we can not change an inherited team permission, though we can override | |||
@@ -143,10 +142,17 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel> | |||
teamPermission.permissionType = PermissionType.TEAM; | |||
teamPermission.source = team.name; | |||
teamPermission.mutable = false; | |||
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; | |||
} | |||
/** |
@@ -15,10 +15,15 @@ | |||
*/ | |||
package com.gitblit.tests; | |||
import com.gitblit.Constants; | |||
import com.gitblit.models.RegistrantAccessPermission; | |||
import com.gitblit.models.TeamModel; | |||
import org.junit.Test; | |||
import com.gitblit.models.UserModel; | |||
import java.util.List; | |||
/** | |||
* @author Alfred Schmid | |||
* | |||
@@ -49,4 +54,48 @@ public class UserModelTest extends GitblitUnitTest { | |||
assertEquals("When displayName is not empty its value has to be returnd from getDisplayName().", displayName, userModel.getDisplayName()); | |||
} | |||
@Test | |||
public void getRepositoryPermissionsMultipleTeams() | |||
{ | |||
TeamModel aTeam = new TeamModel("A team"); | |||
aTeam.addRepositoryPermission("RW+:acerepo.git"); | |||
aTeam.addRepositoryPermission("V:boobrepo.git"); | |||
TeamModel bTeam = new TeamModel("Team B"); | |||
bTeam.addRepositoryPermission("R:acerepo.git"); | |||
bTeam.addRepositoryPermission("RWC:boobrepo.git"); | |||
UserModel user = new UserModel("tessiur"); | |||
user.teams.add(aTeam); | |||
user.teams.add(bTeam); | |||
user.addRepositoryPermission("RW+:myrepo.git"); | |||
List<RegistrantAccessPermission> repoPerms = user.getRepositoryPermissions(); | |||
int found = 0; | |||
for (RegistrantAccessPermission p : repoPerms) { | |||
switch (p.registrant) { | |||
case "acerepo.git": | |||
assertEquals("Expected REWIND(RW+) permission for " + p.registrant, Constants.AccessPermission.REWIND, p.permission); | |||
found++; | |||
break; | |||
case "boobrepo.git": | |||
assertEquals("Expected CREATE(RWC) permission for " + p.registrant, Constants.AccessPermission.CREATE, p.permission); | |||
found++; | |||
break; | |||
case "myrepo.git": | |||
assertEquals("Expected REWIND(RW+) permission for " + p.registrant, Constants.AccessPermission.REWIND, p.permission); | |||
found++; | |||
break; | |||
default: | |||
fail("Unknown repository registrant " + p.registrant); | |||
break; | |||
} | |||
} | |||
assertEquals("Repostory permissions missing in list.", 3, found); | |||
} | |||
} |