none
SPO Hide quick launch for specific group permission RRS feed

  • Question

  • Hello everyone!
    I have a list which contains multiple users that they will access it from 2 different groups permissions, Members (Read Only), Visitors(View Only).

    What i have tried to do:

     - When they are assigned to a group they are able to see it knowing that View only permission is the same as the group one.
     - When i assign the users outside the group as View only permission they are not able to see it.But I want to hide it from group permission because i am using a code that will hide excel feature only for groups.
     - Also,I have tried to remove the groups from quick lunch, but as result nothing happens and they still are able to see it.


    What i want to achieve:

     - Hide the quick lunch in the left pane of the screen from those 2 groups.But the others group like owners are able to see the Quick lunch.

    Is it possible to achieve it?

    Any help will be greatly appreciated.
    Thank you!
    • Edited by SynthBZ Thursday, December 19, 2019 11:50 AM
    Thursday, December 12, 2019 1:44 PM

All replies

  • Hi,

    As navigation is global, we need javascript link to hide the navigation(classic view).

    Create a js file hosts in site assets library(Update the navigation node and group name based on your environment, you could load jquery from your online library to avoid network issue).

    function IsCurrentUserMemberOfGroups(groups, OnComplete) {
                var currentContext = new SP.ClientContext.get_current();
                var currentWeb = currentContext.get_web();
                var currentUser = currentWeb.get_currentUser();            
                var oGroups = currentUser.get_groups();            
                currentContext.load(currentUser);
                currentContext.load(oGroups);
                currentContext.executeQueryAsync(OnSuccess, OnFailure);
    
                function OnSuccess(sender, args) {
                    var userInGroup = false;
    				var isAdmin = currentUser.get_isSiteAdmin();
                    console.log('Admin check' + isAdmin);
                    if (!isAdmin) {
                        var groupEnumerator = oGroups.getEnumerator();
                        while (groupEnumerator.moveNext()) {
                            var oGroup = groupEnumerator.get_current();
                            var groupTitle = oGroup.get_title();
                            console.log(groupTitle);
                            $.each(groups, function (index, value) {
                                if (value == groupTitle) {
                                    console.log('user in group ' + groupTitle);
                                    userInGroup = true;
                                }
                            });
                            if (userInGroup)
                                break;
                        }
                    }
                    OnComplete(userInGroup);
                }
    
                function OnFailure(sender, args) {
                    OnComplete(false);
                }
            }
            function CheckUserGroups() {
                var groups = ["Designers"]
                IsCurrentUserMemberOfGroups(groups, function (isCurrentUserInGroup) {
                    if (isCurrentUserInGroup) {
                        $("span.menu-item-text:contains('test111')").parent().closest('li').hide();
                    }
                });
    
            }
    		var script = document.createElement('script');
    		script.src = 'https://code.jquery.com/jquery-3.4.1.min.js';
    		script.type = 'text/javascript';
    		document.getElementsByTagName('head')[0].appendChild(script);
            ExecuteOrDelayUntilScriptLoaded(CheckUserGroups, 'SP.js');

    Add javascript link by pnp powershell.

    https://github.com/sharepoint/pnp-powershell/releases

    Connect-PNPOnline -Url https://tenant.sharepoint.com/sites/grace/
    Add-PnPJavaScriptLink -Name "JSLoadAfterSP" -Url /sites/sitename/SiteAssets/hideNavigationBasedonGroup.js -Sequence 9999 -Scope Site

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, December 13, 2019 6:56 AM
  • Hi Lee__li,

    I have saved this script in a js file, uploaded to my Site Assets, and i call it by JS Link. It works.
    But the problem i have another script in the same page that will hide Export to Excel feature it was working perfectly.
    When i have added this script, the export to excel feature is displaying back for the users that was related to a specific group where it should be hidden.

    If multiple scripts make conflicts to each other is it possible to hide the export to excel from a specific group using the same script you mentioned ?

    Here is the Export to Excel code:
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript">
            function IsCurrentUserMemberOfGroups(groups, OnComplete) {
                var currentContext = new SP.ClientContext.get_current();
                var currentWeb = currentContext.get_web();
                var currentUser = currentWeb.get_currentUser();
                var oGroups = currentUser.get_groups();
                currentContext.load(currentUser);
                currentContext.load(oGroups);
                currentContext.executeQueryAsync(OnSuccess, OnFailure);
    
                function OnSuccess(sender, args) {
                    var userInGroup = false;
                    var groupEnumerator = oGroups.getEnumerator();
                    while (groupEnumerator.moveNext()) {
                        var oGroup = groupEnumerator.get_current();
                        var groupTitle = oGroup.get_title();
                        console.log(groupTitle);
                        $.each(groups, function (index, value) {
                            if (value == groupTitle) {
                                console.log('user in group ' + groupTitle);
                                userInGroup = true;
                            }
                        });
                        if (userInGroup)
                            break;
                    }
                    OnComplete(userInGroup);
                }
    
                function OnFailure(sender, args) {
                    OnComplete(false);
                }
            }
            function CheckUserGroups() {
                var groups = ["Developer Site Visitors", "Developer Site Members"]
                IsCurrentUserMemberOfGroups(groups, function (isCurrentUserInGroup) {
                    if (isCurrentUserInGroup) {
                        var css = "a[id*='ExportToSpreadsheet']{display:none;}",
                            head = document.head || document.getElementsByTagName('head')[0],
                            style = document.createElement('style');
    
                        head.appendChild(style);
                        style.type = 'text/css';
                        style.title = 'MSCustom';
                        if (style.styleSheet) {
                            style.styleSheet.cssText = css;
                        } else {
                            style.appendChild(document.createTextNode(css));
                        }
                    }
                });
    
            }
            ExecuteOrDelayUntilScriptLoaded(CheckUserGroups, 'SP.js');
        </script>
    Thanks in advance!
    Friday, December 13, 2019 4:13 PM
  • Hi ,

    Try to update the JavaScript function names as different to avoid confliction and check.

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript">
            function IsCurrentUserMemberOfGroups(groups, OnComplete) {
                var currentContext = new SP.ClientContext.get_current();
                var currentWeb = currentContext.get_web();
                var currentUser = currentWeb.get_currentUser();
                var oGroups = currentUser.get_groups();
                currentContext.load(currentUser);
                currentContext.load(oGroups);
                currentContext.executeQueryAsync(OnSuccess, OnFailure);
    
                function OnSuccess(sender, args) {
                    var userInGroup = false;
                    var groupEnumerator = oGroups.getEnumerator();
                    while (groupEnumerator.moveNext()) {
                        var oGroup = groupEnumerator.get_current();
                        var groupTitle = oGroup.get_title();
                        console.log(groupTitle);
                        $.each(groups, function (index, value) {
                            if (value == groupTitle) {
                                console.log('user in group ' + groupTitle);
                                userInGroup = true;
                            }
                        });
                        if (userInGroup)
                            break;
                    }
                    OnComplete(userInGroup);
                }
    
                function OnFailure(sender, args) {
                    OnComplete(false);
                }
            }
            function CheckUserGroupsExcel() {
                var groups = ["Developer Site Visitors", "Developer Site Members"]
                IsCurrentUserMemberOfGroups(groups, function (isCurrentUserInGroup) {
                    if (isCurrentUserInGroup) {
                        var css = "a[id*='ExportToSpreadsheet']{display:none;}",
                            head = document.head || document.getElementsByTagName('head')[0],
                            style = document.createElement('style');
    
                        head.appendChild(style);
                        style.type = 'text/css';
                        style.title = 'MSCustom';
                        if (style.styleSheet) {
                            style.styleSheet.cssText = css;
                        } else {
                            style.appendChild(document.createTextNode(css));
                        }
                    }
                });
    
            }
            ExecuteOrDelayUntilScriptLoaded(CheckUserGroupsExcel, 'SP.js');
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, December 18, 2019 6:38 AM
  • Hi 

    I have updated the script you mentioned.As result, the "Export to Excel feature" still available for the users that exist in the related groups mentioned in the code.

    I will try to summarize the issue.

    Could you please try the following scenario i will mention below, so you will see the issue that I'm faced:

    1.Create a permission called "Restricted Read" and assign to this permission the following:

    2.Go to Site permission and give the user the permission we created above. (Assign this user outside a SharePoint group).
    In this step, you will see that Site contents is hidden from the navigation and from settings gear icon.

    3.Create a list(Classic experience), go to permission for this list and click on stop inheriting permission.

    4.Now assign the same user as read only outside a sharepoint group, and same user inside a group that have permission as View Only.

    Why i assigned 2 different permissions for the same user?

    • Because, i have a flow that will send an email to this user when an item is created in sharepoint in this list, and in this email there is a details about this item created as link to this item.
    • If the user is assigned as Restricted read or view only in a sharepoint group,he will not be able to access the item linked in the email and it keeps asking for request for access.
    • So that's why i have used 2 different permission for the same user for he can access items in the email.
    • I assigned them in a group because the scripts are based if the users exists in a groups.

    So i am pretty sure that the export to excel it's breaking when the user got read only access,even when he exist in a group that got View Only or Restricted read permission.

    What would be the solution for this issue and everything works perfectly?

    Looking to hear from you.

    I really appreciate your help Lee__li, thank you for your time.


    Thursday, December 19, 2019 11:49 AM
  • Hi ,

    I did test followed by the steps you shared, while not reproduced.

    Try to use developer tool to debug the script to check any exception.

    For example:

    Test result.

    More information about debugging if you are not familiar with it.

    https://javascript.info/debugging-chrome

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, December 20, 2019 6:27 AM