Allow users to create a new group
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -23,9 +23,11 @@ public interface AdminConstants extends Constants {
|
||||
String buttonAddGroupMember();
|
||||
String buttonSaveDescription();
|
||||
String buttonRenameGroup();
|
||||
String buttonCreateGroup();
|
||||
|
||||
String headingDescription();
|
||||
String headingMembers();
|
||||
String headingCreateGroup();
|
||||
|
||||
String columnMember();
|
||||
String columnEmailAddress();
|
||||
|
@@ -3,10 +3,12 @@ defaultAccountName = Name or Email
|
||||
buttonDeleteGroupMembers = Delete
|
||||
buttonAddGroupMember = Add
|
||||
buttonRenameGroup = Rename Group
|
||||
buttonSaveDescription = Save Description
|
||||
buttonSaveDescription = Save Description
|
||||
buttonCreateGroup = Create Group
|
||||
|
||||
headingDescription = Description
|
||||
headingMembers = Members
|
||||
headingCreateGroup = Create New Group
|
||||
|
||||
columnMember = Member
|
||||
columnEmailAddress = Email Address
|
||||
|
@@ -26,11 +26,15 @@ import java.util.Set;
|
||||
|
||||
public interface GroupAdminService extends RemoteJsonService {
|
||||
/** Special group, which must not be renamed as its "blessed". */
|
||||
public static final AccountGroup.NameKey ADMIN_GROUP = new AccountGroup.NameKey("admin");
|
||||
public static final AccountGroup.NameKey ADMIN_GROUP =
|
||||
new AccountGroup.NameKey("admin");
|
||||
|
||||
@SignInRequired
|
||||
void ownedGroups(AsyncCallback<List<AccountGroup>> callback);
|
||||
|
||||
@SignInRequired
|
||||
void createGroup(String newName, AsyncCallback<AccountGroup.Id> callback);
|
||||
|
||||
@SignInRequired
|
||||
void groupDetail(AccountGroup.Id groupId,
|
||||
AsyncCallback<AccountGroupDetail> callback);
|
||||
|
@@ -27,6 +27,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwtjsonrpc.client.VoidResult;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.SchemaFactory;
|
||||
import com.google.gwtorm.client.Transaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -62,6 +63,43 @@ public class GroupAdminServiceImpl extends BaseServiceImplementation implements
|
||||
});
|
||||
}
|
||||
|
||||
public void createGroup(final String newName,
|
||||
final AsyncCallback<AccountGroup.Id> callback) {
|
||||
run(callback, new Action<AccountGroup.Id>() {
|
||||
public AccountGroup.Id run(final ReviewDb db) throws OrmException,
|
||||
Failure {
|
||||
final AccountGroup.NameKey nameKey = new AccountGroup.NameKey(newName);
|
||||
if (nameKey.equals(ADMIN_GROUP)) {
|
||||
// Forbid creating the admin group, its highly special because it
|
||||
// has near root level access to the server, based upon its name.
|
||||
//
|
||||
throw new Failure(new NameAlreadyUsedException());
|
||||
}
|
||||
|
||||
if (db.accountGroups().get(nameKey) != null) {
|
||||
throw new Failure(new NameAlreadyUsedException());
|
||||
}
|
||||
|
||||
final AccountGroup group =
|
||||
new AccountGroup(nameKey, new AccountGroup.Id(db
|
||||
.nextAccountGroupId()));
|
||||
group.setNameKey(nameKey);
|
||||
group.setDescription("");
|
||||
|
||||
final AccountGroupMember m =
|
||||
new AccountGroupMember(new AccountGroupMember.Key(RpcUtil
|
||||
.getAccountId(), group.getId()));
|
||||
m.setGroupOwner(true);
|
||||
|
||||
final Transaction txn = db.beginTransaction();
|
||||
db.accountGroups().insert(Collections.singleton(group), txn);
|
||||
db.accountGroupMembers().insert(Collections.singleton(m), txn);
|
||||
txn.commit();
|
||||
return group.getId();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void groupDetail(final AccountGroup.Id groupId,
|
||||
final AsyncCallback<AccountGroupDetail> callback) {
|
||||
run(callback, new Action<AccountGroupDetail>() {
|
||||
|
@@ -20,9 +20,15 @@ import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.AccountScreen;
|
||||
import com.google.gerrit.client.ui.FancyFlexTable;
|
||||
import com.google.gwt.user.client.History;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.ClickListener;
|
||||
import com.google.gwt.user.client.ui.Hyperlink;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.SourcesTableEvents;
|
||||
import com.google.gwt.user.client.ui.TableListener;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
|
||||
import java.util.List;
|
||||
@@ -30,6 +36,9 @@ import java.util.List;
|
||||
public class GroupListScreen extends AccountScreen {
|
||||
private GroupTable groups;
|
||||
|
||||
private TextBox addTxt;
|
||||
private Button addNew;
|
||||
|
||||
public GroupListScreen() {
|
||||
super(Util.C.groupListTitle());
|
||||
}
|
||||
@@ -59,6 +68,38 @@ public class GroupListScreen extends AccountScreen {
|
||||
groups = new GroupTable();
|
||||
groups.setSavePointerId(Link.ADMIN_GROUPS);
|
||||
add(groups);
|
||||
|
||||
final VerticalPanel fp = new VerticalPanel();
|
||||
fp.setStyleName("gerrit-AddSshKeyPanel");
|
||||
final Label hdr = new Label(Util.C.headingCreateGroup());
|
||||
hdr.setStyleName("gerrit-SmallHeading");
|
||||
fp.add(hdr);
|
||||
|
||||
addTxt = new TextBox();
|
||||
addTxt.setVisibleLength(60);
|
||||
fp.add(addTxt);
|
||||
|
||||
addNew = new Button(Util.C.buttonCreateGroup());
|
||||
addNew.addClickListener(new ClickListener() {
|
||||
public void onClick(final Widget sender) {
|
||||
doCreateGroup();
|
||||
}
|
||||
});
|
||||
fp.add(addNew);
|
||||
add(fp);
|
||||
}
|
||||
|
||||
private void doCreateGroup() {
|
||||
final String newName = addTxt.getText();
|
||||
if (newName == null || newName.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Util.GROUP_SVC.createGroup(newName, new GerritCallback<AccountGroup.Id>() {
|
||||
public void onSuccess(final AccountGroup.Id result) {
|
||||
History.newItem(Link.toAccountGroup(result));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class GroupTable extends FancyFlexTable<AccountGroup> {
|
||||
|
Reference in New Issue
Block a user