Changeset 15658 for branches/HiveProjectManagement
- Timestamp:
- 01/26/18 08:51:30 (7 years ago)
- Location:
- branches/HiveProjectManagement
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/MenuItems/AdministratorMenuItem.cs
r15401 r15658 38 38 39 39 public override void Execute() { 40 if (HiveRoles.CheckAdminUserPermissions()) { 40 41 if (HiveRoles.CheckAdminUserPermissions() || HiveAdminClient.Instance.CheckAccessToAdminAreaGranted()) { 41 42 MainFormManager.MainForm.ShowContent(HiveAdminClient.Instance); 42 43 } else if (!UserInformation.Instance.UserExists) { -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectResourcesView.cs
r15642 r15658 44 44 private readonly HashSet<Resource> inheritedResources = new HashSet<Resource>(); 45 45 private readonly HashSet<Resource> newInheritedResources = new HashSet<Resource>(); 46 47 private readonly Dictionary<Guid, HashSet<Project>> projectAncestors = new Dictionary<Guid, HashSet<Project>>(); 48 private readonly Dictionary<Guid, HashSet<Project>> projectDescendants = new Dictionary<Guid, HashSet<Project>>(); 46 49 private readonly Dictionary<Guid, HashSet<Resource>> resourceAncestors = new Dictionary<Guid, HashSet<Resource>>(); 47 50 private readonly Dictionary<Guid, HashSet<Resource>> resourceDescendants = new Dictionary<Guid, HashSet<Resource>>(); 51 48 52 //private readonly Color addedAssignmentColor = Color.FromArgb(255, 0, 174, 179); // #00aeb3 49 53 private readonly Color addedAssignmentColor = Color.FromArgb(255, 87, 191, 193); // #57bfc1 … … 75 79 detailsViewHost.Content = null; 76 80 } else { 81 UpdateProjectGenealogy(); 77 82 UpdateAssignedResources(); 78 83 UpdateResourceGenealogy(); … … 91 96 92 97 private void refreshButton_Click(object sender, EventArgs e) { 98 UpdateProjectGenealogy(); 93 99 UpdateAssignedResources(); 94 100 UpdateResourceGenealogy(); … … 120 126 private void treeView_BeforeCheck(object sender, TreeViewCancelEventArgs e) { 121 127 var checkedResource = (Resource)e.Node.Tag; 122 if (newInheritedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) e.Cancel = true; 128 if (newInheritedResources.Contains(checkedResource) || checkedResource.Id == Guid.Empty) { 129 e.Cancel = true; 130 } else if (!HiveRoles.CheckAdminUserPermissions()) { 131 if (!projectAncestors[Content.Id].Any()) { 132 e.Cancel = true; 133 } 134 } 123 135 } 124 136 … … 285 297 if (newAssignedResources.Contains(newResource)) { 286 298 newNode.Checked = true; 299 if(!HiveRoles.CheckAdminUserPermissions()) { 300 if(!projectAncestors[Content.Id].Any()) { 301 newNode.ForeColor = SystemColors.GrayText; 302 newNode.Text += " [immutable]"; 303 } 304 } 305 287 306 } else if (newInheritedResources.Contains(newResource)) { 288 307 newNode.Checked = true; … … 331 350 } 332 351 333 var ungroupedNode = new TreeNode(ungroupedGroupName) { 334 ForeColor = SystemColors.GrayText, 335 Tag = new SlaveGroup() { 336 Name = ungroupedGroupName, 337 Description = ungroupedGroupDescription 338 } 339 }; 340 341 foreach (var slave in subResources.OfType<Slave>().OrderBy(x => x.Name)) { 342 var slaveNode = new TreeNode(slave.Name) { Tag = slave }; 343 ungroupedNode.Nodes.Add(slaveNode); 344 } 345 346 treeView.Nodes.Add(ungroupedNode); 352 var ungroupedSlaves = subResources.OfType<Slave>().OrderBy(x => x.Name); 353 if(ungroupedSlaves.Any()) { 354 var ungroupedNode = new TreeNode(ungroupedGroupName) { 355 ForeColor = SystemColors.GrayText, 356 Tag = new SlaveGroup() { 357 Name = ungroupedGroupName, 358 Description = ungroupedGroupDescription 359 } 360 }; 361 362 foreach (var slave in ungroupedSlaves) { 363 var slaveNode = new TreeNode(slave.Name) { Tag = slave }; 364 ungroupedNode.Nodes.Add(slaveNode); 365 } 366 treeView.Nodes.Add(ungroupedNode); 367 } 368 347 369 treeView.BeforeCheck += treeView_BeforeCheck; 348 370 treeView.AfterCheck += treeView_AfterCheck; … … 352 374 } 353 375 376 private void UpdateProjectGenealogy() { 377 projectAncestors.Clear(); 378 projectDescendants.Clear(); 379 var projects = HiveAdminClient.Instance.Projects; 380 381 foreach(var p in projects) { 382 projectAncestors.Add(p.Id, new HashSet<Project>()); 383 projectDescendants.Add(p.Id, new HashSet<Project>()); 384 } 385 386 foreach (var p in projects) { 387 var parentProjectId = p.ParentProjectId; 388 while (parentProjectId != null) { 389 var parent = projects.SingleOrDefault(x => x.Id == parentProjectId); 390 if (parent != null) { 391 projectAncestors[p.Id].Add(parent); 392 projectDescendants[parent.Id].Add(p); 393 parentProjectId = parent.ParentProjectId; 394 } else { 395 parentProjectId = null; 396 } 397 } 398 } 399 } 400 354 401 #endregion 355 402 } -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectsView.cs
r15627 r15658 270 270 // selectedProject.PropertyChanged += ProjectViewContent_PropertyChanged; 271 271 272 if (IsAuthorized(selectedProject)) {273 if (!tabControl.TabPages.Contains(permissionsTabPage))274 tabControl.TabPages.Add(permissionsTabPage);275 if (!tabControl.TabPages.Contains(resourcesTabPage))276 tabControl.TabPages.Add(resourcesTabPage);277 } else {278 if (tabControl.TabPages.Contains(permissionsTabPage))279 tabControl.TabPages.Remove(permissionsTabPage);280 if (tabControl.TabPages.Contains(resourcesTabPage))281 tabControl.TabPages.Remove(resourcesTabPage);282 }272 //if (IsAuthorized(selectedProject)) { 273 // if (!tabControl.TabPages.Contains(permissionsTabPage)) 274 // tabControl.TabPages.Add(permissionsTabPage); 275 // if (!tabControl.TabPages.Contains(resourcesTabPage)) 276 // tabControl.TabPages.Add(resourcesTabPage); 277 //} else { 278 // if (tabControl.TabPages.Contains(permissionsTabPage)) 279 // tabControl.TabPages.Remove(permissionsTabPage); 280 // if (tabControl.TabPages.Contains(resourcesTabPage)) 281 // tabControl.TabPages.Remove(resourcesTabPage); 282 //} 283 283 } 284 284 … … 416 416 417 417 private bool IsAuthorized(Project project) { 418 return project != null 419 && UserInformation.Instance.UserExists 420 && (project.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions()); 418 return project != null && UserInformation.Instance.UserExists; 419 //&& (project.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions()); 421 420 } 422 421 -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r15576 r15658 302 302 303 303 var mainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>().Where(x => x.ParentResourceId == null)); 304 var subResources = new HashSet<Resource>(resources.Except(mainResources)); 304 var parentedMainResources = new HashSet<Resource>(resources.OfType<SlaveGroup>() 305 .Where(x => x.ParentResourceId.HasValue && !resources.Select(y => y.Id).Contains(x.ParentResourceId.Value))); 306 mainResources.UnionWith(parentedMainResources); 307 var subResources = new HashSet<Resource>(resources.Except(mainResources).OrderByDescending(x => x.Name)); 305 308 306 309 var stack = new Stack<Resource>(mainResources.OrderByDescending(x => x.Name)); 307 var top = stack.Peek();310 Resource top = null; 308 311 309 312 TreeNode currentNode = null; … … 311 314 312 315 while(stack.Any()) { 316 if (top == null) top = stack.Peek(); 313 317 var newResource = stack.Pop(); 314 318 var newNode = new TreeNode(newResource.Name) { Tag = newResource }; -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs
r15642 r15658 468 468 private static IEnumerable<Resource> GetAssignedResourcesForProject(Guid projectId) { 469 469 var assignedProjectResources = HiveServiceLocator.Instance.CallHiveService(s => s.GetAssignedResourcesForProject(projectId)); 470 return Hive AdminClient.Instance.Resources.Where(x => assignedProjectResources.Select(y => y.ResourceId).Contains(x.Id));470 return HiveClient.Instance.Resources.Where(x => assignedProjectResources.Select(y => y.ResourceId).Contains(x.Id)); 471 471 } 472 472 473 473 private static IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) { 474 474 var assignedJobResources = HiveServiceLocator.Instance.CallHiveService(s => s.GetAssignedResourcesForJob(jobId)); 475 return Hive AdminClient.Instance.Resources.Where(x => assignedJobResources.Select(y => y.ResourceId).Contains(x.Id));475 return HiveClient.Instance.Resources.Where(x => assignedJobResources.Select(y => y.ResourceId).Contains(x.Id)); 476 476 } 477 477 … … 581 581 resourceAncestors.Clear(); 582 582 resourceDescendants.Clear(); 583 var resources = Hive AdminClient.Instance.Resources;583 var resources = HiveClient.Instance.Resources; 584 584 585 585 foreach (var r in resources) { -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelectorDialog.cs
r15642 r15658 80 80 #region Overrides 81 81 protected override void OnLoad(EventArgs e) { 82 Hive AdminClient.Instance.Refreshing += HiveAdminClient_Instance_Refreshing;83 Hive AdminClient.Instance.Refreshed += HiveAdminClient_Instance_Refreshed;82 HiveClient.Instance.Refreshing += HiveClient_Instance_Refreshing; 83 HiveClient.Instance.Refreshed += HiveClient_Instance_Refreshed; 84 84 base.OnLoad(e); 85 85 } 86 86 87 87 protected override void OnClosing(CancelEventArgs e) { 88 Hive AdminClient.Instance.Refreshed -= HiveAdminClient_Instance_Refreshed;89 Hive AdminClient.Instance.Refreshing -= HiveAdminClient_Instance_Refreshing;88 HiveClient.Instance.Refreshed -= HiveClient_Instance_Refreshed; 89 HiveClient.Instance.Refreshing -= HiveClient_Instance_Refreshing; 90 90 base.OnClosing(e); 91 91 } … … 93 93 94 94 #region Event Handlers 95 private void Hive AdminClient_Instance_Refreshing(object sender, EventArgs e) {96 if (InvokeRequired) Invoke((Action<object, EventArgs>)Hive AdminClient_Instance_Refreshing, sender, e);95 private void HiveClient_Instance_Refreshing(object sender, EventArgs e) { 96 if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveClient_Instance_Refreshing, sender, e); 97 97 else { 98 98 var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>(); … … 102 102 } 103 103 104 private void Hive AdminClient_Instance_Refreshed(object sender, EventArgs e) {105 if (InvokeRequired) Invoke((Action<object, EventArgs>)Hive AdminClient_Instance_Refreshed, sender, e);104 private void HiveClient_Instance_Refreshed(object sender, EventArgs e) { 105 if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveClient_Instance_Refreshed, sender, e); 106 106 else { 107 107 var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>(); … … 129 129 130 130 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 131 action: () => Update Projects(),131 action: () => UpdateInstance(), 132 132 finallyCallback: () => updatingProjects = false); 133 133 } … … 151 151 152 152 #region Helpers 153 private void UpdateInstance() { 154 HiveClient.Instance.Refresh(); 155 } 156 153 157 private void UpdateProjects() { 154 Hive AdminClient.Instance.Refresh();158 HiveClient.Instance.RefreshProjectsAndResources(); 155 159 hiveResourceSelector.JobId = jobId; 156 160 hiveResourceSelector.ProjectId = projectId; -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r15576 r15658 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using System.Collections.Generic; 26 27 27 28 namespace HeuristicLab.Clients.Hive { … … 36 37 } 37 38 39 #region Properties 38 40 private IItemList<Resource> resources; 39 41 public IItemList<Resource> Resources { … … 62 64 } 63 65 66 #endregion 67 64 68 #region Events 65 69 public event EventHandler Refreshing; … … 86 90 87 91 HiveServiceLocator.Instance.CallHiveService(service => { 88 service.GetSlaveGroups ().ForEach(g => resources.Add(g));89 service.GetSlaves ().ForEach(s => resources.Add(s));92 service.GetSlaveGroupsForAdministration().ForEach(g => resources.Add(g)); 93 service.GetSlavesForAdministration().ForEach(s => resources.Add(s)); 90 94 service.GetProjectsForAdministration().ForEach(p => projects.Add(p)); 91 95 }); … … 174 178 } 175 179 } 180 181 #region 182 public bool CheckAccessToAdminAreaGranted() { 183 if(projects != null) { 184 return projects.Count > 0; 185 } else { 186 bool accessGranted = false; 187 HiveServiceLocator.Instance.CallHiveService(s => { 188 accessGranted = s.CheckAccessToAdminAreaGranted(); 189 }); 190 return accessGranted; 191 } 192 } 193 #endregion 176 194 } 177 195 } -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r15642 r15658 57 57 } 58 58 59 private IItemList<Project> projects; 60 public IItemList<Project> Projects { 61 get { return projects; } 62 } 63 64 private IItemList<Resource> resources; 65 public IItemList<Resource> Resources { 66 get { return resources; } 67 } 68 69 59 70 private List<Plugin> onlinePlugins; 60 71 public List<Plugin> OnlinePlugins { … … 93 104 94 105 try { 106 projects = new ItemList<Project>(); 107 resources = new ItemList<Resource>(); 95 108 jobs = new HiveItemCollection<RefreshableJob>(); 96 var jobsLoaded = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs()); 97 98 foreach (var j in jobsLoaded) { 99 jobs.Add(new RefreshableJob(j)); 100 } 109 110 HiveServiceLocator.Instance.CallHiveService(service => { 111 service.GetProjects().ForEach(p => projects.Add(p)); 112 service.GetSlaveGroups().ForEach(g => resources.Add(g)); 113 service.GetSlaves().ForEach(s => resources.Add(s)); 114 service.GetJobs().ForEach(p => jobs.Add(new RefreshableJob(p))); 115 }); 101 116 } 102 117 catch { 103 118 jobs = null; 119 projects = null; 120 resources = null; 104 121 throw; 105 122 } 106 123 finally { 124 OnRefreshed(); 125 } 126 } 127 128 public void RefreshProjectsAndResources() { 129 OnRefreshing(); 130 131 try { 132 projects = new ItemList<Project>(); 133 resources = new ItemList<Resource>(); 134 135 HiveServiceLocator.Instance.CallHiveService(service => { 136 service.GetProjects().ForEach(p => projects.Add(p)); 137 service.GetSlaveGroups().ForEach(g => resources.Add(g)); 138 service.GetSlaves().ForEach(s => resources.Add(s)); 139 }); 140 } catch { 141 projects = null; 142 resources = null; 143 throw; 144 } finally { 107 145 OnRefreshed(); 108 146 } … … 124 162 }, null); 125 163 } 164 126 165 #endregion 127 166 -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveServiceClient.cs
r15630 r15658 2492 2492 System.Collections.Generic.List<HeuristicLab.Clients.Hive.SlaveGroup> GetSlaveGroups(); 2493 2493 2494 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetSlavesForAdministration", ReplyAction="http://tempuri.org/IHiveService/GetSlavesForAdministrationResponse")] 2495 System.Collections.Generic.List<HeuristicLab.Clients.Hive.Slave> GetSlavesForAdministration(); 2496 2497 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetSlaveGroupsForAdministration", ReplyAction="http://tempuri.org/IHiveService/GetSlaveGroupsForAdministrationResponse")] 2498 System.Collections.Generic.List<HeuristicLab.Clients.Hive.SlaveGroup> GetSlaveGroupsForAdministration(); 2499 2494 2500 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/UpdateSlave", ReplyAction="http://tempuri.org/IHiveService/UpdateSlaveResponse")] 2495 2501 void UpdateSlave(HeuristicLab.Clients.Hive.Slave slave); … … 2539 2545 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetUserGroupTree", ReplyAction="http://tempuri.org/IHiveService/GetUserGroupTreeResponse")] 2540 2546 System.Collections.Generic.Dictionary<System.Guid, System.Collections.Generic.List<System.Guid>> GetUserGroupTree(); 2547 2548 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/CheckAccessToAdminAreaGranted", ReplyAction="http://tempuri.org/IHiveService/CheckAccessToAdminAreaGrantedResponse")] 2549 bool CheckAccessToAdminAreaGranted(); 2541 2550 2542 2551 [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IHiveService/GetUserPriorities", ReplyAction="http://tempuri.org/IHiveService/GetUserPrioritiesResponse")] … … 2823 2832 } 2824 2833 2834 public System.Collections.Generic.List<HeuristicLab.Clients.Hive.Slave> GetSlavesForAdministration() 2835 { 2836 return base.Channel.GetSlavesForAdministration(); 2837 } 2838 2839 public System.Collections.Generic.List<HeuristicLab.Clients.Hive.SlaveGroup> GetSlaveGroupsForAdministration() 2840 { 2841 return base.Channel.GetSlaveGroupsForAdministration(); 2842 } 2843 2825 2844 public void UpdateSlave(HeuristicLab.Clients.Hive.Slave slave) 2826 2845 { … … 2903 2922 } 2904 2923 2924 public bool CheckAccessToAdminAreaGranted() 2925 { 2926 return base.Channel.CheckAccessToAdminAreaGranted(); 2927 } 2928 2905 2929 public System.Collections.Generic.List<HeuristicLab.Clients.Hive.UserPriority> GetUserPriorities() 2906 2930 { -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/AssignedProjectResourceDao.cs
r15628 r15658 77 77 public IEnumerable<Guid> GetAllGrantedResourceIdsByProjectId(Guid projectId) { 78 78 return DataContext.ExecuteQuery<Guid>(GetAllGrantedResourceIdsByProjectIdQueryString, projectId); 79 } 80 81 public IEnumerable<Resource> GetAllGrantedResourcesByProjectIds(IEnumerable<Guid> projectIds) { 82 string paramProjectIds = string.Join(",", projectIds.ToList().Select(x => string.Format("'{0}'", x))); 83 if (!string.IsNullOrWhiteSpace(paramProjectIds)) { 84 string queryString = string.Format(GetAllGrantedResourcesByProjectIdsQueryString, paramProjectIds); 85 return DataContext.ExecuteQuery<Resource>(queryString); 86 } 87 return Enumerable.Empty<Resource>(); 79 88 } 80 89 … … 173 182 WHERE apr.ProjectId = '{0}' 174 183 "; 184 private const string GetAllGrantedResourcesByProjectIdsQueryString = @" 185 WITH rtree AS 186 ( 187 SELECT ResourceId, ParentResourceId 188 FROM [Resource] 189 UNION ALL 190 SELECT rt.ResourceId, r.ParentResourceId 191 FROM [Resource] r 192 JOIN rtree rt ON rt.ParentResourceId = r.ResourceId 193 ) 194 SELECT res.* 195 FROM rtree, [AssignedProjectResource] apr, [Resource] res 196 WHERE rtree.ParentResourceId = apr.ResourceId 197 AND rtree.ResourceId = res.ResourceId 198 AND apr.ProjectId IN ({0}) 199 UNION 200 SELECT res.* 201 FROM [AssignedProjectResource] apr, [Resource] res 202 WHERE apr.ResourceId = res.ResourceId 203 AND apr.ProjectId IN ({0}) 204 "; 175 205 private const string GetAllGrantedResourceIdsOfOwnedParentProjectsQueryString = @" 176 206 WITH pbranch AS -
branches/HiveProjectManagement/HeuristicLab.Services.Hive.DataAccess/3.3/HeuristicLab.Services.Hive.DataAccess-3.3.csproj
r15644 r15658 110 110 <Compile Include="Daos\HiveStatistics\DimClientDao.cs" /> 111 111 <Compile Include="Daos\HiveStatistics\DimJobDao.cs" /> 112 <Compile Include="Daos\HiveStatistics\DimProjectDao.cs" /> 112 113 <Compile Include="Daos\HiveStatistics\DimTimeDao.cs" /> 113 114 <Compile Include="Daos\HiveStatistics\DimUserDao.cs" /> 114 115 <Compile Include="Daos\HiveStatistics\FactClientInfoDao.cs" /> 116 <Compile Include="Daos\HiveStatistics\FactProjectInfoDao.cs" /> 115 117 <Compile Include="Daos\HiveStatistics\FactTaskDao.cs" /> 116 118 <Compile Include="Daos\JobDao.cs" /> -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/HiveService.cs
r15644 r15658 1129 1129 public IEnumerable<DT.Slave> GetSlaves() { 1130 1130 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1131 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);1132 1131 var pm = PersistenceManager; 1133 1132 using (new PerformanceLogger("GetSlaves")) { 1134 1133 var slaveDao = pm.SlaveDao; 1135 //var projectPermissionDao = pm.ProjectPermissionDao; 1134 var projectDao = pm.ProjectDao; 1135 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 1136 1137 // collect user information 1136 1138 var currentUserId = UserManager.CurrentUserId; 1137 return pm.UseTransaction(() => { 1138 return slaveDao.GetAll().ToList() 1139 .Where( x => isAdministrator 1140 || x.OwnerUserId == null 1141 || x.OwnerUserId == currentUserId) 1139 var userAndGroupIds = new List<Guid> { currentUserId }; 1140 userAndGroupIds.AddRange(UserManager.GetUserGroupIdsOfUser(currentUserId)); 1141 1142 return pm.UseTransaction(() => { 1143 var slaves = slaveDao.GetAll() 1144 .Select(x => x.ToDto()) 1145 .ToList(); 1146 var grantedProjectIds = projectDao.GetUsageGrantedProjectsForUser(userAndGroupIds) 1147 .Select(x => x.ProjectId) 1148 .ToList(); 1149 var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourcesByProjectIds(grantedProjectIds) 1150 .Select(x => x.ResourceId) 1151 .ToList(); 1152 1153 return slaves 1154 .Where(x => grantedResourceIds.Contains(x.Id)) 1155 .ToList(); 1156 }); 1157 } 1158 } 1159 1160 public IEnumerable<DT.SlaveGroup> GetSlaveGroups() { 1161 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1162 var pm = PersistenceManager; 1163 using (new PerformanceLogger("GetSlaveGroups")) { 1164 var slaveGroupDao = pm.SlaveGroupDao; 1165 var projectDao = pm.ProjectDao; 1166 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 1167 1168 // collect user information 1169 var currentUserId = UserManager.CurrentUserId; 1170 var userAndGroupIds = new List<Guid> { currentUserId }; 1171 userAndGroupIds.AddRange(UserManager.GetUserGroupIdsOfUser(currentUserId)); 1172 1173 return pm.UseTransaction(() => { 1174 var slaveGroups = slaveGroupDao.GetAll() 1175 .Select(x => x.ToDto()) 1176 .ToList(); 1177 var grantedProjectIds = projectDao.GetUsageGrantedProjectsForUser(userAndGroupIds) 1178 .Select(x => x.ProjectId) 1179 .ToList(); 1180 var grantedResourceIds = assignedProjectResourceDao.GetAllGrantedResourcesByProjectIds(grantedProjectIds) 1181 .Select(x => x.ResourceId) 1182 .ToList(); 1183 1184 return slaveGroups 1185 .Where(x => grantedResourceIds.Contains(x.Id)) 1186 .ToList(); 1187 }); 1188 } 1189 } 1190 1191 public IEnumerable<DT.Slave> GetSlavesForAdministration() { 1192 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1193 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator); 1194 var pm = PersistenceManager; 1195 using (new PerformanceLogger("GetSlavesForAdministration")) { 1196 var slaveDao = pm.SlaveDao; 1197 var currentUserId = UserManager.CurrentUserId; 1198 1199 if (isAdministrator) { 1200 return pm.UseTransaction(() => { 1201 return slaveDao.GetAll() 1142 1202 .Select(x => x.ToDto()) 1143 1203 .ToList(); 1144 //var projectPermissions = projectPermissionDao.GetAll(); 1145 //return slaveDao.GetAll().ToList() 1146 // .Where(x => isAdministrator 1147 // || x.OwnerUserId == null 1148 // || x.OwnerUserId == currentUserId 1149 // || UserManager.VerifyUser(currentUserId, projectPermissions 1150 // //.Where(y => y.ResourceId == x.ResourceId) 1151 // .Select(z => z.GrantedUserId) 1152 // .ToList()) 1153 // ) 1154 // .Select(x => x.ToDto()) 1155 // .ToList(); 1156 }); 1157 } 1158 } 1159 1160 public IEnumerable<DT.SlaveGroup> GetSlaveGroups() { 1204 }); 1205 } else { 1206 var slaves = slaveDao.GetAll() 1207 .Select(x => x.ToDto()) 1208 .ToList(); 1209 var projectDao = pm.ProjectDao; 1210 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 1211 var projects = projectDao.GetAdministrationGrantedProjectsForUser(currentUserId).ToList(); 1212 var resourceIds = assignedProjectResourceDao 1213 .GetAllGrantedResourcesByProjectIds(projects.Select(x => x.ProjectId).ToList()) 1214 .Select(x => x.ResourceId) 1215 .ToList(); 1216 1217 return slaves 1218 .Where(x => resourceIds.Contains(x.Id)) 1219 .ToList(); 1220 } 1221 } 1222 } 1223 1224 public IEnumerable<DT.SlaveGroup> GetSlaveGroupsForAdministration() { 1161 1225 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1162 1226 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator); 1163 1227 var pm = PersistenceManager; 1164 using (new PerformanceLogger("GetSlaveGroups ")) {1228 using (new PerformanceLogger("GetSlaveGroupsForAdministration")) { 1165 1229 var slaveGroupDao = pm.SlaveGroupDao; 1166 var projectPermissionDao = pm.ProjectPermissionDao;1167 1230 var currentUserId = UserManager.CurrentUserId; 1168 return pm.UseTransaction(() => { 1169 //var projectPermissions = projectPermissionDao.GetAll(); 1170 return slaveGroupDao.GetAll().ToList() 1171 .Where(x => isAdministrator 1172 || x.OwnerUserId == null 1173 || x.OwnerUserId == currentUserId 1174 //|| UserManager.VerifyUser(currentUserId, projectPermissions 1175 // //.Where(y => y.ResourceId == x.ResourceId) 1176 // .Select(z => z.GrantedUserId) 1177 // .ToList()) 1178 ) 1231 1232 if (isAdministrator) { 1233 return pm.UseTransaction(() => { 1234 return slaveGroupDao.GetAll() 1235 .Select(x => x.ToDto()) 1236 .ToList(); 1237 }); 1238 } else { 1239 var slaveGroups = slaveGroupDao.GetAll() 1179 1240 .Select(x => x.ToDto()) 1180 1241 .ToList(); 1181 }); 1242 var projectDao = pm.ProjectDao; 1243 var assignedProjectResourceDao = pm.AssignedProjectResourceDao; 1244 var projects = projectDao.GetAdministrationGrantedProjectsForUser(currentUserId).ToList(); 1245 var resourceIds = assignedProjectResourceDao 1246 .GetAllGrantedResourcesByProjectIds(projects.Select(x => x.ProjectId).ToList()) 1247 .Select(x => x.ResourceId) 1248 .ToList(); 1249 1250 return slaveGroups 1251 .Where(x => resourceIds.Contains(x.Id)) 1252 .ToList(); 1253 } 1182 1254 } 1183 1255 } … … 1185 1257 public void UpdateSlave(DT.Slave slaveDto) { 1186 1258 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1259 AuthorizationManager.AuthorizeForResourceAdministration(slaveDto.Id); 1187 1260 var pm = PersistenceManager; 1188 1261 using (new PerformanceLogger("UpdateSlave")) { … … 1202 1275 public void UpdateSlaveGroup(DT.SlaveGroup slaveGroupDto) { 1203 1276 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1277 AuthorizationManager.AuthorizeForResourceAdministration(slaveGroupDto.Id); 1204 1278 var pm = PersistenceManager; 1205 1279 using (new PerformanceLogger("UpdateSlaveGroup")) { … … 1405 1479 1406 1480 return userGroupTree; 1481 } 1482 1483 public bool CheckAccessToAdminAreaGranted() { 1484 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 1485 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator); 1486 var pm = PersistenceManager; 1487 using(new PerformanceLogger("CheckAccessToAdminAreaGranted")) { 1488 if (isAdministrator) { 1489 return true; 1490 } else { 1491 var projectDao = pm.ProjectDao; 1492 var currentUserId = UserManager.CurrentUserId; 1493 return projectDao.GetAdministrationGrantedProjectsForUser(currentUserId).Any(); 1494 } 1495 } 1407 1496 } 1408 1497 #endregion -
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r15644 r15658 210 210 211 211 [OperationContract] 212 IEnumerable<Slave> GetSlavesForAdministration(); 213 214 [OperationContract] 215 IEnumerable<SlaveGroup> GetSlaveGroupsForAdministration(); 216 217 [OperationContract] 212 218 void UpdateSlave(Slave slave); 213 219 … … 260 266 [OperationContract] 261 267 Dictionary<Guid, HashSet<Guid>> GetUserGroupTree(); 268 269 [OperationContract] 270 bool CheckAccessToAdminAreaGranted(); 262 271 #endregion 263 272
Note: See TracChangeset
for help on using the changeset viewer.