0

How do you check the roles in SharePoint 2010 so you can hide the Navigation Up icon? Users with Read Only access should not see this icon. Any suggestions would be greatly appreciated.

0

Add a Javascript in your Style Library and reference it in the Master Page. Put the following code (extracted from here and modified a liitle bit)

    function isCurrentUserInGroup(groupName, functionUserInGroup, functionUserNotInGroup, functionGroupNotFound, functionOnError) {
    var ctx = new SP.ClientContext.get_current();
    //Get info of current user
    var currentUser = ctx.get_web().get_currentUser();
    ctx.load(currentUser, 'Id', 'LoginName');
    //Retrieve all site groups
    var groups = ctx.get_web().get_siteGroups();
    ctx.load(groups);

    ctx.executeQueryAsync(function (sender, args) {
        //See whether the group exists
        var groupFound = false;
        var groupEnumerator = groups.getEnumerator();
        while (groupEnumerator.moveNext() && !groupFound) {
            var group = groupEnumerator.get_current();
            if (group.get_title() == groupName) {
                //Found the group, now try to load users of this group
                groupFound = true;
                var users = group.get_users();
                ctx.load(users);
                ctx.executeQueryAsync(function (sender, args) {
                    //See whether the user exists
                    var userFound = false;
                    var userEnumerator = users.getEnumerator();
                    while (userEnumerator.moveNext() && !userFound) {
                        var user = userEnumerator.get_current();
                        if (user.get_id() == currentUser.get_id()) {
                            //User exists in the group
                            userFound = true;

                            if (functionUserInGroup != null)
                                functionUserInGroup();
                        }
                    }

                    //User doesn't exist in the group
                    if (!userFound && (functionUserNotInGroup != null))
                        functionUserNotInGroup();

                }, function (sender, args) {
                    if (functionOnError != null)
                        functionOnError(sender, args);

                });
            }
        }

        //Group doesn't exist
        if (!groupFound && (functionGroupNotFound != null))
            functionGroupNotFound();

    }, function (sender, args) {
        if (functionOnError != null)
            functionOnError(sender, args);

    })

}
$(document).ready(function() { 
// Sample usage 
ExecuteOrDelayUntilScriptLoaded(function () {
    isCurrentUserInGroup('Readers',
                         function () {
                            $("#Ribbon\\.Library\\.CustomViews\\.NavigateUp-Medium").hide();
                         },
                         function () {
                            alert('User is NOT in the group.');
                         },
                         function () {
                             alert('Group does NOT exist.');
                         },
                         function (sender, args) {
                             alert('Request failed.' + args.get_message() + '\n' + args.get_stackTrace());
                         });
}, "sp.js");});

Notice that you have to modify the alert by whatever you want

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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