use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.
the class ProjectAccessScreen method resetEditors.
private void resetEditors() {
// Push an empty instance through the driver before pushing the real
// data. This will force GWT to delete and recreate the editors, which
// is required to build initialize them as editable vs. read-only.
ProjectAccess mock = new ProjectAccess();
mock.setProjectName(access.getProjectName());
mock.setRevision(access.getRevision());
mock.setLocal(Collections.<AccessSection>emptyList());
mock.setOwnerOf(Collections.<String>emptySet());
driver.edit(mock);
}
use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.
the class ProjectAccessScreen method onLoad.
@Override
protected void onLoad() {
super.onLoad();
CallbackGroup cbs = new CallbackGroup();
ConfigServerApi.capabilities(cbs.add(new AsyncCallback<NativeMap<CapabilityInfo>>() {
@Override
public void onSuccess(NativeMap<CapabilityInfo> result) {
capabilityMap = result;
}
@Override
public void onFailure(Throwable caught) {
// Handled by ScreenLoadCallback.onFailure().
}
}));
Util.PROJECT_SVC.projectAccess(getProjectKey(), cbs.addFinal(new ScreenLoadCallback<ProjectAccess>(this) {
@Override
public void preDisplay(ProjectAccess access) {
displayReadOnly(access);
}
}));
savedPanel = ACCESS;
}
use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.
the class ProjectAccessFactory method call.
@Override
public ProjectAccess call() throws NoSuchProjectException, IOException, ConfigInvalidException, PermissionBackendException {
ProjectControl pc = checkProjectControl();
// Load the current configuration from the repository, ensuring its the most
// recent version available. If it differs from what was in the project
// state, force a cache flush now.
//
ProjectConfig config;
try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
config = ProjectConfig.read(md);
if (config.updateGroupNames(groupBackend)) {
md.setMessage("Update group names\n");
config.commit(md);
projectCache.evict(config.getProject());
pc = checkProjectControl();
} else if (config.getRevision() != null && !config.getRevision().equals(pc.getProjectState().getConfig().getRevision())) {
projectCache.evict(config.getProject());
pc = checkProjectControl();
}
}
final RefControl metaConfigControl = pc.controlForRef(RefNames.REFS_CONFIG);
List<AccessSection> local = new ArrayList<>();
Set<String> ownerOf = new HashSet<>();
Map<AccountGroup.UUID, Boolean> visibleGroups = new HashMap<>();
for (AccessSection section : config.getAccessSections()) {
String name = section.getName();
if (AccessSection.GLOBAL_CAPABILITIES.equals(name)) {
if (pc.isOwner()) {
local.add(section);
ownerOf.add(name);
} else if (metaConfigControl.isVisible()) {
local.add(section);
}
} else if (RefConfigSection.isValid(name)) {
RefControl rc = pc.controlForRef(name);
if (rc.isOwner()) {
local.add(section);
ownerOf.add(name);
} else if (metaConfigControl.isVisible()) {
local.add(section);
} else if (rc.isVisible()) {
// Filter the section to only add rules describing groups that
// are visible to the current-user. This includes any group the
// user is a member of, as well as groups they own or that
// are visible to all users.
AccessSection dst = null;
for (Permission srcPerm : section.getPermissions()) {
Permission dstPerm = null;
for (PermissionRule srcRule : srcPerm.getRules()) {
AccountGroup.UUID group = srcRule.getGroup().getUUID();
if (group == null) {
continue;
}
Boolean canSeeGroup = visibleGroups.get(group);
if (canSeeGroup == null) {
try {
canSeeGroup = groupControlFactory.controlFor(group).isVisible();
} catch (NoSuchGroupException e) {
canSeeGroup = Boolean.FALSE;
}
visibleGroups.put(group, canSeeGroup);
}
if (canSeeGroup) {
if (dstPerm == null) {
if (dst == null) {
dst = new AccessSection(name);
local.add(dst);
}
dstPerm = dst.getPermission(srcPerm.getName(), true);
}
dstPerm.add(srcRule);
}
}
}
}
}
}
if (ownerOf.isEmpty() && pc.isOwnerAnyRef()) {
// Special case: If the section list is empty, this project has no current
// access control information. Rely on what ProjectControl determines
// is ownership, which probably means falling back to site administrators.
ownerOf.add(AccessSection.ALL);
}
final ProjectAccess detail = new ProjectAccess();
detail.setProjectName(projectName);
if (config.getRevision() != null) {
detail.setRevision(config.getRevision().name());
}
detail.setInheritsFrom(config.getProject().getParent(allProjectsName));
if (projectName.equals(allProjectsName)) {
if (pc.isOwner()) {
ownerOf.add(AccessSection.GLOBAL_CAPABILITIES);
}
}
detail.setLocal(local);
detail.setOwnerOf(ownerOf);
detail.setCanUpload(metaConfigControl.isVisible() && (pc.isOwner() || metaConfigControl.canUpload()));
detail.setConfigVisible(pc.isOwner() || metaConfigControl.isVisible());
detail.setGroupInfo(buildGroupInfo(local));
detail.setLabelTypes(pc.getLabelTypes());
detail.setFileHistoryLinks(getConfigFileLogLinks(projectName.get()));
return detail;
}
use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.
the class ProjectAccessScreen method onReview.
@UiHandler("review")
void onReview(@SuppressWarnings("unused") ClickEvent event) {
final ProjectAccess access = driver.flush();
if (driver.hasErrors()) {
Window.alert(AdminConstants.I.errorsMustBeFixed());
return;
}
String message = commitMessage.getText().trim();
if ("".equals(message)) {
message = null;
}
enable(false);
//
Util.PROJECT_SVC.reviewProjectAccess(//
getProjectKey(), //
access.getRevision(), //
message, //
access.getLocal(), //
access.getInheritsFrom(), new GerritCallback<Change.Id>() {
@Override
public void onSuccess(Change.Id changeId) {
enable(true);
commitMessage.setText("");
error.clear();
if (changeId != null) {
Gerrit.display(PageLinks.toChange(changeId));
} else {
displayReadOnly(access);
}
}
@Override
public void onFailure(Throwable caught) {
error.clear();
enable(true);
super.onFailure(caught);
}
});
}
use of com.google.gerrit.common.data.ProjectAccess in project gerrit by GerritCodeReview.
the class ProjectAccessScreen method onCommit.
@UiHandler("commit")
void onCommit(@SuppressWarnings("unused") ClickEvent event) {
final ProjectAccess access = driver.flush();
if (driver.hasErrors()) {
Window.alert(AdminConstants.I.errorsMustBeFixed());
return;
}
String message = commitMessage.getText().trim();
if ("".equals(message)) {
message = null;
}
enable(false);
//
Util.PROJECT_SVC.changeProjectAccess(//
getProjectKey(), //
access.getRevision(), //
message, //
access.getLocal(), //
access.getInheritsFrom(), new GerritCallback<ProjectAccess>() {
@Override
public void onSuccess(ProjectAccess newAccess) {
enable(true);
commitMessage.setText("");
error.clear();
final Set<String> diffs = getDiffs(access, newAccess);
if (diffs.isEmpty()) {
displayReadOnly(newAccess);
} else {
error.add(new Label(Gerrit.C.projectAccessError()));
for (final String diff : diffs) {
error.add(new Label(diff));
}
if (access.canUpload()) {
error.add(new Label(Gerrit.C.projectAccessProposeForReviewHint()));
}
}
}
private Set<String> getDiffs(ProjectAccess wantedAccess, ProjectAccess newAccess) {
List<AccessSection> wantedSections = mergeSections(removeEmptyPermissionsAndSections(wantedAccess.getLocal()));
List<AccessSection> newSections = removeEmptyPermissionsAndSections(newAccess.getLocal());
HashSet<AccessSection> same = new HashSet<>(wantedSections);
HashSet<AccessSection> different = new HashSet<>(wantedSections.size() + newSections.size());
different.addAll(wantedSections);
different.addAll(newSections);
same.retainAll(newSections);
different.removeAll(same);
Set<String> differentNames = new HashSet<>();
for (AccessSection s : different) {
differentNames.add(s.getName());
}
return differentNames;
}
@Override
public void onFailure(Throwable caught) {
error.clear();
enable(true);
if (caught instanceof RemoteJsonException && caught.getMessage().startsWith(UpdateParentFailedException.MESSAGE)) {
new ErrorDialog(Gerrit.M.parentUpdateFailed(caught.getMessage().substring(UpdateParentFailedException.MESSAGE.length() + 1))).center();
} else {
super.onFailure(caught);
}
}
});
}
Aggregations