SharePoint Judge current user permission via Client Object Model about JavaScript

來源:互聯網
上載者:User

Judge current user permission

sometime, we should 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 includes 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”);}

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.