Add currentUser() to PermissionBackend
Passing in a Provider<CurrentUser> into PermissionBackend is boiler-platy. This change adds a convenience method to PermissionBackend and DefaultPermissionBackend to limit this boiler-plate. Future commits will remove #user(Provider<CurrentUser>) from PermissionBackend, once all callers were moved. Change-Id: Ifcd07fe2c7d2673a66b2b4f9eff06ee8a3b6b943
This commit is contained in:
@@ -32,6 +32,7 @@ import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
@@ -44,12 +45,16 @@ import java.util.Set;
|
||||
public class DefaultPermissionBackend extends PermissionBackend {
|
||||
private static final CurrentUser.PropertyKey<Boolean> IS_ADMIN = CurrentUser.PropertyKey.create();
|
||||
|
||||
private final Provider<CurrentUser> currentUser;
|
||||
private final ProjectCache projectCache;
|
||||
private final ProjectControl.Factory projectControlFactory;
|
||||
|
||||
@Inject
|
||||
DefaultPermissionBackend(
|
||||
ProjectCache projectCache, ProjectControl.Factory projectControlFactory) {
|
||||
Provider<CurrentUser> currentUser,
|
||||
ProjectCache projectCache,
|
||||
ProjectControl.Factory projectControlFactory) {
|
||||
this.currentUser = currentUser;
|
||||
this.projectCache = projectCache;
|
||||
this.projectControlFactory = projectControlFactory;
|
||||
}
|
||||
@@ -58,6 +63,11 @@ public class DefaultPermissionBackend extends PermissionBackend {
|
||||
return projectCache.getAllProjects().getCapabilityCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WithUser currentUser() {
|
||||
return new WithUserImpl(currentUser.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WithUser user(CurrentUser user) {
|
||||
return new WithUserImpl(checkNotNull(user, "user"));
|
||||
|
Reference in New Issue
Block a user