Hide the "Comments" and "Activity" section from the Document View

I need to hide the “Comments” and “Activity” section in the Document View and also disable all the corresponding actions for the Anonymous user - not to view nor write comments on any documents in any domain. I can not find a way to manage this in the nuxeo-web-ui-bundle.html through the slots. I'm not using Studio. Any ideas would be highly appreciated, thanks in advance!

Comments section

0 votes

3 answers

2142 views

ANSWER



Hello,

thank you Anton Petrov for the information to use the anonymous authentication. In my case, even in “incognito” window in Chrome, it didn't work. I needed to clear my cookies everytime I wanted to login as Administrator. I think there is a bug for windows in this authentication method.

Anyway, I have been trying to hide the Comments and Activity sections from the document view without success, and I don't know if it is possible. As Gregory Carlin said, I have created my own “nuxeo-document-page” contribution like follows:

1) First, I have created my own dom-module, copy of the “nuxeo-document-page” module (this module is defined inside the “elements.html” file, in ${NUXEO_HOME}/nxserver/nuxeo.war/ui). I named the module “nuxeo-document-page-v2”, and the file was “nuxeo-document-page-v2.html”:

<dom-module id="nuxeo-document-page-v2" assetpath="document/">
  <template>
    <style include="nuxeo-styles">
      #details {
        width: 28px;
        height: 28px;
        padding: 5px;
        opacity: 0.3;
        margin: 6px 0;
      }

      :host([opened]) #details {
        opacity: 1;
        margin-left: 6px;
      }

      #documentViewsItems {
        @apply --layout-horizontal;
        --paper-listbox-background-color: transparent;
      }

      #documentViewsItems > [name='comments'] {
        margin: 0;
      }

      .scrollerHeader {
        @apply --layout-horizontal;
      }

      :host([opened]) .scrollerHeader {
        box-shadow: 0 3px 5px rgba(0,0,0,0.04) !important;
        border-radius: 0;
        background-color: var(--nuxeo-box) !important;
      }

      .page {
        @apply --layout-horizontal;
      }

      .main {
        @apply --layout-vertical;
        @apply --layout-flex-2;
        padding-right: 8px;
        overflow: hidden;
      }

      :host([opened]) .main {
        padding-right: 16px;
      }

      .side {
        @apply --layout-vertical;
        position: relative;
        margin-bottom: var(--nuxeo-card-margin-bottom, 16px);
        min-height: 60vh;
      }

      :host([opened]) .side {
        @apply --layout-flex;
      }

      .scroller {
        @apply --nuxeo-card;
        margin-bottom: 0;
        overflow: auto;
        display: none;
        left: 0;
        top: 36px;
        right: 0;
        bottom: 0;
        position: absolute;
      }

      :host([opened]) .scroller {
        display: block;
      }

      .section {
        margin-bottom: 32px;
      }

      .section:last-of-type {
        margin-bottom: 64px;
      }

      nuxeo-document-view {
        --nuxeo-document-content-margin-bottom: var(--nuxeo-card-margin-bottom);
      }

      @media (max-width: 1024px) {
        #details {
          opacity: 1;
          margin-left: 6px;
          cursor: default;
        }

        .scrollerHeader {
          box-shadow: 0 3px 5px rgba(0,0,0,0.04) !important;
          font-family: var(--nuxeo-app-font);
          border-radius: 0;
          background-color: var(--nuxeo-box) !important;
        }

        .page {
          @apply --layout-vertical;
        }

        .main,
        :host([opened]) .main {
          padding: 0;
          max-width: initial;
          margin-right: 0;
        }

        .side {
          padding: 0;
          max-width: initial;
          min-height: initial;
          display: block;
          margin-bottom: 16px;
        }

        .scroller {
          top: 0;
          position: relative;
          display: block;
        }
      }
    </style>

    <nuxeo-document-info-bar document="[[document]]"></nuxeo-document-info-bar>

    <div class="page">

      <div class="main">
        <nuxeo-document-view document="[[document]]"></nuxeo-document-view>
      </div>

      <div class="side">
        <div class="scrollerHeader">
          <paper-icon-button id="details" noink="" icon="nuxeo:details" on-tap="_toggleOpened"></paper-icon-button>
          <nuxeo-tooltip for="details">[[i18n('documentPage.details.opened')]]</nuxeo-tooltip>
        </div>
        <div class="scroller">
          <div class="section">
            <nuxeo-document-info document="[[document]]"></nuxeo-document-info>
          </div>

          <div class="section">
            <nuxeo-document-metadata document="[[document]]"></nuxeo-document-metadata>
          </div>

          <div class="section" hidden$="[[!_hasCollections(document)]]">
            <h3>[[i18n('documentPage.collections')]]</h3>
            <nuxeo-document-collections document="[[document]]"></nuxeo-document-collections>
          </div>

          <template is="dom-if" if="[[hasFacet(document, 'NXTag')]]">
            <div class="section">
              <h3>[[i18n('documentPage.tags')]]</h3>
              <nuxeo-tag-suggestion document="[[document]]" allow-new-tags="" placeholder="[[i18n('documentPage.tags.placeholder')]]" readonly="[[!isTaggable(document)]]">
              </nuxeo-tag-suggestion>
            </div>
          </template>
          <div class="section">
            <paper-listbox id="documentViewsItems" selected="{{selectedTab}}" attr-for-selected="name">
              <nuxeo-page-item name="comments" label="[[i18n('documentPage.comments')]]"></nuxeo-page-item>
              <nuxeo-page-item name="activity" label="[[i18n('documentPage.activity')]]"></nuxeo-page-item>
            </paper-listbox>
            <iron-pages selected="[[selectedTab]]" attr-for-selected="name" selected-item="{{page}}">
              <nuxeo-document-comment-thread name="comments" uid="[[document.uid]]"></nuxeo-document-comment-thread>
              <nuxeo-document-activity name="activity" document="[[document]]"></nuxeo-document-activity>
            </iron-pages>
          </div>
        </div>
      </div>
    </div>

  </template>
  <script>
    Polymer({
      is: 'nuxeo-document-page-v2',
      behaviors: [Nuxeo.LayoutBehavior],
      properties: {
        document: {
          type: Object
        },
        selectedTab: {
          type: String,
          value: 'comments',
          notify: true
        },
        opened: {
          type: Boolean,
          value: false,
          notify: true,
          reflectToAttribute: true,
          observer: '_openedChanged',
        }
      },

      _openedChanged: function() {
        Polymer.Async.animationFrame.run(function() {
          // notify that there was a resize
          this.dispatchEvent(new CustomEvent('resize', {
            bubbles: false,
            composed: true,
          }));
        });
      },

      _toggleOpened: function() {
        this.opened = !this.opened;
      },

      _isMutable: function(doc) {
        return !this.hasFacet(doc, 'Immutable') && doc.type !== 'Root' && !this.isTrashed(doc);
      },

      _hasCollections: function(doc) {
        return this.hasCollections(doc);
      }
    });
  </script>

