Search in sources :

Example 6 with RegistrantAccessPermission

use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.

the class GitblitClient 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
	 */
public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
    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 = getRepository(permission.registrant);
            if (rm == null) {
                permission.permissionType = PermissionType.MISSING;
                permission.mutable = false;
                continue;
            }
        }
    }
    // manually specify personal repository ownerships
    for (RepositoryModel rm : allRepositories) {
        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 7 with RegistrantAccessPermission

use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.

the class EditTeamDialog method validateFields.

private boolean validateFields() {
    String tname = teamnameField.getText();
    if (StringUtils.isEmpty(tname)) {
        error("Please enter a team name!");
        return false;
    }
    boolean rename = false;
    // verify teamname uniqueness on create
    if (isCreate) {
        if (teamnames.contains(tname.toLowerCase())) {
            error(MessageFormat.format("Team name ''{0}'' is unavailable.", tname));
            return false;
        }
    } else {
        // check rename collision
        rename = !StringUtils.isEmpty(teamname) && !teamname.equalsIgnoreCase(tname);
        if (rename) {
            if (teamnames.contains(tname.toLowerCase())) {
                error(MessageFormat.format("Failed to rename ''{0}'' because ''{1}'' already exists.", teamname, tname));
                return false;
            }
        }
    }
    team.name = tname;
    team.canAdmin = canAdminCheckbox.isSelected();
    team.canFork = canForkCheckbox.isSelected();
    team.canCreate = canCreateCheckbox.isSelected();
    String ml = mailingListsField.getText();
    if (!StringUtils.isEmpty(ml)) {
        Set<String> list = new HashSet<String>();
        for (String address : ml.split("(,|\\s)")) {
            if (StringUtils.isEmpty(address)) {
                continue;
            }
            list.add(address.toLowerCase());
        }
        team.mailingLists.clear();
        team.mailingLists.addAll(list);
    }
    for (RegistrantAccessPermission rp : repositoryPalette.getPermissions()) {
        team.setRepositoryPermission(rp.registrant, rp.permission);
    }
    team.users.clear();
    team.users.addAll(userPalette.getSelections());
    team.preReceiveScripts.clear();
    team.preReceiveScripts.addAll(preReceivePalette.getSelections());
    team.postReceiveScripts.clear();
    team.postReceiveScripts.addAll(postReceivePalette.getSelections());
    return true;
}
Also used : RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) HashSet(java.util.HashSet)

Example 8 with RegistrantAccessPermission

use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.

the class EditTeamDialog method setRepositories.

public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {
    List<String> restricted = new ArrayList<String>();
    for (RepositoryModel repo : repositories) {
        if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE) && repo.authorizationControl.equals(AuthorizationControl.NAMED)) {
            restricted.add(repo.name);
        }
    }
    StringUtils.sortRepositorynames(restricted);
    List<String> list = new ArrayList<String>();
    // repositories
    list.add(".*");
    String prefix;
    if (settings.hasKey(Keys.git.userRepositoryPrefix)) {
        prefix = settings.get(Keys.git.userRepositoryPrefix).currentValue;
        if (StringUtils.isEmpty(prefix)) {
            prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
        }
    } else {
        prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
    }
    if (prefix.length() == 1) {
        // all repositories excluding personal repositories
        list.add("[^" + prefix + "].*");
    }
    String lastProject = null;
    for (String repo : restricted) {
        String projectPath = StringUtils.getFirstPathElement(repo);
        if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) {
            lastProject = projectPath;
            if (!StringUtils.isEmpty(projectPath)) {
                // regex for all repositories within a project
                list.add(projectPath + "/.*");
            }
            list.add(repo);
        }
    }
    // remove repositories for which user already has a permission
    if (permissions == null) {
        permissions = new ArrayList<RegistrantAccessPermission>();
    } else {
        for (RegistrantAccessPermission rp : permissions) {
            list.remove(rp.registrant);
        }
    }
    repositoryPalette.setObjects(list, permissions);
}
Also used : RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 9 with RegistrantAccessPermission

use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.

the class EditUserDialog method setRepositories.

