Populate the group screens via REST

Finish the migration of the groups screen to the new REST API.

Change-Id: If453bd9ff594b6a424fb0fbecde38825ed03808a
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2013-02-01 16:37:38 +01:00
parent bf75002957
commit accd070eeb
8 changed files with 148 additions and 111 deletions

View File

@ -60,7 +60,6 @@ import com.google.gerrit.client.admin.ProjectDashboardsScreen;
import com.google.gerrit.client.admin.ProjectInfoScreen; import com.google.gerrit.client.admin.ProjectInfoScreen;
import com.google.gerrit.client.admin.ProjectListScreen; import com.google.gerrit.client.admin.ProjectListScreen;
import com.google.gerrit.client.admin.ProjectScreen; import com.google.gerrit.client.admin.ProjectScreen;
import com.google.gerrit.client.admin.Util;
import com.google.gerrit.client.auth.openid.OpenIdSignInDialog; import com.google.gerrit.client.auth.openid.OpenIdSignInDialog;
import com.google.gerrit.client.auth.userpass.UserPassSignInDialog; import com.google.gerrit.client.auth.userpass.UserPassSignInDialog;
import com.google.gerrit.client.changes.AccountDashboardScreen; import com.google.gerrit.client.changes.AccountDashboardScreen;
@ -72,13 +71,14 @@ import com.google.gerrit.client.changes.PublishCommentScreen;
import com.google.gerrit.client.changes.QueryScreen; import com.google.gerrit.client.changes.QueryScreen;
import com.google.gerrit.client.dashboards.DashboardInfo; import com.google.gerrit.client.dashboards.DashboardInfo;
import com.google.gerrit.client.dashboards.DashboardList; import com.google.gerrit.client.dashboards.DashboardList;
import com.google.gerrit.client.groups.GroupApi;
import com.google.gerrit.client.groups.GroupInfo;
import com.google.gerrit.client.patches.PatchScreen; import com.google.gerrit.client.patches.PatchScreen;
import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.RestApi; import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.client.ui.Screen; import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks; import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.auth.SignInMode; import com.google.gerrit.common.auth.SignInMode;
import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.common.data.PatchSetDetail; import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
@ -729,27 +729,26 @@ public class Dispatcher {
private void group() { private void group() {
final String panel; final String panel;
AccountGroup.Id groupId = null; final String group;
AccountGroup.UUID groupUUID = null;
if (matchPrefix("/admin/groups/uuid-", token)) { if (matchPrefix("/admin/groups/uuid-", token)) {
String p = skip(token); String p = skip(token);
int c = p.indexOf(','); int c = p.indexOf(',');
if (c < 0) { if (c < 0) {
groupUUID = AccountGroup.UUID.parse(p); group = p;
panel = null; panel = null;
} else { } else {
groupUUID = AccountGroup.UUID.parse(p.substring(0, c)); group = p.substring(0, c);
panel = p.substring(c + 1); panel = p.substring(c + 1);
} }
} else if (matchPrefix("/admin/groups/", token)) { } else if (matchPrefix("/admin/groups/", token)) {
String p = skip(token); String p = skip(token);
int c = p.indexOf(','); int c = p.indexOf(',');
if (c < 0) { if (c < 0) {
groupId = AccountGroup.Id.parse(p); group = p;
panel = null; panel = null;
} else { } else {
groupId = AccountGroup.Id.parse(p.substring(0, c)); group = p.substring(0, c);
panel = p.substring(c + 1); panel = p.substring(c + 1);
} }
} else { } else {
@ -757,10 +756,9 @@ public class Dispatcher {
return; return;
} }
Util.GROUP_SVC.groupDetail(groupId, groupUUID, GroupApi.getGroup(group, new GerritCallback<GroupInfo>() {
new GerritCallback<GroupDetail>() {
@Override @Override
public void onSuccess(GroupDetail groupDetail) { public void onSuccess(GroupInfo group) {
if (panel == null || panel.isEmpty()) { if (panel == null || panel.isEmpty()) {
// The token does not say which group screen should be shown, // The token does not say which group screen should be shown,
// as default for internal groups show the members, as default // as default for internal groups show the members, as default
@ -768,21 +766,18 @@ public class Dispatcher {
// for external and system groups the members cannot be // for external and system groups the members cannot be
// shown in the web UI). // shown in the web UI).
// //
if (groupDetail.group.getType() == AccountGroup.Type.INTERNAL) { if (AccountGroup.isInternalGroup(group.getGroupUUID())
Gerrit.display(toGroup(groupDetail.group.getId(), && !AccountGroup.isSystemGroup(group.getGroupUUID())) {
AccountGroupScreen.MEMBERS), Gerrit.display(toGroup(group.getGroupId(), AccountGroupScreen.MEMBERS),
new AccountGroupMembersScreen(groupDetail, token)); new AccountGroupMembersScreen(group, token));
} else { } else {
Gerrit.display(toGroup(groupDetail.group.getId(), Gerrit.display(toGroup(group.getGroupId(), AccountGroupScreen.INFO),
AccountGroupScreen.INFO), new AccountGroupInfoScreen(group, token));
new AccountGroupInfoScreen(groupDetail, token));
} }
} else if (AccountGroupScreen.INFO.equals(panel)) { } else if (AccountGroupScreen.INFO.equals(panel)) {
Gerrit.display(token, Gerrit.display(token, new AccountGroupInfoScreen(group, token));
new AccountGroupInfoScreen(groupDetail, token));
} else if (AccountGroupScreen.MEMBERS.equals(panel)) { } else if (AccountGroupScreen.MEMBERS.equals(panel)) {
Gerrit.display(token, Gerrit.display(token, new AccountGroupMembersScreen(group, token));
new AccountGroupMembersScreen(groupDetail, token));
} else { } else {
Gerrit.display(token, new NotFoundScreen()); Gerrit.display(token, new NotFoundScreen());
} }

View File

@ -19,11 +19,12 @@ import com.google.gerrit.client.VoidResult;
import com.google.gerrit.client.groups.GroupApi; import com.google.gerrit.client.groups.GroupApi;
import com.google.gerrit.client.groups.GroupInfo; import com.google.gerrit.client.groups.GroupInfo;
import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.client.ui.AccountGroupSuggestOracle; import com.google.gerrit.client.ui.AccountGroupSuggestOracle;
import com.google.gerrit.client.ui.OnEditEnabler; import com.google.gerrit.client.ui.OnEditEnabler;
import com.google.gerrit.client.ui.RPCSuggestOracle; import com.google.gerrit.client.ui.RPCSuggestOracle;
import com.google.gerrit.client.ui.SmallHeading; import com.google.gerrit.client.ui.SmallHeading;
import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.ClickHandler;
@ -51,7 +52,7 @@ public class AccountGroupInfoScreen extends AccountGroupScreen {
private CheckBox visibleToAllCheckBox; private CheckBox visibleToAllCheckBox;
private Button saveGroupOptions; private Button saveGroupOptions;
public AccountGroupInfoScreen(final GroupDetail toShow, final String token) { public AccountGroupInfoScreen(final GroupInfo toShow, final String token) {
super(toShow, token); super(toShow, token);
} }
@ -212,23 +213,34 @@ public class AccountGroupInfoScreen extends AccountGroupScreen {
} }
@Override @Override
protected void display(final GroupDetail groupDetail) { protected void display(final GroupInfo group, final boolean canModify) {
final AccountGroup group = groupDetail.group;
groupUUIDLabel.setText(group.getGroupUUID().get()); groupUUIDLabel.setText(group.getGroupUUID().get());
groupNameTxt.setText(group.getName()); groupNameTxt.setText(group.name());
if (groupDetail.ownerGroup != null) {
ownerTxt.setText(groupDetail.ownerGroup.getName());
} else {
ownerTxt.setText(Util.M.deletedReference(group.getOwnerGroupUUID().get()));
}
descTxt.setText(group.getDescription());
visibleToAllCheckBox.setValue(group.isVisibleToAll());
setMembersTabVisible(group.getType() == AccountGroup.Type.INTERNAL);
enableForm(groupDetail.canModify); GroupApi.getGroupName(group.getOwnerUUID(), new GerritCallback<NativeString>() {
saveName.setVisible(groupDetail.canModify); @Override
saveOwner.setVisible(groupDetail.canModify); public void onSuccess(NativeString result) {
saveDesc.setVisible(groupDetail.canModify); ownerTxt.setText(result.asString());
saveGroupOptions.setVisible(groupDetail.canModify); }
@Override
public void onFailure(Throwable caught) {
if (RestApi.isNotFound(caught)) {
ownerTxt.setText(Util.M.deletedReference(group.getOwnerUUID().get()));
} else {
super.onFailure(caught);
}
}
});
descTxt.setText(group.description());
visibleToAllCheckBox.setValue(group.options().isVisibleToAll());
setMembersTabVisible(AccountGroup.isInternalGroup(group.getGroupUUID())
&& !AccountGroup.isSystemGroup(group.getGroupUUID()));
enableForm(canModify);
saveName.setVisible(canModify);
saveOwner.setVisible(canModify);
saveDesc.setVisible(canModify);
saveGroupOptions.setVisible(canModify);
} }
} }

View File

@ -30,8 +30,6 @@ import com.google.gerrit.client.ui.AddMemberBox;
import com.google.gerrit.client.ui.FancyFlexTable; import com.google.gerrit.client.ui.FancyFlexTable;
import com.google.gerrit.client.ui.Hyperlink; import com.google.gerrit.client.ui.Hyperlink;
import com.google.gerrit.client.ui.SmallHeading; import com.google.gerrit.client.ui.SmallHeading;
import com.google.gerrit.common.data.AccountInfoCache;
import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
@ -51,7 +49,6 @@ import javax.annotation.Nullable;
public class AccountGroupMembersScreen extends AccountGroupScreen { public class AccountGroupMembersScreen extends AccountGroupScreen {
private AccountInfoCache accounts = AccountInfoCache.empty();
private MemberTable members; private MemberTable members;
private IncludeTable includes; private IncludeTable includes;
@ -65,7 +62,7 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
private FlowPanel noMembersInfo; private FlowPanel noMembersInfo;
public AccountGroupMembersScreen(final GroupDetail toShow, final String token) { public AccountGroupMembersScreen(final GroupInfo toShow, final String token) {
super(toShow, token); super(toShow, token);
} }
@ -153,36 +150,30 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
} }
@Override @Override
protected void display(final GroupDetail groupDetail) { protected void display(final GroupInfo group, final boolean canModify) {
switch (groupDetail.group.getType()) { if (AccountGroup.isInternalGroup(group.getGroupUUID())
case INTERNAL: && !AccountGroup.isSystemGroup(group.getGroupUUID())) {
accounts = groupDetail.accounts;
MemberList.all(getGroupUUID(), new GerritCallback<MemberList>() { MemberList.all(getGroupUUID(), new GerritCallback<MemberList>() {
@Override @Override
public void onSuccess(MemberList result) { public void onSuccess(MemberList result) {
members.display(Natives.asList(result)); members.display(Natives.asList(result));
} }
}); });
GroupList.included(getGroupUUID(), new GerritCallback<GroupList>() { GroupList.included(getGroupUUID(), new GerritCallback<GroupList>() {
@Override @Override
public void onSuccess(GroupList result) { public void onSuccess(GroupList result) {
includes.display(Natives.asList(result)); includes.display(Natives.asList(result));
} }
}); });
} else {
break;
default:
memberPanel.setVisible(false); memberPanel.setVisible(false);
includePanel.setVisible(false); includePanel.setVisible(false);
noMembersInfo.setVisible(true); noMembersInfo.setVisible(true);
break;
} }
enableForm(groupDetail.canModify); enableForm(canModify);
delMember.setVisible(groupDetail.canModify); delMember.setVisible(canModify);
delInclude.setVisible(groupDetail.canModify); delInclude.setVisible(canModify);
} }
void doAddNewMember() { void doAddNewMember() {
@ -290,12 +281,11 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
} }
void populate(final int row, final MemberInfo i) { void populate(final int row, final MemberInfo i) {
final Account.Id accountId = i.getAccountId();
CheckBox checkBox = new CheckBox(); CheckBox checkBox = new CheckBox();
table.setWidget(row, 1, checkBox); table.setWidget(row, 1, checkBox);
checkBox.setEnabled(enabled); checkBox.setEnabled(enabled);
table.setWidget(row, 2, AccountLink.link(accounts, accountId)); table.setWidget(row, 2, new AccountLink(i));
table.setText(row, 3, accounts.get(accountId).getPreferredEmail()); table.setText(row, 3, i.preferredEmail());
final FlexCellFormatter fmt = table.getFlexCellFormatter(); final FlexCellFormatter fmt = table.getFlexCellFormatter();
fmt.addStyleName(row, 1, Gerrit.RESOURCES.css().iconCell()); fmt.addStyleName(row, 1, Gerrit.RESOURCES.css().iconCell());

View File

@ -16,63 +16,64 @@ package com.google.gerrit.client.admin;
import static com.google.gerrit.client.Dispatcher.toGroup; import static com.google.gerrit.client.Dispatcher.toGroup;
import com.google.gerrit.client.groups.GroupApi;
import com.google.gerrit.client.groups.GroupInfo; import com.google.gerrit.client.groups.GroupInfo;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.MenuScreen; import com.google.gerrit.client.ui.MenuScreen;
import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
public abstract class AccountGroupScreen extends MenuScreen { public abstract class AccountGroupScreen extends MenuScreen {
public static final String INFO = "info"; public static final String INFO = "info";
public static final String MEMBERS = "members"; public static final String MEMBERS = "members";
private final GroupDetail groupDetail; private final GroupInfo group;
private final String membersTabToken; private final String membersTabToken;
public AccountGroupScreen(final GroupDetail toShow, final String token) { public AccountGroupScreen(final GroupInfo toShow, final String token) {
setRequiresSignIn(true); setRequiresSignIn(true);
this.groupDetail = toShow; this.group = toShow;
this.membersTabToken = getTabToken(token, MEMBERS); this.membersTabToken = getTabToken(token, MEMBERS);
link(Util.C.groupTabGeneral(), getTabToken(token, INFO)); link(Util.C.groupTabGeneral(), getTabToken(token, INFO));
link(Util.C.groupTabMembers(), membersTabToken, link(Util.C.groupTabMembers(), membersTabToken,
groupDetail.group.getType() == AccountGroup.Type.INTERNAL); AccountGroup.isInternalGroup(group.getGroupUUID())
&& !AccountGroup.isSystemGroup(group.getGroupUUID()));
} }
private String getTabToken(final String token, final String tab) { private String getTabToken(final String token, final String tab) {
if (token.startsWith("/admin/groups/uuid-")) { if (token.startsWith("/admin/groups/uuid-")) {
return toGroup(groupDetail.group.getGroupUUID(), tab); return toGroup(group.getGroupUUID(), tab);
} else { } else {
return toGroup(groupDetail.group.getId(), tab); return toGroup(group.getGroupId(), tab);
} }
} }
@Override @Override
protected void onLoad() { protected void onLoad() {
super.onLoad(); super.onLoad();
setPageTitle(Util.M.group(groupDetail.group.getName())); setPageTitle(Util.M.group(group.name()));
display(); display();
display(groupDetail); GroupApi.isGroupOwner(group.name(), new GerritCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
display(group, result);
}
});
} }
protected abstract void display(final GroupDetail groupDetail); protected abstract void display(final GroupInfo group, final boolean canModify);
protected AccountGroup.Id getGroupId() {
return groupDetail.group.getId();
}
protected AccountGroup.UUID getGroupUUID() { protected AccountGroup.UUID getGroupUUID() {
return groupDetail.group.getGroupUUID(); return group.getGroupUUID();
} }
protected void updateOwnerGroup(GroupInfo ownerGroup) { protected void updateOwnerGroup(GroupInfo ownerGroup) {
groupDetail.group.setOwnerGroupUUID(ownerGroup.getGroupUUID()); group.setOwnerUUID(ownerGroup.getGroupUUID());
groupDetail.ownerGroup.setUUID(ownerGroup.getGroupUUID());
groupDetail.ownerGroup.setName(ownerGroup.name());
} }
protected AccountGroup.UUID getOwnerGroupUUID() { protected AccountGroup.UUID getOwnerGroupUUID() {
return groupDetail.group.getOwnerGroupUUID(); return group.getOwnerUUID();
} }
protected void setMembersTabVisible(final boolean visible) { protected void setMembersTabVisible(final boolean visible) {

View File

@ -16,6 +16,7 @@ package com.google.gerrit.client.groups;
import com.google.gerrit.client.VoidResult; import com.google.gerrit.client.VoidResult;
import com.google.gerrit.client.rpc.Natives; import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.rpc.RestApi; import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroup;
@ -36,6 +37,16 @@ public class GroupApi {
new RestApi("/groups/").id(groupName).ifNoneMatch().put(in, cb); new RestApi("/groups/").id(groupName).ifNoneMatch().put(in, cb);
} }
public static void getGroup(String group, AsyncCallback<GroupInfo> cb) {
group(group).get(cb);
}
/** Get the name of a group */
public static void getGroupName(AccountGroup.UUID group,
AsyncCallback<NativeString> cb) {
group(group).view("name").get(cb);
}
/** Check if the current user is owner of a group */ /** Check if the current user is owner of a group */
public static void isGroupOwner(String groupName, final AsyncCallback<Boolean> cb) { public static void isGroupOwner(String groupName, final AsyncCallback<Boolean> cb) {
GroupMap.myOwned(groupName, new AsyncCallback<GroupMap>() { GroupMap.myOwned(groupName, new AsyncCallback<GroupMap>() {
@ -192,7 +203,11 @@ public class GroupApi {
} }
private static RestApi group(AccountGroup.UUID group) { private static RestApi group(AccountGroup.UUID group) {
return new RestApi("/groups/").id(group.get()); return group(group.get());
}
private static RestApi group(String group) {
return new RestApi("/groups/").id(group);
} }
private static class GroupInput extends JavaScriptObject { private static class GroupInput extends JavaScriptObject {

View File

@ -35,6 +35,7 @@ public class GroupInfo extends JavaScriptObject {
private final native int group_id() /*-{ return this.group_id; }-*/; private final native int group_id() /*-{ return this.group_id; }-*/;
private final native String owner_id() /*-{ return this.owner_id; }-*/; private final native String owner_id() /*-{ return this.owner_id; }-*/;
private final native void owner_id(String o) /*-{ if(o)this.owner_id=o; }-*/;
public final AccountGroup.UUID getOwnerUUID() { public final AccountGroup.UUID getOwnerUUID() {
String owner = owner_id(); String owner = owner_id();
@ -44,6 +45,10 @@ public class GroupInfo extends JavaScriptObject {
return null; return null;
} }
public final void setOwnerUUID(AccountGroup.UUID uuid) {
owner_id(URL.encodePathSegment(uuid.get()));
}
protected GroupInfo() { protected GroupInfo() {
} }

View File

@ -16,6 +16,7 @@ package com.google.gerrit.client.ui;
import com.google.gerrit.client.FormatUtil; import com.google.gerrit.client.FormatUtil;
import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.groups.MemberInfo;
import com.google.gerrit.common.PageLinks; import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.AccountInfo; import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.common.data.AccountInfoCache; import com.google.gerrit.common.data.AccountInfoCache;
@ -35,6 +36,19 @@ public class AccountLink extends InlineHyperlink {
setTitle(FormatUtil.nameEmail(ai)); setTitle(FormatUtil.nameEmail(ai));
} }
public AccountLink(final MemberInfo i) {
this(new AccountInfo(i.getAccountId()) {
@Override
public String getFullName() {
return i.fullName();
}
@Override
public String getPreferredEmail() {
return i.preferredEmail();
}
});
}
private static String owner(AccountInfo ai) { private static String owner(AccountInfo ai) {
if (ai.getPreferredEmail() != null) { if (ai.getPreferredEmail() != null) {
return ai.getPreferredEmail(); return ai.getPreferredEmail();

View File

@ -85,6 +85,11 @@ public final class AccountGroup {
|| uuid.get().matches("^[0-9a-f]{40}$"); || uuid.get().matches("^[0-9a-f]{40}$");
} }
/** @return true if the UUID is for a system group managed within Gerrit. */
public static boolean isSystemGroup(AccountGroup.UUID uuid) {
return uuid.get().startsWith("global:");
}
/** Synthetic key to link to within the database */ /** Synthetic key to link to within the database */
public static class Id extends IntKey<com.google.gwtorm.client.Key<?>> { public static class Id extends IntKey<com.google.gwtorm.client.Key<?>> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;