AnsweredAssumed Answered

Create Site based on group.

Question asked by michaelc on Jul 26, 2010
Latest reply on Oct 13, 2010 by ottopodo
I wanted to allow creating of a site base on the user being in a group ( That is not admin )
So I modified Header.get.js


   // extend to get all the groups a person is assocated to
   if (!user.isGuest)
   {  
      var result = remote.call("/api/people/" + stringUtils.urlEncode(user.name) + "?groups=true");

     
      if (result.status == 200)
         {
          var i;         
        
         // Create javascript objects from the server response
         // This is the User and it also contains all groups.
          var userValue = eval('(' + result + ')');
       
        
          if (userValue.groups.length != 0)
             {
                for (i = 0; i < userValue.groups.length; i++)
                {
                     if (userValue.groups[i].itemName == "GROUP_CreateSiteAdministrator") createSite = true;
                }
             }           

         }
   }

model.createSite = createSite;

Then modified header.get.ftl

         <#if createSite>
         <ul class="create-site-menuitem">
            <li>
               <a href="#" onclick="thisHeader.showCreateSite(); return false;">${msg("header.sites.createSite")}</a>
            </li>
         </ul>
         </#if>

this worked for the header, but how can I pass this to the dashlet ?
I got it working by doing the same in the dashlet, but it seems as there should be another way.

my.sites.get.js


// extend to get all the groups a person is assocated to
   if (!user.isGuest)
   {  
      var result = remote.call("/api/people/" + stringUtils.urlEncode(user.name) + "?groups=true");

     
      if (result.status == 200)
         {
          var i;         
        
         // Create javascript objects from the server response
         // This is the User and it also contains all groups.
          var userValue = eval('(' + result + ')');
       
        
          if (userValue.groups.length != 0)
             {
                for (i = 0; i < userValue.groups.length; i++)
                {
                     if (userValue.groups[i].itemName == "GROUP_CreateSiteAdministrator") createSite = true;
                }
             }           

         }
   }

Outcomes