- Timestamp:
- 06/07/18 17:20:08 (6 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectPermissionsView.cs
r15953 r15954 123 123 private void treeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) { 124 124 var checkedPermission = (UserGroupBase)e.Node.Tag; 125 if (e.Node.Parent == null || newInheritedPermissions.Contains(checkedPermission) || checkedPermission.Id == Guid.Empty) e.Cancel = true; 125 if (e.Node.Parent == null 126 || newInheritedPermissions.Contains(checkedPermission) 127 || checkedPermission.Id == Guid.Empty 128 || Content.OwnerUserId == checkedPermission.Id) 129 e.Cancel = true; 126 130 } 127 131 -
branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15913 r15954 675 675 #region Project Methods 676 676 public Guid AddProject(DT.Project projectDto) { 677 if (projectDto == null ) return Guid.Empty;677 if (projectDto == null || projectDto.Id != Guid.Empty) return Guid.Empty; 678 678 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 679 679 // check if current (non-admin) user is owner of one of projectDto's-parents … … 689 689 using (new PerformanceLogger("AddProject")) { 690 690 var projectDao = pm.ProjectDao; 691 691 692 return pm.UseTransaction(() => { 692 693 var project = projectDao.Save(projectDto.ToEntity()); 694 project.ProjectPermissions.Clear(); 695 project.ProjectPermissions.Add(new DA.ProjectPermission { 696 GrantedUserId = project.OwnerUserId, 697 GrantedByUserId = UserManager.CurrentUserId 698 }); 699 693 700 pm.SubmitChanges(); 694 701 return project.ProjectId; … … 707 714 using (new PerformanceLogger("UpdateProject")) { 708 715 var projectDao = pm.ProjectDao; 716 var assignedJobResourceDao = pm.AssignedJobResourceDao; 709 717 pm.UseTransaction(() => { 710 718 var project = projectDao.GetById(projectDto.Id); 711 if (project != null) { 719 if (project != null) { // update existent 720 var formerOwnerId = project.OwnerUserId; 712 721 projectDto.CopyToEntity(project); 713 } else { 714 projectDao.Save(projectDto.ToEntity()); 722 723 // if owner has changed... 724 if(formerOwnerId != projectDto.OwnerUserId) { 725 var formerPermissionItem = project.ProjectPermissions.Where(x => x.GrantedUserId == formerOwnerId).FirstOrDefault(); 726 if (formerPermissionItem != null) { 727 // remove permissions 728 project.ProjectPermissions.Remove(formerPermissionItem); 729 // remove jobs if former owner is no member of a still permitted group 730 var ugt = GetUserGroupTree(); 731 var permittedGuids = new HashSet<Guid>(); // User- and Group-Guids 732 // get all member-Guids of all still permitted groups 733 foreach (var item in project.ProjectPermissions) { 734 permittedGuids.Add(item.GrantedUserId); 735 if(ugt.ContainsKey(item.GrantedUserId)) { 736 ugt[item.GrantedUserId].ToList().ForEach(x => permittedGuids.Add(x)); 737 } 738 739 // check if former owner Guid is in Member-Guids 740 // if yes: do nothing, if not do: 741 if (!permittedGuids.Contains(formerOwnerId)) { 742 assignedJobResourceDao.DeleteByProjectIdAndUserIds(project.ProjectId, new List<Guid> { formerOwnerId }); 743 } 744 } 745 } 746 project.ProjectPermissions.Add(new DA.ProjectPermission { 747 GrantedUserId = projectDto.OwnerUserId, 748 GrantedByUserId = UserManager.CurrentUserId 749 }); 750 } 751 752 } else { // save new 753 var newProject = projectDao.Save(projectDto.ToEntity()); 754 newProject.ProjectPermissions.Clear(); 755 newProject.ProjectPermissions.Add(new DA.ProjectPermission { 756 GrantedUserId = projectDto.OwnerUserId, 757 GrantedByUserId = UserManager.CurrentUserId 758 }); 715 759 } 716 760 pm.SubmitChanges(); … … 841 885 project.ProjectPermissions.Clear(); 842 886 } else { 843 assignedJobResourceDao.DeleteByProjectIdAndUserIds(project.ProjectId, removedPermissions); 844 foreach(var item in project.ProjectPermissions 887 888 var ugt = GetUserGroupTree(); 889 var permittedGuids = new HashSet<Guid>(); // User- and Group-Guids 890 var notpermittedGuids = new HashSet<Guid>(); 891 892 // remove job assignments: 893 // (1) get all member-Guids of all still or fresh permitted user/groups 894 foreach (var item in grantedUserIds) { 895 permittedGuids.Add(item); 896 if (ugt.ContainsKey(item)) { 897 ugt[item].ToList().ForEach(x => permittedGuids.Add(x)); 898 } 899 } 900 901 // (2) get all member-Guids of users and groups in removedPermissions 902 foreach (var item in removedPermissions) { 903 notpermittedGuids.Add(item); 904 if (ugt.ContainsKey(item)) { 905 ugt[item].ToList().ForEach(x => notpermittedGuids.Add(x)); 906 } 907 } 908 909 // (3) get all Guids which are in removedPermissions but not in grantedUserIds 910 var definatelyNotPermittedGuids = notpermittedGuids.Except(permittedGuids); 911 912 // (4) delete jobs of those 913 assignedJobResourceDao.DeleteByProjectIdAndUserIds(project.ProjectId, definatelyNotPermittedGuids); 914 915 916 // remove project permissions 917 foreach (var item in project.ProjectPermissions 845 918 .Where(x => removedPermissions.Contains(x.GrantedUserId)) 846 919 .ToList()) {
Note: See TracChangeset
for help on using the changeset viewer.