1

Show or Hide SharePoint Ribbon Tab based on User Permissions

This week I wanted to figure out how to show or hide a custom developed SharePoint Ribbon Tab based on the permissions of a logged in SharePoint user.

I have a custom SharePoint 2010 Ribbon Tab with the title ‘Show or Hide Tab’ and I want to hide the tab if a current logged in user is a member of the ‘Root Visitors’ security group.

I do not want to hide the entire ribbon and I also do not want to hide only the inactive buttons. The ribbon with the ‘Documents’ and ‘Library’ tabs must be visible for all users and audience targeting must be applied to the new custom ribbon tab.

I can imagine that the requirement is quite a common one. You might want to develop a set of custom tabs which are only visible to users who are members of a specific SharePoint group.

I assume that you know how to develop a custom ribbon – if not please follow the great blog series by Chris O’Brien on Ribbon Customizations and ensure that your custom ribbon tab works before you continue with this tutorial.

clip_image001

I could not find a blog with an appropriate example on the web so I used a combination of a few blog posts and added my own logic.

I want to thank Chris O’Brien for his series on Ribbon Customizations and Tobias Lekman for his helpful blog post . Their contributions were extremely helpful during my research.

How it works:

I have a custom ribbon with the title ‘Show or Hide Tab’.I also have a SharePoint Group Called ‘Root Visitors’. I log in to SharePoint as a user who is not a member of this group.

clip_image002

I navigate to the Shared Documents library and do not see the custom ribbon tab.

clip_image003

Now I add the user to the security group

clip_image004

 …and I navigate back to the Shared Documents library. Now the custom ribbon tab is visible.

clip_image005

 Ok, so Let’s Get Started

