Michiel Rop pushed to branch feature/wpm at cms-community / 
hippo-addon-channel-manager


Commits:
f61b7a84 by Michiel Rop at 2017-05-01T16:21:17+02:00
CHANNELMGR-1253 Show projects only in Enterprise

It is necessary to add the path to the ChannelManagerPlugin config,
because if a user does not have read rights on this projects node or the
projects tree does not exist the projects dropdown should not be
shown.

The ChannelEditor class get its config from the RootPanel and that one
in turn from the ChannelManagerPerspective. The ExtJs Wicket bridge makes
sure the properties are set on the config object. That object is loaded
into the cms service angular object that is loaded in turn in the
configservice.

- - - - -


4 changed files:

- frontend-ng/src/angularjs/channel/projectToggle/projectToggle.controller.js
- frontend-ng/src/angularjs/channel/projectToggle/projectToggle.html
- 
frontend/src/main/java/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.java
- repository/src/main/resources/channel-manager-cluster.xml


Changes:

=====================================
frontend-ng/src/angularjs/channel/projectToggle/projectToggle.controller.js
=====================================
--- 
a/frontend-ng/src/angularjs/channel/projectToggle/projectToggle.controller.js
+++ 
b/frontend-ng/src/angularjs/channel/projectToggle/projectToggle.controller.js
@@ -17,7 +17,7 @@
 
 
 class ProjectToggleController {
-  constructor($translate, OverlayService, ChannelService, ProjectService) {
+  constructor($translate, OverlayService, ChannelService, ProjectService, 
ConfigService) {
     'ngInject';
 
     this.$translate = $translate;
@@ -28,7 +28,10 @@ class ProjectToggleController {
     this.MASTER = { name: channel.name, id: channel.id };
     this.withBranch = [this.MASTER];
     this.selectedProject = this.MASTER;
-    this._setProjects();
+    this.projectsEnabled = ConfigService.projectsEnabled;
+    if (this.projectsEnabled) {
+      this._setProjects();
+    }
   }
   _setProjects() {
     this.ProjectService.projects()


=====================================
frontend-ng/src/angularjs/channel/projectToggle/projectToggle.html
=====================================
--- a/frontend-ng/src/angularjs/channel/projectToggle/projectToggle.html
+++ b/frontend-ng/src/angularjs/channel/projectToggle/projectToggle.html
@@ -14,7 +14,7 @@
   ~ limitations under the License.
   ~
   -->
-<div layout layout-align="start center">
+<div ng-show="$ctrl.projectsEnabled" layout layout-align="start center">
   <label flex="none">{{ 'TOOLBAR_PROJECT_LABEL' | translate }}</label>
   <md-select aria-label="{{ 'TOOLBAR_PROJECT_LABEL' | translate }}"
              ng-disabled="$ctrl.disabled"


=====================================
frontend/src/main/java/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.java
=====================================
--- 
a/frontend/src/main/java/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.java
+++ 
b/frontend/src/main/java/org/onehippo/cms7/channelmanager/channeleditor/ChannelEditor.java
@@ -16,6 +16,7 @@
 package org.onehippo.cms7.channelmanager.channeleditor;
 
 import java.io.Serializable;
+import java.util.Optional;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
@@ -92,6 +93,10 @@ public class ChannelEditor extends ExtPanel {
 
     @ExtProperty
     @SuppressWarnings("unused")
+    private Boolean projectsEnabled;
+
+    @ExtProperty
+    @SuppressWarnings("unused")
     private Boolean hideHstConfigEditor;
 
     @ExtProperty
@@ -118,7 +123,12 @@ public class ChannelEditor extends ExtPanel {
             this.extAjaxTimeout = config.getLong("extAjaxTimeoutMillis", 
DEFAULT_EXT_AJAX_TIMEOUT);
             registerEditorOpenListener(context, config);
         }
-        this.variantsUuid = getVariantsUuidOrNull(variantsPath);
+        getUuid(variantsPath).ifPresent(uuid -> this.variantsUuid = uuid);
+        Optional.of(config).ifPresent(
+                (c -> getUuid(c.getString("projectsPath"))
+                        .ifPresent(uuid -> this.projectsEnabled = true))
+        );
+
         // TODO: decide how to show hide hst-config-editor. Probably a config 
option in ChannelEditor constructor
         // and a message from the ng app (a click) to show the 
hst-config-editor card
         this.hideHstConfigEditor = true;
@@ -174,22 +184,23 @@ public class ChannelEditor extends ExtPanel {
         }
     }
 
-    private static String getVariantsUuidOrNull(final String variantsPath) {
-        if (StringUtils.isNotEmpty(variantsPath)) {
+    private static Optional<String> getUuid(final String path) {
+        String result = null;
+        if (StringUtils.isNotEmpty(path)) {
             final javax.jcr.Session session = 
UserSession.get().getJcrSession();
             try {
-                if (session.nodeExists(variantsPath)) {
-                    return session.getNode(variantsPath).getIdentifier();
+                if (session.nodeExists(path)) {
+                    result =  session.getNode(path).getIdentifier();
                 } else {
-                    log.info("No node at '{}': variants will not be 
available.", variantsPath);
+                    log.info("No node at '{}': variants will not be 
available.", path);
                 }
             } catch (RepositoryException e) {
-                log.error("Failed to retrieve variants node '" + variantsPath 
+ "'", e);
+                log.error("Failed to retrieve variants node '" + path + "'", 
e);
             }
         } else {
             log.info("Variants path not configured. Only the default variant 
will be available.");
         }
-        return null;
+        return Optional.ofNullable(result);
     }
 
     /**


=====================================
repository/src/main/resources/channel-manager-cluster.xml
=====================================
--- a/repository/src/main/resources/channel-manager-cluster.xml
+++ b/repository/src/main/resources/channel-manager-cluster.xml
@@ -67,6 +67,9 @@
       <sv:property sv:name="variantsPath" sv:type="String">
         <sv:value/>
       </sv:property>
+      <sv:property sv:name="projectsPath" sv:type="String">
+        <sv:value/>
+      </sv:property>
     </sv:node>
     <sv:node sv:name="layout.wireframe">
       <sv:property sv:name="jcr:primaryType" sv:type="Name">



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/commit/f61b7a84d48e6d542a2758ad0e05a35446512555
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to