Search in sources :

Example 21 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method setUseSignedOffBy.

protected void setUseSignedOffBy(InheritableBoolean value) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        ProjectConfig config = ProjectConfig.read(md);
        config.getProject().setUseSignedOffBy(value);
        config.commit(md);
        projectCache.evict(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 22 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method setUseContributorAgreements.

protected void setUseContributorAgreements(InheritableBoolean value) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        ProjectConfig config = ProjectConfig.read(md);
        config.getProject().setUseContributorAgreements(value);
        config.commit(md);
        projectCache.evict(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 23 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class SubmitTypeRuleIT method setRulesPl.

private void setRulesPl(String rule) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        RulesPl r = new RulesPl();
        r.load(md);
        r.rule = rule;
        r.commit(md);
    }
}
Also used : MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 24 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class ProjectAccessFactory method call.

@Override
public ProjectAccess call() throws NoSuchProjectException, IOException, ConfigInvalidException, PermissionBackendException {
    ProjectControl pc = checkProjectControl();
    // Load the current configuration from the repository, ensuring its the most
    // recent version available. If it differs from what was in the project
    // state, force a cache flush now.
    //
    ProjectConfig config;
    try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
        config = ProjectConfig.read(md);
        if (config.updateGroupNames(groupBackend)) {
            md.setMessage("Update group names\n");
            config.commit(md);
            projectCache.evict(config.getProject());
            pc = checkProjectControl();
        } else if (config.getRevision() != null && !config.getRevision().equals(pc.getProjectState().getConfig().getRevision())) {
            projectCache.evict(config.getProject());
            pc = checkProjectControl();
        }
    }
    final RefControl metaConfigControl = pc.controlForRef(RefNames.REFS_CONFIG);
    List<AccessSection> local = new ArrayList<>();
    Set<String> ownerOf = new HashSet<>();
    Map<AccountGroup.UUID, Boolean> visibleGroups = new HashMap<>();
    for (AccessSection section : config.getAccessSections()) {
        String name = section.getName();
        if (AccessSection.GLOBAL_CAPABILITIES.equals(name)) {
            if (pc.isOwner()) {
                local.add(section);
                ownerOf.add(name);
            } else if (metaConfigControl.isVisible()) {
                local.add(section);
            }
        } else if (RefConfigSection.isValid(name)) {
            RefControl rc = pc.controlForRef(name);
            if (rc.isOwner()) {
                local.add(section);
                ownerOf.add(name);
            } else if (metaConfigControl.isVisible()) {
                local.add(section);
            } else if (rc.isVisible()) {
                // Filter the section to only add rules describing groups that
                // are visible to the current-user. This includes any group the
                // user is a member of, as well as groups they own or that
                // are visible to all users.
                AccessSection dst = null;
                for (Permission srcPerm : section.getPermissions()) {
                    Permission dstPerm = null;
                    for (PermissionRule srcRule : srcPerm.getRules()) {
                        AccountGroup.UUID group = srcRule.getGroup().getUUID();
                        if (group == null) {
                            continue;
                        }
                        Boolean canSeeGroup = visibleGroups.get(group);
                        if (canSeeGroup == null) {
                            try {
                                canSeeGroup = groupControlFactory.controlFor(group).isVisible();
                            } catch (NoSuchGroupException e) {
                                canSeeGroup = Boolean.FALSE;
                            }
                            visibleGroups.put(group, canSeeGroup);
                        }
                        if (canSeeGroup) {
                            if (dstPerm == null) {
                                if (dst == null) {
                                    dst = new AccessSection(name);
                                    local.add(dst);
                                }
                                dstPerm = dst.getPermission(srcPerm.getName(), true);
                            }
                            dstPerm.add(srcRule);
                        }
                    }
                }
            }
        }
    }
    if (ownerOf.isEmpty() && pc.isOwnerAnyRef()) {
        // Special case: If the section list is empty, this project has no current
        // access control information. Rely on what ProjectControl determines
        // is ownership, which probably means falling back to site administrators.
        ownerOf.add(AccessSection.ALL);
    }
    final ProjectAccess detail = new ProjectAccess();
    detail.setProjectName(projectName);
    if (config.getRevision() != null) {
        detail.setRevision(config.getRevision().name());
    }
    detail.setInheritsFrom(config.getProject().getParent(allProjectsName));
    if (projectName.equals(allProjectsName)) {
        if (pc.isOwner()) {
            ownerOf.add(AccessSection.GLOBAL_CAPABILITIES);
        }
    }
    detail.setLocal(local);
    detail.setOwnerOf(ownerOf);
    detail.setCanUpload(metaConfigControl.isVisible() && (pc.isOwner() || metaConfigControl.canUpload()));
    detail.setConfigVisible(pc.isOwner() || metaConfigControl.isVisible());
    detail.setGroupInfo(buildGroupInfo(local));
    detail.setLabelTypes(pc.getLabelTypes());
    detail.setFileHistoryLinks(getConfigFileLogLinks(projectName.get()));
    return detail;
}
Also used : HashMap(java.util.HashMap) PermissionRule(com.google.gerrit.common.data.PermissionRule) RefControl(com.google.gerrit.server.project.RefControl) ArrayList(java.util.ArrayList) ProjectControl(com.google.gerrit.server.project.ProjectControl) AccessSection(com.google.gerrit.common.data.AccessSection) NoSuchGroupException(com.google.gerrit.common.errors.NoSuchGroupException) ProjectAccess(com.google.gerrit.common.data.ProjectAccess) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Permission(com.google.gerrit.common.data.Permission) ProjectPermission(com.google.gerrit.server.permissions.ProjectPermission) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) HashSet(java.util.HashSet)

Example 25 with MetaDataUpdate

use of com.google.gerrit.server.git.MetaDataUpdate in project gerrit by GerritCodeReview.

the class SetDiffPreferences method writeToGit.

private DiffPreferencesInfo writeToGit(DiffPreferencesInfo in, Account.Id userId) throws RepositoryNotFoundException, IOException, ConfigInvalidException {
    DiffPreferencesInfo out = new DiffPreferencesInfo();
    try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
        DiffPreferencesInfo allUserPrefs = readDefaultsFromGit(md.getRepository(), null);
        VersionedAccountPreferences prefs = VersionedAccountPreferences.forUser(userId);
        prefs.load(md);
        storeSection(prefs.getConfig(), UserConfigSections.DIFF, null, in, allUserPrefs);
        prefs.commit(md);
        loadSection(prefs.getConfig(), UserConfigSections.DIFF, null, out, allUserPrefs, null);
    }
    return out;
}
Also used : DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)37 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)25 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)18 Project (com.google.gerrit.reviewdb.client.Project)15 AccessSection (com.google.gerrit.common.data.AccessSection)14 IOException (java.io.IOException)13 Repository (org.eclipse.jgit.lib.Repository)12 OrmException (com.google.gwtorm.server.OrmException)11 Permission (com.google.gerrit.common.data.Permission)9 PermissionRule (com.google.gerrit.common.data.PermissionRule)8 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)7 HashMap (java.util.HashMap)6 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)6 GroupReference (com.google.gerrit.common.data.GroupReference)5 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)5 Account (com.google.gerrit.reviewdb.client.Account)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 LabelType (com.google.gerrit.common.data.LabelType)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)4