Last active
November 23, 2015 23:29
-
-
Save willprice76/6b376cfa48aabe5a9777 to your computer and use it in GitHub Desktop.
Update to Simple Data Extender to take into account Group membership
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
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