Skip to content

Instantly share code, notes, and snippets.

@willprice76
Last active November 23, 2015 23:29
Show Gist options
  • Save willprice76/6b376cfa48aabe5a9777 to your computer and use it in GitHub Desktop.
Save willprice76/6b376cfa48aabe5a9777 to your computer and use it in GitHub Desktop.
Update to Simple Data Extender to take into account Group membership
public override XmlTextReader ProcessResponse(XmlTextReader reader, PipelineContext context)
{
var command = context.Parameters["command"] as String;
command = command.ToLower();
if (command == "getpromotions" || command == "getregions")
{
UserData currentUser = new CoreServiceHelper(System.Web.HttpContext.Current.User.Identity.Name).GetCurrentUser();
if (currentUser.Privileges != 1) //Skip for Admins
{
List<String> data = GetRegionPrefixesForUser(currentUser);
switch (command)
{
case "getregions":
return FilterRegions(reader, context, data);
case "getpromotions" :
return FilterPromotions(reader, context, data);
}
}
}
return reader;//default is to return unaltered XML
}
//Cache the region prefixes in a static variable to make processing a bit more efficient
public static ConcurrentDictionary<String, List<String>> UserRegionPrefixes = new ConcurrentDictionary<string, List<string>>();
private List<String> GetRegionPrefixesForUser(UserData currentUser)
{
if (!UserRegionPrefixes.ContainsKey(currentUser.Id))
{
List<String> regionPrefixes = new List<string>();
foreach (var groupTitle in currentUser.GroupMemberships.Select(m => m.Group.Title))
{
var match = Regex.Match(groupTitle, @".*\[Region Prefix (.*?)\]");
if (match.Success)
{
regionPrefixes.Add(match.Groups[1].Value);
}
}
UserRegionPrefixes.AddOrUpdate(currentUser.Id, regionPrefixes, (key, oldvalue) => regionPrefixes);
}
return UserRegionPrefixes[currentUser.Id];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment