Search in sources :

Example 6 with RepositoryModel

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

the class RepositoriesPanel method editRepository.

/**
 * Displays the edit repository dialog and fires a SwingWorker to update the
 * server, if appropriate.
 *
 * @param repository
 */
protected void editRepository(final RepositoryModel repository) {
    EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion(), repository);
    dialog.setLocationRelativeTo(RepositoriesPanel.this);
    List<String> usernames = gitblit.getUsernames();
    List<RegistrantAccessPermission> members = gitblit.getUserAccessPermissions(repository);
    dialog.setUsers(new ArrayList<String>(repository.owners), usernames, members);
    dialog.setTeams(gitblit.getTeamnames(), gitblit.getTeamAccessPermissions(repository));
    dialog.setRepositories(gitblit.getRepositories());
    dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);
    List<String> allLocalBranches = new ArrayList<String>();
    allLocalBranches.add(Constants.DEFAULT_BRANCH);
    allLocalBranches.addAll(repository.getLocalBranches());
    dialog.setIndexedBranches(allLocalBranches, repository.indexedBranches);
    dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(repository), gitblit.getPreReceiveScriptsInherited(repository), repository.preReceiveScripts);
    dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(repository), gitblit.getPostReceiveScriptsInherited(repository), repository.postReceiveScripts);
    if (gitblit.getSettings().hasKey(Keys.groovy.customFields)) {
        Map<String, String> map = gitblit.getSettings().get(Keys.groovy.customFields).getMap();
        dialog.setCustomFields(repository, map);
    }
    dialog.setVisible(true);
    final RepositoryModel revisedRepository = dialog.getRepository();
    final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();
    final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();
    if (revisedRepository == null) {
        return;
    }
    GitblitWorker worker = new GitblitWorker(this, RpcRequest.EDIT_REPOSITORY) {

        @Override
        protected Boolean doRequest() throws IOException {
            boolean success = gitblit.updateRepository(repository.name, revisedRepository, permittedUsers, permittedTeams);
            if (success) {
                gitblit.refreshRepositories();
                gitblit.refreshUsers();
                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(), repository.name);
        }
    };
    worker.execute();
}
Also used : RegistrantAccessPermission(com.gitblit.models.RegistrantAccessPermission) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 7 with RepositoryModel

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

the class RepositoriesPanel method getSelectedRepositories.

private List<RepositoryModel> getSelectedRepositories() {
    List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();
    for (int viewRow : table.getSelectedRows()) {
        int modelRow = table.convertRowIndexToModel(viewRow);
        RepositoryModel model = tableModel.list.get(modelRow);
        repositories.add(model);
    }
    return repositories;
}
Also used : ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 8 with RepositoryModel

use of com.gitblit.models.RepositoryModel 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 9 with RepositoryModel

use of com.gitblit.models.RepositoryModel 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 10 with RepositoryModel

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

the class IndicatorsRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected)
        setBackground(table.getSelectionBackground());
    else
        setBackground(table.getBackground());
    removeAll();
    if (value instanceof RepositoryModel) {
        StringBuilder tooltip = new StringBuilder();
        RepositoryModel model = (RepositoryModel) value;
        if (model.isSparkleshared()) {
            JLabel icon = new JLabel(sparkleshareIcon);
            tooltip.append(Translation.get("gb.isSparkleshared")).append("<br/>");
            add(icon);
        }
        if (model.isMirror) {
            JLabel icon = new JLabel(mirrorIcon);
            tooltip.append(Translation.get("gb.isMirror")).append("<br/>");
            add(icon);
        }
        if (model.isFork()) {
            JLabel icon = new JLabel(forkIcon);
            tooltip.append(Translation.get("gb.isFork")).append("<br/>");
            add(icon);
        }
        if (model.isFrozen) {
            JLabel icon = new JLabel(frozenIcon);
            tooltip.append(Translation.get("gb.isFrozen")).append("<br/>");
            add(icon);
        }
        if (model.isFederated) {
            JLabel icon = new JLabel(federatedIcon);
            tooltip.append(Translation.get("gb.isFederated")).append("<br/>");
            add(icon);
        }
        switch(model.accessRestriction) {
            case NONE:
                {
                    add(new JLabel(blankIcon));
                    break;
                }
            case PUSH:
                {
                    JLabel icon = new JLabel(pushIcon);
                    tooltip.append(Translation.get("gb.pushRestricted")).append("<br/>");
                    add(icon);
                    break;
                }
            case CLONE:
                {
                    JLabel icon = new JLabel(pullIcon);
                    tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");
                    add(icon);
                    break;
                }
            case VIEW:
                {
                    JLabel icon = new JLabel(viewIcon);
                    tooltip.append(Translation.get("gb.viewRestricted")).append("<br/>");
                    add(icon);
                    break;
                }
            default:
                add(new JLabel(blankIcon));
        }
        if (tooltip.length() > 0) {
            tooltip.insert(0, "<html><body>");
            setToolTipText(tooltip.toString().trim());
        }
    }
    return this;
}
Also used : JLabel(javax.swing.JLabel) RepositoryModel(com.gitblit.models.RepositoryModel)

Aggregations

RepositoryModel (com.gitblit.models.RepositoryModel)236 Test (org.junit.Test)146 Date (java.util.Date)135 UserModel (com.gitblit.models.UserModel)116 TeamModel (com.gitblit.models.TeamModel)68 ArrayList (java.util.ArrayList)39 File (java.io.File)21 Repository (org.eclipse.jgit.lib.Repository)20 CloneCommand (org.eclipse.jgit.api.CloneCommand)16 Git (org.eclipse.jgit.api.Git)13 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)13 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)12 GitBlitException (com.gitblit.GitBlitException)11 Label (org.apache.wicket.markup.html.basic.Label)11 PushResult (org.eclipse.jgit.transport.PushResult)10 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)10 RegistrantAccessPermission (com.gitblit.models.RegistrantAccessPermission)9 BufferedWriter (java.io.BufferedWriter)9 FileOutputStream (java.io.FileOutputStream)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9