- Timestamp:
- 02/09/18 07:56:01 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r15658 r15742 25 25 using HeuristicLab.Core; 26 26 using System.Collections.Generic; 27 using System.Linq; 27 28 28 29 namespace HeuristicLab.Clients.Hive { … … 64 65 } 65 66 67 private Dictionary<Guid, HashSet<Project>> projectAncestors; 68 public Dictionary<Guid, HashSet<Project>> ProjectAncestors { 69 get { return projectAncestors; } 70 } 71 72 private Dictionary<Guid, HashSet<Project>> projectDescendants; 73 public Dictionary<Guid, HashSet<Project>> ProjectDescendants { 74 get { return projectDescendants; } 75 } 76 77 private Dictionary<Guid, HashSet<Resource>> resourceAncestors; 78 public Dictionary<Guid, HashSet<Resource>> ResourceAncestors { 79 get { return ResourceAncestors; } 80 } 81 82 private Dictionary<Guid, HashSet<Resource>> resourceDescendants; 83 public Dictionary<Guid, HashSet<Resource>> ResourceDescendants { 84 get { return ResourceDescendants; } 85 } 86 87 66 88 #endregion 67 89 … … 89 111 projects = new ItemList<Project>(); 90 112 113 projectAncestors = new Dictionary<Guid, HashSet<Project>>(); 114 projectDescendants = new Dictionary<Guid, HashSet<Project>>(); 115 resourceAncestors = new Dictionary<Guid, HashSet<Resource>>(); 116 resourceDescendants = new Dictionary<Guid, HashSet<Resource>>(); 117 91 118 HiveServiceLocator.Instance.CallHiveService(service => { 92 119 service.GetSlaveGroupsForAdministration().ForEach(g => resources.Add(g)); … … 94 121 service.GetProjectsForAdministration().ForEach(p => projects.Add(p)); 95 122 }); 123 124 UpdateResourceGenealogy(); 125 UpdateProjectGenealogy(); 96 126 } 97 127 catch { … … 100 130 finally { 101 131 OnRefreshed(); 132 } 133 } 134 135 private void UpdateResourceGenealogy() { 136 resourceAncestors.Clear(); 137 resourceDescendants.Clear(); 138 139 foreach (var r in resources) { 140 resourceAncestors.Add(r.Id, new HashSet<Resource>()); 141 resourceDescendants.Add(r.Id, new HashSet<Resource>()); 142 } 143 144 foreach (var r in resources) { 145 var parentResourceId = r.ParentResourceId; 146 while (parentResourceId != null) { 147 var parent = resources.SingleOrDefault(x => x.Id == parentResourceId); 148 if (parent != null) { 149 resourceAncestors[r.Id].Add(parent); 150 resourceDescendants[parent.Id].Add(r); 151 parentResourceId = parent.ParentResourceId; 152 } else { 153 parentResourceId = null; 154 } 155 } 156 } 157 } 158 159 private void UpdateProjectGenealogy() { 160 projectAncestors.Clear(); 161 projectDescendants.Clear(); 162 163 foreach (var p in projects) { 164 projectAncestors.Add(p.Id, new HashSet<Project>()); 165 projectDescendants.Add(p.Id, new HashSet<Project>()); 166 } 167 168 foreach (var p in projects) { 169 var parentProjectId = p.ParentProjectId; 170 while (parentProjectId != null) { 171 var parent = projects.SingleOrDefault(x => x.Id == parentProjectId); 172 if (parent != null) { 173 projectAncestors[p.Id].Add(parent); 174 projectDescendants[parent.Id].Add(p); 175 parentProjectId = parent.ParentProjectId; 176 } else { 177 parentProjectId = null; 178 } 179 } 102 180 } 103 181 } … … 179 257 } 180 258 181 #region 259 #region Helper 182 260 public bool CheckAccessToAdminAreaGranted() { 183 261 if(projects != null) { … … 191 269 } 192 270 } 271 272 public bool CheckOwnershipOfResource(Resource res, Guid userId) { 273 if (res == null || userId == Guid.Empty) return false; 274 275 if (res.OwnerUserId == userId) { 276 return true; 277 } else if(resourceAncestors.ContainsKey(res.Id)) { 278 return resourceAncestors[res.Id].Where(x => x.OwnerUserId == userId).Any(); 279 } 280 281 return false; 282 } 283 284 public bool CheckOwnershipOfProject(Project pro, Guid userId) { 285 if (pro == null || userId == Guid.Empty) return false; 286 287 if (pro.OwnerUserId == userId) { 288 return true; 289 } else if (projectAncestors.ContainsKey(pro.Id)) { 290 return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any(); 291 } 292 293 return false; 294 } 295 296 public bool CheckOwnershipOfParentProject(Project pro, Guid userId) { 297 if (pro == null || userId == Guid.Empty) return false; 298 299 if(projectAncestors.ContainsKey(pro.Id)) { 300 return projectAncestors[pro.Id].Where(x => x.OwnerUserId == userId).Any(); 301 } 302 303 return false; 304 } 193 305 #endregion 194 306 }
Note: See TracChangeset
for help on using the changeset viewer.