Make access panel read-only when it opens

The access panel should be read-only when it opens, even if the user
has write permission. If the access panel is in read-only mode the
overview is better since the UI does not contain the controls for
editing the access rights. For users that have the permission to edit
the access rights there is an 'Edit' button to switch the access
panel into edit mode.

Bug: issue 956
Change-Id: I04b1072750455932779e95a0f7424b8fd4198901
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2011-05-20 01:09:35 +02:00 committed by Shawn O. Pearce
parent 08ad16693e
commit eb077023ad
5 changed files with 70 additions and 3 deletions

View File

@ -54,6 +54,10 @@ public class PageLinks {
return "change," + ps.getParentKey().toString() + ",patchset=" + ps.get();
}
public static String toProjectAcceess(final Project.NameKey p) {
return "admin,project," + p.get() + ",access";
}
public static String toAccountDashboard(final AccountInfo acct) {
return toAccountDashboard(acct.getId());
}

View File

@ -80,6 +80,7 @@ public class AccessSectionEditor extends Composite implements
private final ProjectAccess projectAccess;
private AccessSection value;
private boolean editing;
private boolean readOnly;
private boolean isDeleted;
@ -154,7 +155,7 @@ public class AccessSectionEditor extends Composite implements
@Override
public void setValue(AccessSection value) {
this.value = value;
this.readOnly = !projectAccess.isOwnerOf(value);
this.readOnly = !editing || !projectAccess.isOwnerOf(value);
refPattern.setEnabled(!readOnly);
deleteSection.setVisible(!readOnly);
@ -166,6 +167,10 @@ public class AccessSectionEditor extends Composite implements
}
}
void setEditing(final boolean editing) {
this.editing = editing;
}
private void rebuildPermissionSelector() {
List<String> perms = new ArrayList<String>();
for (ApprovalType t : Gerrit.getConfig().getApprovalTypes()

View File

@ -61,6 +61,8 @@ public class ProjectAccessEditor extends Composite implements
private ProjectAccess value;
private boolean editing;
public ProjectAccessEditor() {
initWidget(uiBinder.createAndBindUi(this));
local = ListEditor.of(new Source(localContainer));
@ -90,7 +92,7 @@ public class ProjectAccessEditor extends Composite implements
inheritsFrom.getStyle().setDisplay(Display.NONE);
}
addSection.setVisible(value != null && !value.getOwnerOf().isEmpty());
addSection.setVisible(value != null && editing && !value.getOwnerOf().isEmpty());
}
@Override
@ -115,6 +117,11 @@ public class ProjectAccessEditor extends Composite implements
public void setDelegate(EditorDelegate<ProjectAccess> delegate) {
}
void setEditing(final boolean editing) {
this.editing = editing;
addSection.setVisible(editing);
}
private class Source extends EditorSource<AccessSectionEditor> {
private final FlowPanel container;
@ -125,6 +132,7 @@ public class ProjectAccessEditor extends Composite implements
@Override
public AccessSectionEditor create(int index) {
AccessSectionEditor subEditor = new AccessSectionEditor(value);
subEditor.setEditing(editing);
container.insert(subEditor, index);
return subEditor;
}

View File

@ -14,8 +14,10 @@
package com.google.gerrit.client.admin;
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.ProjectAccess;
import com.google.gerrit.reviewdb.Project;
import com.google.gwt.core.client.GWT;
@ -42,6 +44,15 @@ public class ProjectAccessScreen extends ProjectScreen {
ProjectAccessEditor> {
}
@UiField
DivElement editTools;
@UiField
Button edit;
@UiField
Button cancel;
@UiField
ProjectAccessEditor accessEditor;
@ -56,6 +67,8 @@ public class ProjectAccessScreen extends ProjectScreen {
private Driver driver;
private ProjectAccess access;
public ProjectAccessScreen(final Project.NameKey toShow) {
super(toShow);
}
@ -66,6 +79,7 @@ public class ProjectAccessScreen extends ProjectScreen {
add(uiBinder.createAndBindUi(this));
driver = GWT.create(Driver.class);
accessEditor.setEditing(false);
driver.initialize(accessEditor);
}
@ -82,8 +96,27 @@ public class ProjectAccessScreen extends ProjectScreen {
}
void edit(ProjectAccess access) {
this.access = access;
final boolean editing = !edit.isEnabled();
accessEditor.setEditing(editing);
UIObject.setVisible(editTools, !access.getOwnerOf().isEmpty());
cancel.setVisible(editing);
UIObject.setVisible(commitTools, editing);
driver.edit(access);
UIObject.setVisible(commitTools, !access.getOwnerOf().isEmpty());
}
@UiHandler("edit")
void onEdit(ClickEvent event) {
edit.setEnabled(false);
cancel.setVisible(true);
UIObject.setVisible(commitTools, true);
accessEditor.setEditing(true);
driver.edit(access);
}
@UiHandler(value={"cancel", "cancel2"})
void onCancel(ClickEvent event) {
Gerrit.display(PageLinks.toProjectAcceess(getProjectKey()));
}
@UiHandler("commit")

View File

@ -35,6 +35,18 @@ limitations under the License.
</ui:style>
<g:HTMLPanel>
<div ui:field='editTools'>
<g:Button
ui:field='edit'
text='Edit'>
<ui:attribute name='text'/>
</g:Button>
<g:Button
ui:field='cancel'
text='Cancel'>
<ui:attribute name='text'/>
</g:Button>
</div>
<my:ProjectAccessEditor ui:field='accessEditor'/>
<div ui:field='commitTools'>
<div class='{style.commitMessage}'>
@ -51,6 +63,11 @@ limitations under the License.
text='Save Changes'>
<ui:attribute name='text'/>
</g:Button>
<g:Button
ui:field='cancel2'
text='Cancel'>
<ui:attribute name='text'/>
</g:Button>
</div>
<div style='width: 35em; visibility: hidden;' />
</g:HTMLPanel>