use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.
the class RepositoryManager method getUserAccessPermissions.
/**
* Returns the effective list of permissions for this user, taking into account
* team memberships, ownerships.
*
* @param user
* @return the effective list of permissions for the user
*/
@Override
public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
if (StringUtils.isEmpty(user.username)) {
// new user
return new ArrayList<RegistrantAccessPermission>();
}
Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>();
set.addAll(user.getRepositoryPermissions());
// Flag missing repositories
for (RegistrantAccessPermission permission : set) {
if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
RepositoryModel rm = getRepositoryModel(permission.registrant);
if (rm == null) {
permission.permissionType = PermissionType.MISSING;
permission.mutable = false;
continue;
}
}
}
// manually specify personal repository ownerships
for (RepositoryModel rm : repositoryListCache.values()) {
if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND, PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
// user may be owner of a repository to which they've inherited
// a team permission, replace any existing perm with owner perm
set.remove(rp);
set.add(rp);
}
}
List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(set);
Collections.sort(list);
return list;
}
use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.
the class RepositoryManager method setTeamAccessPermissions.
/**
* Sets the access permissions to the specified repository for the specified teams.
*
* @param repository
* @param permissions
* @return true if the team models have been updated
*/
@Override
public boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {
List<TeamModel> teams = new ArrayList<TeamModel>();
for (RegistrantAccessPermission tp : permissions) {
if (tp.mutable) {
// only set explicitly defined access permissions
TeamModel team = userManager.getTeamModel(tp.registrant);
team.setRepositoryPermission(repository.name, tp.permission);
teams.add(team);
}
}
return userManager.updateTeamModels(teams);
}
use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.
the class RepositoryManager method getTeamAccessPermissions.
/**
* Returns the list of teams and their access permissions for the specified
* repository including the source of the permission such as the admin flag
* or a regular expression.
*
* @param repository
* @return a list of RegistrantAccessPermissions
*/
@Override
public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
for (TeamModel team : userManager.getAllTeams()) {
RegistrantAccessPermission ap = team.getRepositoryPermission(repository);
if (ap.permission.exceeds(AccessPermission.NONE)) {
list.add(ap);
}
}
Collections.sort(list);
return list;
}
use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.
the class RpcTests method testRepositoryAdministration.
@Test
public void testRepositoryAdministration() throws IOException {
RepositoryModel model = new RepositoryModel();
model.name = "garbagerepo.git";
model.description = "created by RpcUtils";
model.addOwner("garbage");
model.accessRestriction = AccessRestrictionType.VIEW;
model.authorizationControl = AuthorizationControl.AUTHENTICATED;
// create
RpcUtils.deleteRepository(model, url, account, password.toCharArray());
assertTrue("Failed to create repository!", RpcUtils.createRepository(model, url, account, password.toCharArray()));
RepositoryModel retrievedRepository = findRepository(model.name);
assertNotNull("Failed to find " + model.name, retrievedRepository);
assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);
assertEquals(AuthorizationControl.AUTHENTICATED, retrievedRepository.authorizationControl);
// rename and change access restriciton
String originalName = model.name;
model.name = "garbagerepo2.git";
model.accessRestriction = AccessRestrictionType.CLONE;
model.authorizationControl = AuthorizationControl.NAMED;
RpcUtils.deleteRepository(model, url, account, password.toCharArray());
assertTrue("Failed to update repository!", RpcUtils.updateRepository(originalName, model, url, account, password.toCharArray()));
retrievedRepository = findRepository(model.name);
assertNotNull("Failed to find " + model.name, retrievedRepository);
assertTrue("Access retriction type is wrong", AccessRestrictionType.CLONE.equals(retrievedRepository.accessRestriction));
// restore VIEW restriction
retrievedRepository.accessRestriction = AccessRestrictionType.VIEW;
assertTrue("Failed to update repository!", RpcUtils.updateRepository(retrievedRepository.name, retrievedRepository, url, account, password.toCharArray()));
retrievedRepository = findRepository(retrievedRepository.name);
// memberships
UserModel testMember = new UserModel("justadded");
assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));
List<RegistrantAccessPermission> permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account, password.toCharArray());
assertEquals("Unexpected permissions! " + permissions.toString(), 1, permissions.size());
permissions.add(new RegistrantAccessPermission(testMember.username, AccessPermission.VIEW, PermissionType.EXPLICIT, RegistrantType.USER, null, true));
assertTrue("Failed to set member permissions!", RpcUtils.setRepositoryMemberPermissions(retrievedRepository, permissions, url, account, password.toCharArray()));
permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account, password.toCharArray());
boolean foundMember = false;
for (RegistrantAccessPermission permission : permissions) {
if (permission.registrant.equalsIgnoreCase(testMember.username)) {
foundMember = true;
assertEquals(AccessPermission.VIEW, permission.permission);
break;
}
}
assertTrue("Failed to find member!", foundMember);
// delete
assertTrue("Failed to delete " + model.name, RpcUtils.deleteRepository(retrievedRepository, url, account, password.toCharArray()));
retrievedRepository = findRepository(model.name);
assertNull("Failed to delete " + model.name, retrievedRepository);
for (UserModel u : RpcUtils.getUsers(url, account, password.toCharArray())) {
if (u.username.equals(testMember.username)) {
assertTrue(RpcUtils.deleteUser(u, url, account, password.toCharArray()));
break;
}
}
}
Aggregations