Changeset 15552 for branches/HiveProjectManagement
- Timestamp:
- 12/20/17 11:27:33 (7 years ago)
- Location:
- branches/HiveProjectManagement
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedJobResourceDao.cs
r15530 r15552 18 18 } 19 19 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 20 58 public bool CheckJobGrantedForResource(Guid jobId, Guid resourceId) { 21 59 return DataContext.ExecuteQuery<int>(CheckJobGrantedForResourceQueryString, jobId, resourceId).First() > 0; … … 44 82 45 83 #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 "; 46 133 private const string CheckJobGrantedForResourceQueryString = @" 47 134 WITH rbranch AS ( -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectDao.cs
r15540 r15552 31 31 public override Project GetById(Guid id) { 32 32 return GetByIdQuery(DataContext, id); 33 } 34 35 public IEnumerable<Project> GetGrantedProjectsForUser(IEnumerable<Guid> userAndGroupIds) { 36 return GetGrantedProjectsForUserQuery(DataContext, userAndGroupIds); 33 37 } 34 38 … … 63 67 where project.ProjectId == projectId 64 68 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()); 65 76 #endregion 66 77 67 #region String queries78 #region String queries 68 79 private const string GetChildProjectsByIdQuery = @" 69 80 WITH ptree AS -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs
r15530 r15552 88 88 AND pp.GrantedUserId IN ({1}) 89 89 "; 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 "; 90 96 #endregion 91 97 } -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IPersistenceManager.cs
r15546 r15552 32 32 #region Hive daos 33 33 AssignedTaskResourceDao AssignedTaskResourceDao { get; } 34 AssignedJobResourceDao AssignedJobResourceDao { get; } 34 35 AssignedProjectResourceDao AssignedProjectResourceDao { get; } 35 36 DowntimeDao DowntimeDao { get; } -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs
r15546 r15552 41 41 public AssignedTaskResourceDao AssignedTaskResourceDao { 42 42 get { return assignedTaskResourceDao ?? (assignedTaskResourceDao = new AssignedTaskResourceDao(dataContext)); } 43 } 44 45 private AssignedJobResourceDao assignedJobResourceDao; 46 public AssignedJobResourceDao AssignedJobResourceDao { 47 get { return assignedJobResourceDao ?? (assignedJobResourceDao = new AssignedJobResourceDao(dataContext)); } 43 48 } 44 49 -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql
r15528 r15552 36 36 CONSTRAINT [PK_dbo.ResourceIdTaskId] PRIMARY KEY ([ResourceId], [TaskId]) 37 37 ) 38 CREATE TABLE [dbo].[AssignedJobResource]( 39 [ResourceId] UniqueIdentifier NOT NULL, 40 [JobId] UniqueIdentifier NOT NULL, 41 CONSTRAINT [PK_dbo.ResourceIdJobId] PRIMARY KEY ([ResourceId], [JobId]) 42 ) 38 43 CREATE TABLE [dbo].[Plugin]( 39 44 [PluginId] UniqueIdentifier NOT NULL, … … 73 78 CONSTRAINT [PK_dbo.Resource] PRIMARY KEY ([ResourceId]) 74 79 ) 75 CREATE TABLE [dbo].[ResourcePermission](76 [ResourceId] UniqueIdentifier NOT NULL,77 [GrantedUserId] UniqueIdentifier NOT NULL,78 [GrantedByUserId] UniqueIdentifier NOT NULL,79 CONSTRAINT [PK_dbo.ResourcePermission] PRIMARY KEY ([ResourceId], [GrantedUserId])80 )81 80 CREATE TABLE [dbo].[Task]( 82 81 [TaskId] UniqueIdentifier NOT NULL, … … 180 179 ALTER TABLE [dbo].[AssignedTaskResource] 181 180 ADD CONSTRAINT [Task_AssignedTaskResource] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId]) 181 ALTER TABLE [dbo].[AssignedJobResource] 182 ADD CONSTRAINT [Resource_AssignedJobResource] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId]) 183 ALTER TABLE [dbo].[AssignedJobResource] 184 ADD CONSTRAINT [Job_AssignedJobResource] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId]) 182 185 ALTER TABLE [dbo].[RequiredPlugins] 183 186 ADD CONSTRAINT [Plugin_RequiredPlugin] FOREIGN KEY ([PluginId]) REFERENCES [dbo].[Plugin]([PluginId]) … … 186 189 ALTER TABLE [dbo].[Resource] 187 190 ADD CONSTRAINT [Resource_Resource] FOREIGN KEY ([ParentResourceId]) REFERENCES [dbo].[Resource]([ResourceId]) 188 ALTER TABLE [dbo].[ResourcePermission]189 ADD CONSTRAINT [Resource_ResourcePermission] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId])190 191 ALTER TABLE [dbo].[Task] 191 192 ADD CONSTRAINT [Task_Task] FOREIGN KEY ([ParentTaskId]) REFERENCES [dbo].[Task]([TaskId]) -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Prepare Hive Database.sql
r15528 r15552 42 42 ALTER TABLE [dbo].[AssignedTaskResource] DROP CONSTRAINT [Resource_AssignedTaskResource] 43 43 ALTER TABLE [dbo].[AssignedTaskResource] WITH CHECK ADD CONSTRAINT [Resource_AssignedTaskResource] FOREIGN KEY([ResourceId]) 44 REFERENCES [dbo].[Resource] ([ResourceId]) 45 ON UPDATE CASCADE 46 ON DELETE CASCADE 47 GO 48 49 ALTER TABLE [dbo].[AssignedJobResource] DROP CONSTRAINT [Job_AssignedJobResource] 50 ALTER TABLE [dbo].[AssignedJobResource] WITH CHECK ADD CONSTRAINT [Job_AssignedJobResource] FOREIGN KEY([JobId]) 51 REFERENCES [dbo].[Job] ([JobId]) 52 ON UPDATE CASCADE 53 ON DELETE CASCADE 54 GO 55 ALTER TABLE [dbo].[AssignedJobResource] DROP CONSTRAINT [Resource_AssignedJobResource] 56 ALTER TABLE [dbo].[AssignedJobResource] WITH CHECK ADD CONSTRAINT [Resource_AssignedJobResource] FOREIGN KEY([ResourceId]) 44 57 REFERENCES [dbo].[Resource] ([ResourceId]) 45 58 ON UPDATE CASCADE … … 105 118 REFERENCES [dbo].[Project] ([ProjectId]) 106 119 ON UPDATE CASCADE 107 ON DELETE CASCADE120 -- ON DELETE CASCADE 108 121 GO 109 122 -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15547 r15552 69 69 70 70 #region Task Methods 71 [Obsolete] 71 72 public Guid AddTask(DT.Task task, DT.TaskData taskData, IEnumerable<Guid> resourceIds) { 72 73 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); … … 353 354 var pm = PersistenceManager; 354 355 using (new PerformanceLogger("GetJobs")) { 356 // TODO-JAN: optimization potential - avoid using too many joins in linq 355 357 var jobDao = pm.JobDao; 356 358 var jobPermissionDao = pm.JobPermissionDao; … … 364 366 .Select(x => x.ToDto()) 365 367 .ToList(); 368 // calculate stats only for owned & permitted jobs; TODO: query only needed ones, not all 366 369 var statistics = taskDao.GetAll() 370 .Where(x => jobs.Select(y => y.Id).Contains(x.JobId)) 367 371 .GroupBy(x => x.JobId) 368 372 .Select(x => new { … … 393 397 } 394 398 399 [Obsolete] 395 400 public Guid AddJob(DT.Job jobDto) { 396 401 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); … … 515 520 var jobDao = pm.JobDao; 516 521 pm.UseTransaction(() => { 517 // child task will be deleted by db-trigger 522 // child tasks will be deleted by db-trigger 523 // entries in AssignedJobResource will be deleted by foreign key clause CASCADE ON DELETE 518 524 jobDao.Delete(jobId); 519 525 pm.SubmitChanges(); … … 728 734 public void DeleteProject(Guid projectId) { 729 735 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 730 AuthorizationManager.AuthorizeForProjectAdministration(projectId);731 736 var pm = PersistenceManager; 732 737 using (new PerformanceLogger("DeleteProject")) { 733 738 var projectDao = pm.ProjectDao; 734 pm.UseTransaction(() => { 739 var assignedJobResourceDao = pm.AssignedJobResourceDao; 740 pm.UseTransaction(() => { 741 assignedJobResourceDao.DeleteByProjectId(projectId); 735 742 projectDao.Delete(projectId); 736 743 pm.SubmitChanges(); … … 748 755 } 749 756 757 // query granted projects for use (i.e. to calculate on) 750 758 public IEnumerable<DT.Project> GetProjects() { 751 759 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); … … 757 765 var currentUserId = UserManager.CurrentUserId; 758 766 return pm.UseTransaction(() => { 759 var projectPermissions = projectPermissionDao.GetAll(); 760 return projectDao.GetAll().ToList() 761 .Where(x => isAdministrator 762 || x.OwnerUserId == currentUserId 763 || UserManager.VerifyUser(currentUserId, projectPermissions 764 .Where(y => y.ProjectId == x.ProjectId) 765 .Select(z => z.GrantedUserId) 766 .ToList()) 767 ) 768 .Select(x => x.ToDto()) 769 .ToList(); 767 var userAndGroupIds = new List<Guid> { currentUserId }; 768 userAndGroupIds.AddRange(UserManager.GetUserGroupIdsOfUser(currentUserId)); 769 return projectDao.GetGrantedProjectsForUser(userAndGroupIds) 770 .Select(x => x.ToDto()); 771 //var projectPermissions = projectPermissionDao.GetAll(); 772 //return projectDao.GetAll().ToList() 773 // .Where(x => isAdministrator 774 // || x.OwnerUserId == currentUserId 775 // || UserManager.VerifyUser(currentUserId, projectPermissions 776 // .Where(y => y.ProjectId == x.ProjectId) 777 // .Select(z => z.GrantedUserId) 778 // .ToList()) 779 // ) 780 // .Select(x => x.ToDto()) 781 // .ToList(); 770 782 }); 771 783 } … … 816 828 var projectPermissionDao = pm.ProjectPermissionDao; 817 829 var projectDao = pm.ProjectDao; 830 var assignedJobResourceDao = pm.AssignedJobResourceDao; 818 831 pm.UseTransaction(() => { 819 832 if (cascading) { 820 833 var childProjectIds = projectDao.GetChildProjectIdsById(projectId); 821 834 projectPermissionDao.DeleteByProjectIdsAndGrantedUserIds(childProjectIds, grantedUserIds); 835 assignedJobResourceDao.DeleteByProjectIdsAndUserIds(childProjectIds, grantedUserIds); 822 836 } 823 837 projectPermissionDao.DeleteByProjectIdAndGrantedUserIds(projectId, grantedUserIds); 838 assignedJobResourceDao.DeleteByProjectIdAndUserIds(projectId, grantedUserIds); 824 839 pm.SubmitChanges(); 825 840 }); … … 829 844 public IEnumerable<DT.ProjectPermission> GetProjectPermissions(Guid projectId) { 830 845 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 846 AuthorizationManager.AuthorizeForProjectAdministration(projectId); 831 847 var pm = PersistenceManager; 832 848 using (new PerformanceLogger("GetProjectPermissions")) { … … 880 896 using (new PerformanceLogger("UnassignProjectResources")) { 881 897 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 898 var assignedJobResourceDao = pm.AssignedJobResourceDao; 882 899 var projectDao = pm.ProjectDao; 883 900 pm.UseTransaction(() => { … … 885 902 var childProjectIds = projectDao.GetChildProjectIdsById(projectId); 886 903 assignedProjectResourceDao.DeleteByProjectIdsAndResourceIds(childProjectIds, resourceIds); 904 assignedJobResourceDao.DeleteByProjectIdsAndResourceIds(childProjectIds, resourceIds); 887 905 } 888 906 assignedProjectResourceDao.DeleteByProjectIdAndResourceIds(projectId, resourceIds); 889 pm.SubmitChanges(); 890 }); 891 } 892 } 893 894 public IEnumerable<AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId) { 907 assignedJobResourceDao.DeleteByProjectIdAndResourceIds(projectId, resourceIds); 908 pm.SubmitChanges(); 909 }); 910 } 911 } 912 913 public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProject(Guid projectId) { 895 914 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 896 915 var pm = PersistenceManager; … … 903 922 } 904 923 } 924 905 925 #endregion 906 926 -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r15540 r15552 35 35 private const string NOT_AUTHORIZED_USERRESOURCE = "Current user is not authorized to access the requested resource"; 36 36 private const string NOT_AUTHORIZED_USERPROJECT = "Current user is not authorized to access the requested project"; 37 private const string NOT_AUTHORIZED_USERJOB = "Current user is not authorized to access the requested job"; 37 38 private const string NOT_AUTHORIZED_PROJECTRESOURCE = "Selected project is not authorized to access the requested resource"; 38 39 … … 169 170 if (permission == Permission.NotAllowed 170 171 || ((permission != requiredPermissionEntity) && requiredPermissionEntity == Permission.Full)) { 171 throw new SecurityException(NOT_AUTHORIZED_USER RESOURCE);172 throw new SecurityException(NOT_AUTHORIZED_USERJOB); 172 173 } 173 174 }
Note: See TracChangeset
for help on using the changeset viewer.