</dom-module>

2) Then, I have added the contribution in another html file, defining the slot contribution (I named this file “nuxeo-custom-none-bundle.html”):

<link rel="import" href="nuxeo-document-page-v2.html">

<nuxeo-slot-content name="documentViewPage" slot="DOCUMENT_VIEWS_PAGES" order="10">
  <template>
    <nuxeo-filter document="[[document]]" expression="document.facets.indexOf('Folderish') === -1
                                                   && document.facets.indexOf('Collection') === -1">
      <template>
        <nuxeo-document-page-v2 name="view" document="[[document]]" opened=""></nuxeo-document-page-v2>
      </template>
    </nuxeo-filter>
  </template>
</nuxeo-slot-content>

Both files are located in the same directory in my project, in web/nuxeo.war/ui.

3) Finally, I added the extensions:

<extension target="org.nuxeo.ecm.platform.WebResources" point="resources">
    <resource name="nuxeo-custom-none-bundle.html" type="import" shrinkable="false">
        <uri>/ui/nuxeo-custom-none-bundle.html</uri>
    </resource>
</extension>
<extension target="org.nuxeo.ecm.platform.WebResources" point="bundles">
    <bundle name="web-ui">
        <resources append="true">
            <resource>nuxeo-custom-none-bundle.html</resource>
        </resources>
    </bundle>
</extension>

The contribution seems to be working properly, as when I access to a document, I can see that the module loaded is the “nuxeo-document-page-v2” as expected:

type an image title

However, without modifying anything in the copied dom-module, it doesn't work as expected, as for example the comments tab is empty when the document has comments. This only happens if I am logged as Anonymous user (yes, I know that this is what we want to achieve, but this happens because of an error, not because of a filter for anonymous users).

type an image title

Anyway, what I have tried to do is to use a nuxeo-filter to remove the full “Comments & Activity” section according to user.isAnonymous property, but then I found another problem: we don't have the “user” object in that module!

I tried to modify the slot contriution as follows in order to get the “user” object in the module:

<nuxeo-document-page-v2 name="view" document="[[document]]" user="[[user]]" opened=""></nuxeo-document-page-v2>

And I also added it in “properties”, inside the Polymer object in the nuxeo-document-page-v2.html file, after the “document” property:

user: {
   type: Object
},

However, the behaviour is really strange, as when I try to use the “user” object, sometimes it is the user, sometimes it is the document, and sometimes it is undefined. So I don't understand what's happening here.

