Remove PermissionBackend.*#user()
This commit removes the user() method from all PermissionBackend subclasses. This method just encourages callers to pass around a PermissionBackend when they really want to pass around a CurrentUser and/or ChangeNotes. Passing around heavy objects that represent a subsystem for the benefit of getting smaller objects from it is an anti-pattern. We had this issue at a larger scale with {Ref,Project,Change}Control that were often just passed around to have a user and/or entity information. Removing the user() methods should prevent that. This refactoring also uncovered some wrongdoing that we already had in the code as a direct result from passing PermissionBackends around (see previous commit). Removing user() comes at the (small) const that every PermissionBackend has to implement #testCond by itsself, which seems fair and like a better pattern in general. Change-Id: Ibae1fc25e51228dca2acaf0faec76beee539da01
This commit is contained in:
@@ -23,6 +23,7 @@ import com.google.gerrit.common.data.PermissionRule;
|
||||
import com.google.gerrit.common.data.PermissionRule.Action;
|
||||
import com.google.gerrit.extensions.api.access.GlobalOrPluginPermission;
|
||||
import com.google.gerrit.extensions.api.access.PluginPermission;
|
||||
import com.google.gerrit.extensions.conditions.BooleanCondition;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
@@ -32,6 +33,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.PeerDaemonUser;
|
||||
import com.google.gerrit.server.account.CapabilityCollection;
|
||||
import com.google.gerrit.server.cache.PerThreadCache;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendCondition.WithUser;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.inject.Inject;
|
||||
@@ -97,11 +99,6 @@ public class DefaultPermissionBackend extends PermissionBackend {
|
||||
this.user = checkNotNull(user, "user");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrentUser user() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForProject project(Project.NameKey project) {
|
||||
try {
|
||||
@@ -138,6 +135,11 @@ public class DefaultPermissionBackend extends PermissionBackend {
|
||||
return ok;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanCondition testCond(GlobalOrPluginPermission perm) {
|
||||
return new PermissionBackendCondition.WithUser(this, perm, user);
|
||||
}
|
||||
|
||||
private boolean can(GlobalOrPluginPermission perm) throws PermissionBackendException {
|
||||
if (perm instanceof GlobalPermission) {
|
||||
return can((GlobalPermission) perm);
|
||||
|
Reference in New Issue
Block a user