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:
parent
bf75002957
commit
accd070eeb
@ -60,7 +60,6 @@ import com.google.gerrit.client.admin.ProjectDashboardsScreen;
|
||||
import com.google.gerrit.client.admin.ProjectInfoScreen;
|
||||
import com.google.gerrit.client.admin.ProjectListScreen;
|
||||
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.userpass.UserPassSignInDialog;
|
||||
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.dashboards.DashboardInfo;
|
||||
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.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.rpc.RestApi;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
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.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@ -729,27 +729,26 @@ public class Dispatcher {
|
||||
|
||||
private void group() {
|
||||
final String panel;
|
||||
AccountGroup.Id groupId = null;
|
||||
AccountGroup.UUID groupUUID = null;
|
||||
final String group;
|
||||
|
||||
if (matchPrefix("/admin/groups/uuid-", token)) {
|
||||
String p = skip(token);
|
||||
int c = p.indexOf(',');
|
||||
if (c < 0) {
|
||||
groupUUID = AccountGroup.UUID.parse(p);
|
||||
group = p;
|
||||
panel = null;
|
||||
} else {
|
||||
groupUUID = AccountGroup.UUID.parse(p.substring(0, c));
|
||||
group = p.substring(0, c);
|
||||
panel = p.substring(c + 1);
|
||||
}
|
||||
} else if (matchPrefix("/admin/groups/", token)) {
|
||||
String p = skip(token);
|
||||
int c = p.indexOf(',');
|
||||
if (c < 0) {
|
||||
groupId = AccountGroup.Id.parse(p);
|
||||
group = p;
|
||||
panel = null;
|
||||
} else {
|
||||
groupId = AccountGroup.Id.parse(p.substring(0, c));
|
||||
group = p.substring(0, c);
|
||||
panel = p.substring(c + 1);
|
||||
}
|
||||
} else {
|
||||
@ -757,37 +756,33 @@ public class Dispatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
Util.GROUP_SVC.groupDetail(groupId, groupUUID,
|
||||
new GerritCallback<GroupDetail>() {
|
||||
@Override
|
||||
public void onSuccess(GroupDetail groupDetail) {
|
||||
if (panel == null || panel.isEmpty()) {
|
||||
// The token does not say which group screen should be shown,
|
||||
// as default for internal groups show the members, as default
|
||||
// for external and system groups show the info screen (since
|
||||
// for external and system groups the members cannot be
|
||||
// shown in the web UI).
|
||||
//
|
||||
if (groupDetail.group.getType() == AccountGroup.Type.INTERNAL) {
|
||||
Gerrit.display(toGroup(groupDetail.group.getId(),
|
||||
AccountGroupScreen.MEMBERS),
|
||||
new AccountGroupMembersScreen(groupDetail, token));
|
||||
} else {
|
||||
Gerrit.display(toGroup(groupDetail.group.getId(),
|
||||
AccountGroupScreen.INFO),
|
||||
new AccountGroupInfoScreen(groupDetail, token));
|
||||
}
|
||||
} else if (AccountGroupScreen.INFO.equals(panel)) {
|
||||
Gerrit.display(token,
|
||||
new AccountGroupInfoScreen(groupDetail, token));
|
||||
} else if (AccountGroupScreen.MEMBERS.equals(panel)) {
|
||||
Gerrit.display(token,
|
||||
new AccountGroupMembersScreen(groupDetail, token));
|
||||
} else {
|
||||
Gerrit.display(token,new NotFoundScreen());
|
||||
}
|
||||
GroupApi.getGroup(group, new GerritCallback<GroupInfo>() {
|
||||
@Override
|
||||
public void onSuccess(GroupInfo group) {
|
||||
if (panel == null || panel.isEmpty()) {
|
||||
// The token does not say which group screen should be shown,
|
||||
// as default for internal groups show the members, as default
|
||||
// for external and system groups show the info screen (since
|
||||
// for external and system groups the members cannot be
|
||||
// shown in the web UI).
|
||||
//
|
||||
if (AccountGroup.isInternalGroup(group.getGroupUUID())
|
||||
&& !AccountGroup.isSystemGroup(group.getGroupUUID())) {
|
||||
Gerrit.display(toGroup(group.getGroupId(), AccountGroupScreen.MEMBERS),
|
||||
new AccountGroupMembersScreen(group, token));
|
||||
} else {
|
||||
Gerrit.display(toGroup(group.getGroupId(), AccountGroupScreen.INFO),
|
||||
new AccountGroupInfoScreen(group, token));
|
||||
}
|
||||
});
|
||||
} else if (AccountGroupScreen.INFO.equals(panel)) {
|
||||
Gerrit.display(token, new AccountGroupInfoScreen(group, token));
|
||||
} else if (AccountGroupScreen.MEMBERS.equals(panel)) {
|
||||
Gerrit.display(token, new AccountGroupMembersScreen(group, token));
|
||||
} else {
|
||||
Gerrit.display(token, new NotFoundScreen());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Screen selectProject() {
|
||||
|
@ -19,11 +19,12 @@ import com.google.gerrit.client.VoidResult;
|
||||
import com.google.gerrit.client.groups.GroupApi;
|
||||
import com.google.gerrit.client.groups.GroupInfo;
|
||||
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.OnEditEnabler;
|
||||
import com.google.gerrit.client.ui.RPCSuggestOracle;
|
||||
import com.google.gerrit.client.ui.SmallHeading;
|
||||
import com.google.gerrit.common.data.GroupDetail;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
@ -51,7 +52,7 @@ public class AccountGroupInfoScreen extends AccountGroupScreen {
|
||||
private CheckBox visibleToAllCheckBox;
|
||||
private Button saveGroupOptions;
|
||||
|
||||
public AccountGroupInfoScreen(final GroupDetail toShow, final String token) {
|
||||
public AccountGroupInfoScreen(final GroupInfo toShow, final String token) {
|
||||
super(toShow, token);
|
||||
}
|
||||
|
||||
@ -212,23 +213,34 @@ public class AccountGroupInfoScreen extends AccountGroupScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void display(final GroupDetail groupDetail) {
|
||||
final AccountGroup group = groupDetail.group;
|
||||
protected void display(final GroupInfo group, final boolean canModify) {
|
||||
groupUUIDLabel.setText(group.getGroupUUID().get());
|
||||
groupNameTxt.setText(group.getName());
|
||||
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);
|
||||
groupNameTxt.setText(group.name());
|
||||
|
||||
enableForm(groupDetail.canModify);
|
||||
saveName.setVisible(groupDetail.canModify);
|
||||
saveOwner.setVisible(groupDetail.canModify);
|
||||
saveDesc.setVisible(groupDetail.canModify);
|
||||
saveGroupOptions.setVisible(groupDetail.canModify);
|
||||
GroupApi.getGroupName(group.getOwnerUUID(), new GerritCallback<NativeString>() {
|
||||
@Override
|
||||
public void onSuccess(NativeString result) {
|
||||
ownerTxt.setText(result.asString());
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ import com.google.gerrit.client.ui.AddMemberBox;
|
||||
import com.google.gerrit.client.ui.FancyFlexTable;
|
||||
import com.google.gerrit.client.ui.Hyperlink;
|
||||
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.AccountGroup;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
@ -51,7 +49,6 @@ import javax.annotation.Nullable;
|
||||
|
||||
public class AccountGroupMembersScreen extends AccountGroupScreen {
|
||||
|
||||
private AccountInfoCache accounts = AccountInfoCache.empty();
|
||||
private MemberTable members;
|
||||
private IncludeTable includes;
|
||||
|
||||
@ -65,7 +62,7 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
|
||||
|
||||
private FlowPanel noMembersInfo;
|
||||
|
||||
public AccountGroupMembersScreen(final GroupDetail toShow, final String token) {
|
||||
public AccountGroupMembersScreen(final GroupInfo toShow, final String token) {
|
||||
super(toShow, token);
|
||||
}
|
||||
|
||||
@ -153,36 +150,30 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void display(final GroupDetail groupDetail) {
|
||||
switch (groupDetail.group.getType()) {
|
||||
case INTERNAL:
|
||||
accounts = groupDetail.accounts;
|
||||
|
||||
MemberList.all(getGroupUUID(), new GerritCallback<MemberList>() {
|
||||
@Override
|
||||
public void onSuccess(MemberList result) {
|
||||
members.display(Natives.asList(result));
|
||||
}
|
||||
});
|
||||
|
||||
GroupList.included(getGroupUUID(), new GerritCallback<GroupList>() {
|
||||
@Override
|
||||
public void onSuccess(GroupList result) {
|
||||
includes.display(Natives.asList(result));
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
default:
|
||||
memberPanel.setVisible(false);
|
||||
includePanel.setVisible(false);
|
||||
noMembersInfo.setVisible(true);
|
||||
break;
|
||||
protected void display(final GroupInfo group, final boolean canModify) {
|
||||
if (AccountGroup.isInternalGroup(group.getGroupUUID())
|
||||
&& !AccountGroup.isSystemGroup(group.getGroupUUID())) {
|
||||
MemberList.all(getGroupUUID(), new GerritCallback<MemberList>() {
|
||||
@Override
|
||||
public void onSuccess(MemberList result) {
|
||||
members.display(Natives.asList(result));
|
||||
}
|
||||
});
|
||||
GroupList.included(getGroupUUID(), new GerritCallback<GroupList>() {
|
||||
@Override
|
||||
public void onSuccess(GroupList result) {
|
||||
includes.display(Natives.asList(result));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
memberPanel.setVisible(false);
|
||||
includePanel.setVisible(false);
|
||||
noMembersInfo.setVisible(true);
|
||||
}
|
||||
|
||||
enableForm(groupDetail.canModify);
|
||||
delMember.setVisible(groupDetail.canModify);
|
||||
delInclude.setVisible(groupDetail.canModify);
|
||||
enableForm(canModify);
|
||||
delMember.setVisible(canModify);
|
||||
delInclude.setVisible(canModify);
|
||||
}
|
||||
|
||||
void doAddNewMember() {
|
||||
@ -290,12 +281,11 @@ public class AccountGroupMembersScreen extends AccountGroupScreen {
|
||||
}
|
||||
|
||||
void populate(final int row, final MemberInfo i) {
|
||||
final Account.Id accountId = i.getAccountId();
|
||||
CheckBox checkBox = new CheckBox();
|
||||
table.setWidget(row, 1, checkBox);
|
||||
checkBox.setEnabled(enabled);
|
||||
table.setWidget(row, 2, AccountLink.link(accounts, accountId));
|
||||
table.setText(row, 3, accounts.get(accountId).getPreferredEmail());
|
||||
table.setWidget(row, 2, new AccountLink(i));
|
||||
table.setText(row, 3, i.preferredEmail());
|
||||
|
||||
final FlexCellFormatter fmt = table.getFlexCellFormatter();
|
||||
fmt.addStyleName(row, 1, Gerrit.RESOURCES.css().iconCell());
|
||||
|
@ -16,63 +16,64 @@ package com.google.gerrit.client.admin;
|
||||
|
||||
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.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.MenuScreen;
|
||||
import com.google.gerrit.common.data.GroupDetail;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
|
||||
public abstract class AccountGroupScreen extends MenuScreen {
|
||||
public static final String INFO = "info";
|
||||
public static final String MEMBERS = "members";
|
||||
|
||||
private final GroupDetail groupDetail;
|
||||
private final GroupInfo group;
|
||||
private final String membersTabToken;
|
||||
|
||||
public AccountGroupScreen(final GroupDetail toShow, final String token) {
|
||||
public AccountGroupScreen(final GroupInfo toShow, final String token) {
|
||||
setRequiresSignIn(true);
|
||||
|
||||
this.groupDetail = toShow;
|
||||
this.group = toShow;
|
||||
this.membersTabToken = getTabToken(token, MEMBERS);
|
||||
|
||||
link(Util.C.groupTabGeneral(), getTabToken(token, INFO));
|
||||
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) {
|
||||
if (token.startsWith("/admin/groups/uuid-")) {
|
||||
return toGroup(groupDetail.group.getGroupUUID(), tab);
|
||||
return toGroup(group.getGroupUUID(), tab);
|
||||
} else {
|
||||
return toGroup(groupDetail.group.getId(), tab);
|
||||
return toGroup(group.getGroupId(), tab);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad() {
|
||||
super.onLoad();
|
||||
setPageTitle(Util.M.group(groupDetail.group.getName()));
|
||||
setPageTitle(Util.M.group(group.name()));
|
||||
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 AccountGroup.Id getGroupId() {
|
||||
return groupDetail.group.getId();
|
||||
}
|
||||
protected abstract void display(final GroupInfo group, final boolean canModify);
|
||||
|
||||
protected AccountGroup.UUID getGroupUUID() {
|
||||
return groupDetail.group.getGroupUUID();
|
||||
return group.getGroupUUID();
|
||||
}
|
||||
|
||||
protected void updateOwnerGroup(GroupInfo ownerGroup) {
|
||||
groupDetail.group.setOwnerGroupUUID(ownerGroup.getGroupUUID());
|
||||
groupDetail.ownerGroup.setUUID(ownerGroup.getGroupUUID());
|
||||
groupDetail.ownerGroup.setName(ownerGroup.name());
|
||||
group.setOwnerUUID(ownerGroup.getGroupUUID());
|
||||
}
|
||||
|
||||
protected AccountGroup.UUID getOwnerGroupUUID() {
|
||||
return groupDetail.group.getOwnerGroupUUID();
|
||||
return group.getOwnerUUID();
|
||||
}
|
||||
|
||||
protected void setMembersTabVisible(final boolean visible) {
|
||||
|
@ -16,6 +16,7 @@ package com.google.gerrit.client.groups;
|
||||
|
||||
import com.google.gerrit.client.VoidResult;
|
||||
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.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@ -36,6 +37,16 @@ public class GroupApi {
|
||||
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 */
|
||||
public static void isGroupOwner(String groupName, final AsyncCallback<Boolean> cb) {
|
||||
GroupMap.myOwned(groupName, new AsyncCallback<GroupMap>() {
|
||||
@ -192,7 +203,11 @@ public class GroupApi {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -35,6 +35,7 @@ public class GroupInfo extends JavaScriptObject {
|
||||
|
||||
private final native int group_id() /*-{ return this.group_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() {
|
||||
String owner = owner_id();
|
||||
@ -44,6 +45,10 @@ public class GroupInfo extends JavaScriptObject {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final void setOwnerUUID(AccountGroup.UUID uuid) {
|
||||
owner_id(URL.encodePathSegment(uuid.get()));
|
||||
}
|
||||
|
||||
protected GroupInfo() {
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ package com.google.gerrit.client.ui;
|
||||
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.groups.MemberInfo;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.data.AccountInfo;
|
||||
import com.google.gerrit.common.data.AccountInfoCache;
|
||||
@ -35,6 +36,19 @@ public class AccountLink extends InlineHyperlink {
|
||||
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) {
|
||||
if (ai.getPreferredEmail() != null) {
|
||||
return ai.getPreferredEmail();
|
||||
|
@ -85,6 +85,11 @@ public final class AccountGroup {
|
||||
|| 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 */
|
||||
public static class Id extends IntKey<com.google.gwtorm.client.Key<?>> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
Loading…
Reference in New Issue
Block a user