cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove site's options to non admin users in 4.2.e

douglascrp
World-Class Innovator
World-Class Innovator
Hi.

I'm trying to remove some options in collaboration title component in my 4.2.e Share, but I'm unable to make that work.

I tried to override the javascript controller with the code bellow using the web-extension folder approach, but it seems Share is ignoring my file. This same approach used to work on older Share versions.


    /**
     * Collaboration Site Title component GET method
     */
    function main()
    {
       // Call the repository for the site profile
       var json = remote.call("/api/sites/" + page.url.templateArgs.site);
      
       var profile =
       {
          title: "",
          shortName: "",
          visibility: "PUBLIC"
       };
      
       if (json.status == 200)
       {
          // Create javascript objects from the repo response
          var obj = eval('(' + json + ')');
          if (obj)
          {
             profile = obj;
          }
       }
      
       // Call the repository to see if the user is site manager or not
       var userIsSiteManager = false,
           userIsMember = false,
           userIsDirectMember = false;
    
       json = remote.call("/api/sites/" + page.url.templateArgs.site + "/memberships/" + encodeURIComponent(user.name));
       if (json.status == 200)
       {
          var obj = eval('(' + json + ')');
          if (obj)
          {
             userIsMember = true;
             userIsDirectMember = !(obj.isMemberOfGroup);
             userIsSiteManager = (obj.role == "SiteManager");
          }
       }
    
       var activePage = page.url.templateArgs.pageid || "";
       var siteTitle = (profile.title != "") ? profile.title : profile.shortName;
       var siteDashboardUrl = page.url.context + "/page/site/" + page.url.templateArgs.site + "/dashboard";
    
       var links = [];
    
    //   if (userIsSiteManager)
    //   {
    //      links.push(
    //      {
    //         id: "inviteUser-link",
    //         href: "invite",
    //         cssClass: ("invite" == activePage) ? "active-page" : null,
    //         label: "link.invite"
    //      });
    //   }
    
       // Join links
    //   if (!userIsMember)
    //   {
    //      if (profile.visibility == "PUBLIC")
    //      {
    //         links.push(
    //         {
    //            id: "join-link",
    //            label: "link.join"
    //         });
    //      }
    //      else
    //      {
    //         links.push(
    //         {
    //            id: "requestJoin-link",
    //            label: "link.request-join"
    //         });
    //      }
    //   }
    
       if (user.isAdmin && !userIsSiteManager)
       {
          links.push(
          {
             id: "become-manager-link",
             label: "link.become-manager"
          });
       }
    
       // Customise Site link
       if (userIsSiteManager && (page.url.uri == siteDashboardUrl || "customise-site-dashboard" == activePage))
       {
          links.push(
          {
             id: "customiseDashboard-link",
             href: "customise-site-dashboard",
             cssClass: "customise-site-dashboard" == activePage ? "active-page" : null,
             label: "link.customiseDashboard"
          });
       }
    
       var moreMenu = null;
    
    //   if (userIsSiteManager)
       if (user.isAdmin)
       {
          moreMenu = {
             label: "link.more",
             options: [
                { value: "editSite", label: "link.editSite" },
                { value: "customiseSite", label: "link.customiseSite" }
             ]
          };
    //      if (userIsDirectMember)
    //      {
    //         moreMenu.options.push({ value: "leaveSite", label: "link.leave" });
    //      }
       }
    //   else if (userIsMember)
    //   {
    //      moreMenu = {
    //         label: "link.actions",
    //         options: [
    //            { value: "leaveSite", label: "link.leave" }
    //         ]
    //      };
    //   }
    
       // Prepare the model
       model.activePage = activePage;
       model.siteTitle = siteTitle;
       model.siteDashboardUrl = siteDashboardUrl;
       model.profile = profile;
       model.userIsSiteManager = userIsSiteManager;
       model.userIsMember = userIsMember;
       model.links = links;
       model.moreMenu = moreMenu;
       model.userIsDirectMember = userIsDirectMember;
      
       // Widget instantiation metadata…
       var collaborationTitle = {
          id : "CollaborationTitle",
          name : "Alfresco.CollaborationTitle",
          options : {
             site : (page.url.templateArgs.site != null) ? page.url.templateArgs.site : "",
             siteTitle : model.siteTitle,
             user : (user.name != null) ? user.name : ""
          }
       };
       model.widgets = [collaborationTitle];
    }
    
    main();

After that, I tried to create a extension module in order to get that javascript controller manipulated:


<module>
   <id>Remove opções do site para não administradores</id>
   <version>1.0</version>
   <customizations>
      <customization>
         <targetPackageRoot>org.alfresco.components.title</targetPackageRoot>
         <sourcePackageRoot>digibox.components.title</sourcePackageRoot>
      </customization>
   </customizations>
</module>

and in digibox.components.title.collaboration-title.get.js, I did this:


var links = [];

if (user.isAdmin && !userIsSiteManager) {
   links.push({
      id : "become-manager-link",
      label : "link.become-manager"
   });
}

// Customise Site link
if (userIsSiteManager
      && (page.url.uri == siteDashboardUrl || "customise-site-dashboard" == activePage)) {
   links.push({
      id : "customiseDashboard-link",
      href : "customise-site-dashboard",
      cssClass : "customise-site-dashboard" == activePage ? "active-page"
            : null,
      label : "link.customiseDashboard"
   });
}

var moreMenu = null;

if (user.isAdmin) {
   moreMenu = {
      label : "link.more",
      options : [ {
         value : "editSite",
         label : "link.editSite"
      }, {
         value : "customiseSite",
         label : "link.customiseSite"
      } ]
   };
}

model.links = links;
model.moreMenu = moreMenu;

But again, after I deploy that module using Module Deployment, nothing is changed.

Can anyone help me with that?

Thanks in advance.
2 REPLIES 2

ddraper
World-Class Innovator
World-Class Innovator
In versions prior to Alfresco 4.2.d the header, title bar and navigation toolbar were all rendered by different Regions/Components/WebScripts… since 4.2.d they are now all rendered by a single new Region "share-header" which is bound through a Component to the "org.alfresco.share.header.share-header.get" WebScript. This new WebScript renders the display using a new approach that we're going to be taking from now on for Share development (this is the first of a series of blog posts explaining the changes http://blogs.alfresco.com/wp/developer/2013/02/20/latest-updates-to-share-and-surf/)

This is why your old customization is not working on 4.2.e - however, the good news is that it should be a fairly straightforward exercise to port your customization to the new approach. You simply need to target the JavaScript controller for the new WebScript and make the changes you need by removing the widget definitions from the model based on the current user. You can use this blog post (http://blogs.alfresco.com/wp/developer/2013/09/04/customizing-the-share-header-menu-part-1/) as a guide to achieve what you need.

Please let me know if you have any follow up questions,

Regards,
Dave

douglascrp
World-Class Innovator
World-Class Innovator
Thanks Dave for pointing me that out.

I could achieve my goals using your tips from here and from IRC channel.

Just to let it registered here for those facing the same problem, you can follow the tutorials suggested by Dave.

In my requirements, I had not only to override the javascript controller in order to get the options removed from site's dashboard, but also control that behavior based on the user groups. Those options should appear only to Alfresco Admins and for site's managers.
To be able to make that decision I used the groups.module.evaluator, with the parameters:

<groups>GROUP_ALFRESCO_ADMINISTRATORS,SiteManager</groups>
<groupRelation>OR</groupRelation>
<negate>true</negate>
I got to know those parameters looking at this source file from Alfresco's SVN
http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/slingshot/source/java...

I hope this sumary of ideas be useful for someone else.

See ya