use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class SubmitRequirementsValidationIT method updateProjectConfig.
private void updateProjectConfig(Consumer<Config> configUpdater) throws Exception {
RevCommit head = getHead(testRepo.getRepository(), RefNames.REFS_CONFIG);
Config projectConfig = readProjectConfig(head);
configUpdater.accept(projectConfig);
RevCommit commit = testRepo.update(RefNames.REFS_CONFIG, testRepo.commit().parent(head).message("Update project config").author(admin.newIdent()).committer(admin.newIdent()).add(ProjectConfig.PROJECT_CONFIG, projectConfig.toText()));
testRepo.reset(commit);
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byLabelMulti.
@Test
public void byLabelMulti() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Project.NameKey project = Project.nameKey(repo.getRepository().getDescription().getRepositoryName());
LabelType verified = label(LabelId.VERIFIED, value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
ProjectConfig cfg = projectConfigFactory.create(project);
cfg.load(md);
cfg.upsertLabelType(verified);
cfg.commit(md);
}
projectCache.evictAndReindex(project);
String heads = RefNames.REFS_HEADS + "*";
projectOperations.project(project).forUpdate().add(allowLabel(verified.getName()).ref(heads).group(REGISTERED_USERS).range(-1, 1)).update();
ReviewInput reviewVerified = new ReviewInput().label(LabelId.VERIFIED, 1);
ChangeInserter ins = newChange(repo);
ChangeInserter ins2 = newChange(repo);
ChangeInserter ins3 = newChange(repo);
ChangeInserter ins4 = newChange(repo);
ChangeInserter ins5 = newChange(repo);
// CR+1
Change reviewCRplus1 = insert(repo, ins);
gApi.changes().id(reviewCRplus1.getId().get()).current().review(ReviewInput.recommend());
// CR+2
Change reviewCRplus2 = insert(repo, ins2);
gApi.changes().id(reviewCRplus2.getId().get()).current().review(ReviewInput.approve());
// CR+1 VR+1
Change reviewCRplus1VRplus1 = insert(repo, ins3);
gApi.changes().id(reviewCRplus1VRplus1.getId().get()).current().review(ReviewInput.recommend());
gApi.changes().id(reviewCRplus1VRplus1.getId().get()).current().review(reviewVerified);
// CR+2 VR+1
Change reviewCRplus2VRplus1 = insert(repo, ins4);
gApi.changes().id(reviewCRplus2VRplus1.getId().get()).current().review(ReviewInput.approve());
gApi.changes().id(reviewCRplus2VRplus1.getId().get()).current().review(reviewVerified);
// VR+1
Change reviewVRplus1 = insert(repo, ins5);
gApi.changes().id(reviewVRplus1.getId().get()).current().review(reviewVerified);
assertQuery("label:Code-Review=+1", reviewCRplus1VRplus1, reviewCRplus1);
assertQuery("label:Code-Review>=+1", reviewCRplus2VRplus1, reviewCRplus1VRplus1, reviewCRplus2, reviewCRplus1);
assertQuery("label:Code-Review>=+2", reviewCRplus2VRplus1, reviewCRplus2);
assertQuery("label:Code-Review>=+1 label:Verified=+1", reviewCRplus2VRplus1, reviewCRplus1VRplus1);
assertQuery("label:Code-Review>=+2 label:Verified=+1", reviewCRplus2VRplus1);
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class PutDescription method apply.
@Override
public Response<String> apply(ProjectResource resource, DescriptionInput input) throws AuthException, ResourceConflictException, ResourceNotFoundException, IOException, PermissionBackendException {
if (input == null) {
// Delete would set description to null.
input = new DescriptionInput();
}
IdentifiedUser user = resource.getUser().asIdentifiedUser();
permissionBackend.user(user).project(resource.getNameKey()).check(ProjectPermission.WRITE_CONFIG);
try (MetaDataUpdate md = updateFactory.get().create(resource.getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
String desc = input.description;
config.updateProject(p -> p.setDescription(Strings.emptyToNull(desc)));
String msg = MoreObjects.firstNonNull(Strings.emptyToNull(input.commitMessage), "Update description\n");
if (!msg.endsWith("\n")) {
msg += "\n";
}
md.setAuthor(user);
md.setMessage(msg);
config.commit(md);
cache.evictAndReindex(resource.getProjectState().getProject());
md.getRepository().setGitwebDescription(config.getProject().getDescription());
return Strings.isNullOrEmpty(config.getProject().getDescription()) ? Response.none() : Response.ok(config.getProject().getDescription());
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(resource.getName(), notFound);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage()));
}
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class SetDefaultDashboard method apply.
@Override
public Response<DashboardInfo> apply(DashboardResource rsrc, SetDashboardInput input) throws RestApiException, IOException, PermissionBackendException {
if (input == null) {
// Delete would set input to null.
input = new SetDashboardInput();
}
input.id = Strings.emptyToNull(input.id);
permissionBackend.user(rsrc.getUser()).project(rsrc.getProjectState().getNameKey()).check(ProjectPermission.WRITE_CONFIG);
DashboardResource target = null;
if (input.id != null) {
try {
target = dashboards.parse(new ProjectResource(rsrc.getProjectState(), rsrc.getUser()), IdString.fromUrl(input.id));
} catch (ResourceNotFoundException e) {
throw new BadRequestException("dashboard " + input.id + " not found", e);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(e.getMessage());
}
}
try (MetaDataUpdate md = updateFactory.create(rsrc.getProjectState().getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
String id = input.id;
if (inherited) {
config.updateProject(p -> p.setDefaultDashboard(id));
} else {
config.updateProject(p -> p.setLocalDefaultDashboard(id));
}
String msg = MoreObjects.firstNonNull(Strings.emptyToNull(input.commitMessage), input.id == null ? "Removed default dashboard.\n" : String.format("Changed default dashboard to %s.\n", input.id));
if (!msg.endsWith("\n")) {
msg += "\n";
}
md.setAuthor(rsrc.getUser().asIdentifiedUser());
md.setMessage(msg);
config.commit(md);
cache.evictAndReindex(rsrc.getProjectState().getProject());
if (target != null) {
Response<DashboardInfo> response = get.get().apply(target);
response.value().isDefault = true;
return response;
}
return Response.none();
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(rsrc.getProjectState().getProject().getName(), notFound);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage()));
}
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class SetAccess method apply.
@Override
public Response<ProjectAccessInfo> apply(ProjectResource rsrc, ProjectAccessInput input) throws Exception {
MetaDataUpdate.User metaDataUpdateUser = metaDataUpdateFactory.get();
ProjectConfig config;
List<AccessSection> removals = accessUtil.getAccessSections(input.remove);
List<AccessSection> additions = accessUtil.getAccessSections(input.add);
try (MetaDataUpdate md = metaDataUpdateUser.create(rsrc.getNameKey())) {
config = projectConfigFactory.read(md);
// Check that the user has the right permissions.
boolean checkedAdmin = false;
for (AccessSection section : Iterables.concat(additions, removals)) {
boolean isGlobalCapabilities = AccessSection.GLOBAL_CAPABILITIES.equals(section.getName());
if (isGlobalCapabilities) {
if (!checkedAdmin) {
permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER);
checkedAdmin = true;
}
} else {
permissionBackend.currentUser().project(rsrc.getNameKey()).ref(section.getName()).check(RefPermission.WRITE_CONFIG);
}
}
accessUtil.validateChanges(config, removals, additions);
accessUtil.applyChanges(config, removals, additions);
accessUtil.setParentName(identifiedUser.get(), config, rsrc.getNameKey(), input.parent == null ? null : Project.nameKey(input.parent), !checkedAdmin);
if (!Strings.isNullOrEmpty(input.message)) {
if (!input.message.endsWith("\n")) {
input.message += "\n";
}
md.setMessage(input.message);
} else {
md.setMessage("Modify access rules\n");
}
config.commit(md);
projectCache.evictAndReindex(config.getProject());
createGroupPermissionSyncer.syncIfNeeded();
} catch (InvalidNameException e) {
throw new BadRequestException(e.toString());
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(rsrc.getName(), e);
}
return Response.ok(getAccess.apply(rsrc.getNameKey()));
}
Aggregations