use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class CreateGroupPermissionSyncer method syncIfNeeded.
/**
* Checks if {@code GlobalCapability.CREATE_GROUP} and {@code CREATE} permission on {@code
* refs/groups/*} have diverged and syncs them by applying the {@code CREATE} permission to {@code
* refs/groups/*}.
*/
public void syncIfNeeded() throws IOException, ConfigInvalidException {
ProjectState allProjectsState = projectCache.getAllProjects();
ProjectState allUsersState = projectCache.getAllUsers();
Set<PermissionRule> createGroupsGlobal = new HashSet<>(allProjectsState.getCapabilityCollection().createGroup);
Set<PermissionRule> createGroupsRef = new HashSet<>();
Optional<AccessSection> allUsersCreateGroupAccessSection = allUsersState.getConfig().getAccessSection(RefNames.REFS_GROUPS + "*");
if (allUsersCreateGroupAccessSection.isPresent()) {
Permission create = allUsersCreateGroupAccessSection.get().getPermission(Permission.CREATE);
if (create != null && create.getRules() != null) {
createGroupsRef.addAll(create.getRules());
}
}
if (Sets.symmetricDifference(createGroupsGlobal, createGroupsRef).isEmpty()) {
// Nothing to sync
return;
}
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsers)) {
ProjectConfig config = projectConfigFactory.read(md);
config.upsertAccessSection(RefNames.REFS_GROUPS + "*", refsGroupsAccessSectionBuilder -> {
if (createGroupsGlobal.isEmpty()) {
refsGroupsAccessSectionBuilder.modifyPermissions(permissions -> {
permissions.removeIf(p -> Permission.CREATE.equals(p.getName()));
});
} else {
// The create permission is managed by Gerrit at this point only so there is no
// concern of overwriting user-defined permissions here.
Permission.Builder createGroupPermission = Permission.builder(Permission.CREATE);
refsGroupsAccessSectionBuilder.remove(createGroupPermission);
refsGroupsAccessSectionBuilder.addPermission(createGroupPermission);
createGroupsGlobal.stream().map(p -> p.toBuilder()).forEach(createGroupPermission::add);
}
});
config.commit(md);
projectCache.evictAndReindex(config.getProject());
}
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class AbstractDaemonTest method setRequireChangeId.
protected void setRequireChangeId(InheritableBoolean value) throws Exception {
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
ProjectConfig config = projectConfigFactory.read(md);
config.updateProject(p -> p.setBooleanConfig(BooleanProjectConfig.REQUIRE_CHANGE_ID, value));
config.commit(md);
projectCache.evictAndReindex(config.getProject());
}
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class ProjectIT method renamingGroupGetsPersisted.
@Test
public void renamingGroupGetsPersisted() throws Exception {
String name = name("Name1");
GroupInfo group = gApi.groups().create(name).get();
// Use group in a permission
projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref(RefNames.REFS_CONFIG).group(AccountGroup.uuid(group.id))).update();
Optional<String> beforeRename = projectCache.get(project).get().getLocalGroups().stream().filter(g -> g.getUUID().get().equals(group.id)).map(GroupReference::getName).findAny();
// Groups created with ProjectOperations always have their UUID as local name
assertThat(beforeRename).hasValue(group.id);
// Rename the group directly on the project config
String newName = name("Name2");
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
ProjectConfig config = projectConfigFactory.read(md);
config.renameGroup(AccountGroup.uuid(group.id), newName);
config.commit(md);
projectCache.evictAndReindex(config.getProject());
}
Optional<String> afterRename = projectCache.get(project).get().getLocalGroups().stream().filter(g -> g.getUUID().get().equals(group.id)).map(GroupReference::getName).findAny();
assertThat(afterRename).hasValue(newName);
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class AgreementsIT method setUseContributorAgreements.
protected void setUseContributorAgreements(InheritableBoolean value) throws Exception {
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
ProjectConfig config = projectConfigFactory.read(md);
config.updateProject(p -> p.setBooleanConfig(BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS, value));
config.commit(md);
projectCache.evictAndReindex(config.getProject());
}
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class LabelNormalizerTest method loadAllProjects.
private ProjectConfig loadAllProjects() throws Exception {
try (Repository repo = repoManager.openRepository(allProjects)) {
ProjectConfig pc = projectConfigFactory.create(allProjects);
pc.load(repo);
return pc;
}
}
Aggregations