Adapt to introduction of new View Secondary Emails capability in core

Change Iec901ec05 in Gerrit core added a new global capability that
allows users to see secondary emails. Adapt the code-owners plugin to
respect this capability as well.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I0819eb95805478bdcfb29253d2e98be6c0b422fe
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
index 7db6b68..427e5eb 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
@@ -841,7 +841,7 @@
       // emails
       try {
         if (user != null) {
-          if (!permissionBackend.user(user).test(GlobalPermission.MODIFY_ACCOUNT)) {
+          if (!permissionBackend.user(user).test(GlobalPermission.VIEW_SECONDARY_EMAILS)) {
             transientCodeOwnerCache.cacheNonResolvable(email);
             messages.add(
                 String.format(
@@ -856,7 +856,7 @@
                       + " and user %s can see secondary emails",
                   email, accountState.account().id(), user.getLoggableName()));
           return true;
-        } else if (!permissionBackend.currentUser().test(GlobalPermission.MODIFY_ACCOUNT)) {
+        } else if (!permissionBackend.currentUser().test(GlobalPermission.VIEW_SECONDARY_EMAILS)) {
           transientCodeOwnerCache.cacheNonResolvable(email);
           messages.add(
               String.format(
@@ -875,7 +875,7 @@
       } catch (PermissionBackendException ex) {
         throw newInternalServerError(
             String.format(
-                "failed to test the %s global capability", GlobalPermission.MODIFY_ACCOUNT),
+                "failed to test the %s global capability", GlobalPermission.VIEW_SECONDARY_EMAILS),
             ex);
       }
     };
diff --git a/java/com/google/gerrit/plugins/codeowners/restapi/AbstractGetCodeOwnersForPath.java b/java/com/google/gerrit/plugins/codeowners/restapi/AbstractGetCodeOwnersForPath.java
index 522da89..0fbb01d 100644
--- a/java/com/google/gerrit/plugins/codeowners/restapi/AbstractGetCodeOwnersForPath.java
+++ b/java/com/google/gerrit/plugins/codeowners/restapi/AbstractGetCodeOwnersForPath.java
@@ -485,7 +485,7 @@
     if (options.contains(ListAccountsOption.ALL_EMAILS)) {
       // Secondary emails are only visible to users that have the 'Modify Account' global
       // capability.
-      permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
+      permissionBackend.currentUser().check(GlobalPermission.VIEW_SECONDARY_EMAILS);
       fillOptions.add(FillOptions.EMAIL);
       fillOptions.add(FillOptions.SECONDARY_EMAILS);
     }
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
index cd6f9a2..1ca5fd9 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
@@ -387,8 +387,9 @@
   }
 
   @Test
-  public void cannotGetCodeOwnersWithSecondaryEmailsWithoutModifyAccountCapability()
-      throws Exception {
+  public void
+      cannotGetCodeOwnersWithSecondaryEmailsWithoutViewSecondaryEmailAndWithoutModifyAccountCapability()
+          throws Exception {
     // create a code owner config
     codeOwnerConfigOperations
         .newCodeOwnerConfig()
@@ -412,7 +413,7 @@
                 queryCodeOwners(
                     getCodeOwnersApi().query().withOptions(ListAccountsOption.ALL_EMAILS),
                     "/foo/bar/baz.md"));
-    assertThat(exception).hasMessageThat().isEqualTo("modify account not permitted");
+    assertThat(exception).hasMessageThat().isEqualTo("view secondary emails not permitted");
   }
 
   @Test
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
index 8a920dd..4b1432a 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
@@ -298,7 +298,7 @@
     projectOperations
         .project(allProjects)
         .forUpdate()
-        .add(allowCapability(GlobalCapability.MODIFY_ACCOUNT).group(REGISTERED_USERS))
+        .add(allowCapability(GlobalCapability.VIEW_SECONDARY_EMAILS).group(REGISTERED_USERS))
         .update();
 
     String secondaryEmail = "admin-foo@example.com";