3

I have custom master page with top navigation such as Home, Admin, Finance etc. but need to hide these options according to user permission. For eg, if any user from Finance login, he should see only navigation Home, Finance (Admin should be hidden). How to achieve this? thanks in advance

1
  • check my updated answer Oct 17, 2016 at 7:54

3 Answers 3

1

You can set the permission for navigation link:

  • Go to Site Settings > Navigation
  • Select Navigation Link & Click on Edit

enter image description here

  • Set Audience for the link by assigning specific groups

enter image description here

EDIT:

Assuming that you have custom navigation like:

<ul>
  <li id='liFinance' style='display:none;'>Finance</li>
  <li id='liAdmin' style='display:none;'>Admin</li>
</ul> 

Now add following script to master page which will show the appropriate link as per user group:

var currentContext, currentWeb, currentUser, allGroups, arrGroups;

$(document).ready(function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', setNavigationPermissions);
});

function setNavigationPermissions() {
    currentContext = new SP.ClientContext.get_current();
    currentWeb = currentContext.get_web();

    currentUser = currentContext.get_web().get_currentUser();
    currentContext.load(currentUser);

    allGroups = currentUser.get_groups();
    currentContext.load(allGroups);

    currentContext.executeQueryAsync(OnSuccess, OnFailure);
    function OnSuccess(sender, args) {
        var grpsEnumerator = allGroups.getEnumerator();
        while (grpsEnumerator.moveNext()) {
            var group = grpsEnumerator.get_current();
            arrGroups.push(group.get_title());
        }
        if (arrGroups.indexOf('Admin Group') > -1) { // If User in 'Admin Group'
            document.getElementById('liAdmin').style.display = ''; // Show Admin link
        }
        if (arrGroups.indexOf('Finance Group') > -1) { // If User in 'Finance Group'
            document.getElementById('liFinance').style.display = ''; // Show Finance link
        }
    }
    function OnFailure(sender, args) {
        alert(args.get_message());
    }
}
2
  • I am not using SharePoint default navigation but the custom navigation created by design manager Oct 17, 2016 at 5:36
  • Means ? Have you hide the existing SP navigation and design your own with i.e. with <ul><li> ?? Oct 17, 2016 at 6:04
0

If you have custom navigation, you need to handle via client side to hide/show links accordingly. For e.g.

If you have custom navigation list, it should have a column(people or group) which will hold people or group name for whicn you wanted to display particular link.

Now when the navigation is created dynamically, you have to first check current loggedin user is member of which group and its corresponding entry in navigation list.

Hope this helps!!!

0

It will require a lot more effort than expected. I suggest rather add a top navigation snippet on your custom Master page. Now apply similar styling as you had for your custom top navigation. For this you can take idea from this tutorial:

http://akashkarda.blogspot.in/2014/05/quick-launch-styles-in-sharepoint-2013.html

You might not end up with an exact match, but this will save you a lot of time. The navigation can then be easily handled as suggested by @Ronak in other answer. Hope that helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.