diff --git a/Documentation/cmd-show-caches.txt b/Documentation/cmd-show-caches.txt index 12a2d70439..dd79d8b976 100644 --- a/Documentation/cmd-show-caches.txt +++ b/Documentation/cmd-show-caches.txt @@ -30,9 +30,15 @@ Display statistics about the size and hit ratio of in-memory caches. Width of the output table. == ACCESS -Caller must be a member of the privileged 'Administrators' group, -or have been granted -link:access-control.html#capability_viewCaches[the 'View Caches' global capability]. +The caller must be a member of a group that is granted the +link:access-control.html#capability_viewCaches[View Caches] capability +or the link:access-control.html#capability_administrateServer[ +Administrate Server] capability. + +The summary information about SSH, threads, tasks, memory and JVM are +only printed out if the caller is a member of a group that is granted +the link:access-control.html#capability_administrateServer[Administrate +Server] capability. == SCRIPTING Intended for interactive use only. diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java index 64897c8458..caf74525eb 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ShowCaches.java @@ -23,6 +23,7 @@ import com.google.gerrit.common.Version; import com.google.gerrit.common.data.GlobalCapability; import com.google.gerrit.extensions.annotations.RequiresCapability; import com.google.gerrit.extensions.events.LifecycleListener; +import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.config.ConfigResource; import com.google.gerrit.server.config.ListCaches; import com.google.gerrit.server.config.ListCaches.CacheInfo; @@ -100,6 +101,9 @@ final class ShowCaches extends SshCommand { @Inject private Provider listCaches; + @Inject + private Provider self; + @Option(name = "--width", aliases = {"-w"}, metaVar = "COLS", usage = "width of output table") private int columns = 80; private int nw; @@ -163,19 +167,21 @@ final class ShowCaches extends SshCommand { printDiskCaches(caches); stdout.print('\n'); - if (gc) { - System.gc(); - System.runFinalization(); - System.gc(); - } + if (self.get().getCapabilities().canAdministrateServer()) { + if (gc) { + System.gc(); + System.runFinalization(); + System.gc(); + } - sshSummary(); - taskSummary(); - memSummary(); - threadSummary(); + sshSummary(); + taskSummary(); + memSummary(); + threadSummary(); - if (showJVM) { - jvmSummary(); + if (showJVM) { + jvmSummary(); + } } stdout.flush();