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