Created
May 13, 2015 19:56
-
-
Save beckettkev/cbdbff7bc57f3eff9ef2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var context = new SP.ClientContext.get_current(); | |
//You can do this on the current web, for this example we will be testing against a specific sub web | |
var targetWeb = site.openWeb(_spPageContextInfo.siteServerRelativeUrl + '/MySubWeb'); | |
context.load(targetWeb); | |
var currentUser = targetWeb.get_currentUser(); | |
var allGroups = targetWeb.get_siteGroups(); | |
var group = allGroups.getByName('My SP Permission Group Name'); | |
var groupUsers = group.get_users(); | |
context.load(currentUser); | |
context.load(allGroups); | |
context.load(group); | |
context.load(groupUsers); | |
//do the Async call to retrieve the object information (see context load) | |
context.executeQueryAsync(function () { | |
var valid = false; | |
var groupUserEnumerator = groupUsers.getEnumerator(); | |
//this group will have less than 50 people in it so enumerating the collection is deemed ok | |
while (groupUserEnumerator.moveNext()) { | |
var groupUser = groupUserEnumerator.get_current(); | |
if (groupUser.get_id() == currentUser.get_id()) { | |
//we have a match, the user is in the SP Group | |
valid = true; | |
break; | |
} | |
} | |
/* | |
The valid variable at this point tells you if the current person is in | |
the SP Permissions Group | |
*/ | |
}, | |
function (sender, args) { | |
//Handle any errors with loading the SP Group | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment