Automatically create the admin group on database creation

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2008-12-30 09:11:51 -08:00
parent ebb6378cac
commit a013d20949
3 changed files with 11 additions and 2 deletions

View File

@@ -25,6 +25,9 @@ import java.util.List;
import java.util.Set; import java.util.Set;
public interface GroupAdminService extends RemoteJsonService { 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");
@SignInRequired @SignInRequired
void ownedGroups(AsyncCallback<List<AccountGroup>> callback); void ownedGroups(AsyncCallback<List<AccountGroup>> callback);

View File

@@ -184,8 +184,7 @@ public class GroupAdminServiceImpl extends BaseServiceImplementation implements
} }
private static boolean amAdmin(final ReviewDb db) throws OrmException { private static boolean amAdmin(final ReviewDb db) throws OrmException {
final AccountGroup admin = final AccountGroup admin = db.accountGroups().get(ADMIN_GROUP);
db.accountGroups().get(new AccountGroup.NameKey("admin"));
if (admin == null) { if (admin == null) {
return false; return false;
} }

View File

@@ -14,9 +14,11 @@
package com.google.gerrit.server; package com.google.gerrit.server;
import com.google.gerrit.client.admin.GroupAdminService;
import com.google.gerrit.client.data.ApprovalType; import com.google.gerrit.client.data.ApprovalType;
import com.google.gerrit.client.data.GerritConfig; import com.google.gerrit.client.data.GerritConfig;
import com.google.gerrit.client.data.GitwebLink; import com.google.gerrit.client.data.GitwebLink;
import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.ApprovalCategory; import com.google.gerrit.client.reviewdb.ApprovalCategory;
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue; import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
import com.google.gerrit.client.reviewdb.ReviewDb; import com.google.gerrit.client.reviewdb.ReviewDb;
@@ -153,6 +155,11 @@ public class GerritServer {
s.accountPrivateKey = SignedToken.generateRandomKey(); s.accountPrivateKey = SignedToken.generateRandomKey();
s.sshdPort = 29418; s.sshdPort = 29418;
c.systemConfig().insert(Collections.singleton(s)); c.systemConfig().insert(Collections.singleton(s));
final AccountGroup admin =
new AccountGroup(GroupAdminService.ADMIN_GROUP, new AccountGroup.Id(c
.nextAccountGroupId()));
c.accountGroups().insert(Collections.singleton(admin));
} }
private void initVerifiedCategory(final ReviewDb c) throws OrmException { private void initVerifiedCategory(final ReviewDb c) throws OrmException {