- Timestamp:
- 02/08/18 11:13:15 (7 years ago)
- Location:
- branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15715 r15737 680 680 if (!RoleVerifier.IsInRole(HiveRoles.Administrator)) { 681 681 if(projectDto.ParentProjectId.HasValue) { 682 AuthorizationManager.AuthorizeForProjectAdministration(projectDto.ParentProjectId.Value );682 AuthorizationManager.AuthorizeForProjectAdministration(projectDto.ParentProjectId.Value, false); 683 683 } else { 684 684 throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); … … 701 701 // check if current (non-admin) user is owner of the project or the projectDto's-parents 702 702 if (!RoleVerifier.IsInRole(HiveRoles.Administrator)) { 703 AuthorizationManager.AuthorizeForProjectAdministration(projectDto.Id );703 AuthorizationManager.AuthorizeForProjectAdministration(projectDto.Id, false); 704 704 } 705 705 … … 720 720 721 721 public void DeleteProject(Guid projectId) { 722 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 723 // check if current (non-admin) user is owner of the project or the projectDto's-parents 722 if (projectId == Guid.Empty) return; 723 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 724 // check if current (non-admin) user is owner of one of the projectDto's-parents 724 725 if (!RoleVerifier.IsInRole(HiveRoles.Administrator)) { 725 AuthorizationManager.AuthorizeForProjectAdministration(projectId );726 AuthorizationManager.AuthorizeForProjectAdministration(projectId, true); 726 727 } 727 728 … … 731 732 var assignedJobResourceDao = pm.AssignedJobResourceDao; 732 733 pm.UseTransaction(() => { 733 assignedJobResourceDao.DeleteByProjectId(projectId); 734 projectDao.Delete(projectId); 734 var projectIds = new HashSet<Guid> { projectId }; 735 projectIds.Union(projectDao.GetChildProjectIdsById(projectId)); 736 737 assignedJobResourceDao.DeleteByProjectIds(projectIds); 738 projectDao.DeleteByIds(projectIds); 735 739 pm.SubmitChanges(); 736 740 }); … … 797 801 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 798 802 if (projectId == null || grantedUserIds == null) return; 799 AuthorizationManager.AuthorizeForProjectAdministration(projectId );803 AuthorizationManager.AuthorizeForProjectAdministration(projectId, false); 800 804 var pm = PersistenceManager; 801 805 using (new PerformanceLogger("SaveProjectPermissions")) { … … 883 887 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 884 888 if (projectId == null || grantedUserIds == null || !grantedUserIds.Any()) return; 885 AuthorizationManager.AuthorizeForProjectAdministration(projectId );889 AuthorizationManager.AuthorizeForProjectAdministration(projectId, false); 886 890 var pm = PersistenceManager; 887 891 using (new PerformanceLogger("RevokeProjectPermissions")) { … … 904 908 public IEnumerable<DT.ProjectPermission> GetProjectPermissions(Guid projectId) { 905 909 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 906 AuthorizationManager.AuthorizeForProjectAdministration(projectId );910 AuthorizationManager.AuthorizeForProjectAdministration(projectId, false); 907 911 var pm = PersistenceManager; 908 912 using (new PerformanceLogger("GetProjectPermissions")) { … … 1040 1044 public IEnumerable<DT.AssignedProjectResource> GetAssignedResourcesForProjectAdministration(Guid projectId) { 1041 1045 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1042 AuthorizationManager.AuthorizeForProjectAdministration(projectId );1046 AuthorizationManager.AuthorizeForProjectAdministration(projectId, false); 1043 1047 var pm = PersistenceManager; 1044 1048 using (new PerformanceLogger("GetAssignedResourcesForProject")) { … … 1263 1267 1264 1268 public void DeleteSlave(Guid slaveId) { 1269 if (slaveId == Guid.Empty) return; 1265 1270 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1266 1271 AuthorizationManager.AuthorizeForResourceAdministration(slaveId); … … 1276 1281 1277 1282 public void DeleteSlaveGroup(Guid slaveGroupId) { 1283 if (slaveGroupId == Guid.Empty) return; 1278 1284 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1279 1285 AuthorizationManager.AuthorizeForResourceAdministration(slaveGroupId); 1280 1286 var pm = PersistenceManager; 1281 1287 using (new PerformanceLogger("DeleteSlaveGroup")) { 1282 var slaveGroupDao = pm.SlaveGroupDao; 1283 pm.UseTransaction(() => { 1284 slaveGroupDao.Delete(slaveGroupId); 1288 var resourceDao = pm.ResourceDao; 1289 pm.UseTransaction(() => { 1290 var resourceIds = new HashSet<Guid> { slaveGroupId }; 1291 resourceIds.Union(resourceDao.GetChildResourceIdsById(slaveGroupId)); 1292 resourceDao.DeleteByIds(resourceIds); 1285 1293 pm.SubmitChanges(); 1286 1294 }); -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Interfaces/IAuthorizationManager.cs
r15540 r15737 37 37 void AuthorizeForResourceAdministration(Guid resourceId); 38 38 39 void AuthorizeForProjectAdministration(Guid projectId );39 void AuthorizeForProjectAdministration(Guid projectId, bool parentalOwnership); 40 40 41 41 void AuthorizeForProjectResourceAdministration(Guid projectId, IEnumerable<Guid> resourceIds); -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r15715 r15737 92 92 93 93 // authorize if user is admin, project owner or owner of a parent project 94 public void AuthorizeForProjectAdministration(Guid projectId ) {94 public void AuthorizeForProjectAdministration(Guid projectId, bool parentalOwnership) { 95 95 if (projectId == null) return; 96 96 var currentUserId = UserManager.CurrentUserId; … … 98 98 var projectDao = pm.ProjectDao; 99 99 pm.UseTransaction(() => { 100 var projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId).ToList(); 101 if(!projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId) 102 && !RoleVerifier.IsInRole(HiveRoles.Administrator)) { 100 List<Project> projectBranch = null; 101 if(parentalOwnership) projectDao.GetParentProjectsById(projectId).ToList(); 102 else projectBranch = projectDao.GetCurrentAndParentProjectsById(projectId).ToList(); 103 104 if(!RoleVerifier.IsInRole(HiveRoles.Administrator) 105 && !projectBranch.Select(x => x.OwnerUserId).Contains(currentUserId)) { 103 106 throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); 104 107 }
Note: See TracChangeset
for help on using the changeset viewer.