Forum Discussion

phil333's avatar
phil333
Brass Contributor
Nov 02, 2020
Solved

How can I hide the gear icon based off permissions?

In the top right corner of modern sites is the settings gear. This gives to much access to those who don't need it. Is there any way to hide this based off permissions or groups, spfx extension? Any h...
  • phil333's avatar
    Nov 09, 2020

    phil333 

    A spfx extension solved my problem!

     

    In my application customizer I imported SPPermission and then used some js to do what I needed.
    My Code below:

    const canEdit = this.context.pageContext.web.permissions.hasAnyPermissions(SPPermission.manageWeb);
    if(!canEdit){
    let checkExist = setInterval(function() {
    const element = document.querySelector("#O365_MainLink_Settings_container").firstChild.firstChild.firstChild.firstChild;
    if(typeof(element) != "undefined" && element != null){
    element.parentElement.parentElement.parentElement.remove();
    console.log("GFC user only has view rights.");
    clearInterval(checkExist);
    }
    }, 100);
    }


    References:
    Setup Environment: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-development-environment
    Build an extension: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/get-started/build-a-hello-world-extension

Resources