Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/17 11:27:33 (7 years ago)
Author:
jzenisek
Message:

#2839 worked on permission checks in listing methods

Location:
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedJobResourceDao.cs

    r15530 r15552  
    1818    }
    1919
     20    public void DeleteByProjectId(Guid projectId) {
     21      DataContext.ExecuteCommand(DeleteByProjectIdQueryString, projectId);
     22    }
     23
     24    public void DeleteByProjectIdAndUserIds(Guid projectId, IEnumerable<Guid> userIds) {
     25      string paramUserIds = string.Join(",", userIds.Select(x => string.Format("'{0}'", x)));
     26      if (!string.IsNullOrWhiteSpace(paramUserIds)) {
     27        string queryString = string.Format(DeleteByProjectIdAndUserIdsQueryString, projectId, paramUserIds);
     28        DataContext.ExecuteCommand(queryString);
     29      }
     30    }
     31
     32    public void DeleteByProjectIdsAndUserIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> userIds) {
     33      string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x)));
     34      string paramUserIds = string.Join(",", userIds.Select(x => string.Format("'{0}'", x)));
     35      if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramUserIds)) {
     36        string queryString = string.Format(DeleteByProjectIdsAndUserIdsQueryString, paramProjectIds, paramUserIds);
     37        DataContext.ExecuteCommand(queryString);
     38      }
     39    }
     40
     41    public void DeleteByProjectIdAndResourceIds(Guid projectId, IEnumerable<Guid> resourceIds) {
     42      string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x)));
     43      if (!string.IsNullOrWhiteSpace(paramResourceIds)) {
     44        string queryString = string.Format(DeleteByProjectIdAndResourceIdsQueryString, projectId, paramResourceIds);
     45        DataContext.ExecuteCommand(queryString);
     46      }
     47    }
     48
     49    public void DeleteByProjectIdsAndResourceIds(IEnumerable<Guid> projectIds, IEnumerable<Guid> resourceIds) {
     50      string paramProjectIds = string.Join(",", projectIds.Select(x => string.Format("'{0}'", x)));
     51      string paramResourceIds = string.Join(",", resourceIds.Select(x => string.Format("'{0}'", x)));
     52      if (!string.IsNullOrWhiteSpace(paramProjectIds) && !string.IsNullOrWhiteSpace(paramResourceIds)) {
     53        string queryString = string.Format(DeleteByProjectIdsAndResourceIdsQueryString, paramProjectIds, paramResourceIds);
     54        DataContext.ExecuteCommand(queryString);
     55      }
     56    }
     57
    2058    public bool CheckJobGrantedForResource(Guid jobId, Guid resourceId) {
    2159      return DataContext.ExecuteQuery<int>(CheckJobGrantedForResourceQueryString, jobId, resourceId).First() > 0;
     
    4482
    4583    #region String queries
     84    private const string DeleteByProjectIdQueryString = @"
     85      DELETE FROM [AssignedJobResource] ajr
     86      WHERE ajr.JobId IN
     87        (
     88          SELECT j.JobId
     89          FROM [Job] j
     90          WHERE j.ProjectId = {0}
     91        )
     92    ";
     93    private const string DeleteByProjectIdAndUserIdsQueryString = @"
     94      DELETE FROM [AssignedJobResource] ajr
     95      WHERE ajr.JobId IN
     96        (
     97          SELECT j.JobId
     98          FROM [Job] j
     99          WHERE j.ProjectId = {0}
     100          AND j.OwnerUserId IN ({1})
     101        )
     102    ";
     103    private const string DeleteByProjectIdsAndUserIdsQueryString = @"
     104      DELETE FROM [AssignedJobResource] ajr
     105      WHERE ajr.JobId IN
     106        (
     107          SELECT j.JobId
     108          FROM [Job] j
     109          WHERE j.ProjectId IN ({0})
     110          AND j.OwnerUserId IN ({1})
     111        )
     112    ";
     113    private const string DeleteByProjectIdAndResourceIdsQueryString = @"
     114      DELETE FROM [AssignedJobResource] ajr
     115      WHERE ajr.JobId IN
     116        (
     117          SELECT j.JobId
     118          FROM [Job] j
     119          WHERE j.ProjectId = {0}
     120        )
     121      AND ajr.ResourceId IN ({1})
     122    ";
     123    private const string DeleteByProjectIdsAndResourceIdsQueryString = @"
     124      DELETE FROM [AssignedJobResource] ajr
     125      WHERE ajr.JobId IN
     126        (
     127          SELECT j.JobId
     128          FROM [Job] j
     129          WHERE j.ProjectId IN ({0})
     130        )
     131      AND ajr.ResourceId IN ({1})
     132    ";
    46133    private const string CheckJobGrantedForResourceQueryString = @"
    47134      WITH rbranch AS (
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs

    r15540 r15552  
    3131    public override Project GetById(Guid id) {
    3232      return GetByIdQuery(DataContext, id);
     33    }
     34
     35    public IEnumerable<Project> GetGrantedProjectsForUser(IEnumerable<Guid> userAndGroupIds) {
     36      return GetGrantedProjectsForUserQuery(DataContext, userAndGroupIds);
    3337    }
    3438
     
    6367         where project.ProjectId == projectId
    6468         select project).SingleOrDefault());
     69    private static readonly Func<DataContext, IEnumerable<Guid>, IEnumerable<Project>> GetGrantedProjectsForUserQuery =
     70      CompiledQuery.Compile((DataContext db, IEnumerable<Guid> userAndGroupIds) =>
     71      (from project in db.GetTable<Project>()
     72       join projectPermission in db.GetTable<ProjectPermission>()
     73       on project.ProjectId equals projectPermission.ProjectId
     74       where userAndGroupIds.Contains(projectPermission.GrantedUserId)
     75       select project).Distinct());
    6576    #endregion
    6677
    67     #region String queries
     78      #region String queries
    6879    private const string GetChildProjectsByIdQuery = @"
    6980      WITH ptree AS
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs

    r15530 r15552  
    8888      AND pp.GrantedUserId IN ({1})
    8989    ";
     90    private const string GetGrantedProjectsForUserQueryString = @"
     91      SELECT DISTINCT p.*
     92      FROM [ProjectPermission] pp, [Project] p
     93      WHERE pp.GrantedUserId IN ({0})
     94      AND  pp.ProjectId = p.ProjectId
     95    ";
    9096    #endregion
    9197  }
Note: See TracChangeset for help on using the changeset viewer.