Allow to disable REST API and UI

Add 2 new configuration options enableREST and enableUI which can be
set in the reviewers.config file in the site's etc folder.

When enableREST is disabled, the REST API is not exposed.

When enableUI is disabled, the 'Reviewers' menu is not added to the
project screen. This option is forcibly disabled when enableREST is
disabled.

Disabling the REST API and UI means that a project's reviewers.config
file may only be modified by directly pushing changes for review on the
project's refs/meta/config branch. This can be used to enforce code
reviews of the reviewer configuration.

Change-Id: I79ed94347a427385820c85c12f747432a2b4690b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewers/Module.java b/src/main/java/com/googlesource/gerrit/plugins/reviewers/Module.java
index 97e21cc..dd3895b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewers/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewers/Module.java
@@ -17,26 +17,48 @@
 import static com.google.gerrit.server.project.ProjectResource.PROJECT_KIND;
 
 import com.google.gerrit.common.EventListener;
+import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.registration.DynamicSet;
 import com.google.gerrit.extensions.restapi.RestApiModule;
 import com.google.gerrit.extensions.webui.TopMenu;
 import com.google.gerrit.server.config.FactoryModule;
+import com.google.gerrit.server.config.PluginConfigFactory;
+import com.google.inject.Inject;
+
+import org.eclipse.jgit.lib.Config;
 
 class Module extends FactoryModule {
+  private final boolean enableUI;
+  private final boolean enableREST;
+
+  @Inject
+  public Module(@PluginName String pluginName,
+      PluginConfigFactory pluginCfgFactory) {
+    Config c = pluginCfgFactory.getGlobalPluginConfig(pluginName);
+    this.enableREST = c.getBoolean("reviewers", null, "enableREST", true);
+    this.enableUI = enableREST
+        ? c.getBoolean("reviewers", null, "enableUI", true)
+        : false;
+  }
+
   @Override
   protected void configure() {
-    DynamicSet.bind(binder(), TopMenu.class).to(
-        ReviewersTopMenu.class);
+    if (enableUI) {
+      DynamicSet.bind(binder(), TopMenu.class).to(
+          ReviewersTopMenu.class);
+    }
     DynamicSet.bind(binder(), EventListener.class).to(
         ChangeEventListener.class);
     factory(DefaultReviewers.Factory.class);
     factory(ReviewersConfig.Factory.class);
-    install(new RestApiModule() {
-      @Override
-      protected void configure() {
-        get(PROJECT_KIND, "reviewers").to(GetReviewers.class);
-        put(PROJECT_KIND, "reviewers").to(PutReviewers.class);
-      }
-    });
+    if (enableREST) {
+      install(new RestApiModule() {
+        @Override
+        protected void configure() {
+          get(PROJECT_KIND, "reviewers").to(GetReviewers.class);
+          put(PROJECT_KIND, "reviewers").to(PutReviewers.class);
+        }
+      });
+    }
   }
 }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index fe05e25..f592c29 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -1,8 +1,26 @@
 Configuration
 =============
 
-The configuration of the @PLUGIN@ plugin is done on project level in
-the `reviewers.config` file of the project. Missing values are inherited
+Global configuration of the @PLUGIN@ plugin is done in the
+`reviewers.config` file in the site's `etc` directory.
+
+```
+  [reviewers]
+    enableREST = true
+    enableUI = false
+```
+
+reviewers.enableREST
+:	Enable the REST API. When set to false, the REST API is not available.
+	Defaults to true.
+
+reviewers.enableUI
+:	Enable the UI.  When set to false, the 'Reviewers' menu is not displayed
+	on the project screen. Defaults to true, or false when `enableREST` is false.
+
+
+Per project configuration of the @PLUGIN@ plugin is done in the
+`reviewers.config` file of the project. Missing values are inherited
 from the parent projects. This means a global default configuration can
 be done in the `reviewers.config` file of the `All-Projects` root project.
 Other projects can then override the configuration in their own