Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15497


Ignore:
Timestamp:
12/06/17 16:16:01 (7 years ago)
Author:
jzenisek
Message:

#2839 worked on permission check at AddTask

Location:
branches/HiveProjectManagement
Files:
6 edited

Legend:

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

    r14185 r15497  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Data.Linq;
    2425using System.Linq;
     
    4041    }
    4142
     43    public IEnumerable<Guid> GetResourceIdsByParentId(Guid id) {
     44      return DataContext.ExecuteQuery<Guid>(GetResourceIdsByParentIdQuery, id);
     45    }
     46
     47    public IEnumerable<Resource> GetResourcesByParentId(Guid id) {
     48      return DataContext.ExecuteQuery<Resource>(GetResourcesByParentIdQuery, id);
     49    }
     50
    4251    #region Compiled queries
    4352    private static readonly Func<DataContext, Guid, Resource> GetByIdQuery =
     
    5362        select resource).FirstOrDefault());
    5463    #endregion
     64
     65    #region String queries
     66    private const string GetResourcesByParentIdQuery = @"
     67      WITH rtree AS
     68      (
     69        SELECT ResourceId, ParentResourceId
     70        FROM [Resource]
     71        UNION ALL
     72        SELECT rt.ResourceId, r.ParentResourceId
     73        FROM [Resource] r
     74        JOIN rtree rt ON rt.ParentResourceId = r.ResourceId AND r.ParentResourceId <> r.ResourceId AND rt.ParentResourceId <> rt.ResourceId
     75      )
     76      SELECT DISTINCT rtree.ResourceId
     77      FROM rtree
     78      WHERE rtree.ParentResourceId = ({0})
     79    ";
     80    private const string GetResourceIdsByParentIdQuery = @"
     81      WITH rtree AS
     82      (
     83        SELECT ResourceId, ParentResourceId
     84        FROM [Resource]
     85        UNION ALL
     86        SELECT rt.ResourceId, r.ParentResourceId
     87        FROM [Resource] r
     88        JOIN rtree rt ON rt.ParentResourceId = r.ResourceId AND r.ParentResourceId <> r.ResourceId AND rt.ParentResourceId <> rt.ResourceId
     89      )
     90      SELECT DISTINCT res.*
     91      FROM rtree, [Resource] res
     92      WHERE rtree.ParentResourceId = ({0})
     93      AND rtree.ResourceId = res.ResourceId
     94    ";
     95    #endregion
    5596  }
    5697}
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ResourcePermissionDao.cs

    r15496 r15497  
    5656      (
    5757        SELECT ResourceId, ParentResourceId
    58         FROM [dbo].Resource
     58        FROM [Resource]
    5959        UNION ALL
    6060        SELECT rt.ResourceId, r.ParentResourceId
    61         FROM [dbo].Resource r
     61        FROM [Resource] r
    6262        JOIN rtree rt ON rt.ParentResourceId = r.ResourceId AND r.ParentResourceId <> r.ResourceId AND rt.ParentResourceId <> rt.ResourceId
    6363      )
    64       SELECT DISTINCT rtree.ResourceId FROM rtree, ResourcePermission rp
    65       WHERE rtree.ParentResourceId = rp.ResourceId
    66       AND rp.GrantedUserId IN ({0})
     64      SELECT DISTINCT rtree.ResourceId
     65      FROM rtree, [ResourcePermission] rp
     66      WHERE rtree.ParentResourceId = rp.ResourceId AND rp.GrantedUserId IN ({0})
    6767      UNION ALL
    6868      SELECT rp.ResourceId
    69       FROM ResourcePermission rp
     69      FROM [ResourcePermission] rp
    7070      WHERE rp.GrantedUserId IN ({0})
    7171      ;";
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs

    r15411 r15497  
    106106      )
    107107      SELECT DISTINCT t.TaskId, t.JobId, t.Priority
    108       FROM pr JOIN AssignedTaskResources ar ON ar.ResourceId = pr.ResourceId
     108      FROM pr JOIN AssignedTaskResource ar ON ar.ResourceId = pr.ResourceId
    109109          JOIN Task t ON t.TaskId = ar.TaskId
    110110      WHERE NOT (t.IsParentTask = 1 AND t.FinishWhenChildJobsFinished = 1)
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IPersistenceManager.cs

    r15411 r15497  
    4343    RequiredPluginDao RequiredPluginDao { get; }
    4444    ResourceDao ResourceDao { get; }
     45    ResourcePermissionDao ResourcePermissionDao { get; }
    4546    SlaveDao SlaveDao { get; }
    4647    SlaveGroupDao SlaveGroupDao { get; }
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs

    r15411 r15497  
    8383    }
    8484
    85     private ProjectPermissionDao resourcePermissionDao;
     85    private ProjectPermissionDao projectPermissionDao;
    8686    public ProjectPermissionDao ProjectPermissionDao {
    87       get { return resourcePermissionDao ?? (resourcePermissionDao = new ProjectPermissionDao(dataContext)); }
     87      get { return projectPermissionDao ?? (projectPermissionDao = new ProjectPermissionDao(dataContext)); }
    8888    }
    8989
     
    9696    public ResourceDao ResourceDao {
    9797      get { return resourceDao ?? (resourceDao = new ResourceDao(dataContext)); }
     98    }
     99
     100    private ResourcePermissionDao resourcePermissionDao;
     101    public ResourcePermissionDao ResourcePermissionDao {
     102      get { return resourcePermissionDao ?? (resourcePermissionDao = new ResourcePermissionDao(dataContext)); }
    98103    }
    99104
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15411 r15497  
    7272        var taskDao = pm.TaskDao;
    7373        var stateLogDao = pm.StateLogDao;
     74
     75        var resourceDao = pm.ResourceDao;
     76        var resourcePermissionDao = pm.ResourcePermissionDao;
     77
     78        var currentUserId = UserManager.CurrentUserId;
     79
     80        // V1 (without child check; with resourcePermission-oriented check for user grants)
     81        // granted (parent) resources
     82        var userGrantedResources = resourcePermissionDao.GetAll().ToList()
     83          .Where(x => x.GrantedUserId == currentUserId
     84          || UserManager.VerifyUser(currentUserId, new List<Guid> { x.GrantedUserId })
     85          )
     86          .Select(x => x.Resource)
     87          .ToList();
     88
     89        //// children
     90        //var userGrantedResourceChildren = userGrantedResources
     91        //  .SelectMany(x => resourceDao.GetResourcesByParentId(x.ResourceId));
     92        //// join parent and child resources
     93        //userGrantedResources.AddRange(userGrantedResourceChildren);
     94
     95        var userGrantedResourceIds = resourceIds
     96          .Where(x => userGrantedResources
     97            .Select(y => y.ResourceId)
     98            .Contains(x))
     99          .Distinct().ToList();
     100
    74101        var newTask = task.ToEntity();
    75102        newTask.JobData = taskData.ToEntity();
     
    830857              || x.OwnerUserId == currentUserId
    831858              || UserManager.VerifyUser(currentUserId, resourcePermissions
    832                   .Where(y => y.ResourceId == x.ResourceId)
     859                  //.Where(y => y.ResourceId == x.ResourceId)
    833860                  .Select(z => z.GrantedUserId)
    834861                  .ToList())
     
    855882              || x.OwnerUserId == currentUserId
    856883              || UserManager.VerifyUser(currentUserId, resourcePermissions
    857                   .Where(y => y.ResourceId == x.ResourceId)
     884                  //.Where(y => y.ResourceId == x.ResourceId)
    858885                  .Select(z => z.GrantedUserId)
    859886                  .ToList())
Note: See TracChangeset for help on using the changeset viewer.