Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/29/12 12:45:22 (12 years ago)
Author:
ascheibe
Message:

#1174 added authorization for algorithms and problems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs

    r7360 r7914  
    3434  public class RunCreationService : IRunCreationService {
    3535    IRoleVerifier roleVerifier = AccessServiceLocator.Instance.RoleVerifier;
     36    IUserManager userManager = AccessServiceLocator.Instance.UserManager;
    3637
    3738    public IEnumerable<DataTransfer.Algorithm> GetAlgorithms(string platformName) {
     
    4243        dlo.LoadWith<Algorithm>(x => x.AlgorithmClass);
    4344        dlo.LoadWith<Algorithm>(x => x.DataType);
     45        dlo.LoadWith<Algorithm>(x => x.AlgorithmUsers);
    4446        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();
    4661      }
    4762    }
     
    5166
    5267      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        }
    5480      }
    5581    }
     
    6288        dlo.LoadWith<Problem>(x => x.ProblemClass);
    6389        dlo.LoadWith<Problem>(x => x.DataType);
     90        dlo.LoadWith<Problem>(x => x.ProblemUsers);
    6491        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();
    66106      }
    67107    }
     
    71111
    72112      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        }
    74125      }
    75126    }
Note: See TracChangeset for help on using the changeset viewer.