Merge "Display error if modifying access rights for a ref is forbidden"

This commit is contained in:
Shawn Pearce
2012-06-19 17:27:00 -07:00
committed by gerrit code review
8 changed files with 110 additions and 4 deletions

View File

@@ -118,4 +118,13 @@ public class AccessSection extends RefConfigSection implements
public String toString() {
return "AccessSection[" + getName() + "]";
}
@Override
public boolean equals(final Object obj) {
if (!super.equals(obj) || !(obj instanceof AccessSection)) {
return false;
}
return new HashSet<Permission>(permissions).equals(new HashSet<Permission>(
((AccessSection) obj).permissions));
}
}

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.common.data;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -220,4 +221,23 @@ public class Permission implements Comparable<Permission> {
int index = NAMES_LC.indexOf(a.getName().toLowerCase());
return 0 <= index ? index : NAMES_LC.size();
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof Permission)) {
return false;
}
final Permission other = (Permission) obj;
if (!name.equals(other.name) || exclusiveGroup != other.exclusiveGroup) {
return false;
}
return new HashSet<PermissionRule>(rules)
.equals(new HashSet<PermissionRule>(other.rules));
}
@Override
public int hashCode() {
return name.hashCode();
}
}

View File

@@ -257,4 +257,19 @@ public class PermissionRule implements Comparable<PermissionRule> {
}
return Integer.parseInt(value);
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof PermissionRule)) {
return false;
}
final PermissionRule other = (PermissionRule)obj;
return action.equals(other.action) && force == other.force
&& min == other.min && max == other.max && group.equals(other.group);
}
@Override
public int hashCode() {
return group.hashCode();
}
}

View File

@@ -48,4 +48,17 @@ public abstract class RefConfigSection {
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof RefConfigSection)) {
return false;
}
return name.equals(((RefConfigSection) obj).name);
}
@Override
public int hashCode() {
return name.hashCode();
}
}

View File

@@ -99,4 +99,6 @@ public interface GerritConstants extends Constants {
String jumpMineWatched();
String jumpMineStarred();
String jumpMineDraftComments();
String projectAccessError();
}

View File

@@ -81,4 +81,6 @@ jumpMine = Go to my dashboard
jumpMineWatched = Go to watched changes
jumpMineDrafts = Go to drafts
jumpMineStarred = Go to starred changes
jumpMineDraftComments = Go to draft comments
jumpMineDraftComments = Go to draft comments
projectAccessError = You don't have permissions to modify the access rights for the following refs:

View File

@@ -31,10 +31,14 @@ import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwtexpui.globalkey.client.NpTextArea;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class ProjectAccessScreen extends ProjectScreen {
interface Binder extends UiBinder<HTMLPanel, ProjectAccessScreen> {
@@ -59,6 +63,9 @@ public class ProjectAccessScreen extends ProjectScreen {
@UiField
Button cancel2;
@UiField
VerticalPanel error;
@UiField
ProjectAccessEditor accessEditor;
@@ -141,7 +148,7 @@ public class ProjectAccessScreen extends ProjectScreen {
@UiHandler("commit")
void onCommit(ClickEvent event) {
ProjectAccess access = driver.flush();
final ProjectAccess access = driver.flush();
if (driver.hasErrors()) {
Window.alert(Util.C.errorsMustBeFixed());
@@ -161,14 +168,43 @@ public class ProjectAccessScreen extends ProjectScreen {
access.getLocal(), //
new GerritCallback<ProjectAccess>() {
@Override
public void onSuccess(ProjectAccess access) {
public void onSuccess(ProjectAccess newAccess) {
enable(true);
commitMessage.setText("");
displayReadOnly(access);
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));
}
}
}
private Set<String> getDiffs(ProjectAccess wantedAccess,
ProjectAccess newAccess) {
final HashSet<AccessSection> same =
new HashSet<AccessSection>(wantedAccess.getLocal());
final HashSet<AccessSection> different =
new HashSet<AccessSection>(wantedAccess.getLocal().size()
+ newAccess.getLocal().size());
different.addAll(wantedAccess.getLocal());
different.addAll(newAccess.getLocal());
same.retainAll(newAccess.getLocal());
different.removeAll(same);
final Set<String> differentNames = new HashSet<String>();
for (final AccessSection s : different) {
differentNames.add(s.getName());
}
return differentNames;
}
@Override
public void onFailure(Throwable caught) {
error.clear();
enable(true);
super.onFailure(caught);
}

View File

@@ -32,6 +32,11 @@ limitations under the License.
.commitMessage .gwt-TextArea {
margin: 5px 5px 5px 5px;
}
.errorMessage {
margin-top: 5px;
margin-bottom: 5px;
color: red;
}
</ui:style>
<g:HTMLPanel>
@@ -58,6 +63,10 @@ limitations under the License.
spellCheck='true'
/>
</div>
<g:VerticalPanel
styleName='{style.errorMessage}'
ui:field='error'>
</g:VerticalPanel>
<g:Button
ui:field='commit'
text='Save Changes'>