AnsweredAssumed Answered

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

Question asked by douglascrp Moderator on Nov 7, 2013
Latest reply on Nov 9, 2013 by douglascrp
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.

Outcomes