Changeset 15379
- Timestamp:
- 09/25/17 15:36:54 (7 years ago)
- Location:
- branches/HiveProjectManagement
- Files:
-
- 2 added
- 9 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/ProjectPermissionDao.cs
r15378 r15379 26 26 27 27 namespace HeuristicLab.Services.Hive.DataAccess.Daos { 28 public class ResourcePermissionDao : GenericDao<Guid, ResourcePermission> {29 public ResourcePermissionDao(DataContext dataContext) : base(dataContext) { }28 public class ProjectPermissionDao : GenericDao<Guid, ProjectPermission> { 29 public ProjectPermissionDao(DataContext dataContext) : base(dataContext) { } 30 30 31 public override ResourcePermission GetById(Guid id) {31 public override ProjectPermission GetById(Guid id) { 32 32 throw new NotImplementedException(); 33 33 } 34 34 35 public IEnumerable< ResourcePermission> GetByResourceId(Guid id) {36 return GetBy ResourceIdGetByIdQuery(DataContext, id);35 public IEnumerable<ProjectPermission> GetByProjectId(Guid id) { 36 return GetByProjectIdGetByIdQuery(DataContext, id); 37 37 } 38 38 39 public void DeleteBy ResourceAndGrantedUserId(Guid resourceId, IEnumerable<Guid> grantedUserId) {39 public void DeleteByProjectAndGrantedUserId(Guid projectId, IEnumerable<Guid> grantedUserId) { 40 40 string paramIds = string.Join(",", grantedUserId.Select(x => string.Format("'{0}'", x))); 41 41 if (!string.IsNullOrWhiteSpace(paramIds)) { 42 string query = string.Format(DeleteByGrantedUserQuery, resourceId, paramIds);42 string query = string.Format(DeleteByGrantedUserQuery, projectId, paramIds); 43 43 DataContext.ExecuteCommand(query); 44 44 } … … 46 46 47 47 #region Compiled queries 48 private static readonly Func<DataContext, Guid, IEnumerable< ResourcePermission>> GetByResourceIdGetByIdQuery =49 CompiledQuery.Compile((DataContext db, Guid resourceId) =>50 from resourcePermission in db.GetTable<ResourcePermission>()51 where resourcePermission.ResourceId == resourceId52 select resourcePermission);48 private static readonly Func<DataContext, Guid, IEnumerable<ProjectPermission>> GetByProjectIdGetByIdQuery = 49 CompiledQuery.Compile((DataContext db, Guid projectId) => 50 from projectPermission in db.GetTable<ProjectPermission>() 51 where projectPermission.ProjectId == projectId 52 select projectPermission); 53 53 #endregion 54 54 55 55 #region String queries 56 56 private const string DeleteByGrantedUserQuery = 57 @"DELETE FROM [ ResourcePermission]58 WHERE ResourceId = '{0}'57 @"DELETE FROM [ProjectPermission] 58 WHERE ProjectId = '{0}' 59 59 AND GrantedUserId IN ({1});"; 60 60 #endregion -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HeuristicLab.Services.Hive.DataAccess-3.3.csproj
r12878 r15379 118 118 <Compile Include="Daos\PluginDao.cs" /> 119 119 <Compile Include="Daos\PluginDataDao.cs" /> 120 <Compile Include="Daos\ProjectDao.cs" /> 121 <Compile Include="Daos\ProjectPermissionDao.cs" /> 120 122 <Compile Include="Daos\RequiredPluginDao.cs" /> 121 123 <Compile Include="Daos\ResourceDao.cs" /> 122 <Compile Include="Daos\ResourcePermissionDao.cs" />123 124 <Compile Include="Daos\SlaveDao.cs" /> 124 125 <Compile Include="Daos\SlaveGroupDao.cs" /> -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml
r15378 r15379 265 265 <Column Name="OwnerUserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" /> 266 266 <Column Name="StartDate" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" /> 267 <Column Name="EndDate" Type="System.DateTime" DbType="DateTime" CanBeNull=" false" />267 <Column Name="EndDate" Type="System.DateTime" DbType="DateTime" CanBeNull="true" /> 268 268 <Association Name="Project_AssignedResource" Member="AssignedResources" ThisKey="ProjectId" OtherKey="ProjectId" Type="AssignedResource" /> 269 269 <Association Name="Project_Job" Member="Jobs" ThisKey="ProjectId" OtherKey="ProjectId" Type="Job" /> -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs
r15378 r15379 5681 5681 private System.DateTime _StartDate; 5682 5682 5683 private System. DateTime_EndDate;5683 private System.Nullable<System.DateTime> _EndDate; 5684 5684 5685 5685 private EntitySet<AssignedResource> _AssignedResources; … … 5711 5711 partial void OnStartDateChanging(System.DateTime value); 5712 5712 partial void OnStartDateChanged(); 5713 partial void OnEndDateChanging(System. DateTimevalue);5713 partial void OnEndDateChanging(System.Nullable<System.DateTime> value); 5714 5714 partial void OnEndDateChanged(); 5715 5715 #endregion … … 5870 5870 5871 5871 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EndDate", DbType="DateTime")] 5872 public System. DateTimeEndDate5872 public System.Nullable<System.DateTime> EndDate 5873 5873 { 5874 5874 get -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Interfaces/IPersistenceManager.cs
r14185 r15379 38 38 PluginDao PluginDao { get; } 39 39 PluginDataDao PluginDataDao { get; } 40 ProjectDao ProjectDao { get; } 41 ProjectPermissionDao ProjectPermissionDao { get; } 40 42 RequiredPluginDao RequiredPluginDao { get; } 41 43 ResourceDao ResourceDao { get; } 42 ResourcePermissionDao ResourcePermissionDao { get; }43 44 SlaveDao SlaveDao { get; } 44 45 SlaveGroupDao SlaveGroupDao { get; } -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Manager/PersistenceManager.cs
r14185 r15379 73 73 } 74 74 75 private ProjectDao projectDao; 76 public ProjectDao ProjectDao { 77 get { return projectDao ?? (projectDao = new ProjectDao(dataContext)); } 78 } 79 80 private ProjectPermissionDao resourcePermissionDao; 81 public ProjectPermissionDao ProjectPermissionDao { 82 get { return resourcePermissionDao ?? (resourcePermissionDao = new ProjectPermissionDao(dataContext)); } 83 } 84 75 85 private RequiredPluginDao requiredPluginDao; 76 86 public RequiredPluginDao RequiredPluginDao { … … 81 91 public ResourceDao ResourceDao { 82 92 get { return resourceDao ?? (resourceDao = new ResourceDao(dataContext)); } 83 }84 85 private ResourcePermissionDao resourcePermissionDao;86 public ResourcePermissionDao ResourcePermissionDao {87 get { return resourcePermissionDao ?? (resourcePermissionDao = new ResourcePermissionDao(dataContext)); }88 93 } 89 94 -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Converter.cs
r14185 r15379 333 333 #endregion 334 334 335 #region ResourcePermission 336 public static DT.ResourcePermission ToDto(this DA.ResourcePermission source) { 337 if (source == null) return null; 338 return new DT.ResourcePermission { 339 ResourceId = source.ResourceId, 335 #region Project 336 public static DT.Project ToDto(this DA.Project source) { 337 if (source == null) return null; 338 return new DT.Project { 339 Id = source.ProjectId, 340 ParentProjectId = source.ParentProjectId, 341 DateCreated = source.DateCreated, 342 Name = source.Name, 343 Description = source.Description, 344 OwnerUserId = source.OwnerUserId, 345 StartDate = source.StartDate, 346 EndDate = source.EndDate 347 }; 348 } 349 public static DA.Project ToEntity(this DT.Project source) { 350 if (source == null) return null; 351 var result = new DA.Project(); 352 source.CopyToEntity(result); 353 return result; 354 } 355 public static void CopyToEntity(this DT.Project source, DA.Project target) { 356 if ((source == null) || (target == null)) return; 357 target.ProjectId = source.Id; 358 target.ParentProjectId = source.ParentProjectId; 359 target.DateCreated = source.DateCreated; 360 target.Name = source.Name; 361 target.Description = source.Description; 362 target.OwnerUserId = source.OwnerUserId; 363 target.StartDate = source.StartDate; 364 target.EndDate = source.EndDate; 365 } 366 #endregion 367 368 #region ProjectPermission 369 public static DT.ProjectPermission ToDto(this DA.ProjectPermission source) { 370 if (source == null) return null; 371 return new DT.ProjectPermission { 372 ProjectId = source.ProjectId, 340 373 GrantedUserId = source.GrantedUserId, 341 374 GrantedByUserId = source.GrantedByUserId 342 375 }; 343 376 } 344 public static DA. ResourcePermission ToEntity(this DT.ResourcePermission source) {345 if (source == null) return null; 346 var result = new DA. ResourcePermission();347 source.CopyToEntity(result); 348 return result; 349 } 350 public static void CopyToEntity(this DT. ResourcePermission source, DA.ResourcePermission target) {351 if ((source == null) || (target == null)) return; 352 target. ResourceId = source.ResourceId;377 public static DA.ProjectPermission ToEntity(this DT.ProjectPermission source) { 378 if (source == null) return null; 379 var result = new DA.ProjectPermission(); 380 source.CopyToEntity(result); 381 return result; 382 } 383 public static void CopyToEntity(this DT.ProjectPermission source, DA.ProjectPermission target) { 384 if ((source == null) || (target == null)) return; 385 target.ProjectId = source.ProjectId; 353 386 target.GrantedUserId = source.GrantedUserId; 354 387 target.GrantedByUserId = source.GrantedByUserId; -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/DataTransfer/ProjectPermission.cs
r15378 r15379 26 26 [DataContract] 27 27 [Serializable] 28 public class ResourcePermission : HiveItem {28 public class ProjectPermission : HiveItem { 29 29 // info: this class is derived from HiveItem to simplify handling on the client side, altough it does not have a Id. 30 30 [DataMember] 31 public Guid ResourceId { get; set; }31 public Guid ProjectId { get; set; } 32 32 [DataMember] 33 33 public Guid GrantedUserId { get; set; } … … 35 35 public Guid GrantedByUserId { get; set; } 36 36 37 public ResourcePermission() { }37 public ProjectPermission() { } 38 38 } 39 39 } -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r12878 r15379 120 120 <Compile Include="Converter.cs" /> 121 121 <Compile Include="DataTransfer\Command.cs" /> 122 <Compile Include="DataTransfer\Project.cs" /> 123 <Compile Include="DataTransfer\ProjectPermission.cs" /> 122 124 <Compile Include="DataTransfer\UserPriority.cs" /> 123 <Compile Include="DataTransfer\ResourcePermission.cs" />124 125 <Compile Include="DataTransfer\Downtime.cs" /> 125 126 <Compile Include="DataTransfer\Heartbeat.cs" /> -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15358 r15379 532 532 result = HeartbeatManager.ProcessHeartbeat(heartbeat); 533 533 } 534 } 535 catch (Exception ex) { 534 } catch (Exception ex) { 536 535 DA.LogFactory.GetLogger(this.GetType().Namespace).Log(string.Format("Exception processing Heartbeat: {0}", ex)); 537 536 } … … 604 603 #endregion 605 604 606 #region ResourcePermission Methods 607 public void GrantResourcePermissions(Guid resourceId, Guid[] grantedUserIds) { 608 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 609 var pm = PersistenceManager; 610 using (new PerformanceLogger("GrantResourcePermissions")) { 611 pm.UseTransaction(() => { 612 var resource = AuthorizeForResource(pm, resourceId); 613 var resourcePermissions = resource.ResourcePermissions.ToList(); 605 #region Project Methods 606 public Guid AddProject(DT.Project projectDto) { 607 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 608 var pm = PersistenceManager; 609 using (new PerformanceLogger("AddProject")) { 610 var projectDao = pm.ProjectDao; 611 return pm.UseTransaction(() => { 612 var project = projectDao.Save(projectDto.ToEntity()); 613 pm.SubmitChanges(); 614 return project.ProjectId; 615 }); 616 } 617 } 618 619 public void UpdateProject(DT.Project projectDto) { 620 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 621 var pm = PersistenceManager; 622 using (new PerformanceLogger("UpdateProject")) { 623 var projectDao = pm.ProjectDao; 624 pm.UseTransaction(() => { 625 var project = projectDao.GetById(projectDto.Id); 626 if (project != null) { 627 projectDto.CopyToEntity(project); 628 } else { 629 projectDao.Save(projectDto.ToEntity()); 630 } 631 pm.SubmitChanges(); 632 }); 633 } 634 } 635 636 public void DeleteProject(Guid projectId) { 637 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 638 AuthorizationManager.AuthorizeForResourceAdministration(projectId); 639 var pm = PersistenceManager; 640 using (new PerformanceLogger("DeleteProject")) { 641 var projectDao = pm.ProjectDao; 642 pm.UseTransaction(() => { 643 projectDao.Delete(projectId); 644 pm.SubmitChanges(); 645 }); 646 } 647 } 648 649 public DT.Project GetProject(Guid projectId) { 650 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator); 651 var pm = PersistenceManager; 652 using (new PerformanceLogger("GetProject")) { 653 var projectDao = pm.ProjectDao; 654 return pm.UseTransaction(() => projectDao.GetById(projectId).ToDto()); 655 } 656 } 657 658 public IEnumerable<DT.Project> GetProjects() { 659 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 660 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator); 661 var pm = PersistenceManager; 662 using (new PerformanceLogger("GetProjects")) { 663 var projectDao = pm.ProjectDao; 664 var projectPermissionDao = pm.ProjectPermissionDao; 665 var currentUserId = UserManager.CurrentUserId; 666 return pm.UseTransaction(() => { 667 var resourcePermissions = projectPermissionDao.GetAll(); 668 return projectDao.GetAll().ToList() 669 .Where(x => isAdministrator 670 || x.OwnerUserId == currentUserId 671 || UserManager.VerifyUser(currentUserId, resourcePermissions 672 .Where(y => y.ProjectId == x.ProjectId) 673 .Select(z => z.GrantedUserId) 674 .ToList()) 675 ) 676 .Select(x => x.ToDto()) 677 .ToList(); 678 }); 679 } 680 } 681 #endregion 682 683 #region ProjectPermission Methods 684 public void GrantProjectPermissions(Guid projectId, Guid[] grantedUserIds) { 685 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 686 var pm = PersistenceManager; 687 using (new PerformanceLogger("GrantProjectPermissions")) { 688 pm.UseTransaction(() => { 689 var project = AuthorizeForProject(pm, projectId); 690 var projectPermissions = project.ProjectPermissions.ToList(); 614 691 foreach (var id in grantedUserIds) { 615 if ( resourcePermissions.All(x => x.GrantedUserId != id)) {616 resource.ResourcePermissions.Add(new DA.ResourcePermission {692 if (projectPermissions.All(x => x.GrantedUserId != id)) { 693 project.ProjectPermissions.Add(new DA.ProjectPermission { 617 694 GrantedUserId = id, 618 695 GrantedByUserId = UserManager.CurrentUserId … … 625 702 } 626 703 627 public void Revoke ResourcePermissions(Guid resourceId, Guid[] grantedUserIds) {628 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 629 var pm = PersistenceManager; 630 using (new PerformanceLogger("Revoke ResourcePermissions")) {631 var resourcePermissionDao = pm.ResourcePermissionDao;632 pm.UseTransaction(() => { 633 AuthorizeFor Resource(pm, resourceId);634 resourcePermissionDao.DeleteByResourceAndGrantedUserId(resourceId, grantedUserIds);635 pm.SubmitChanges(); 636 }); 637 } 638 } 639 640 public IEnumerable<DT. ResourcePermission> GetResourcePermissions(Guid resourceId) {641 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 642 var pm = PersistenceManager; 643 using (new PerformanceLogger("Get ResourcePermissions")) {644 var resourcePermissionDao = pm.ResourcePermissionDao;645 return pm.UseTransaction(() => resourcePermissionDao.GetByResourceId(resourceId)704 public void RevokeProjectPermissions(Guid projectId, Guid[] grantedUserIds) { 705 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 706 var pm = PersistenceManager; 707 using (new PerformanceLogger("RevokeProjectPermissions")) { 708 var projectPermissionDao = pm.ProjectPermissionDao; 709 pm.UseTransaction(() => { 710 AuthorizeForProject(pm, projectId); 711 projectPermissionDao.DeleteByProjectAndGrantedUserId(projectId, grantedUserIds); 712 pm.SubmitChanges(); 713 }); 714 } 715 } 716 717 public IEnumerable<DT.ProjectPermission> GetProjectPermissions(Guid projectId) { 718 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 719 var pm = PersistenceManager; 720 using (new PerformanceLogger("GetProjectPermissions")) { 721 var projectPermissionDao = pm.ProjectPermissionDao; 722 return pm.UseTransaction(() => projectPermissionDao.GetByProjectId(projectId) 646 723 .Select(x => x.ToDto()) 647 724 .ToList() … … 696 773 using (new PerformanceLogger("GetSlaves")) { 697 774 var slaveDao = pm.SlaveDao; 698 var resourcePermissionDao = pm. ResourcePermissionDao;775 var resourcePermissionDao = pm.ProjectPermissionDao; 699 776 var currentUserId = UserManager.CurrentUserId; 700 777 return pm.UseTransaction(() => { … … 721 798 using (new PerformanceLogger("GetSlaveGroups")) { 722 799 var slaveGroupDao = pm.SlaveGroupDao; 723 var resourcePermissionDao = pm. ResourcePermissionDao;800 var resourcePermissionDao = pm.ProjectPermissionDao; 724 801 var currentUserId = UserManager.CurrentUserId; 725 802 return pm.UseTransaction(() => { … … 990 1067 } 991 1068 992 private DA. Resource AuthorizeForResource(IPersistenceManager pm, Guid resourceId) {993 var resourceDao = pm.ResourceDao;994 var resource = resourceDao.GetById(resourceId);995 if ( resource== null) throw new SecurityException("Not authorized");996 if ( resource.OwnerUserId != UserManager.CurrentUserId1069 private DA.Project AuthorizeForProject(IPersistenceManager pm, Guid projectId) { 1070 var projectDao = pm.ProjectDao; 1071 var project = projectDao.GetById(projectId); 1072 if (project == null) throw new SecurityException("Not authorized"); 1073 if (project.OwnerUserId != UserManager.CurrentUserId 997 1074 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { 998 1075 throw new SecurityException("Not authorized"); 999 1076 } 1000 return resource;1077 return project; 1001 1078 } 1002 1079 #endregion -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r14185 r15379 132 132 #endregion 133 133 134 #region Project Methods 135 [OperationContract] 136 Guid AddProject(Project projectDto); 137 138 [OperationContract] 139 void UpdateProject(Project projectDto); 140 141 [OperationContract] 142 void DeleteProject(Guid projectId); 143 144 [OperationContract] 145 Project GetProject(Guid projectId); 146 147 [OperationContract] 148 IEnumerable<Project> GetProjects(); 149 #endregion 150 134 151 #region ResourcePermission Methods 135 152 [OperationContract] … … 140 157 141 158 [OperationContract] 142 IEnumerable< ResourcePermission> GetResourcePermissions(Guid resourceId);159 IEnumerable<ProjectPermission> GetResourcePermissions(Guid resourceId); 143 160 #endregion 144 161
Note: See TracChangeset
for help on using the changeset viewer.