Changeset 16043
- Timestamp:
- 08/03/18 13:50:29 (6 years ago)
- Location:
- branches/2839_HiveProjectManagement
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.Designer.cs
r15953 r16043 153 153 this.startDateTimePicker.Size = new System.Drawing.Size(200, 20); 154 154 this.startDateTimePicker.TabIndex = 9; 155 this.startDateTimePicker.ValueChanged += new System.EventHandler(this.startDateTimePicker_ValueChanged); 155 this.startDateTimePicker.ValueChanged += new System.EventHandler(this.startDateTimePicker_ValueChanged); 156 156 // 157 157 // startLabel -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectView.cs
r16040 r16043 67 67 } 68 68 69 protected void RegisterControlEvents() { 70 nameTextBox.TextChanged += nameTextBox_TextChanged; 71 nameTextBox.Validating += nameTextBox_Validating; 72 descriptionTextBox.TextChanged += descriptionTextBox_TextChanged; 73 ownerComboBox.SelectedIndexChanged += ownerComboBox_SelectedIndexChanged; 74 startDateTimePicker.ValueChanged += startDateTimePicker_ValueChanged; 75 endDateTimePicker.ValueChanged += endDateTimePicker_ValueChanged; 76 indefiniteCheckBox.CheckedChanged += indefiniteCheckBox_CheckedChanged; 77 } 78 79 protected void DeregisterControlEvents() { 80 nameTextBox.TextChanged -= nameTextBox_TextChanged; 81 nameTextBox.Validating -= nameTextBox_Validating; 82 descriptionTextBox.TextChanged -= descriptionTextBox_TextChanged; 83 ownerComboBox.SelectedIndexChanged -= ownerComboBox_SelectedIndexChanged; 84 startDateTimePicker.ValueChanged -= startDateTimePicker_ValueChanged; 85 endDateTimePicker.ValueChanged -= endDateTimePicker_ValueChanged; 86 indefiniteCheckBox.CheckedChanged -= indefiniteCheckBox_CheckedChanged; 87 } 88 69 89 protected override void OnContentChanged() { 70 90 base.OnContentChanged(); 91 DeregisterControlEvents(); 71 92 if (Content == null) { 72 93 idTextBox.Clear(); … … 98 119 endDateTimePicker.Enabled = !indefiniteCheckBox.Checked; 99 120 } 121 RegisterControlEvents(); 100 122 } 101 123 … … 112 134 indefiniteCheckBox.Enabled = enabled; 113 135 114 if (!IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) { 115 ownerComboBox.Enabled = false; 116 startDateTimePicker.Enabled = false; 117 endDateTimePicker.Enabled = false; 118 indefiniteCheckBox.Enabled = false; 119 } 136 if(Content != null) { 137 var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault(); 138 if (parentProject == null || parentProject.EndDate.HasValue) { 139 indefiniteCheckBox.Enabled = false; 140 } 141 142 if (!IsAdmin() && !HiveAdminClient.Instance.CheckOwnershipOfParentProject(Content, UserInformation.Instance.User.Id)) { 143 ownerComboBox.Enabled = false; 144 startDateTimePicker.Enabled = false; 145 endDateTimePicker.Enabled = false; 146 indefiniteCheckBox.Enabled = false; 147 } 148 } 120 149 } 121 150 #endregion … … 187 216 188 217 private void nameTextBox_TextChanged(object sender, EventArgs e) { 189 if (Content != null && Content.Name != nameTextBox.Text) 218 if (Content != null && Content.Name != nameTextBox.Text) { 219 DeregisterContentEvents(); 190 220 Content.Name = nameTextBox.Text; 221 RegisterContentEvents(); 222 } 191 223 } 192 224 193 225 private void descriptionTextBox_TextChanged(object sender, EventArgs e) { 194 if (Content != null && Content.Description != descriptionTextBox.Text) 226 if (Content != null && Content.Description != descriptionTextBox.Text) { 227 DeregisterContentEvents(); 195 228 Content.Description = descriptionTextBox.Text; 229 RegisterContentEvents(); 230 } 196 231 } 197 232 … … 199 234 var selectedItem = (LightweightUser)ownerComboBox.SelectedItem; 200 235 var selectedOwnerUserId = selectedItem != null ? selectedItem.Id : Guid.Empty; 201 if (Content != null && Content.OwnerUserId != selectedOwnerUserId) 236 if (Content != null && Content.OwnerUserId != selectedOwnerUserId) { 237 DeregisterContentEvents(); 202 238 Content.OwnerUserId = selectedOwnerUserId; 239 RegisterContentEvents(); 240 } 203 241 } 204 242 205 243 private void startDateTimePicker_ValueChanged(object sender, EventArgs e) { 206 244 if (Content == null) return; 207 245 startDateTimePicker.ValueChanged -= startDateTimePicker_ValueChanged; 246 247 if (!IsAdmin()) { 248 var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault(); 249 if (parentProject != null) { 250 if(startDateTimePicker.Value < parentProject.StartDate) 251 startDateTimePicker.Value = parentProject.StartDate; 252 } else { 253 startDateTimePicker.Value = Content.StartDate; 254 } 255 } 256 208 257 if (!Content.EndDate.HasValue || startDateTimePicker.Value > Content.EndDate) 209 258 endDateTimePicker.Value = startDateTimePicker.Value; 210 if (Content.StartDate != startDateTimePicker.Value) 259 if (Content.StartDate != startDateTimePicker.Value) { 260 DeregisterContentEvents(); 211 261 Content.StartDate = startDateTimePicker.Value; 262 RegisterContentEvents(); 263 } 264 265 startDateTimePicker.ValueChanged += startDateTimePicker_ValueChanged; 212 266 } 213 267 214 268 private void endDateTimePicker_ValueChanged(object sender, EventArgs e) { 215 269 if (Content == null) return; 270 endDateTimePicker.ValueChanged -= endDateTimePicker_ValueChanged; 271 272 if (!IsAdmin()) { 273 var parentProject = HiveAdminClient.Instance.GetAvailableProjectAncestors(Content.Id).LastOrDefault(); 274 if (parentProject != null) { 275 if (parentProject.EndDate.HasValue && endDateTimePicker.Value > parentProject.EndDate.Value) { 276 endDateTimePicker.Value = parentProject.EndDate.Value; 277 } 278 } else if(Content.EndDate.HasValue) { 279 endDateTimePicker.Value = Content.EndDate.Value; 280 } 281 } 216 282 217 283 if (endDateTimePicker.Value < startDateTimePicker.Value) 218 284 endDateTimePicker.Value = startDateTimePicker.Value; 219 if (Content.EndDate != endDateTimePicker.Value) 285 if (Content.EndDate != endDateTimePicker.Value) { 286 DeregisterContentEvents(); 220 287 Content.EndDate = endDateTimePicker.Value; 288 RegisterContentEvents(); 289 } 290 291 endDateTimePicker.ValueChanged += endDateTimePicker_ValueChanged; 221 292 } 222 293 -
branches/2839_HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
r16040 r16043 197 197 } 198 198 199 private void addButton_Click(object sender, EventArgs e) { 200 Guid? parentProjectId = null; 201 202 if(selectedProject == null && !IsAdmin()) { 199 private void addButton_Click(object sender, EventArgs e) { 200 201 if (selectedProject == null && !IsAdmin()) { 203 202 MessageBox.Show( 204 203 "You are not allowed to add a root project - please select a parent project.", … … 218 217 } 219 218 220 if (selectedProject != null) parentProjectId = selectedProject.Id;221 219 var project = new Project { 222 220 Name = "New Project", 223 OwnerUserId = UserInformation.Instance.User.Id, 224 ParentProjectId = parentProjectId 221 OwnerUserId = UserInformation.Instance.User.Id, 225 222 }; 223 if(selectedProject != null) { 224 project.ParentProjectId = selectedProject.Id; 225 project.EndDate = selectedProject.EndDate; 226 } 226 227 227 228 SelectedProject = project; … … 508 509 509 510 bool addEnabled = !locked; 510 if (!IsAdmin() && project == null) addEnabled = false; 511 if(addEnabled) { 512 var now = DateTime.Now; 513 if (now < project.StartDate || now > project.EndDate) addEnabled = false; 514 } 511 515 512 516 bool saveEnabled = project != null; -
branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r16040 r16043 770 770 // check if current (non-admin) user is owner of one of projectDto's-parents 771 771 // note: non-admin users are not allowed to administer root projects (i.e. projects without parental entry) 772 if (!RoleVerifier.IsInRole(HiveRoles.Administrator)) { 772 bool isAdmin = RoleVerifier.IsInRole(HiveRoles.Administrator); 773 if (!isAdmin) { 773 774 if(projectDto != null && projectDto.ParentProjectId.HasValue) { 774 775 AuthorizationManager.AuthorizeForProjectAdministration(projectDto.ParentProjectId.Value, false); … … 792 793 return pm.UseTransaction(() => { 793 794 var project = projectDao.Save(projectDto.ToEntity()); 795 796 var parentProjects = projectDao.GetParentProjectsById(project.ProjectId); 797 bool isParent = parentProjects.Select(x => x.OwnerUserId == UserManager.CurrentUserId).Any(); 798 799 // if user is no admin, but owner of a parent project 800 // check start/end date time boundaries of parent projects before updating child project 801 if (!isAdmin) { 802 var parentProject = parentProjects.Where(x => x.ProjectId == project.ParentProjectId).FirstOrDefault(); 803 if (parentProject != null) { 804 if (project.StartDate < parentProject.StartDate) project.StartDate = parentProject.StartDate; 805 if ((parentProject.EndDate.HasValue && project.EndDate.HasValue && project.EndDate > parentProject.EndDate) 806 || (parentProject.EndDate.HasValue && !project.EndDate.HasValue)) 807 project.EndDate = parentProject.EndDate; 808 } 809 } 810 811 794 812 project.ProjectPermissions.Clear(); 795 813 project.ProjectPermissions.Add(new DA.ProjectPermission { … … 808 826 // check if current (non-admin) user is owner of the project or the projectDto's-parents 809 827 // note: non-admin users are not allowed to administer root projects (i.e. projects without parental entry) 810 if (!RoleVerifier.IsInRole(HiveRoles.Administrator)) { 828 bool isAdmin = RoleVerifier.IsInRole(HiveRoles.Administrator); 829 if (!isAdmin) { 811 830 if (projectDto != null && projectDto.ParentProjectId.HasValue) { 812 AuthorizationManager.AuthorizeForProjectAdministration(projectDto.Id, false); 831 AuthorizationManager.AuthorizeForProjectAdministration(projectDto.Id, false); 813 832 } else { 814 833 throw new SecurityException(NOT_AUTHORIZED_USERPROJECT); … … 830 849 pm.UseTransaction(() => { 831 850 var project = projectDao.GetById(projectDto.Id); 832 if (project != null) { // update existent project 833 var owner = UserManager.GetUserById(projectDto.OwnerUserId); 851 if (project != null) { // (1) update existent project 834 852 var parentProjects = projectDao.GetParentProjectsById(project.ProjectId); 835 bool parentalOwnership = RoleVerifier.IsUserInRole(owner.UserName, HiveRoles.Administrator) 836 || parentProjects.Select(x => x.OwnerUserId == project.OwnerUserId).Any(); 853 bool isParent = parentProjects.Select(x => x.OwnerUserId == UserManager.CurrentUserId).Any(); 837 854 838 855 var formerOwnerId = project.OwnerUserId; … … 841 858 projectDto.CopyToEntity(project); 842 859 843 if(parentalOwnership) { 860 // if user is no admin, but owner of parent project(s) 861 // check start/end date time boundaries of parent projects before updating child project 862 if (!isAdmin && isParent) { 863 var parentProject = parentProjects.Where(x => x.ProjectId == project.ParentProjectId).FirstOrDefault(); 864 if (parentProject != null) { 865 if (project.StartDate < parentProject.StartDate) project.StartDate = formerStartDate; 866 if ((parentProject.EndDate.HasValue && project.EndDate.HasValue && project.EndDate > parentProject.EndDate) 867 || (parentProject.EndDate.HasValue && !project.EndDate.HasValue)) 868 project.EndDate = formerEndDate; 869 } 870 } 871 872 // if user is admin or owner of parent project(s) 873 if (isAdmin || isParent) { 844 874 // if owner has changed... 845 875 if (formerOwnerId != projectDto.OwnerUserId) { 846 // OBSOLETE: former owner looses permission and project-related jobs847 //var formerPermissionItem = project.ProjectPermissions.Where(x => x.GrantedUserId == formerOwnerId).FirstOrDefault();848 //if (formerPermissionItem != null) {849 // // remove permissions850 // project.ProjectPermissions.Remove(formerPermissionItem);851 // // remove jobs if former owner is no member of a still permitted group852 // var ugt = GetUserGroupTree();853 // var permittedGuids = new HashSet<Guid>(); // User- and Group-Guids854 // // get all member-Guids of all still permitted groups855 // foreach (var item in project.ProjectPermissions) {856 // permittedGuids.Add(item.GrantedUserId);857 // if(ugt.ContainsKey(item.GrantedUserId)) {858 // ugt[item.GrantedUserId].ToList().ForEach(x => permittedGuids.Add(x));859 // }860 861 // // check if former owner Guid is in Member-Guids862 // // if yes: do nothing, if not do:863 // if (!permittedGuids.Contains(formerOwnerId)) {864 // assignedJobResourceDao.DeleteByProjectIdAndUserIds(project.ProjectId, new List<Guid> { formerOwnerId });865 // }866 // }867 //}868 876 // Add permission for new owner if not already done 869 877 if (!project.ProjectPermissions … … 876 884 } 877 885 } 878 } else { 886 } else { // if user is only owner of current project, but no admin and no owner of parent project(s) 879 887 project.OwnerUserId = formerOwnerId; 880 888 project.StartDate = formerStartDate; … … 882 890 } 883 891 884 } else { // save new project892 } else { // (2) save new project 885 893 var newProject = projectDao.Save(projectDto.ToEntity()); 894 895 var parentProjects = projectDao.GetParentProjectsById(project.ProjectId); 896 bool isParent = parentProjects.Select(x => x.OwnerUserId == UserManager.CurrentUserId).Any(); 897 898 // if user is no admin, but owner of a parent project 899 // check start/end date time boundaries of parent projects before updating child project 900 if (!isAdmin) { 901 var parentProject = parentProjects.Where(x => x.ProjectId == project.ParentProjectId).FirstOrDefault(); 902 if (parentProject != null) { 903 if (project.StartDate < parentProject.StartDate) project.StartDate = parentProject.StartDate; 904 if ((parentProject.EndDate.HasValue && project.EndDate.HasValue && project.EndDate > parentProject.EndDate) 905 || (parentProject.EndDate.HasValue && !project.EndDate.HasValue)) 906 project.EndDate = parentProject.EndDate; 907 } 908 } 909 886 910 newProject.ProjectPermissions.Clear(); 887 911 newProject.ProjectPermissions.Add(new DA.ProjectPermission { … … 890 914 }); 891 915 } 916 892 917 pm.SubmitChanges(); 893 918 }); … … 1204 1229 if (projectId == null || resourceIds == null) return; 1205 1230 AuthorizationManager.AuthorizeForProjectResourceAdministration(projectId, resourceIds); 1231 bool isAdmin = RoleVerifier.IsInRole(HiveRoles.Administrator); 1206 1232 var pm = PersistenceManager; 1207 1233 using (new PerformanceLogger("SaveProjectResourceAssignments")) { … … 1211 1237 pm.UseTransaction(() => { 1212 1238 var project = projectDao.GetById(projectId); 1213 1214 var owner = UserManager.GetUserById(project.OwnerUserId); 1239 1215 1240 var parentProjects = projectDao.GetParentProjectsById(project.ProjectId); 1216 bool parentalOwnership = RoleVerifier.IsUserInRole(owner.UserName, HiveRoles.Administrator) 1217 || parentProjects.Select(x => x.OwnerUserId == project.OwnerUserId).Any(); 1241 bool isParent = parentProjects.Select(x => x.OwnerUserId == UserManager.CurrentUserId).Any(); 1218 1242 1219 1243 var assignedResources = project.AssignedProjectResources.Select(x => x.ResourceId).ToArray(); 1220 if (! parentalOwnership) resourceIds = assignedResources.ToList();1244 if (!isParent) resourceIds = assignedResources.ToList(); 1221 1245 var removedAssignments = assignedResources.Except(resourceIds); 1222 1246 1223 1247 // if user is admin or owner of parent project(s) 1224 if( parentalOwnership) {1248 if(isAdmin || isParent) { 1225 1249 // remove job and project assignments 1226 1250 if (reassign) { -
branches/2839_HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r16040 r16043 117 117 } 118 118 119 // authorize if user is admin, or owner of a p arent project, for which the resources are assigned to119 // authorize if user is admin, or owner of a project or parent project, for which the resources are assigned to 120 120 public void AuthorizeForProjectResourceAdministration(Guid projectId, IEnumerable<Guid> resourceIds) { 121 121 if (projectId == null || projectId == Guid.Empty) return;
Note: See TracChangeset
for help on using the changeset viewer.