SOLVED

How can I hide the gear icon based off permissions?

%3CLINGO-SUB%20id%3D%22lingo-sub-1844401%22%20slang%3D%22en-US%22%3EHow%20can%20I%20hide%20the%20gear%20icon%20based%20off%20permissions%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1844401%22%20slang%3D%22en-US%22%3EIn%20the%20top%20right%20corner%20of%20modern%20sites%20is%20the%20settings%20gear.%20This%20gives%20to%20much%20access%20to%20those%20who%20don't%20need%20it.%20Is%20there%20any%20way%20to%20hide%20this%20based%20off%20permissions%20or%20groups%2C%20spfx%20extension%3F%20Any%20help%20would%20be%20great.%20Thank%20you.%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1844401%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPermissions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESecurity%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1857997%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20hide%20the%20gear%20icon%20based%20off%20permissions%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1857997%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F849419%22%20target%3D%22_blank%22%3E%40phil333%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20hopes%20that%20this%20may%20help%20someone%20else...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20been%20having%20luck%20using%20an%20spfx%20extension%20to%20view%20if%20the%20user%20has%20certain%20permissions.%20I%20still%20haven't%20been%20able%20to%20successfully%20hide%20the%20gear%20Icon%20though.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20js%20I%20use%20works%20well%20on%20the%20first%20page%20load%20but%20then%20doesn't%20after%20that.%26nbsp%3B%20Not%20sure%20what's%20off.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1859772%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20hide%20the%20gear%20icon%20based%20off%20permissions%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1859772%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F849419%22%20target%3D%22_blank%22%3E%40phil333%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESPFx%20extension%20will%20work%20only%20on%26nbsp%3B%3CSTRONG%3Emodern%3C%2FSTRONG%3E%20pages%20in%20SharePoint.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20it%20is%20not%20working%20on%20modern%20page%20then%20it%20might%20be%20the%20issue%20of%20browser%20cache.%20If%20you%20are%20testing%20in%20debugging%20mode%20then%20try%20uploading%20SPFX%20extension%20package%20in%20App%20catalog%20and%20then%20on%20your%20site.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20try%20testing%20by%20clearing%20browser%20cache.%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%20%3CSTRONG%3EMark%20as%20Best%20Response%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20to%20solve%20your%20issue.%20This%20will%20help%20others%20to%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20post%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3ELike%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1866764%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20I%20hide%20the%20gear%20icon%20based%20off%20permissions%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1866764%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373269%22%20target%3D%22_blank%22%3E%40ganeshsanap%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20was%20starting%20to%20wonder%20if%20anyone%20would%20reply%2C%20thank%20you.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20deployed%20and%20ran%20the%20extension%20on%20a%20test%20site%20but%20again%2C%20it%20works%20on%20first%20load%20and%20not%20after.%20Do%20you%20know%20how%20I%20would%20handle%20the%20cache%20issue%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERight%20now%20my%20js%20uses%20a%20function%20with%20set%20interval%20to%20check%20if%20the%20element%20is%20loaded.%20This%20doesnt%20always%20work%20though%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3Elet%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EcheckExist%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EsetInterval%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3Efunction%3C%2FSPAN%3E%3CSPAN%3E()%26nbsp%3B%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nb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SPAN%3E%3CSPAN%3E%22Element%26nbsp%3Bexists!%22%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Edocument.querySelector('%23O365_MainLink_Settings_container').style.visibility%26nbsp%3B%3D%26nbsp%3B%22hidden%22%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EclearInterval%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3EcheckExist%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%2C%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E100%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EAny%20thoughts%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1866843%22%20slang%3D%22de-DE%22%3ESubject%3A%20How%20can%20I%20hide%20the%20gear%20icon%20based%20off%20permissions%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1866843%22%20slang%3D%22de-DE%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F849419%22%20target%3D%22_blank%22%3E%40phil333%3C%2FA%3E%20%2C%20The%20Gear%20Icon%20shows%20only%20the%20things%2C%20your%20user%20will%20get%20to%20see%20according%20to%20their%20permission%20levels.%20I%20think%20it%20is%20a%20good%20one%20to%20NOT%20hide%20icons%20in%20a%20SharePoint.%20SharePoint%20is%20not%20a%20HidePoint.%20Make%20sure%2C%20your%20users%20get%20a%20basic%20training%20or%20online%20course%20to%20learn%2C%20what%20the%20icons%20can%20do%20to%20for%20them.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20instance%2C%20you%20can%20always%20restrict%20certain%20pages%20or%20the%20whole%20pages%20library%20of%20a%20site%20with%20a%20content%20approval%2C%20so%20that%20they%20cannot%20manipulate%20on%20whats%20in%20your%20pages%20without%20your%20approval.%20The%20pages%20library%20is%20in%20the%20site%20content%20of%20a%20site%2C%20you%20can%20go%20to%20%22Library%20Settings%22%20as%20a%20site%20owner%2C%20than%20go%20to%20%22advanced%20settings%22%20-%20activate%20the%20first%20check%20box%20in%20this%20page%20here%20to%20set%20on%20a%20content%20approval.%20So%20each%20time%20someone%20changes%20the%20content%2C%20you'll%20get%20an%20alert%20by%20Mail%20and%20also%20can%20easily%20approve%20or%20reject%20a%20change.%20This%20is%20by%20far%20better%20than%20bother%20with%20coding%20in%20SharePoint%20Framework%2C%20I%20suggest.%20Have%20a%20good%20day%20today!%20And%20if%20I%20can%20help%2C%20pls.%20Give%20a%20LIKe.%20Greets%20from%20Eva.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor
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 help would be great. Thank you.
6 Replies

