Merge "Don't show error on ACL modification if a section is added more than once"
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.common;
|
||||
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ProjectAccessUtil {
|
||||
public static List<AccessSection> mergeSections(final List<AccessSection> src) {
|
||||
final Map<String, AccessSection> map =
|
||||
new LinkedHashMap<String, AccessSection>();
|
||||
for (final AccessSection section : src) {
|
||||
if (section.getPermissions().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final AccessSection prior = map.get(section.getName());
|
||||
if (prior != null) {
|
||||
prior.mergeFrom(section);
|
||||
} else {
|
||||
map.put(section.getName(), section);
|
||||
}
|
||||
}
|
||||
return new ArrayList<AccessSection>(map.values());
|
||||
}
|
||||
|
||||
public static List<AccessSection> removeEmptyPermissionsAndSections(
|
||||
final List<AccessSection> src) {
|
||||
final Set<AccessSection> sectionsToRemove = new HashSet<AccessSection>();
|
||||
for (final AccessSection section : src) {
|
||||
final Set<Permission> permissionsToRemove = new HashSet<Permission>();
|
||||
for (final Permission permission : section.getPermissions()) {
|
||||
if (permission.getRules().isEmpty()) {
|
||||
permissionsToRemove.add(permission);
|
||||
}
|
||||
}
|
||||
for (final Permission permissionToRemove : permissionsToRemove) {
|
||||
section.remove(permissionToRemove);
|
||||
}
|
||||
if (section.getPermissions().isEmpty()) {
|
||||
sectionsToRemove.add(section);
|
||||
}
|
||||
}
|
||||
for (final AccessSection sectionToRemove : sectionsToRemove) {
|
||||
src.remove(sectionToRemove);
|
||||
}
|
||||
return src;
|
||||
}
|
||||
}
|
@@ -14,12 +14,14 @@
|
||||
|
||||
package com.google.gerrit.client.admin;
|
||||
|
||||
import static com.google.gerrit.common.ProjectAccessUtil.mergeSections;
|
||||
import static com.google.gerrit.common.ProjectAccessUtil.removeEmptyPermissionsAndSections;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.common.data.ProjectAccess;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
@@ -198,7 +200,7 @@ public class ProjectAccessScreen extends ProjectScreen {
|
||||
private Set<String> getDiffs(ProjectAccess wantedAccess,
|
||||
ProjectAccess newAccess) {
|
||||
final List<AccessSection> wantedSections =
|
||||
removeEmptyPermissionsAndSections(wantedAccess.getLocal());
|
||||
mergeSections(removeEmptyPermissionsAndSections(wantedAccess.getLocal()));
|
||||
final HashSet<AccessSection> same =
|
||||
new HashSet<AccessSection>(wantedSections);
|
||||
final HashSet<AccessSection> different =
|
||||
@@ -216,29 +218,6 @@ public class ProjectAccessScreen extends ProjectScreen {
|
||||
return differentNames;
|
||||
}
|
||||
|
||||
private List<AccessSection> removeEmptyPermissionsAndSections(
|
||||
final List<AccessSection> src) {
|
||||
final Set<AccessSection> sectionsToRemove = new HashSet<AccessSection>();
|
||||
for (final AccessSection section : src) {
|
||||
final Set<Permission> permissionsToRemove = new HashSet<Permission>();
|
||||
for (final Permission permission : section.getPermissions()) {
|
||||
if (permission.getRules().isEmpty()) {
|
||||
permissionsToRemove.add(permission);
|
||||
}
|
||||
}
|
||||
for (final Permission permissionToRemove : permissionsToRemove) {
|
||||
section.remove(permissionToRemove);
|
||||
}
|
||||
if (section.getPermissions().isEmpty()) {
|
||||
sectionsToRemove.add(section);
|
||||
}
|
||||
}
|
||||
for (final AccessSection sectionToRemove : sectionsToRemove) {
|
||||
src.remove(sectionToRemove);
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
error.clear();
|
||||
|
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.httpd.rpc.project;
|
||||
|
||||
import static com.google.gerrit.common.ProjectAccessUtil.mergeSections;
|
||||
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
@@ -36,11 +38,8 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class ProjectAccessHandler<T> extends Handler<T> {
|
||||
@@ -151,23 +150,6 @@ public abstract class ProjectAccessHandler<T> extends Handler<T> {
|
||||
toDelete.remove(section.getName());
|
||||
}
|
||||
|
||||
private static List<AccessSection> mergeSections(List<AccessSection> src) {
|
||||
Map<String, AccessSection> map = new LinkedHashMap<String, AccessSection>();
|
||||
for (AccessSection section : src) {
|
||||
if (section.getPermissions().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AccessSection prior = map.get(section.getName());
|
||||
if (prior != null) {
|
||||
prior.mergeFrom(section);
|
||||
} else {
|
||||
map.put(section.getName(), section);
|
||||
}
|
||||
}
|
||||
return new ArrayList<AccessSection>(map.values());
|
||||
}
|
||||
|
||||
private static Set<String> scanSectionNames(ProjectConfig config) {
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (AccessSection section : config.getAccessSections()) {
|
||||
|
Reference in New Issue
Block a user