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:
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.permissions;
|
||||
|
||||
import com.google.gerrit.extensions.api.access.GlobalOrPluginPermission;
|
||||
import com.google.gerrit.extensions.conditions.BooleanCondition;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
@@ -83,11 +84,6 @@ public class FailedPermissionBackend {
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrentUser user() {
|
||||
throw new UnsupportedOperationException("FailedPermissionBackend is not scoped to user");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForProject project(Project.NameKey project) {
|
||||
return new FailedProject(message, cause);
|
||||
@@ -103,6 +99,12 @@ public class FailedPermissionBackend {
|
||||
throws PermissionBackendException {
|
||||
throw new PermissionBackendException(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanCondition testCond(GlobalOrPluginPermission perm) {
|
||||
throw new UnsupportedOperationException(
|
||||
"FailedPermissionBackend does not support conditions");
|
||||
}
|
||||
}
|
||||
|
||||
private static class FailedProject extends ForProject {
|
||||
@@ -119,11 +121,6 @@ public class FailedPermissionBackend {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrentUser user() {
|
||||
throw new UnsupportedOperationException("FailedPermissionBackend is not scoped to user");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForProject user(CurrentUser user) {
|
||||
return this;
|
||||
@@ -156,6 +153,12 @@ public class FailedPermissionBackend {
|
||||
throw new PermissionBackendException(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanCondition testCond(ProjectPermission perm) {
|
||||
throw new UnsupportedOperationException(
|
||||
"FailedPermissionBackend does not support conditions");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Ref> filter(Map<String, Ref> refs, Repository repo, RefFilterOptions opts)
|
||||
throws PermissionBackendException {
|
||||
@@ -177,11 +180,6 @@ public class FailedPermissionBackend {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrentUser user() {
|
||||
throw new UnsupportedOperationException("FailedPermissionBackend is not scoped to user");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForRef user(CurrentUser user) {
|
||||
return this;
|
||||
@@ -223,6 +221,12 @@ public class FailedPermissionBackend {
|
||||
throws PermissionBackendException {
|
||||
throw new PermissionBackendException(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanCondition testCond(RefPermission perm) {
|
||||
throw new UnsupportedOperationException(
|
||||
"FailedPermissionBackend does not support conditions");
|
||||
}
|
||||
}
|
||||
|
||||
private static class FailedChange extends ForChange {
|
||||
@@ -267,8 +271,9 @@ public class FailedPermissionBackend {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrentUser user() {
|
||||
throw new UnsupportedOperationException("FailedPermissionBackend is not scoped to user");
|
||||
public BooleanCondition testCond(ChangePermissionOrLabel perm) {
|
||||
throw new UnsupportedOperationException(
|
||||
"FailedPermissionBackend does not support conditions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user