@phil333 

In the hopes that this may help someone else...

 

I've been having luck using an spfx extension to view if the user has certain permissions. I still haven't been able to successfully hide the gear Icon though.  

 

The js I use works well on the first page load but then doesn't after that.  Not sure what's off.

@phil333 

SPFx extension will work only on modern pages in SharePoint.

 

If it is not working on modern page then it might be the issue of browser cache. If you are testing in debugging mode then try uploading SPFX extension package in App catalog and then on your site.

 

Also try testing by clearing browser cache.


Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

 

@ganeshsanap 

 

I was starting to wonder if anyone would reply, thank you.

 

I have deployed and ran the extension on a test site but again, it works on first load and not after. Do you know how I would handle the cache issue? 

 

Right now my js uses a function with set interval to check if the element is loaded. This doesnt always work though: 

 

let checkExist = setInterval(function() {
    const element = document.querySelector("#O365_MainLink_Settings_container");
    if(typeof(element) != "undefined" && element != null){

        console.log("Element exists!");
        document.querySelector('#O365_MainLink_Settings_container').style.visibility = "hidden";
        clearInterval(checkExist);
    }
    
}, 100);
 
Any thoughts?

Hi @phil333 , The Gear Icon shows only the things, your User will get to see according to their permission levels. I think, it is a good one to NOT hide icons in a SharePoint. SharePoint is not a HidePoint. Make sure, your users get a basic training or online course to learn, what the icons can do to for them. 

 

For instance, you always can restrict certain pages or the whole pages library of a site with a content approval, so that they cannot manipulate on whats in your pages without your approval. The pages library is in the site content of a site, you can go to "Library Settings" as a site Owner, than go to "advanced settings" - activate the first check box in this page here to set on a content approval. So each time someone changes the content, you'll get an alert by Mail and also can easily approve or reject a change. This is by far better than bother with coding in SharePoint Framework, I suggest. Have a good day today! And if I can help, pls. give a LIKe. Greets from Eva.

@Eva Vogel Thank you for your response.

 

"SharePoint is not a HidePoint" was a good one. Unfortunately in this situation, SP is what ever the project manager wants it to be. Of which they don't want site contents and site usage visible to just every one. 

I do like your solution though for what is is worth. In a different scenario (probably most) I think it would really do the trick.

Best Response confirmed by phil333 (Occasional Contributor)
Solution

@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-exte...