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.
- <script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
-
- <script language="javascript" type="text/javascript">
-
- $(document).ready(function() {
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', checkUserPermissions);
- });
-
- var oGroupColl,oWeb;
- function checkUserPermissions() {
-
-
-
- var clientContext = new SP.ClientContext.get_current();
- oWeb = clientContext.get_web();
- oCurrentUser = oWeb.get_currentUser();
-
-
- clientContext.load(oWeb,'EffectiveBasePermissions')
- clientContext.load(oCurrentUser);
-
-
- clientContext.executeQueryAsync(QuerySuccess, QueryFailure);
- }
-
- function QuerySuccess() {
-
-
-
- var userName = oCurrentUser.get_loginName();
- console.log("Does the user has full permission in the web ? : "+oWeb.get_effectiveBasePermissions().has(SP.PermissionKind.manageWeb));
- }
-
- function QueryFailure(sender,args) {
- console.log('Request failed'+ args.get_message());
- }
-
- </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.