Prerequisites (…you need the following in place before you start coding):

    1. the ID of the Ribbon Tab which you want to hide ( I created a custom ribbon tab –see elements file contents below)
    2. the name of the SharePoint Security Group which can see the ribbon item
    3. jquery-1.6.2.min.js (download from http://docs.jquery.com/Downloading_jQuery)
    4. jquery.SPServices-0.6.2.js - this is a jQuery library which abstracts SharePoint’s Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install. http://spservices.codeplex.com

Development Tasks (…you will code the following):

    1. Construct the JQuery to hide the ribbon tab
    2. Register the JQuery to hide the ribbon tab
    3. Verify that it all works fine

 

Prerequisites:

1.       Get the ID of the Ribbon Tab which you want to hide:

If you have a custom ribbon tab then you can get the ID value from the Elements.xml file. In the example below the ID of my custom ribbon is ‘DemoHideRibbonTab’

       ?xml version="1.0" encoding="utf-8"?>

       <Elements xmlns="http://schemas.microsoft.com/sharepoint/">

        <CustomAction

         Id="DemoHideRibbonTab"

As an alternative you can use the following handy piece of JQuery to view the IDs of all the Ribbon Tabs on a page.

Copy the JQuery code below and paste it inside a Content Editor Web Part on the SharePoint library AllItems.aspx page and save the page. 

<script type="text/javascript">

   $("a.ms-cui-tt-a").each(function ()

   {

     var objTabTitle = $(this).parent().attr("id");

     alert( objTabTitle );

   });

</script>

When you refresh the page the JQuery will iterate through all the ribbon tabs and display their IDs.

You should see the IDs of the different ribbon tabs:

clip_image006 

2.       Get the name of the SharePoint Security Group:

The security group for which you must hide the ribbon tab must be a SharePoint group –it’s simple, you must have the name of the group. 

3.       Download and distribute jquery-1.6.2.min.js

The jQuery library is a single JavaScript file, containing all of its common DOM, event, effects, and Ajax functions. It can be included within a SharePoint page by linking to a local copy.

Download jquery-1.6.2.min.js from http://docs.jquery.com/Downloading_jQuery and distribute into the 14-hive of your SharePoint web-front-end server.

Example: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\HideRibbonSample\Scripts\ jquery-1.6.2.min.js

4.       Download and distribute jquery.SPServices-0.6.2.js

This is a jQuery library which abstracts SharePoint’s Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.

Download jquery.SPServices-0.6.2.js from http://spservices.codeplex.com and distribute into the 14-hive of your SharePoint web-front-end server.

Exanple: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\HideRibbonSample\Scripts\ jquery.SPServices-0.6.2.js

 

Development Tasks:

1.       Construct the JQuery to hide the ribbon tab

We now have all the prerequisites in place and we can start coding the JQuery which will hide the ribbon tab.

Create a new empty file and save the file to the 14-hive of your SharePoint web-front-end server.

Exanple: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\HideRibbonSample\Scripts\HideRibbonSample.js 

Add the following JQuery to the file.

function checkIfUserIsInGroup()

{

$(document).ready(function() { $().SPServices({ 

      operation: "GetGroupCollectionFromUser", 

      userLoginName: $().SPServices.SPGetCurrentUser(), 

      async: false, 

      completefunc: function(xData, Status) { 

      if($(xData.responseXML).find("Group[Name='Root Visitors']").length == 1) 

         { 

                       return "true";

         } 

      else

         {

HideTab();

                       return "false";

         }

       } 

     });

     });

}

 

function HideTab()

{

$("a.ms-cui-tt-a").each(function ()

{

var objTabTitle = $(this).parent().attr("id");

if(objTabTitle == "DemoHideRibbonTab-title")

{

$(this).parent().hide();

}

});

}

 

var ribbonSelected;

function checkRibbonState() {

       var id = $("li.ms-cui-tt-s").attr("id");

        if (ribbonSelected != id)

       { 

              ribbonSelected = id;

              checkIfUserIsInGroup();

       }

}

 

function beginCheckRibbon()

{

var checkRibbonStateInterval = setInterval("checkRibbonState()", 10);

 }

$(document).ready(function ()

{

        setTimeout("beginCheckRibbon()", 1000);

});

 

2.       Register the JQuery as a custom action on the relevant ribbon tab

Open the elements.xml file in which your custom ribbon tab is defined.

You have to register the JQuery scripts in the correct sequence.

Use the ScriptLink class to register the following scripts:

1.       The jquery-1.6.2.min.js script.

2.       The jquery.SPServices-0.6.2.js script.

3.       Your custom JQuery Hide Ribbon script. 

 

<CustomAction Id="JohanJQuery.Script" Location="ScriptLink" ScriptSrc ="/_layouts/HideRibbonSample/Scripts/jquery-1.6.2.min.js" Sequence="100"/>

 

<CustomAction Id="SPS_SERVICE_JohanJQuery.Script" Location="ScriptLink" ScriptSrc ="/_layouts/HideRibbonSample/Scripts/jquery.SPServices-0.6.2.js" Sequence="101"/>

 

<CustomAction Id="JohanHideTab_JohanJQuery.Script" Location="ScriptLink" ScriptSrc ="/_layouts/HideRibbonSample/Scripts/HideRibbonSample.js" Sequence="102"/> 

 

My complete Ribbon Tab definition with the script registration is as follows:

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <CustomAction

    Id="DemoHideRibbonTab"

    Location="CommandUI.Ribbon"

    RegistrationId="101"

    RegistrationType="List">

    <CommandUIExtension>

      <CommandUIDefinitions>

        <CommandUIDefinition

          Location="Ribbon.Tabs._children">

          <Tab Id="DemoHideRibbonTab" Title="Show or Hide Tab" Description="Show or Hide Tab" Sequence="501">

            <Scaling

              Id="DemoHideRibbonTab.Scaling">

              <MaxSize

                Id="DemoHideRibbonTab.OneLargeGroupMaxSize"

                GroupId="DemoHideRibbonTab.OneLargeGroupExample"

                Size="OneLarge"/>

            </Scaling>

         

            <Groups Id="DemoHideRibbonTab.GeneralControls.Groups">

              <Group

                Id="DemoHideRibbonTab.OneLargeGroupExample"

                Description="Contains custom controls"

                Title="Show Message"

                Sequence="55"

                Template="Ribbon.Templates.OneLarge">

                <Controls Id="DemoHideRibbonTab.OneLargeGroupExample.Controls">

                  <Button

                      Id="DemoHideRibbonTab.OneLargeGroupExample.Controls.Button"

                      LabelText="Show Message"

                      Image16by16="/_layouts/images/newtargetapp16.png"

                      Image32by32="/_layouts/images/newtargetapp32.png"

                      Command="COB.Command.SayHello"

                      Sequence="10"

                      TemplateAlias="custLarge1" />

                </Controls>

              </Group>

            </Groups>

          </Tab>

        </CommandUIDefinition>

        <CommandUIDefinition Location="Ribbon.Templates._children">

          <GroupTemplate Id="Ribbon.Templates.OneLarge">

            <Layout

              Title="OneLarge"

              LayoutTitle="OneLarge">

              <Section Alignment="Top" Type="OneRow">

                <Row>

                  <ControlRef DisplayMode="Large" TemplateAlias="custLarge1" />

                </Row>

              </Section>

            </Layout>

          </GroupTemplate>

        </CommandUIDefinition>

      </CommandUIDefinitions>

      <CommandUIHandlers>

        <CommandUIHandler

       Command="COB.Command.SayHello"

       CommandAction="javascript:alert('Hello World');" />

      </CommandUIHandlers>

    </CommandUIExtension>

  </CustomAction>

 

  <CustomAction Id="JohanJQuery.Script" Location="ScriptLink" ScriptSrc ="/_layouts/HideRibbonSample/Scripts/jquery-1.6.2.min.js" Sequence="100"/>

  <CustomAction Id="SPS_SERVICE_JohanJQuery.Script" Location="ScriptLink" ScriptSrc ="/_layouts/HideRibbonSample/Scripts/jquery.SPServices-0.6.2.js" Sequence="101"/>

  <CustomAction Id="JohanHideTab_JohanJQuery.Script" Location="ScriptLink" ScriptSrc ="/_layouts/HideRibbonSample/Scripts/HideRibbonSample.js" Sequence="102"/>

</Elements>

 

3.       Verify that it works fine

Build, Package and Deploy your custom ribbon feature.

Deactivate and Activate the feature in your site and refresh the SharePoint page on which the ribbon should appear (because the registration ID of my ribbon is ‘101’ the page which I should see the ribbon tab is http://demoweb/Shared%20Documents/Forms/AllItems.aspx.

If I am a member of the ‘Root Visitors’ group then the tab is visible.

clip_image005 

If I am not a member of the ‘Root Visitors’ group then the tab is not visible.

clip_image003

 

Enjoy!!

 

References:

Once again, thanks for the contributions made by members of the community.

Chris O’Brien: Ribbon Customizations

Tobias Lekman: Hiding Inactive Ribbon Commands in SharePoint 2010  

 

1

European SP Conference Exceeded Expectations

clip_image001

Wow, time flies when you're having fun!

During the past few weeks I have been on a very exciting SharePoint journey during which I travelled almost 39 000 kilometres and took part in SharePoint activities in Istanbul, Berlin and New York.

Each stop was a very different experience and each SharePoint activity offered a unique view into the SharePoint world.

The European SharePoint Conference was the highlight of this tour and exceeded all my expectations.

I have been to many conferences before and I can without a doubt say that the European SP conference was out of the ordinary.

A few highlights of the conference include the following:

· It was clear that we have moved on from the ‘Understand SharePoint’ topics to ‘Let’s provide solutions’ topics.

Conference content and vendor exhibitions were aimed at how to extend SharePoint with custom development and 3rd Party value-add features in order to provide better solutions. Strategic thinking was the order of the day and I am sure that over the course of the 3 days a significant number of industry leaders had to at some point shift their thinking from product to solution. For me as a solutions architect it is very exciting to experience how well established SharePoint is in the industry and that we are now comfortable enough to move on to a next phase in the SharePoint lifecycle.

As an example of how far we’ve come, a few years ago we had topics like ‘What’s new in SharePoint workflow development’. This year at the EUSPC 2011 we had a SharePoint Shootout session for workflow during which various workflow products were compared in order to help architects and decision makers to understand the differences between the available workflow engines.

· I experienced an instant comradeship between delegates and solid friendships were established

This is without a doubt the most important take-away from the conference. It is normally quite a challenge to ensure we make most of a conference by not allowing for the experience to end at the closing keynote. The SharePint event and other similar social get-togethers provided a great way for us to connect, have a beer (or few) and socialize. I have made friends with SharePoint comrades from around the world and appreciate that we can stay connected and exchange ideas and support one another.

· Great Presentations

The 45 minutes allocated per session was not enough time to provide a proper introduction, do a knowledge transfer and take some questions. Many delegates expressed this concern and I also battled during my presentation to stay within time.

However, the benefit of short sessions is that the audience receive high-impact and to-the-point presentations.

The speakers came from across the world to share their experiences and having 4 simultaneous tracks ensured that a wide spectrum of SharePoint topics were covered.

The presentations are available for download on the conference website.

(The presentations are immediately available to delegates and will be available to the general public after 25 November 2011)

clip_image002

clip_image003

· Exhibitors showcased valuable solutions applicable to solving real-world challenges

I am very impressed with the products which the vendors showcased. As a solution architect I always try to keep a wide range of SharePoint solution enablers in my toolbox and I am very excited to see that there is a very high industry standard and that the vendors do help us to take SharePoint further through rapid implementation of great add-ons.

· The conference was very well organized

Hats off to Helen, Mary, Declan, Tracy, and the rest of the European SharePoint team for doing a brilliant job in planning and coordinating the event. Everything went very well and I had a great time overall.

Content:

90 presentations were delivered across 4 tracks (IT DM, IT Pro, Dev and Gen). The 4 tracks provided a very rich selection of outstanding topics and at times made it difficult to choose which one of simultaneous presentations to attend. The 60 speakers came from across the globe. There was an obvious variance in the quality of the presentations but some were really good.

What I did pick up from most sessions is the fact that the speakers tend to jump in and start showing code and technical know-how without taking the time to explain to the audience how they can benefit from the feature. I believe it is extremely important for the audience to appreciate the importance and value-ad of a technical discussion before the code syntax is explained. The occasional lack of proper introductions and closing statements could be because the sessions were limited to 45 minutes each.

The presentations are available for download by the public after 25 November on the conference website.

SharePint:

AvePoint hosted a “Red-Party” on the second night of the conference but could only accommodate a limited number of people and many of us who registered for the party were disappointed to find out that we did not collect the entrance tags in time and therefore could no longer attend.

Fortunately on the Tuesday afternoon, in an effort to offer an alternative social gathering for attendees unable to attend the AvePoint party, a SharePint event was organized and co-sponsored by Qorus, Axceler, Newsgator, Metalogix, and HiSoftware. Arrangements were made, flyers were handed out, tweets were sent out, and a few hours later we enjoyed free German beer, great company and awesome music at the AM to PM Bar located in Hackescher Markt, one of Berlin’s coolest locales.

Many thanks to Qorus, Axceler, Newsgator, Metalogix, and HiSoftware for organizing and sponsoring the great evening!

clip_image005

Solution Enablers:

I was very impressed by the products and services showcased by the exhibitors. It is always important to understand when to develop custom solution parts vs. when to make use of 3-rd party solution enablers. And having the right mix between technical presentations and a wide range of exhibitors at the conference gives me the confidence that SharePoint solution architects will take a step back and carefully consider how a mixture of SharePoint OOB features, 3rd-party products and custom development can solve business requirements.

Once again, think “solution” and not single product.

See the section ‘Interesting solution enablers’ at the bottom of this blog for a brief overview of a few of the products available.

clip_image006

Immediate Actions:

There are thousands who did not have the opportunity to attend the conference. It is our responsibility to take the conference into the workplace and I cannot wait to share the relevant knowledge with my team and local community.

I am already in touch with a number of speakers, vendors and delegates and I will trial / explore some of the products, download and research some of the presentations and use my findings to conduct at least 5 geek-talk-round-table discussions with my team in order to see how we can benefit from the conference content.

Conclusion:

Overall a very well organized conference with great structured content relevant to solving problems which we currently experience in the SharePoint industry.

A fantastic vibe between conference delegates, great relationships established and an absolute great experience.

Well done to everyone who participated and please continue with your efforts to share the knowledge and passion for SharePoint with those around you!

clip_image007


Interesting Solution Enablers:

Qorus Software

clip_image009

Qorus DocGeneration works with Microsoft SharePoint 2007 / 2010 and Microsoft Word to dramatically reduce the time and effort required to generate complex, customized documents while improving quality, consistency and effectiveness. http://www.qorusdocs.com/

 

SurfRay – Ontolica Search

clip_image010

Ontolica Search Preview allows you to preview and read documents in any format directly in SharePoint search results, with hit highlighting, and navigation to the most relevant pages in your documents . This reduces search costs and increases user adoption dramatically. http://www.surfray.com/

 

NewsGator

clip_image011

NewsGator solutions help you overcome business challenges by providing an integrated, behind-the-firewall, social computing platform that supports collaboration, facilitates communication, and improves worker knowledge. http://www.newsgator.com/

 

Kaldeera

clip_image013

KAF is a tool that allows you to modify the standard SharePoint® forms and create powerful web form-based applications. Hide fields, display "uneditable" fields, grouping and display the information in a more intuitive way adding static text, images, Web Parts, etc. http://www.kaldeera.com

 

GetOrganized

clip_image014

In brief GetOrganized is a user friendly standard product which organizes e-mails, documents, tasks etc. in a relevant context in order to optimize collaboration and business processes in your company in a simple and efficient way. http://en.getorganized.net

 

Bamboo Solutions

clip_image015

Bamboo® Solutions provides technologies that augment the SharePoint platform, and more than 60 products that provide a broad range of enhanced capabilities and solutions that maximize the value of SharePoint deployments. http://bamboosolutions.com

 

MetaLogix

image

Provides comprehensive content lifecycle management solutions that allow you to easily move data, reduce compliance risk, cut the cost of discovery, reduce storage and simplify management of Microsoft content, whether it’s on-premises or in the cloud. http://www.metalogix.com

 

Axceler

image 

Axceler provides SharePoint solutions that help the SharePoint management team get the most out of their platform and address the most pressing SharePoint challenges facing enterprises today. Solutions include SharePoint Governance, SharePoint Administration, SharePoint Migration, SharePoint Security, SharePoint Reporting and SharePoint Visibility. http://www.axceler.com

 

HiSoftware

image

HiSoftware provides content-aware compliance solutions for both Web and SharePoint® environments that detect private or confidential data and report on violations to ensure compliance with regulatory and other internal policies. http://www.hisoftware.com