public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {
    Map<String, RepositoryModel> repoMap = new HashMap<String, RepositoryModel>();
    List<String> restricted = new ArrayList<String>();
    for (RepositoryModel repo : repositories) {
        // exclude Owner or personal repositories
        if (!repo.isOwner(username) && !repo.isUsersPersonalRepository(username)) {
            if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE) && repo.authorizationControl.equals(AuthorizationControl.NAMED)) {
                restricted.add(repo.name);
            }
        }
        repoMap.put(repo.name.toLowerCase(), repo);
    }
    StringUtils.sortRepositorynames(restricted);
    List<String> list = new ArrayList<String>();
    // repositories
    list.add(".*");
    String prefix;
    if (settings.hasKey(Keys.git.userRepositoryPrefix)) {
        prefix = settings.get(Keys.git.userRepositoryPrefix).currentValue;
        if (StringUtils.isEmpty(prefix)) {
            prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
        }
    } else {
        prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
    }
    if (prefix.length() == 1) {
        // all repositories excluding personal repositories
        list.add("[^" + prefix + "].*");
    }
    String lastProject = null;
    for (String repo : restricted) {
        String projectPath = StringUtils.getFirstPathElement(repo).toLowerCase();
        if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) {
            lastProject = projectPath;
            if (!StringUtils.isEmpty(projectPath)) {
                // regex for all repositories within a project
                list.add(projectPath + "/.*");
            }
        }
        list.add(repo);
    }
    // remove repositories for which user already has a permission
    if (permissions == null) {
        permissions = new ArrayList<RegistrantAccessPermission>();
    } else {
        for (RegistrantAccessPermission rp : permissions) {
            list.remove(rp.registrant.toLowerCase());
        }
    }
    // update owner and missing permissions for editing
    for (RegistrantAccessPermission permission : permissions) {
        if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
            // Ensure this is NOT an owner permission - which is non-editable
            // We don't know this from within the usermodel, ownership is a
            // property of a repository.
            RepositoryModel rm = repoMap.get(permission.registrant.toLowerCase());
            if (rm == null) {
                permission.permissionType = PermissionType.MISSING;
                permission.mutable = false;
                continue;
            }
            boolean isOwner = rm.isOwner(username);
            if (isOwner) {
                permission.permissionType = PermissionType.OWNER;
                permission.mutable = false;
            }
        }
    }
    repositoryPalette.setObjects(list, permissions);
}
Also used : HashMap(java.util.HashMap) RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 10 with RegistrantAccessPermission

use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.

the class RepositoriesPanel method createRepository.

/**
	 * Displays the create repository dialog and fires a SwingWorker to update
	 * the server, if appropriate.
	 *
	 */
protected void createRepository() {
    EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion());
    dialog.setLocationRelativeTo(RepositoriesPanel.this);
    dialog.setAccessRestriction(gitblit.getDefaultAccessRestriction());
    dialog.setAuthorizationControl(gitblit.getDefaultAuthorizationControl());
    dialog.setUsers(null, gitblit.getUsernames(), null);
    dialog.setTeams(gitblit.getTeamnames(), null);
    dialog.setRepositories(gitblit.getRepositories());
    dialog.setFederationSets(gitblit.getFederationSets(), null);
    dialog.setIndexedBranches(new ArrayList<String>(Arrays.asList(Constants.DEFAULT_BRANCH)), null);
    dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null), gitblit.getPreReceiveScriptsInherited(null), null);
    dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null), gitblit.getPostReceiveScriptsInherited(null), null);
    dialog.setVisible(true);
    final RepositoryModel newRepository = dialog.getRepository();
    final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();
    final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();
    if (newRepository == null) {
        return;
    }
    GitblitWorker worker = new GitblitWorker(this, RpcRequest.CREATE_REPOSITORY) {

        @Override
        protected Boolean doRequest() throws IOException {
            boolean success = gitblit.createRepository(newRepository, permittedUsers, permittedTeams);
            if (success) {
                gitblit.refreshRepositories();
                if (permittedUsers.size() > 0) {
                    gitblit.refreshUsers();
                }
                if (permittedTeams.size() > 0) {
                    gitblit.refreshTeams();
                }
            }
            return success;
        }

        @Override
        protected void onSuccess() {
            updateTable(false);
            updateUsersTable();
            updateTeamsTable();
        }

        @Override
        protected void onFailure() {
            showFailure("Failed to execute request \"{0}\" for repository \"{1}\".", getRequestType(), newRepository.name);
        }
    };
    worker.execute();
}
Also used : RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) RepositoryModel(com.gitblit.models.RepositoryModel)

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