Check If User has Full Control Permission In a Web In SharePoint 2016

Security Management is a prime concern in SharePoint, as the right content has to be served to the right people with the adequate permissions. SharePoint recommends assigning role-based permissions. All the permissions are managed through the roles. Roles are classified in two sections:

  • Role Definition
  • Role Assignment

Role definition, also known as a permission level, is the list of permissions, associated with the role. Full control, contribute, read, design, and limited access are some of the role definitions available.

Role assignment is the relationship established between users/groups and the role definition.

In this blog, let’s use JavaScript Object Model to check if user has Full Control Permission level in the web.

  1. <script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>  
  2.   
  3. <script language="javascript" type="text/javascript">  
  4.   
  5. $(document).ready(function() {  
  6. SP.SOD.executeFunc('sp.js''SP.ClientContext', checkUserPermissions);  
  7. });  
  8.   
  9. var oGroupColl,oWeb;  
  10. function checkUserPermissions() {  
  11.   
  12.   
  13. //Get the client context, web and current user object  
  14. var clientContext = new SP.ClientContext.get_current();  
  15. oWeb = clientContext.get_web();  
  16. oCurrentUser = oWeb.get_currentUser();  
  17.   
  18. //Load the client context with the required objects  
  19. clientContext.load(oWeb,'EffectiveBasePermissions')  
  20. clientContext.load(oCurrentUser);  
  21.   
  22. //Execute the batch  
  23. clientContext.executeQueryAsync(QuerySuccess, QueryFailure);  
  24. }  
  25.   
  26. function QuerySuccess() {  
  27.   
  28.   
  29. //Check if user has Full Control Permission Level  
  30. var userName = oCurrentUser.get_loginName();  
  31. console.log("Does the user has full permission in the web ? : "+oWeb.get_effectiveBasePermissions().has(SP.PermissionKind.manageWeb));  
  32. }  
  33.   
  34. function QueryFailure(sender,args) {  
  35. console.log('Request failed'+ args.get_message());  
  36. }  
  37.   
  38. </script>  

 We can add the above code in the Content Editor Web Part to see it in action.


Specify the URL of the text file containing the JSOM Code in the content link field.


Upon clicking "Apply", we will get the output in the console, as shown below.



Summary

Thus, we saw how to check if a user has a specific permission level in SharePoint 2016. 
Ebook Download
View all
Learn
View all