Merge changes I1437296d,Ifd2cce2c

* changes:
  Test that change is submittable if code owners is disabled and config is invalid
  GetCodeOwnerProjectConfig: If disabled set only status.disabled
diff --git a/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJson.java b/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJson.java
index 846b1c2..b82e25d 100644
--- a/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJson.java
+++ b/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJson.java
@@ -60,11 +60,17 @@
   CodeOwnerProjectConfigInfo format(ProjectResource projectResource)
       throws RestApiException, PermissionBackendException, IOException {
     CodeOwnerProjectConfigInfo info = new CodeOwnerProjectConfigInfo();
-    info.general = formatGeneralInfo(projectResource.getNameKey());
     info.status = formatStatusInfo(projectResource);
+
+    if (codeOwnersPluginConfiguration.isDisabled(projectResource.getNameKey())) {
+      return info;
+    }
+
+    info.general = formatGeneralInfo(projectResource.getNameKey());
     info.backend = formatBackendInfo(projectResource);
     info.requiredApproval = formatRequiredApprovalInfo(projectResource.getNameKey());
     info.overrideApproval = formatOverrideApprovalInfo(projectResource.getNameKey());
+
     return info;
   }
 
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
index d7eb981..41658e2 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
@@ -56,6 +56,28 @@
   }
 
   @Test
+  @GerritConfig(name = "plugin.code-owners.disabled", value = "true")
+  @GerritConfig(name = "plugin.code-owners.requiredApproval", value = "INVALID")
+  public void changeIsSubmittableIfCodeOwnersFuctionalityIsDisabled_invalidPluginConfig()
+      throws Exception {
+    String changeId = createChange("Test Change", "foo/bar.baz", "file content").getChangeId();
+
+    // Approve by a non-code-owner.
+    approve(changeId);
+
+    // Check the submittable flag.
+    ChangeInfo changeInfo = gApi.changes().id(changeId).get(ListChangesOption.SUBMITTABLE);
+    assertThat(changeInfo.submittable).isTrue();
+
+    // Check that there is no submit requirement.
+    assertThat(changeInfo.requirements).isEmpty();
+
+    // Submit the change.
+    gApi.changes().id(changeId).current().submit();
+    assertThat(gApi.changes().id(changeId).get().status).isEqualTo(ChangeStatus.MERGED);
+  }
+
+  @Test
   public void changeWithInsufficentReviewersIsNotSubmittable() throws Exception {
     // create arbitrary code owner config to avoid entering the bootstrapping code path in
     // CodeOwnerApprovalCheck
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetCodeOwnerProjectConfigIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetCodeOwnerProjectConfigIT.java
index 5b879dc..b820d98 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetCodeOwnerProjectConfigIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetCodeOwnerProjectConfigIT.java
@@ -19,6 +19,7 @@
 import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
 import static com.google.gerrit.testing.GerritJUnit.assertThrows;
 
+import com.google.gerrit.acceptance.config.GerritConfig;
 import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
 import com.google.gerrit.common.Nullable;
 import com.google.gerrit.entities.Permission;
@@ -134,6 +135,24 @@
         projectCodeOwnersApiFactory.project(project).getConfig();
     assertThat(codeOwnerProjectConfigInfo.status.disabled).isTrue();
     assertThat(codeOwnerProjectConfigInfo.status.disabledBranches).isNull();
+    assertThat(codeOwnerProjectConfigInfo.general).isNull();
+    assertThat(codeOwnerProjectConfigInfo.backend).isNull();
+    assertThat(codeOwnerProjectConfigInfo.requiredApproval).isNull();
+    assertThat(codeOwnerProjectConfigInfo.overrideApproval).isNull();
+  }
+
+  @Test
+  @GerritConfig(name = "plugin.code-owners.disabled", value = "true")
+  @GerritConfig(name = "plugin.code-owners.requiredApproval", value = "INVALID")
+  public void getConfigForDisabledProject_invalidPluginConfig() throws Exception {
+    CodeOwnerProjectConfigInfo codeOwnerProjectConfigInfo =
+        projectCodeOwnersApiFactory.project(project).getConfig();
+    assertThat(codeOwnerProjectConfigInfo.status.disabled).isTrue();
+    assertThat(codeOwnerProjectConfigInfo.status.disabledBranches).isNull();
+    assertThat(codeOwnerProjectConfigInfo.general).isNull();
+    assertThat(codeOwnerProjectConfigInfo.backend).isNull();
+    assertThat(codeOwnerProjectConfigInfo.requiredApproval).isNull();
+    assertThat(codeOwnerProjectConfigInfo.overrideApproval).isNull();
   }
 
   @Test