Sorry for not being able to be more helpful. I will keep trying to make it work.

Regards.

1 votes



HI, Rodri ! I did pretty the same as you and it worked! Digging the native code, I found that the problem with the "user" object is solved by adding the nuxeo-connection in the dom-module. I added it right after the nuxeo-document-info-bar tag:

...
&lt;nuxeo-document-info-bar document=&quot;[[document]]&quot;&gt;&lt;/nuxeo-document-info-bar&gt;
&lt;nuxeo-connection id=&quot;nxcon&quot; user=&quot;{{currentUser}}&quot;&gt;&lt;/nuxeo-connection&gt;
...

Then wrapped the Activity section in the dom-if template:

&lt;template is=&quot;dom-if&quot; if=&quot;[[!checkAnonymousUser(currentUser)]]&quot;&gt;
    &lt;div class=&quot;section&quot;&gt;
        &lt;paper-listbox id=&quot;documentViewsItems&quot; selected=&quot;{{selectedTab}}&quot; attr-for-selected=&quot;name&quot;&gt;

    ...

    &lt;/div&gt;
&lt;/template&gt;

And the function checkAnonymousUser(currentUser) is in Polymer object simply:

checkAnonymousUser: function(user){return user.isAnonymous;}

Thanks for your effort!

02/27/2020


Hi, Rodri ! I managed to enable Anonymous user with the following contribution:

<?xml version="1.0"?>
<component name="org.nuxeo.ecm.platform.login.anonymous.config">

  <require>org.nuxeo.ecm.platform.ui.web.auth.defaultConfig</require>
  <require>org.nuxeo.ecm.platform.ui.web.auth.WebEngineConfig</require>
  <require>org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService</require>

  <!-- Add an Anonymous user -->
  <extension target="org.nuxeo.ecm.platform.usermanager.UserService"
    point="userManager">
    <userManager>
      <users>
        <anonymousUser id="Guest">
          <property name="firstName">Guest</property>
          <property name="lastName">User</property>
        </anonymousUser>
      </users>
    </userManager>
  </extension>

  <extension
    target="org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService"
    point="chain">
    <authenticationChain>
      <plugins>
        <plugin>BASIC_AUTH</plugin>
    <plugin>FORM_AUTH</plugin>
    <plugin>ANONYMOUS_AUTH</plugin>
      </plugins>
    </authenticationChain>
  </extension>  
</component>

Don't forget to add your contribution in the MANIFEST.MF of your bundle, something like:

Bundle-ActivationPolicy: lazy
------
------
Nuxeo-Component: OSGI-INF/anonymous-auth-config.xml

I also had the same problem as you and asked in stackoverflow without adequate answer: https://stackoverflow.com/questions/57058139/nuxeo-after-activating-the-anonymous-user-cant-log-in

The problem persists on my test Windows 10 installation, but on the ubuntu server installation the same contribution works ok without any issues. The odd thing I discovered by chance is that opening an *incognito window * on my local Windows installation works fine, giving me the ability to log as Administrator and as the Guest!

0 votes



Hi, Rodri , I've just noticed, that in the addition of the above contribution and the incognito mode requirement, in the nuxeo.conf the `org.nuxeo.dev=true` must be set to Anonymous user account work under Windows installation! I could't imagine that setting a developer mode has something to do with the problem! Also after the server restart a new incognito window (not tab) must be started, previously used wont work!
04/07/2020


Hello,

You have to override the default nuxeo-document-page.html So, basically:

  • Create in your Designer resources a copy of this element, rename it, and comment the part you need to remove
  • Reference your new element in your custom bundle
  • Add a slot contibution in the same file like:
    <nuxeo-slot-content name="documentViewPage" slot="DOCUMENT_VIEWS_PAGES" order="10">
    <template>
    <nuxeo-filter document="[[document]]" expression="document.facets.indexOf('Folderish') === -1
                                                   && document.facets.indexOf('Collection') === -1">
      <template>
        <nuxeo-document-page-v2 name="view" document="[[document]]" opened></nuxeo-partners-document-page-v2>
      </template>
    </nuxeo-filter>
    </template>
    </nuxeo-slot-content>
    
  • Et voilà!
0 votes



Thanks, Gregory, but I'm not using Studio and Designer. And I can't find "nuxeo-document-page.html" on my server too… I can't see in your example how you hide only "Comments" section?
02/13/2020

Hello Anton Petrov . I think I was able to implement a solution, but I cannot test it as I've never used the "Anonymous user" feature, and I think I am missing something while configuring it. How did you enable the Anonymous Authentication? It always redirects me to the anonymous user, without being able to login as Administrator.
02/15/2020