use of com.google.gerrit.server.project.ProjectState 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.ProjectState in project gerrit by GerritCodeReview.
the class GroupMembers method getProjectOwners.
private Set<Account> getProjectOwners(final Project.NameKey project, Set<AccountGroup.UUID> seen) throws NoSuchProjectException, IOException {
seen.add(SystemGroupBackend.PROJECT_OWNERS);
if (project == null) {
return Collections.emptySet();
}
ProjectState projectState = projectCache.get(project).orElseThrow(noSuchProject(project));
final HashSet<Account> projectOwners = new HashSet<>();
for (AccountGroup.UUID ownerGroup : projectState.getAllOwners()) {
if (!seen.contains(ownerGroup)) {
projectOwners.addAll(listAccounts(ownerGroup, project, seen));
}
}
return projectOwners;
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class PatchSetUtil method isPatchSetLocked.
/**
* Is the current patch set locked against state changes?
*/
public boolean isPatchSetLocked(ChangeNotes notes) {
Change change = notes.getChange();
if (change.isMerged()) {
return false;
}
ProjectState projectState = projectCache.get(notes.getProjectName()).orElseThrow(illegalState(notes.getProjectName()));
ApprovalsUtil approvalsUtil = approvalsUtilProvider.get();
for (PatchSetApproval ap : approvalsUtil.byPatchSet(notes, change.currentPatchSetId())) {
Optional<LabelType> type = projectState.getLabelTypes(notes).byLabel(ap.label());
if (type.isPresent() && ap.value() == 1 && type.get().getFunction() == LabelFunction.PATCH_SET_LOCK) {
return true;
}
}
return false;
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class MagicLabelPredicate method match.
@Override
public boolean match(ChangeData changeData) {
Change change = changeData.change();
if (change == null) {
//
return false;
}
Optional<ProjectState> project = args.projectCache.get(change.getDest().project());
if (!project.isPresent()) {
//
return false;
}
LabelType labelType = type(project.get().getLabelTypes(), magicLabelVote.label());
if (labelType == null) {
// Label is not defined by this project.
return false;
}
switch(magicLabelVote.value()) {
case ANY:
return matchAny(changeData, labelType);
case MIN:
return matchNumeric(changeData, magicLabelVote.label(), labelType.getMin().getValue());
case MAX:
return matchNumeric(changeData, magicLabelVote.label(), labelType.getMax().getValue());
}
throw new IllegalStateException("Unsupported magic label value: " + magicLabelVote.value());
}
use of com.google.gerrit.server.project.ProjectState in project gerrit by GerritCodeReview.
the class ChangeData method getLabelTypes.
public LabelTypes getLabelTypes() {
if (labelTypes == null) {
ProjectState state = projectCache.get(project()).orElseThrow(illegalState(project()));
labelTypes = state.getLabelTypes(change().getDest());
}
return labelTypes;
}
Aggregations