- Timestamp:
- 05/25/12 15:29:44 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/UserManager.cs
r7355 r7909 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using System.Web.Security; 26 using DA = HeuristicLab.Services.Access.DataAccess; 24 27 25 28 namespace HeuristicLab.Services.Access { … … 40 43 return Membership.GetUser(userId); 41 44 } 45 46 public bool VerifyUser(Guid userId, List<Guid> allowedUserGroups) { 47 List<DA.UserGroupUserGroup> userGroupBases; 48 List<DA.UserGroup> groups; 49 Dictionary<Guid, Guid> ugMapping = new Dictionary<Guid, Guid>(); 50 51 if (allowedUserGroups.Contains(userId)) return true; 52 53 using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) { 54 userGroupBases = context.UserGroupUserGroups.ToList(); 55 groups = context.UserGroupBases.OfType<DA.UserGroup>().ToList(); 56 } 57 58 foreach (var ugug in userGroupBases) { 59 ugMapping[ugug.UserGroupId] = ugug.UserGroupUserGroupId; 60 } 61 62 foreach (Guid guid in allowedUserGroups) { 63 if (CheckInGroupHierarchy(userId, guid, ugMapping, groups)) return true; 64 } 65 return false; 66 } 67 68 private bool CheckInGroupHierarchy(Guid userId, Guid group, Dictionary<Guid, Guid> ugMapping, List<DA.UserGroup> groups) { 69 //check all subgroups 70 var childs = ugMapping.Where(x => x.Value == group).Select(x => x.Key); 71 var childGroups = childs.Where(x => groups.Where(y => y.Id == x).Count() > 0).ToList(); 72 //also check if user is in group 73 childGroups.Add(group); 74 75 foreach (Guid id in childGroups) { 76 if (ugMapping.Where(x => x.Value == id).Select(x => x.Key).Contains(userId)) { 77 return true; 78 } 79 } 80 return false; 81 } 42 82 } 43 83 }
Note: See TracChangeset
for help on using the changeset viewer.