diff --git a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java
index 704d34d..ee7cca1 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java
@@ -18,6 +18,7 @@
 import static com.google.gerrit.server.project.ProjectCache.illegalState;
 import static com.google.gerrit.server.schema.AllProjectsInput.getDefaultCodeReviewLabel;
 import static com.google.gerrit.testing.GerritJUnit.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
 import com.google.gerrit.entities.BranchNameKey;
@@ -133,7 +134,8 @@
     createOwnersOverrideLabel();
     createBranch(BranchNameKey.create(project, "stable-2.10"));
 
-    when(codeOwnersPluginConfiguration.isDisabled(project)).thenReturn(true);
+    when(codeOwnersPluginConfiguration.isDisabled(project)).thenReturn(false);
+    when(codeOwnersPluginConfiguration.isDisabled(any(BranchNameKey.class))).thenReturn(false);
     when(codeOwnersPluginConfiguration.getBackend(project)).thenReturn(findOwnersBackend);
     when(codeOwnersPluginConfiguration.getBackend(BranchNameKey.create(project, "master")))
         .thenReturn(findOwnersBackend);
@@ -158,7 +160,7 @@
 
     CodeOwnerProjectConfigInfo codeOwnerProjectConfigInfo =
         codeOwnerProjectConfigJson.format(createProjectResource());
-    assertThat(codeOwnerProjectConfigInfo.status.disabled).isTrue();
+    assertThat(codeOwnerProjectConfigInfo.status.disabled).isNull();
     assertThat(codeOwnerProjectConfigInfo.status.disabledBranches).isNull();
     assertThat(codeOwnerProjectConfigInfo.general.fileExtension).isEqualTo("foo");
     assertThat(codeOwnerProjectConfigInfo.general.overrideInfoUrl)
diff --git a/resources/Documentation/rest-api.md b/resources/Documentation/rest-api.md
index 335daae..73bb403 100644
--- a/resources/Documentation/rest-api.md
+++ b/resources/Documentation/rest-api.md
@@ -484,11 +484,11 @@
 
 | Field Name |          | Description |
 | ---------- | -------- | ----------- |
-| `general`  || The general code owners configuration as [GeneralInfo](#general-info) entity.
+| `general`  | optional | The general code owners configuration as [GeneralInfo](#general-info) entity. Not set if `status.disabled` is `true`.
 | `status`   | optional | The code owner status configuration as [CodeOwnersStatusInfo](#code-owners-status-info) entity. Contains information about whether the code owners functionality is disabled for the project or for any branch.
-| `backend`  || The code owner backend configuration as [BackendInfo](#backend-info) entity.
-| `required_approval` || The approval that is required from code owners to approve the files in a change as [RequiredApprovalInfo](#required-approval-info) entity. The required approval defines which approval counts as code owner approval.
-| `override_approval` | optional | The approval that is required to override the code owners submit check as [RequiredApprovalInfo](#required-approval-info) entity. If unset, overriding the code owners submit check is disabled.
+| `backend`  | optional | The code owner backend configuration as [BackendInfo](#backend-info) entity. Not set if `status.disabled` is `true`.
+| `required_approval` | optional | The approval that is required from code owners to approve the files in a change as [RequiredApprovalInfo](#required-approval-info) entity. The required approval defines which approval counts as code owner approval. Not set if `status.disabled` is `true`.
+| `override_approval` | optional | The approval that is required to override the code owners submit check as [RequiredApprovalInfo](#required-approval-info) entity. If unset, overriding the code owners submit check is disabled. Not set if `status.disabled` is `true`.
 
 ---