ChangeQueryBuilder#label: Reject using 'user' and 'group' args together

Using the 'user' and 'group' args together is not supported. Currently
trying to use them together doesn't fail, but silently ignores the
'user' arg, which is bad. This is because both args result in setting
the 'accounts' variable and when we process the 'groups' arg the value
of 'accounts' that has been set for the 'user' arg gets overwritten.

This change may cause disruption to users. For example for projects that
have a submit requirement configured that uses 'submittableIf =
label:Code-Review=MAX,user=non_uploader,group=myGroup' the submit
requirement currently passes if a 'Code-Review=MAX' vote from a user of
the 'myGroup' is present (but the 'user=non_uploader' arg is ignored)
and with this change it will start failing (because the 'user' and
'group' args cannot be used in conjunction).

Release-Notes: Reject using the 'user' and 'group' args together for the 'label' search predicate
Bug: Google b/428579680
Change-Id: I72d088e4aba1f20f71ec13c483085b699f51c890
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java
index dac0e97..c76a1e1 100644
--- a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java
+++ b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java
@@ -1099,6 +1099,9 @@
       assertDisjunctive(lblArgs, ARG_COUNT, ARG_ID_USER);
       assertDisjunctive(lblArgs, ARG_COUNT, ARG_ID_GROUP);
 
+      // Using "user=" or "group=" args is not supported.
+      assertDisjunctive(lblArgs, ARG_ID_USER, ARG_ID_GROUP);
+
       for (Map.Entry<String, ValOp> pair : lblArgs.keyValue.entrySet()) {
         String key = pair.getKey();
         String value = pair.getValue().value();
diff --git a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
index 19eab46..ab1bc8e 100644
--- a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
+++ b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
@@ -1554,6 +1554,15 @@
         .hasMessageThat()
         .isEqualTo("Cannot use the 'count' argument in conjunction with the 'group' argument");
 
+    // "user" and "group" args cannot be used simultaneously.
+    thrown =
+        assertThrows(
+            BadRequestException.class,
+            () -> assertQuery("label:Code-Review=+1,user=non_uploader,group=gerrit"));
+    assertThat(thrown)
+        .hasMessageThat()
+        .isEqualTo("Cannot use the 'user' argument in conjunction with the 'group' argument");
+
     // "non_contributor arg for the label operator is not allowed in change queries
     thrown =
         assertThrows(