Search This Blog

Sunday, September 27, 2020

SPFx - Hide / Show ribbon menu - based on permission

 // Add this import statement    

import {spfrom '@pnp/sp';  
import pnp, { PermissionKind } from "sp-pnp-js";
 public render(): void {

    this._trimSuiteBar();
    this.domElement.innerHTML = `    
          <div class="main-wrapper"> </div>`;
        //Show the loading indicator inside an element      
     
      this.context.statusRenderer.clearLoadingIndicator(this.domElement);
  }

 private _trimSuiteBar(): void {
    debugger
    pnp.sp.web.usingCaching()
      .currentUserHasPermissions(PermissionKind.EditListItems)
      .then(perms => {
        var suiteBar = document.getElementById("suiteBarTop");
        if (!suiteBar || !permsreturn//return if no suite bar OR perms not high enough

        suiteBar.setAttribute("style""display: block !important");
      });
  }  

No comments:

Post a Comment