SharePoint judge current user permission via client object model about Javascript

Source: Internet
Author: User

Judge current user permission

Sometime, We shocould judge the permisson of current user when view different page. Here, we can complete it via JS, follow the code.

For example: the permission site center contains des different permission groups, Here we only need admin and product. Then we can know the current belong to admin or product.

Here, we complete the progress via client object mode about Js.

 

Function getWebUserData(){Var context  = new SP.ClientContext.get_current();Var web = new context.get_web();Var currentUser = web.get_currentUser();Var ProductGroup = context.get_web().get_siteGroups().getById(40); // my ProductGroup Id is 40Var AdminGroup = context.get_web().get_Groups().getById(12); // my AdminGroupId is 12
productGroupUser =  ProductGroup.get_users();adminGroupUser = AdminGroup.get_users();context.load(currentUser);context.load(productGroupUser);context.load(adminGroupUser);context.executeQueryAsync(success, failure);}
Function success(){For(var  i  = 0; i < adminGroupUser.get_count();  i ++  ){If(currentUser.get_id() == adminGroupUser.get_item(i).get_id()){Alert(“The user  is  admin”);}}For(var  i  = 0; i < productGroupUser.get_count();  i ++  ){If(currentUser.get_id() == productGroupUser.get_item(i).get_id()){Alert(“The user  is  == productGroupUser”);}}}

Function failure(){{Alert(“The user  is  not existed”);}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.