Move IsVisibleToPredicate#describe to IndexUtils
This is one of very few outgoing dependencies from the query package to the rest of gerrit-server; removing it will allow us to move this class to gerrit-index. Change-Id: Ibe0409c445daf9d21a3bb31d5828ccb1dc909aed
This commit is contained in:
@@ -21,9 +21,11 @@ import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.config.SitePaths;
|
import com.google.gerrit.server.config.SitePaths;
|
||||||
import com.google.gerrit.server.index.account.AccountField;
|
import com.google.gerrit.server.index.account.AccountField;
|
||||||
import com.google.gerrit.server.index.group.GroupField;
|
import com.google.gerrit.server.index.group.GroupField;
|
||||||
|
import com.google.gerrit.server.query.change.SingleGroupUser;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||||
@@ -81,6 +83,16 @@ public final class IndexUtils {
|
|||||||
: Sets.union(fs, ImmutableSet.of(GroupField.UUID.getName()));
|
: Sets.union(fs, ImmutableSet.of(GroupField.UUID.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String describe(CurrentUser user) {
|
||||||
|
if (user.isIdentifiedUser()) {
|
||||||
|
return user.getAccountId().toString();
|
||||||
|
}
|
||||||
|
if (user instanceof SingleGroupUser) {
|
||||||
|
return "group:" + user.getEffectiveGroups().getKnownGroups().iterator().next().toString();
|
||||||
|
}
|
||||||
|
return user.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private IndexUtils() {
|
private IndexUtils() {
|
||||||
// hide default constructor
|
// hide default constructor
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,21 +14,8 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.query;
|
package com.google.gerrit.server.query;
|
||||||
|
|
||||||
import com.google.gerrit.server.CurrentUser;
|
|
||||||
import com.google.gerrit.server.query.change.SingleGroupUser;
|
|
||||||
|
|
||||||
public abstract class IsVisibleToPredicate<T> extends OperatorPredicate<T> implements Matchable<T> {
|
public abstract class IsVisibleToPredicate<T> extends OperatorPredicate<T> implements Matchable<T> {
|
||||||
public IsVisibleToPredicate(String name, String value) {
|
public IsVisibleToPredicate(String name, String value) {
|
||||||
super(name, value);
|
super(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String describe(CurrentUser user) {
|
|
||||||
if (user.isIdentifiedUser()) {
|
|
||||||
return user.getAccountId().toString();
|
|
||||||
}
|
|
||||||
if (user instanceof SingleGroupUser) {
|
|
||||||
return "group:" + user.getEffectiveGroups().getKnownGroups().iterator().next().toString();
|
|
||||||
}
|
|
||||||
return user.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ package com.google.gerrit.server.query.account;
|
|||||||
|
|
||||||
import com.google.gerrit.server.account.AccountControl;
|
import com.google.gerrit.server.account.AccountControl;
|
||||||
import com.google.gerrit.server.account.AccountState;
|
import com.google.gerrit.server.account.AccountState;
|
||||||
|
import com.google.gerrit.server.index.IndexUtils;
|
||||||
import com.google.gerrit.server.query.IsVisibleToPredicate;
|
import com.google.gerrit.server.query.IsVisibleToPredicate;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ public class AccountIsVisibleToPredicate extends IsVisibleToPredicate<AccountSta
|
|||||||
protected final AccountControl accountControl;
|
protected final AccountControl accountControl;
|
||||||
|
|
||||||
public AccountIsVisibleToPredicate(AccountControl accountControl) {
|
public AccountIsVisibleToPredicate(AccountControl accountControl) {
|
||||||
super(AccountQueryBuilder.FIELD_VISIBLETO, describe(accountControl.getUser()));
|
super(AccountQueryBuilder.FIELD_VISIBLETO, IndexUtils.describe(accountControl.getUser()));
|
||||||
this.accountControl = accountControl;
|
this.accountControl = accountControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package com.google.gerrit.server.query.change;
|
|||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
|
import com.google.gerrit.server.index.IndexUtils;
|
||||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||||
import com.google.gerrit.server.permissions.ChangePermission;
|
import com.google.gerrit.server.permissions.ChangePermission;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||||
@@ -40,7 +41,7 @@ public class ChangeIsVisibleToPredicate extends IsVisibleToPredicate<ChangeData>
|
|||||||
ChangeControl.GenericFactory changeControlFactory,
|
ChangeControl.GenericFactory changeControlFactory,
|
||||||
CurrentUser user,
|
CurrentUser user,
|
||||||
PermissionBackend permissionBackend) {
|
PermissionBackend permissionBackend) {
|
||||||
super(ChangeQueryBuilder.FIELD_VISIBLETO, describe(user));
|
super(ChangeQueryBuilder.FIELD_VISIBLETO, IndexUtils.describe(user));
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.notesFactory = notesFactory;
|
this.notesFactory = notesFactory;
|
||||||
this.changeControlFactory = changeControlFactory;
|
this.changeControlFactory = changeControlFactory;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import com.google.gerrit.common.errors.NoSuchGroupException;
|
|||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.account.GroupControl;
|
import com.google.gerrit.server.account.GroupControl;
|
||||||
|
import com.google.gerrit.server.index.IndexUtils;
|
||||||
import com.google.gerrit.server.query.IsVisibleToPredicate;
|
import com.google.gerrit.server.query.IsVisibleToPredicate;
|
||||||
import com.google.gerrit.server.query.account.AccountQueryBuilder;
|
import com.google.gerrit.server.query.account.AccountQueryBuilder;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@@ -28,7 +29,7 @@ public class GroupIsVisibleToPredicate extends IsVisibleToPredicate<AccountGroup
|
|||||||
|
|
||||||
public GroupIsVisibleToPredicate(
|
public GroupIsVisibleToPredicate(
|
||||||
GroupControl.GenericFactory groupControlFactory, CurrentUser user) {
|
GroupControl.GenericFactory groupControlFactory, CurrentUser user) {
|
||||||
super(AccountQueryBuilder.FIELD_VISIBLETO, describe(user));
|
super(AccountQueryBuilder.FIELD_VISIBLETO, IndexUtils.describe(user));
|
||||||
this.groupControlFactory = groupControlFactory;
|
this.groupControlFactory = groupControlFactory;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user