- Timestamp:
- 05/29/12 12:45:22 (12 years ago)
- Location:
- branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/Query/QueryService.cs
r7589 r7914 25 25 using System.Linq; 26 26 using System.ServiceModel; 27 using HeuristicLab.Services.Access; 27 28 using HeuristicLab.Services.OKB.DataAccess; 28 29 using HeuristicLab.Services.OKB.Query.DataTransfer; … … 35 36 [ServiceBehavior(IncludeExceptionDetailInFaults = true)] 36 37 public class QueryService : IQueryService { 38 IRoleVerifier roleVerifier = AccessServiceLocator.Instance.RoleVerifier; 39 IUserManager userManager = AccessServiceLocator.Instance.UserManager; 40 37 41 public IEnumerable<Filter> GetFilters() { 38 42 List<Filter> filters = new List<Filter>(); … … 238 242 public long GetNumberOfRuns(Filter filter) { 239 243 using (OKBDataContext okb = new OKBDataContext()) { 240 return FilterRuns(okb.Runs, filter ).LongCount();244 return FilterRuns(okb.Runs, filter, okb).LongCount(); 241 245 } 242 246 } … … 244 248 public IEnumerable<long> GetRunIds(Filter filter) { 245 249 using (OKBDataContext okb = new OKBDataContext()) { 246 return FilterRuns(okb.Runs, filter ).Select(x => x.Id).ToArray();250 return FilterRuns(okb.Runs, filter, okb).Select(x => x.Id).ToArray(); 247 251 } 248 252 } … … 254 258 okb.LoadOptions = dlo; 255 259 256 return okb.Runs.Where(x => ids.Contains(x.Id)).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray();260 return FilterUnauthorizedRuns(okb.Runs.Where(x => ids.Contains(x.Id)).ToList(), okb).Select(x => Convert.ToDto(x, includeBinaryValues)).ToArray(); 257 261 } 258 262 } … … 264 268 okb.LoadOptions = dlo; 265 269 266 return okb.Runs.Where(x => ids.Contains(x.Id)).Select(x => Convert.ToDto(x, includeBinaryValues, valueNames)).ToArray();270 return FilterUnauthorizedRuns(okb.Runs.Where(x => ids.Contains(x.Id)).ToList(), okb).Select(x => Convert.ToDto(x, includeBinaryValues, valueNames)).ToArray(); 267 271 } 268 272 } … … 274 278 } 275 279 276 private IQueryable<DataAccess.Run> FilterRuns(IQueryable<DataAccess.Run> runs, Filter filter) {280 private List<DataAccess.Run> FilterRuns(IQueryable<DataAccess.Run> runs, Filter filter, OKBDataContext okb) { 277 281 IFilter f = (IFilter)Activator.CreateInstance(Type.GetType(filter.FilterTypeName), filter); 278 return runs.Where(f.Expression); 282 283 var query = runs.Where(f.Expression); 284 List<DataAccess.Run> results = new List<DataAccess.Run>(); 285 286 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 287 results.AddRange(query); 288 } else { 289 foreach (DataAccess.Run r in query) { 290 if (IsAuthorizedForAlgorithm(r.AlgorithmId, okb) && IsAuthorizedForProblem(r.ProblemId, okb)) { 291 results.Add(r); 292 } 293 } 294 } 295 return results; 296 } 297 298 private List<DataAccess.Run> FilterUnauthorizedRuns(List<DataAccess.Run> runs, OKBDataContext okb) { 299 List<DataAccess.Run> results = new List<DataAccess.Run>(); 300 301 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 302 results.AddRange(runs); 303 } else { 304 foreach (DataAccess.Run r in runs) { 305 if (IsAuthorizedForAlgorithm(r.AlgorithmId, okb) && IsAuthorizedForProblem(r.ProblemId, okb)) { 306 results.Add(r); 307 } 308 } 309 } 310 return results; 311 } 312 313 private bool IsAuthorizedForAlgorithm(long algorithmId, OKBDataContext okb) { 314 var algUsers = okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId).Select(x => x.UserGroupId).ToList(); 315 316 if (algUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, algUsers)) { 317 return true; 318 } 319 return false; 320 } 321 322 private bool IsAuthorizedForProblem(long problemId, OKBDataContext okb) { 323 var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == problemId).Select(x => x.UserGroupId).ToList(); 324 325 if (problemUsers.Count == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers)) { 326 return true; 327 } 328 return false; 279 329 } 280 330 } -
branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs
r7360 r7914 34 34 public class RunCreationService : IRunCreationService { 35 35 IRoleVerifier roleVerifier = AccessServiceLocator.Instance.RoleVerifier; 36 IUserManager userManager = AccessServiceLocator.Instance.UserManager; 36 37 37 38 public IEnumerable<DataTransfer.Algorithm> GetAlgorithms(string platformName) { … … 42 43 dlo.LoadWith<Algorithm>(x => x.AlgorithmClass); 43 44 dlo.LoadWith<Algorithm>(x => x.DataType); 45 dlo.LoadWith<Algorithm>(x => x.AlgorithmUsers); 44 46 okb.LoadOptions = dlo; 45 return okb.Algorithms.Where(x => x.Platform.Name == platformName).Select(x => Convert.ToDto(x)).ToArray(); 47 48 var query = okb.Algorithms.Where(x => x.Platform.Name == platformName); 49 List<Algorithm> results = new List<Algorithm>(); 50 51 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 52 results.AddRange(query); 53 } else { 54 foreach (var alg in query) { 55 if (alg.AlgorithmUsers.Count() == 0 || userManager.VerifyUser(userManager.CurrentUserId, alg.AlgorithmUsers.Select(y => y.UserGroupId).ToList())) { 56 results.Add(alg); 57 } 58 } 59 } 60 return results.Select(x => Convert.ToDto(x)).ToArray(); 46 61 } 47 62 } … … 51 66 52 67 using (OKBDataContext okb = new OKBDataContext()) { 53 return okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault(); 68 var result = okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault(); 69 70 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 71 return result; 72 } else { 73 var algUsers = okb.AlgorithmUsers.Where(x => x.AlgorithmId == algorithmId); 74 if (algUsers.Count() == 0 || userManager.VerifyUser(userManager.CurrentUserId, algUsers.Select(y => y.UserGroupId).ToList())) { 75 return result; 76 } else { 77 return null; 78 } 79 } 54 80 } 55 81 } … … 62 88 dlo.LoadWith<Problem>(x => x.ProblemClass); 63 89 dlo.LoadWith<Problem>(x => x.DataType); 90 dlo.LoadWith<Problem>(x => x.ProblemUsers); 64 91 okb.LoadOptions = dlo; 65 return okb.Problems.Where(x => x.Platform.Name == platformName).Select(x => Convert.ToDto(x)).ToArray(); 92 93 var query = okb.Problems.Where(x => x.Platform.Name == platformName); 94 List<Problem> results = new List<Problem>(); 95 96 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 97 results.AddRange(query); 98 } else { 99 foreach (var problem in query) { 100 if (problem.ProblemUsers.Count() == 0 || userManager.VerifyUser(userManager.CurrentUserId, problem.ProblemUsers.Select(y => y.UserGroupId).ToList())) { 101 results.Add(problem); 102 } 103 } 104 } 105 return results.Select(x => Convert.ToDto(x)).ToArray(); 66 106 } 67 107 } … … 71 111 72 112 using (OKBDataContext okb = new OKBDataContext()) { 73 return okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault(); 113 var result = okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault(); 114 115 if (roleVerifier.IsInRole(OKBRoles.OKBAdministrator)) { 116 return result; 117 } else { 118 var problemUsers = okb.ProblemUsers.Where(x => x.ProblemId == problemId); 119 if (problemUsers.Count() == 0 || userManager.VerifyUser(userManager.CurrentUserId, problemUsers.Select(y => y.UserGroupId).ToList())) { 120 return result; 121 } else { 122 return null; 123 } 124 } 74 125 } 75 126 }
Note: See TracChangeset
for help on using the changeset viewer.