use of com.google.gerrit.common.data.PermissionRule in project gerrit by GerritCodeReview.
the class ProjectAccessHandler method replace.
private void replace(ProjectConfig config, Set<String> toDelete, AccessSection section) throws NoSuchGroupException {
for (Permission permission : section.getPermissions()) {
for (PermissionRule rule : permission.getRules()) {
lookupGroup(rule);
}
}
config.replace(section);
toDelete.remove(section.getName());
}
use of com.google.gerrit.common.data.PermissionRule in project gerrit by GerritCodeReview.
the class ReviewProjectAccess method addAdministratorsAsReviewers.
private void addAdministratorsAsReviewers(ChangeResource rsrc) {
List<PermissionRule> adminRules = projectCache.getAllProjects().getConfig().getAccessSection(AccessSection.GLOBAL_CAPABILITIES).getPermission(GlobalCapability.ADMINISTRATE_SERVER).getRules();
for (PermissionRule r : adminRules) {
try {
AddReviewerInput input = new AddReviewerInput();
input.reviewer = r.getGroup().getUUID().get();
reviewersProvider.get().apply(rsrc, input);
} catch (Exception e) {
// ignore
Throwables.throwIfUnchecked(e);
}
}
}
use of com.google.gerrit.common.data.PermissionRule in project gerrit by GerritCodeReview.
the class ProjectConfigTest method editConfig.
@Test
public void editConfig() throws Exception {
RevCommit rev = util.commit(//
util.tree(//
util.file("groups", util.blob(group(developers))), util.file("project.config", util.blob(//
"" + //
"[access \"refs/heads/*\"]\n" + //
" exclusiveGroupPermissions = read submit\n" + //
" submit = group Developers\n" + //
" upload = group Developers\n" + //
" read = group Developers\n" + //
"[accounts]\n" + //
" sameGroupVisibility = deny group Developers\n" + //
" sameGroupVisibility = block group Staff\n" + //
"[contributor-agreement \"Individual\"]\n" + //
" description = A simple description\n" + //
" accepted = group Developers\n" + //
" autoVerify = group Developers\n" + //
" agreementUrl = http://www.example.com/agree\n" + //
"[label \"CustomLabel\"]\n" + //
LABEL_SCORES_CONFIG))));
update(rev);
ProjectConfig cfg = read(rev);
AccessSection section = cfg.getAccessSection("refs/heads/*");
cfg.getAccountsSection().setSameGroupVisibility(Collections.singletonList(new PermissionRule(cfg.resolve(staff))));
Permission submit = section.getPermission(Permission.SUBMIT);
submit.add(new PermissionRule(cfg.resolve(staff)));
ContributorAgreement ca = cfg.getContributorAgreement("Individual");
ca.setAccepted(Collections.singletonList(new PermissionRule(cfg.resolve(staff))));
ca.setAutoVerify(null);
ca.setDescription("A new description");
rev = commit(cfg);
assertThat(text(rev, "project.config")).isEqualTo(//
"" + //
"[access \"refs/heads/*\"]\n" + //
" exclusiveGroupPermissions = read submit\n" + //
" submit = group Developers\n" + //
"\tsubmit = group Staff\n" + //
" upload = group Developers\n" + //
" read = group Developers\n" + //
"[accounts]\n" + //
" sameGroupVisibility = group Staff\n" + //
"[contributor-agreement \"Individual\"]\n" + //
" description = A new description\n" + //
" accepted = group Staff\n" + " agreementUrl = http://www.example.com/agree\n" + //
"[label \"CustomLabel\"]\n" + LABEL_SCORES_CONFIG + // label gets this function when it is created
"\tfunction = MaxWithBlock\n" + // label gets this value when it is created
"\tdefaultValue = 0\n");
}
use of com.google.gerrit.common.data.PermissionRule in project gerrit by GerritCodeReview.
the class ProjectConfigTest method editConfigMissingGroupTableEntry.
@Test
public void editConfigMissingGroupTableEntry() throws Exception {
RevCommit rev = util.commit(//
util.tree(//
util.file("groups", util.blob(group(developers))), util.file("project.config", util.blob(//
"" + //
"[access \"refs/heads/*\"]\n" + //
" exclusiveGroupPermissions = read submit\n" + //
" submit = group People Who Can Submit\n" + //
" upload = group Developers\n" + //
" read = group Developers\n"))));
update(rev);
ProjectConfig cfg = read(rev);
AccessSection section = cfg.getAccessSection("refs/heads/*");
Permission submit = section.getPermission(Permission.SUBMIT);
submit.add(new PermissionRule(cfg.resolve(staff)));
rev = commit(cfg);
assertThat(text(rev, "project.config")).isEqualTo(//
"" + //
"[access \"refs/heads/*\"]\n" + //
" exclusiveGroupPermissions = read submit\n" + //
" submit = group People Who Can Submit\n" + //
"\tsubmit = group Staff\n" + //
" upload = group Developers\n" + " read = group Developers\n");
}
use of com.google.gerrit.common.data.PermissionRule in project gerrit by GerritCodeReview.
the class Schema_135 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
try (Repository git = repoManager.openRepository(allProjectsName);
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjectsName, git)) {
ProjectConfig config = ProjectConfig.read(md);
AccessSection meta = config.getAccessSection(RefNames.REFS_CONFIG, true);
Permission createRefsMetaConfigPermission = meta.getPermission(Permission.CREATE, true);
Set<GroupReference> groups = Stream.concat(config.getAccessSection(AccessSection.GLOBAL_CAPABILITIES, true).getPermission(GlobalCapability.ADMINISTRATE_SERVER, true).getRules().stream().map(PermissionRule::getGroup), Stream.of(systemGroupBackend.getGroup(PROJECT_OWNERS))).filter(g -> createRefsMetaConfigPermission.getRule(g) == null).collect(toSet());
for (GroupReference group : groups) {
createRefsMetaConfigPermission.add(new PermissionRule(config.resolve(group)));
}
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
md.setMessage(COMMIT_MSG);
config.commit(md);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException(ex);
}
}
Aggregations