SharePoint Judge current user permission via Client Object Model about JavaScript

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 40
	Var 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”);
		}



 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值