use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class SetParent method apply.
public String apply(ProjectResource rsrc, ParentInput input, boolean checkIfAdmin) throws AuthException, ResourceConflictException, ResourceNotFoundException, UnprocessableEntityException, IOException, PermissionBackendException, BadRequestException {
IdentifiedUser user = rsrc.getUser().asIdentifiedUser();
String parentName = MoreObjects.firstNonNull(Strings.emptyToNull(input.parent), allProjects.get());
validateParentUpdate(rsrc.getProjectState().getNameKey(), user, parentName, checkIfAdmin);
try (MetaDataUpdate md = updateFactory.get().create(rsrc.getNameKey())) {
ProjectConfig config = projectConfigFactory.read(md);
config.updateProject(p -> p.setParent(parentName));
String msg = Strings.emptyToNull(input.commitMessage);
if (msg == null) {
msg = String.format("Changed parent to %s.\n", parentName);
} else if (!msg.endsWith("\n")) {
msg += "\n";
}
md.setAuthor(user);
md.setMessage(msg);
config.commit(md);
cache.evictAndReindex(rsrc.getProjectState().getProject());
Project.NameKey parent = config.getProject().getParent(allProjects);
requireNonNull(parent);
return parent.get();
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(rsrc.getName(), notFound);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(String.format("invalid project.config: %s", e.getMessage()));
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GrantRevertPermission method execute.
public void execute(Project.NameKey projectName) throws IOException, ConfigInvalidException {
GroupReference registeredUsers = systemGroupBackend.getGroup(REGISTERED_USERS);
try (Repository repo = repoManager.openRepository(projectName)) {
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, projectName, repo);
ProjectConfig projectConfig = projectConfigFactory.read(md);
AtomicBoolean shouldExit = new AtomicBoolean(false);
projectConfig.upsertAccessSection(AccessSection.HEADS, heads -> {
Permission permissionOnRefsHeads = heads.build().getPermission(Permission.REVERT);
if (permissionOnRefsHeads != null) {
if (permissionOnRefsHeads.getRule(registeredUsers) == null || permissionOnRefsHeads.getRules().size() > 1) {
// If admins already changed the permission, don't do anything.
shouldExit.set(true);
return;
}
// permission already exists in refs/heads/*, delete it for Registered Users.
remove(projectConfig, heads, Permission.REVERT, registeredUsers);
}
});
if (shouldExit.get()) {
return;
}
projectConfig.upsertAccessSection(AccessSection.ALL, all -> {
Permission permissionOnRefsStar = all.build().getPermission(Permission.REVERT);
if (permissionOnRefsStar != null && permissionOnRefsStar.getRule(registeredUsers) != null) {
// permission already exists in refs/*, don't do anything.
return;
}
// If the permission doesn't exist of refs/* for Registered Users, grant it.
grant(projectConfig, all, Permission.REVERT, registeredUsers);
});
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage("Add revert permission for all registered users\n");
projectConfig.commit(md);
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class Schema_184 method createMetaDataUpdate.
private MetaDataUpdate createMetaDataUpdate(AllUsersName allUsersName, PersonIdent serverUser, Repository allUsersRepo, @Nullable BatchRefUpdate batchRefUpdate) {
MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, allUsersRepo, batchRefUpdate);
metaDataUpdate.getCommitBuilder().setAuthor(serverUser);
metaDataUpdate.getCommitBuilder().setCommitter(serverUser);
return metaDataUpdate;
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class SchemaCreatorImpl method createMetaDataUpdate.
private MetaDataUpdate createMetaDataUpdate(Repository allUsersRepo, @Nullable BatchRefUpdate batchRefUpdate) {
MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, allUsersRepo, batchRefUpdate);
metaDataUpdate.getCommitBuilder().setAuthor(serverUser);
metaDataUpdate.getCommitBuilder().setCommitter(serverUser);
return metaDataUpdate;
}
use of com.google.gerrit.server.git.meta.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);
}
projectCache.evict(project);
}
Aggregations