Merge "Allow group includes to be by UUID instead of group ID"
This commit is contained in:
@@ -127,15 +127,15 @@ public class GroupControl {
|
||||
return canSeeMembers();
|
||||
}
|
||||
|
||||
public boolean canAddGroup(AccountGroup.Id id) {
|
||||
public boolean canAddGroup(AccountGroup.UUID uuid) {
|
||||
return isOwner();
|
||||
}
|
||||
|
||||
public boolean canRemoveGroup(AccountGroup.Id id) {
|
||||
public boolean canRemoveGroup(AccountGroup.UUID uuid) {
|
||||
return isOwner();
|
||||
}
|
||||
|
||||
public boolean canSeeGroup(AccountGroup.Id id) {
|
||||
public boolean canSeeGroup(AccountGroup.UUID uuid) {
|
||||
return canSeeMembers();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupInclude;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupMember;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
@@ -123,21 +123,21 @@ public class GroupDetailFactory implements Callable<GroupDetail> {
|
||||
return members;
|
||||
}
|
||||
|
||||
private List<AccountGroupInclude> loadIncludes() throws OrmException {
|
||||
List<AccountGroupInclude> groups = new ArrayList<AccountGroupInclude>();
|
||||
private List<AccountGroupIncludeByUuid> loadIncludes() throws OrmException {
|
||||
List<AccountGroupIncludeByUuid> groups = new ArrayList<AccountGroupIncludeByUuid>();
|
||||
|
||||
for (final AccountGroupInclude m : db.accountGroupIncludes().byGroup(groupId)) {
|
||||
if (control.canSeeGroup(m.getIncludeId())) {
|
||||
gic.want(m.getIncludeId());
|
||||
for (final AccountGroupIncludeByUuid m : db.accountGroupIncludesByUuid().byGroup(groupId)) {
|
||||
if (control.canSeeGroup(m.getIncludeUUID())) {
|
||||
gic.want(m.getIncludeUUID());
|
||||
groups.add(m);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(groups, new Comparator<AccountGroupInclude>() {
|
||||
public int compare(final AccountGroupInclude o1,
|
||||
final AccountGroupInclude o2) {
|
||||
final AccountGroup a = gic.get(o1.getIncludeId());
|
||||
final AccountGroup b = gic.get(o2.getIncludeId());
|
||||
Collections.sort(groups, new Comparator<AccountGroupIncludeByUuid>() {
|
||||
public int compare(final AccountGroupIncludeByUuid o1,
|
||||
final AccountGroupIncludeByUuid o2) {
|
||||
final AccountGroup a = gic.get(o1.getIncludeUUID());
|
||||
final AccountGroup b = gic.get(o2.getIncludeUUID());
|
||||
return n(a).compareTo(n(b));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupInclude;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.cache.CacheModule;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
@@ -102,8 +102,8 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
|
||||
}
|
||||
|
||||
Set<AccountGroup.Id> ids = Sets.newHashSet();
|
||||
for (AccountGroupInclude agi : db.accountGroupIncludes()
|
||||
.byInclude(group.get(0).getId())) {
|
||||
for (AccountGroupIncludeByUuid agi : db.accountGroupIncludesByUuid()
|
||||
.byIncludeUUID(group.get(0).getGroupUUID())) {
|
||||
ids.add(agi.getGroupId());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,35 +31,35 @@ public class GroupInfoCacheFactory {
|
||||
}
|
||||
|
||||
private final GroupCache groupCache;
|
||||
private final Map<AccountGroup.Id, AccountGroup> out;
|
||||
private final Map<AccountGroup.UUID, AccountGroup> out;
|
||||
|
||||
@Inject
|
||||
GroupInfoCacheFactory(final GroupCache groupCache) {
|
||||
this.groupCache = groupCache;
|
||||
this.out = new HashMap<AccountGroup.Id, AccountGroup>();
|
||||
this.out = new HashMap<AccountGroup.UUID, AccountGroup>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate a group will be needed later on.
|
||||
*
|
||||
* @param id identity that will be needed in the future; may be null.
|
||||
* @param uuid identity that will be needed in the future; may be null.
|
||||
*/
|
||||
public void want(final AccountGroup.Id id) {
|
||||
if (id != null && !out.containsKey(id)) {
|
||||
out.put(id, groupCache.get(id));
|
||||
public void want(final AccountGroup.UUID uuid) {
|
||||
if (uuid != null && !out.containsKey(uuid)) {
|
||||
out.put(uuid, groupCache.get(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
/** Indicate one or more groups will be needed later on. */
|
||||
public void want(final Iterable<AccountGroup.Id> ids) {
|
||||
for (final AccountGroup.Id id : ids) {
|
||||
want(id);
|
||||
public void want(final Iterable<AccountGroup.UUID> uuids) {
|
||||
for (final AccountGroup.UUID uuid : uuids) {
|
||||
want(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public AccountGroup get(final AccountGroup.Id id) {
|
||||
want(id);
|
||||
return out.get(id);
|
||||
public AccountGroup get(final AccountGroup.UUID uuid) {
|
||||
want(uuid);
|
||||
return out.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,6 +68,7 @@ public class GroupInfoCacheFactory {
|
||||
public GroupInfoCache create() {
|
||||
final List<GroupInfo> r = new ArrayList<GroupInfo>(out.size());
|
||||
for (final AccountGroup a : out.values()) {
|
||||
if (a == null) continue;
|
||||
r.add(new GroupInfo(a));
|
||||
}
|
||||
return new GroupInfoCache(r);
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.google.gerrit.common.data.GroupDetail;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupInclude;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupMember;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
@@ -111,9 +111,9 @@ public class GroupMembers {
|
||||
}
|
||||
}
|
||||
if (groupDetail.includes != null) {
|
||||
for (final AccountGroupInclude groupInclude : groupDetail.includes) {
|
||||
for (final AccountGroupIncludeByUuid groupInclude : groupDetail.includes) {
|
||||
final AccountGroup includedGroup =
|
||||
groupCache.get(groupInclude.getIncludeId());
|
||||
groupCache.get(groupInclude.getIncludeUUID());
|
||||
if (!seen.contains(includedGroup.getGroupUUID())) {
|
||||
members.addAll(listAccounts(includedGroup.getGroupUUID(), project, seen));
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ import com.google.gerrit.common.errors.NameAlreadyUsedException;
|
||||
import com.google.gerrit.common.errors.PermissionDeniedException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupInclude;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupIncludeAudit;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuidAudit;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupMember;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupMemberAudit;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupName;
|
||||
@@ -35,7 +35,6 @@ import org.eclipse.jgit.lib.PersonIdent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class PerformCreateGroup {
|
||||
@@ -89,7 +88,7 @@ public class PerformCreateGroup {
|
||||
final String groupDescription, final boolean visibleToAll,
|
||||
final AccountGroup.Id ownerGroupId,
|
||||
final Collection<? extends Account.Id> initialMembers,
|
||||
final Collection<? extends AccountGroup.Id> initialGroups)
|
||||
final Collection<? extends AccountGroup.UUID> initialGroups)
|
||||
throws OrmException, NameAlreadyUsedException, PermissionDeniedException {
|
||||
if (!currentUser.getCapabilities().canCreateGroup()) {
|
||||
throw new PermissionDeniedException(String.format(
|
||||
@@ -160,26 +159,25 @@ public class PerformCreateGroup {
|
||||
}
|
||||
|
||||
private void addGroups(final AccountGroup.Id groupId,
|
||||
final Collection<? extends AccountGroup.Id> groups) throws OrmException {
|
||||
final List<AccountGroupInclude> includeList =
|
||||
new ArrayList<AccountGroupInclude>();
|
||||
final List<AccountGroupIncludeAudit> includesAudit =
|
||||
new ArrayList<AccountGroupIncludeAudit>();
|
||||
for (AccountGroup.Id includeId : groups) {
|
||||
final AccountGroupInclude groupInclude =
|
||||
new AccountGroupInclude(new AccountGroupInclude.Key(groupId, includeId));
|
||||
final Collection<? extends AccountGroup.UUID> groups) throws OrmException {
|
||||
final List<AccountGroupIncludeByUuid> includeList =
|
||||
new ArrayList<AccountGroupIncludeByUuid>();
|
||||
final List<AccountGroupIncludeByUuidAudit> includesAudit =
|
||||
new ArrayList<AccountGroupIncludeByUuidAudit>();
|
||||
for (AccountGroup.UUID includeUUID : groups) {
|
||||
final AccountGroupIncludeByUuid groupInclude =
|
||||
new AccountGroupIncludeByUuid(new AccountGroupIncludeByUuid.Key(groupId, includeUUID));
|
||||
includeList.add(groupInclude);
|
||||
|
||||
final AccountGroupIncludeAudit audit =
|
||||
new AccountGroupIncludeAudit(groupInclude, currentUser.getAccountId());
|
||||
final AccountGroupIncludeByUuidAudit audit =
|
||||
new AccountGroupIncludeByUuidAudit(groupInclude, currentUser.getAccountId());
|
||||
includesAudit.add(audit);
|
||||
}
|
||||
db.accountGroupIncludes().insert(includeList);
|
||||
db.accountGroupIncludesAudit().insert(includesAudit);
|
||||
db.accountGroupIncludesByUuid().insert(includeList);
|
||||
db.accountGroupIncludesByUuidAudit().insert(includesAudit);
|
||||
|
||||
for (AccountGroup group : db.accountGroups().get(
|
||||
new HashSet<AccountGroup.Id>(groups))) {
|
||||
groupIncludeCache.evictInclude(group.getGroupUUID());
|
||||
for (AccountGroup.UUID uuid : groups) {
|
||||
groupIncludeCache.evictInclude(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user