Search in sources :

Example 16 with RegistrantAccessPermission

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 17 with RegistrantAccessPermission

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);
}
Also used : TeamModel(com.gitblit.models.TeamModel) RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) ArrayList(java.util.ArrayList)

Example 18 with RegistrantAccessPermission

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;
}
Also used : TeamModel(com.gitblit.models.TeamModel) RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) ArrayList(java.util.ArrayList)

Example 19 with RegistrantAccessPermission

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;
        }
    }
}
Also used : UserModel(com.gitblit.models.UserModel) RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) RepositoryModel(com.gitblit.models.RepositoryModel) Test(org.junit.Test)

Aggregations

RegistrantAccessPermission (com.gitblit.models.RegistrantAccessPermission)19 ArrayList (java.util.ArrayList)13 RepositoryModel (com.gitblit.models.RepositoryModel)9 TeamModel (com.gitblit.models.TeamModel)6 UserModel (com.gitblit.models.UserModel)4 GitBlitException (com.gitblit.GitBlitException)3 StringChoiceRenderer (com.gitblit.wicket.StringChoiceRenderer)3 RegistrantPermissionsPanel (com.gitblit.wicket.panels.RegistrantPermissionsPanel)3 HashSet (java.util.HashSet)3 SimpleAttributeModifier (org.apache.wicket.behavior.SimpleAttributeModifier)3 Palette (org.apache.wicket.extensions.markup.html.form.palette.Palette)3 Button (org.apache.wicket.markup.html.form.Button)3 CheckBox (org.apache.wicket.markup.html.form.CheckBox)3 Form (org.apache.wicket.markup.html.form.Form)3 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)3 UserChoice (com.gitblit.models.UserChoice)2 BulletListPanel (com.gitblit.wicket.panels.BulletListPanel)2 LinkedHashSet (java.util.LinkedHashSet)2 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)2 TextField (org.apache.wicket.markup.html.form.TextField)2