Changeset 15500


Ignore:
Timestamp:
12/07/17 14:41:47 (21 months ago)
Author:
jzenisek
Message:

#2839 worked on resource permission checks (v2 = accelerated verison)

Location:
branches/HiveProjectManagement
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Services.Access/3.3/Interfaces/IUserManager.cs

    r14185 r15500  
    3131    MembershipUser GetUserById(Guid userId);
    3232    string GetUserNameById(Guid userId);
     33    IEnumerable<Guid> GetUserGroupIdsOfUser(Guid userId);
    3334    bool VerifyUser(Guid userId, List<Guid> allowedUserGroups);
    3435  }
  • branches/HiveProjectManagement/HeuristicLab.Services.Access/3.3/UserManager.cs

    r14185 r15500  
    5454    }
    5555
     56    public IEnumerable<Guid> GetUserGroupIdsOfUser(Guid userId) {
     57      using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
     58        var groupIds = from g in context.UserGroupUserGroups
     59                       where g.UserGroupId == userId
     60                       select g.UserGroupUserGroupId;
     61
     62        var query = from g in context.UserGroupBases.OfType<DA.UserGroup>()
     63                    where groupIds.Contains(g.Id)
     64                    select g.Id;
     65
     66        return query.ToList();
     67      }
     68    }
     69
    5670    public bool VerifyUser(Guid userId, List<Guid> allowedUserGroups) {
    5771      List<DA.UserGroupUserGroup> userGroupBases;
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ResourcePermissionDao.cs

    r15497 r15500  
    3434    }
    3535
    36     public IEnumerable<Guid> GetByGrantedUserId(IEnumerable<Guid> grantedUserId) {
    37       string paramIds = string.Join(",", grantedUserId.Select(x => string.Format("'{0}'", x)));
     36    public IEnumerable<Guid> GetByUserAndGroupIds(IEnumerable<Guid> userAndGroupIds) {
     37      string paramIds = string.Join(",", userAndGroupIds.Select(x => string.Format("'{0}'", x)));
    3838      if (!string.IsNullOrWhiteSpace(paramIds)) {
    3939        string query = string.Format(GetGrantedResourcesQuery, paramIds);
  • branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r15497 r15500  
    7575        var resourceDao = pm.ResourceDao;
    7676        var resourcePermissionDao = pm.ResourcePermissionDao;
    77 
    7877        var currentUserId = UserManager.CurrentUserId;
    7978
    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();
     79        //// V1 user grant check
     80        //// get granted (parent) resources
     81        //var userGrantedResourceIds = pm.UseTransaction(() => {
     82        //  return resourcePermissionDao.GetAll().ToList()
     83        //    .Where(x => x.GrantedUserId == currentUserId
     84        //      || UserManager.VerifyUser(currentUserId, new List<Guid> { x.GrantedUserId }))
     85        //    .Select(y => y.ResourceId)
     86        //    .ToList();
     87        //});
     88
     89        //// get children of granted parent resources
     90        //var userGrantedChildResourceIds = pm.UseTransaction(() => {
     91        //  return userGrantedResourceIds
     92        //  .SelectMany(x => resourceDao.GetResourcesByParentId(x))
     93        //  .Select(y => y.ResourceId);
     94        //});
     95
     96        //// join list of parent and child resources
     97        //userGrantedResourceIds.AddRange(userGrantedChildResourceIds);
     98
     99        //// filter initial resourceId list with the list of the granted ones
     100        //var allUserGrantedResourceIds = resourceIds
     101        //  .Where(x => userGrantedResourceIds.Contains(x))
     102        //  .Distinct().ToList();
     103
     104        // V2 user grant check
     105        var allUserGrantedResourceIds = pm.UseTransaction(() => {
     106          var groupAndGroupIds = new List<Guid> { currentUserId };
     107          groupAndGroupIds.AddRange(UserManager.GetUserGroupIdsOfUser(currentUserId));
     108          return resourcePermissionDao.GetByUserAndGroupIds(groupAndGroupIds);
     109        });
    100110
    101111        var newTask = task.ToEntity();
    102112        newTask.JobData = taskData.ToEntity();
    103113        newTask.JobData.LastUpdate = DateTime.Now;
    104         newTask.AssignedTaskResources.AddRange(resourceIds.Select(
     114        newTask.AssignedTaskResources.AddRange(allUserGrantedResourceIds.Select(
    105115          x => new DA.AssignedTaskResource {
    106116            ResourceId = x
Note: See TracChangeset for help on using the changeset viewer.