InitAdminUser: Don't assume the group ID of the Administrators group

When using a database configuration where auto-increment column values
are pre-allocated, it is possible that the "Administrators" group is
created with an ID other than "1". In this case, the created admin user
will not be added to the correct group, and will not have the correct
admin permissions.

Instead of hard-coding the group ID, get it from the database.

Bug: Issue 3698
Change-Id: Ie9b3f4f9166d03e91d58b2ec584c5ce47aa2021c
This commit is contained in:
David Pursehouse 2015-11-27 14:41:24 +09:00
parent 713551b095
commit 8e414350c8

View File

@ -23,6 +23,7 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountExternalId;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.client.AccountGroupName;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.server.SchemaFactory;
@ -94,9 +95,11 @@ public class InitAdminUser implements InitStep {
a.setPreferredEmail(email);
db.accounts().insert(Collections.singleton(a));
AccountGroupName adminGroup = db.accountGroupNames().get(
new AccountGroup.NameKey("Administrators"));
AccountGroupMember m =
new AccountGroupMember(new AccountGroupMember.Key(id,
new AccountGroup.Id(1)));
adminGroup.getId()));
db.accountGroupMembers().insert(Collections.singleton(m));
}
}