1

I like to show or hide extension as per user permission in SPFx ,suppose if user present in SP-group extension is visible or hide it

 @override
  public onListViewUpdated(event: IListViewCommandSetListViewUpdatedParameters): void {
    var Libraryurl = this.context.pageContext.list.title; 
   
    
    const compareTwoCommand: Command = this.tryGetCommand('COMMAND_2');
    if (compareTwoCommand) {
      // This command should be hidden unless exactly one row is selected.
      const listname:string =this.context.pageContext.list.title
      const Librarylistname:string ="Documents"
      
      compareTwoCommand.visible =(event.selectedRows.length > 0 && Libraryurl == "Documents" )
    }
  }

1 Answer 1

1

You can do that by writing your business logic to check the user permissions based on SharePoint group membership (or list permissions) in onListViewUpdated method and show/hide the list view command.

All you need to do is set the visible property of your command to true/false based on user permissions.

const compareTwoCommand: Command = this.tryGetCommand('COMMAND_2');

if (compareTwoCommand) {
    //write business logic to check user permissions here
    compareTwoCommand.visible = true; //show command

    //compareTwoCommand.visible = hide; //Hide command
}

References:

  1. Show and hide commands based on users its permissions
  2. Showing a ListView CommandSet if a user is in a SharePoint Group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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