Use provider to inject current user into CheckCodeOwnerConfigFiles singleton If current user is directly injected into a singleton, the user is never updated after the instance was created. Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: Id32e4a1131743bc40e4cf7d7eefc214cd7a4eb4a
diff --git a/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFiles.java b/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFiles.java index ff75b43..fac3c36 100644 --- a/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFiles.java +++ b/java/com/google/gerrit/plugins/codeowners/restapi/CheckCodeOwnerConfigFiles.java
@@ -69,7 +69,7 @@ implements RestModifyView<ProjectResource, CheckCodeOwnerConfigFilesInput> { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - private final CurrentUser currentUser; + private final Provider<CurrentUser> currentUser; private final PermissionBackend permissionBackend; private final Provider<ListBranches> listBranches; private final CodeOwnersPluginConfiguration codeOwnersPluginConfiguration; @@ -78,7 +78,7 @@ @Inject public CheckCodeOwnerConfigFiles( - CurrentUser currentUser, + Provider<CurrentUser> currentUser, PermissionBackend permissionBackend, Provider<ListBranches> listBranches, CodeOwnersPluginConfiguration codeOwnersPluginConfiguration, @@ -96,7 +96,7 @@ public Response<Map<String, Map<String, List<ConsistencyProblemInfo>>>> apply( ProjectResource projectResource, CheckCodeOwnerConfigFilesInput input) throws RestApiException, PermissionBackendException, IOException { - if (!currentUser.isIdentifiedUser()) { + if (!currentUser.get().isIdentifiedUser()) { throw new AuthException("Authentication required"); } @@ -164,7 +164,8 @@ private ImmutableList<ConsistencyProblemInfo> checkCodeOwnerConfig( CodeOwnerBackend codeOwnerBackend, CodeOwnerConfig codeOwnerConfig) { return codeOwnerConfigValidator - .validateCodeOwnerConfig(currentUser.asIdentifiedUser(), codeOwnerBackend, codeOwnerConfig) + .validateCodeOwnerConfig( + currentUser.get().asIdentifiedUser(), codeOwnerBackend, codeOwnerConfig) .map(CheckCodeOwnerConfigFiles::createConsistencyProblemInfo) .filter(Optional::isPresent) .map(Optional::get)