Changeset 16209
- Timestamp:
- 10/03/18 15:06:21 (6 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs
r16208 r16209 44 44 private const string JOB_STATE = "State"; 45 45 private const string JOB_EXECUTIONSTATE = "Execution State"; 46 private const string JOB_EXECUTIONTIME = "Execution Time"; 46 47 private const string JOB_DESCRIPTION = "Description"; 47 48 private const string JOB_TASKCOUNT = "Tasks"; 49 private const string JOB_WAITINGTASKCOUNT = "Waiting"; 48 50 private const string JOB_CALCULATINGTASKCOUNT = "Calculating"; 49 51 private const string JOB_FINISHEDTASKCOUNT = "Finished"; … … 112 114 var jobs = GetSelectedJobs().ToList(); 113 115 if (jobs.Any()) { 114 115 // TODO: include isControllable?! 116 116 117 startButton.Enabled = jobs.All(x => 117 !x.IsProgressing && x.HiveTasks != null && x.HiveTasks.Count > 0118 && x.Job.ProjectId != null && x.Job.ProjectId != Guid.Empty&& x.Job.ResourceIds != null && x.Job.ResourceIds.Any()118 !x.IsProgressing && HiveAdminClient.Instance.Tasks.ContainsKey(x.Id) && HiveAdminClient.Instance.Tasks[x.Id].Count > 0 119 && x.Job.ProjectId != Guid.Empty //&& x.Job.ResourceIds != null && x.Job.ResourceIds.Any() 119 120 && (x.ExecutionState == ExecutionState.Prepared || x.ExecutionState == ExecutionState.Paused)); 120 121 pauseButton.Enabled = jobs.All(x => !x.IsProgressing && x.ExecutionState == ExecutionState.Started); … … 138 139 139 140 private void refreshButton_Click(object sender, EventArgs e) { 140 var task = System.Threading.Tasks.Task.Factory.StartNew(RefreshJobsAsync);141 141 progress.Start("Refreshing jobs..."); 142 142 SetEnabledStateOfControls(); 143 var task = System.Threading.Tasks.Task.Factory.StartNew(RefreshJobsAsync); 143 144 144 145 task.ContinueWith((t) => { 145 matrixView.DataGridView.ClearSelection(); 146 progress.Finish(); 147 SetEnabledStateOfControls(); 146 148 }); 147 149 } … … 157 159 MessageBoxIcon.Question); 158 160 159 if (result == DialogResult.Yes) { 161 if (result == DialogResult.Yes) { 162 progress.Start("Removing job(s)..."); 163 SetEnabledStateOfControls(); 160 164 var task = System.Threading.Tasks.Task.Factory.StartNew(RemoveJobsAsync, jobs); 161 progress.Start(); 162 SetEnabledStateOfControls(); 163 164 task.ContinueWith((t) => { 165 matrixView.DataGridView.ClearSelection(); 166 RefreshJobs(); 167 progress.Finish(); 165 166 task.ContinueWith((t) => { 167 RefreshJobs(); 168 progress.Finish(); 169 SetEnabledStateOfControls(); 168 170 }, TaskContinuationOptions.NotOnFaulted); 169 171 170 172 task.ContinueWith((t) => { 171 matrixView.DataGridView.ClearSelection();172 RefreshJobs();173 progress.Finish();174 MessageBox.Show("An error occured removing the job(s). " + t.Exception.Message, "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);173 RefreshJobs(); 174 progress.Finish(); 175 SetEnabledStateOfControls(); 176 MessageBox.Show("An error occured removing the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 175 177 }, TaskContinuationOptions.OnlyOnFaulted); 176 178 } … … 189 191 190 192 if (result == DialogResult.Yes) { 193 progress.Start("Resuming job(s)..."); 194 SetEnabledStateOfControls(); 191 195 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobsAsync, jobs); 192 progress.Start(); 193 SetEnabledStateOfControls(); 194 195 task.ContinueWith((t) => { 196 matrixView.DataGridView.ClearSelection(); 197 RefreshJobs(); 198 progress.Finish(); 199 }); 200 201 task.ContinueWith((t) => { 202 matrixView.DataGridView.ClearSelection(); 203 RefreshJobs(); 204 progress.Finish(); 196 197 task.ContinueWith((t) => { 198 RefreshJobs(); 199 progress.Finish(); 200 SetEnabledStateOfControls(); 201 }, TaskContinuationOptions.NotOnFaulted); 202 203 task.ContinueWith((t) => { 204 RefreshJobs(); 205 progress.Finish(); 206 SetEnabledStateOfControls(); 205 207 MessageBox.Show("An error occured resuming the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 206 208 }, TaskContinuationOptions.OnlyOnFaulted); … … 220 222 221 223 if (result == DialogResult.Yes) { 224 progress.Start("Pausing job(s)..."); 225 SetEnabledStateOfControls(); 222 226 var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobsAsync, jobs); 223 progress.Start(); 224 SetEnabledStateOfControls(); 225 226 task.ContinueWith((t) => { 227 matrixView.DataGridView.ClearSelection(); 228 RefreshJobs(); 229 progress.Finish(); 230 }); 231 232 task.ContinueWith((t) => { 233 matrixView.DataGridView.ClearSelection(); 234 RefreshJobs(); 235 progress.Finish(); 227 228 task.ContinueWith((t) => { 229 RefreshJobs(); 230 progress.Finish(); 231 SetEnabledStateOfControls(); 232 }, TaskContinuationOptions.NotOnFaulted); 233 234 task.ContinueWith((t) => { 235 RefreshJobs(); 236 progress.Finish(); 237 SetEnabledStateOfControls(); 236 238 MessageBox.Show("An error occured pausing the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 237 239 }, TaskContinuationOptions.OnlyOnFaulted); … … 251 253 252 254 if (result == DialogResult.Yes) { 255 progress.Start("Stopping job(s)..."); 256 SetEnabledStateOfControls(); 253 257 var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobsAsync, jobs); 254 progress.Start(); 255 SetEnabledStateOfControls(); 256 257 task.ContinueWith((t) => { 258 matrixView.DataGridView.ClearSelection(); 259 RefreshJobs(); 260 progress.Finish(); 261 }); 262 263 task.ContinueWith((t) => { 264 matrixView.DataGridView.ClearSelection(); 265 RefreshJobs(); 266 progress.Finish(); 258 259 task.ContinueWith((t) => { 260 RefreshJobs(); 261 progress.Finish(); 262 SetEnabledStateOfControls(); 263 }, TaskContinuationOptions.NotOnFaulted); 264 265 task.ContinueWith((t) => { 266 RefreshJobs(); 267 progress.Finish(); 268 SetEnabledStateOfControls(); 267 269 MessageBox.Show("An error occured stopping the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 268 270 }, TaskContinuationOptions.OnlyOnFaulted); … … 287 289 foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) { 288 290 if (((string)r.Cells[0].Value) == JobState.Online.ToString()) { 289 jobs.Add(HiveAdminClient.Instance.Jobs[Content.Id].FirstOrDefault(x => x.Id == Guid.Parse((string) r.Cells[ 9].Value)));291 jobs.Add(HiveAdminClient.Instance.Jobs[Content.Id].FirstOrDefault(x => x.Id == Guid.Parse((string) r.Cells[11].Value))); 290 292 } 291 293 } … … 306 308 var jobs = HiveAdminClient.Instance.Jobs[Content.Id]; 307 309 var resources = HiveAdminClient.Instance.Resources; 308 string[,] values = new string[jobs.Count, 1 1];310 string[,] values = new string[jobs.Count, 13]; 309 311 310 312 for(int i = 0; i < jobs.Count; i++) { … … 312 314 values[i, 0] = job.Job.State.ToString(); 313 315 values[i, 1] = job.ExecutionState.ToString(); 314 values[i, 2] = job.Job.DateCreated.ToString(); 315 values[i, 3] = job.Job.OwnerUsername; 316 values[i, 4] = job.Job.Name; 317 values[i, 5] = job.Job.JobCount.ToString(); 318 values[i, 6] = job.Job.CalculatingCount.ToString(); 319 values[i, 7] = job.Job.FinishedCount.ToString(); 320 values[i, 8] = job.Job.Description; 321 values[i, 9] = job.Job.Id.ToString(); 322 values[i, 10] = job.Job.OwnerUserId.ToString(); 316 values[i, 2] = job.ExecutionTime.ToString(); 317 values[i, 3] = job.Job.DateCreated.ToString(); 318 values[i, 4] = job.Job.OwnerUsername; 319 values[i, 5] = job.Job.Name; 320 values[i, 6] = job.Job.JobCount.ToString(); 321 values[i, 7] = (job.Job.JobCount - job.Job.CalculatingCount - job.Job.FinishedCount).ToString(); 322 values[i, 8] = job.Job.CalculatingCount.ToString(); 323 values[i, 9] = job.Job.FinishedCount.ToString(); 324 values[i, 10] = job.Job.Description; 325 values[i, 11] = job.Job.Id.ToString(); 326 values[i, 12] = job.Job.OwnerUserId.ToString(); 323 327 } 324 328 325 329 var matrix = new StringMatrix(values); 326 matrix.ColumnNames = new string[] { JOB_STATE, JOB_EXECUTIONSTATE, JOB_ DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID };330 matrix.ColumnNames = new string[] { JOB_STATE, JOB_EXECUTIONSTATE, JOB_EXECUTIONTIME, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_WAITINGTASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID }; 327 331 matrix.SortableView = true; 328 332 return matrix; … … 356 360 357 361 private void RefreshJobsAsync() { 358 RefreshJobs(); 362 HiveAdminClient.Instance.RefreshJobs(); 363 UpdateJobs(); 359 364 } 360 365 … … 387 392 progress.Start(); 388 393 foreach (var job in jobList) { 389 progress.Status = " Deleting job \"" + job.Job.Name + "\"...";394 progress.Status = "Removing job \"" + job.Job.Name + "\"..."; 390 395 HiveAdminClient.RemoveJob(job); 391 396 } -
trunk/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r16185 r16209 318 318 319 319 private void treeSlaveGroup_BeforeCheck(object sender, TreeViewCancelEventArgs e) { 320 if ( e.Node == ungroupedGroupNode) {320 if (!IsAdmin() || e.Node == ungroupedGroupNode) { 321 321 e.Cancel = true; 322 322 } else { -
trunk/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
r16117 r16209 139 139 } 140 140 141 // project look up 141 142 if (Content.Job != null && Content.Job.ProjectId == Guid.Empty) { 142 143 if (HiveClient.Instance != null && HiveClient.Instance.Projects != null && HiveClient.Instance.Projects.Count == 1) { … … 150 151 } 151 152 } 152 } 153 154 155 nameTextBox.Text = Content.Job.Name; 156 descriptionTextBox.Text = Content.Job.Description; 157 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 158 refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically; 159 160 // project look up 161 if(Content.Job.ProjectId != null && Content.Job.ProjectId != Guid.Empty) { 162 if(selectedProject == null || selectedProject.Id != Content.Job.ProjectId) { 153 } else if (Content.Job != null && Content.Job.ProjectId != Guid.Empty) { 154 if (selectedProject == null || selectedProject.Id != Content.Job.ProjectId) { 163 155 selectedProject = GetProject(Content.Job.ProjectId); 156 hiveResourceSelectorDialog = null; 164 157 if (selectedProject != null) { 165 158 projectNameTextBox.Text = selectedProject.Name; … … 168 161 } 169 162 } 163 164 if(hiveResourceSelectorDialog == null) 165 hiveResourceSelectorDialog = new HiveResourceSelectorDialog(Content.Job.Id, Content.Job.ProjectId); 166 167 if (Content.Job.ResourceIds == null) { 168 Content.Job.ResourceIds = HiveClient.Instance.GetAssignedResourcesForJob(Content.Job.Id) 169 .Select(x => x.Id) 170 .ToList(); 171 hiveResourceSelectorDialog.SelectedResourceIds = Content.Job.ResourceIds; 172 } 173 170 174 } else { 171 175 selectedProject = null; … … 173 177 Content.Job.ResourceIds = null; 174 178 } 179 180 181 nameTextBox.Text = Content.Job.Name; 182 descriptionTextBox.Text = Content.Job.Description; 183 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 184 refreshAutomaticallyCheckBox.Checked = Content.RefreshAutomatically; 175 185 176 186 logView.Content = Content.Log; … … 501 511 } 502 512 503 private void updateButton_Click2(object sender, EventArgs e) {504 if (Content.ExecutionState == ExecutionState.Stopped) {505 MessageBox.Show("Job cannot be updated once it stopped.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);506 return;507 }508 509 HiveClient.UpdateJob(510 (Exception ex) => ErrorHandling.ShowErrorDialog(this, "Update failed.", ex),511 Content,512 new CancellationToken());513 UpdateSelectorDialog();514 }515 516 513 private void updateButton_Click(object sender, EventArgs e) { 517 514 if (Content.ExecutionState == ExecutionState.Stopped) { … … 556 553 } else { 557 554 startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 558 && Content.Job.ProjectId != null && Content.Job.ProjectId !=Guid.Empty && Content.Job.ResourceIds != null && Content.Job.ResourceIds.Any()555 && Content.Job.ProjectId != Guid.Empty && Content.Job.ResourceIds != null && Content.Job.ResourceIds.Any() 559 556 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused) && !Content.IsProgressing; 560 557 pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing; -
trunk/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs
r16208 r16209 80 80 } 81 81 82 private Dictionary<Guid, List<LightweightTask>> tasks; 83 public Dictionary<Guid, List<LightweightTask>> Tasks { 84 get { return tasks; } 85 } 86 82 87 private Dictionary<Guid, HashSet<Guid>> projectAncestors; 83 88 public Dictionary<Guid, HashSet<Guid>> ProjectAncestors { … … 145 150 projectResourceAssignments = new ItemList<AssignedProjectResource>(); 146 151 jobs = new Dictionary<Guid, HiveItemCollection<RefreshableJob>>(); 152 tasks = new Dictionary<Guid, List<LightweightTask>>(); 147 153 projectNames = new Dictionary<Guid, string>(); 148 154 resourceNames = new Dictionary<Guid, string>(); … … 311 317 var projectIds = new List<Guid>(); 312 318 jobs = new Dictionary<Guid, HiveItemCollection<RefreshableJob>>(); 319 tasks = new Dictionary<Guid, List<LightweightTask>>(); 313 320 314 321 HiveServiceLocator.Instance.CallHiveService(service => { … … 329 336 } 330 337 331 public staticvoid LoadLightweightJob(RefreshableJob refreshableJob) {338 public void LoadLightweightJob(RefreshableJob refreshableJob) { 332 339 var job = refreshableJob.Job; 333 var tasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(job.Id)); 334 if (tasks != null && tasks.Count > 0 && tasks.All(x => x.Id != Guid.Empty)) { 335 if (tasks.All(x => 340 var lightweightTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(job.Id)); 341 342 if (tasks.ContainsKey(job.Id)) { 343 tasks[job.Id].Clear(); 344 tasks[job.Id].AddRange(lightweightTasks); 345 } else { 346 tasks.Add(job.Id, new List<LightweightTask>(lightweightTasks)); 347 } 348 349 if (lightweightTasks != null && lightweightTasks.Count > 0 && lightweightTasks.All(x => x.Id != Guid.Empty)) { 350 if (lightweightTasks.All(x => 336 351 x.State == TaskState.Finished 337 352 || x.State == TaskState.Aborted … … 340 355 refreshableJob.RefreshAutomatically = false; 341 356 } else if ( 342 tasks357 lightweightTasks 343 358 .Where(x => x.ParentTaskId != null) 344 359 .All(x => … … 346 361 || x.State != TaskState.Transferring 347 362 || x.State != TaskState.Calculating) 348 && tasks363 && lightweightTasks 349 364 .Where(x => x.ParentTaskId != null) 350 365 .Any(x => x.State == TaskState.Paused)) { 351 366 refreshableJob.ExecutionState = ExecutionState.Paused; 352 367 refreshableJob.RefreshAutomatically = false; 353 } else if ( tasks.Any(x => x.State == TaskState.Calculating368 } else if (lightweightTasks.Any(x => x.State == TaskState.Calculating 354 369 || x.State == TaskState.Transferring 355 370 || x.State == TaskState.Waiting)) { 356 371 refreshableJob.ExecutionState = ExecutionState.Started; 357 372 } 373 374 refreshableJob.ExecutionTime = TimeSpan.FromMilliseconds(lightweightTasks.Sum(x => x.ExecutionTime.TotalMilliseconds)); 358 375 } 359 376 } … … 451 468 public static void ResumeJob(RefreshableJob refreshableJob) { 452 469 HiveServiceLocator.Instance.CallHiveService(service => { 453 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { 454 if (task.Task.State == TaskState.Paused) { 455 service.RestartTask(task.Task.Id); 470 var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); 471 foreach (var task in tasks) { 472 if (task.State == TaskState.Paused) { 473 service.RestartTask(task.Id); 456 474 } 457 475 } … … 462 480 public static void PauseJob(RefreshableJob refreshableJob) { 463 481 HiveServiceLocator.Instance.CallHiveService(service => { 464 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { 465 if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed) 466 service.PauseTask(task.Task.Id); 482 var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); 483 foreach (var task in tasks) { 484 if (task.State != TaskState.Finished && task.State != TaskState.Aborted && task.State != TaskState.Failed) 485 service.PauseTask(task.Id); 467 486 } 468 487 }); … … 472 491 public static void StopJob(RefreshableJob refreshableJob) { 473 492 HiveServiceLocator.Instance.CallHiveService(service => { 474 foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) { 475 if (task.Task.State != TaskState.Finished && task.Task.State != TaskState.Aborted && task.Task.State != TaskState.Failed) 476 service.StopTask(task.Task.Id); 493 var tasks = service.GetLightweightJobTasksWithoutStateLog(refreshableJob.Id); 494 foreach (var task in tasks) { 495 if (task.State != TaskState.Finished && task.State != TaskState.Aborted && task.State != TaskState.Failed) 496 service.StopTask(task.Id); 477 497 } 478 498 }); … … 481 501 482 502 public static void RemoveJob(RefreshableJob refreshableJob) { 483 HiveServiceLocator.Instance.CallHiveService((s ) => {484 s .UpdateJobState(refreshableJob.Id, JobState.StatisticsPending);503 HiveServiceLocator.Instance.CallHiveService((service) => { 504 service.UpdateJobState(refreshableJob.Id, JobState.StatisticsPending); 485 505 }); 486 506 } … … 624 644 } 625 645 646 public IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) { 647 var assignedJobResource = HiveServiceLocator.Instance.CallHiveService(service => service.GetAssignedResourcesForJob(jobId)); 648 return Resources.Where(x => assignedJobResource.Select(y => y.ResourceId).Contains(x.Id)); 649 } 650 626 651 private bool IsAdmin() { 627 652 return HiveRoles.CheckAdminUserPermissions(); -
trunk/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r16202 r16209 756 756 return string.Join(" » ", projects.Select(x => ProjectNames[x]).ToArray()); 757 757 } 758 759 public IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) { 760 var assignedJobResource = HiveServiceLocator.Instance.CallHiveService(service => service.GetAssignedResourcesForJob(jobId)); 761 return Resources.Where(x => assignedJobResource.Select(y => y.ResourceId).Contains(x.Id)); 762 } 758 763 } 759 764 } -
trunk/HeuristicLab.Services.Hive/3.3/HiveService.cs
r16208 r16209 483 483 } 484 484 485 486 485 jobDto.CopyToEntity(job); 487 486 … … 523 522 524 523 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 525 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator);526 var currentUserId = UserManager.CurrentUserId;524 // check if user is an admin, or granted to administer a job-parenting project, or job owner 525 AuthorizationManager.AuthorizeForJob(jobId, DT.Permission.Full); 527 526 528 527 var pm = PersistenceManager; 529 528 using (new PerformanceLogger("UpdateJobState")) { 530 var jobDao = pm.JobDao; 531 var projectDao = pm.ProjectDao; 529 var jobDao = pm.JobDao; 532 530 pm.UseTransaction(() => { 533 531 var job = jobDao.GetById(jobId); 534 if (job != null) { 535 536 var administrationGrantedProjects = projectDao 537 .GetAdministrationGrantedProjectsForUser(currentUserId) 538 .ToList(); 539 540 // check if user is an admin, or granted to administer a job-parenting project,... 541 if (!isAdministrator && !administrationGrantedProjects.Contains(job.Project)) 542 AuthorizationManager.AuthorizeForJob(jobId, DT.Permission.Full); // ... or job owner 532 if (job != null) { 543 533 544 534 // note: allow solely state changes from "Online" to "StatisticsPending" = deletion request by user for HiveStatisticGenerator … … 563 553 564 554 RoleVerifier.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 565 bool isAdministrator = RoleVerifier.IsInRole(HiveRoles.Administrator); 566 var currentUserId = UserManager.CurrentUserId; 555 // check if user is an admin, or granted to administer a job-parenting project, or job owner 556 foreach (var jobId in jobIds) 557 AuthorizationManager.AuthorizeForJob(jobId, DT.Permission.Full); 567 558 568 559 var pm = PersistenceManager; … … 571 562 var projectDao = pm.ProjectDao; 572 563 pm.UseTransaction(() => { 573 var administrationGrantedProjects = projectDao574 .GetAdministrationGrantedProjectsForUser(currentUserId)575 .ToList();576 577 564 foreach (var jobId in jobIds) { 578 565 var job = jobDao.GetById(jobId); 579 566 if (job != null) { 580 581 // check if user is an admin, or granted to administer a job-parenting project,...582 if (!isAdministrator && !administrationGrantedProjects.Contains(job.Project))583 AuthorizationManager.AuthorizeForJob(jobId, DT.Permission.Full); // ... or job owner584 567 585 568 // note: allow solely state changes from "Online" to "StatisticsPending" = deletion request by user for HiveStatisticGenerator -
trunk/HeuristicLab.Services.Hive/3.3/Manager/AuthorizationManager.cs
r16117 r16209 38 38 private const string NOT_AUTHORIZED_PROJECTRESOURCE = "Selected project is not authorized to access the requested resource"; 39 39 private const string USER_NOT_IDENTIFIED = "User could not be identified"; 40 private const string JOB_NOT_EXISTENT = "Queried job could not be found"; 40 41 private const string TASK_NOT_EXISTENT = "Queried task could not be found"; 41 42 private const string PROJECT_NOT_EXISTENT = "Queried project could not be found"; … … 60 61 public void AuthorizeForTask(Guid taskId, DT.Permission requiredPermission) { 61 62 if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Slave)) return; // slave-users can access all tasks 63 if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Administrator)) return; // administrator can access all tasks 64 var currentUserId = UserManager.CurrentUserId; 62 65 var pm = PersistenceManager; 63 66 var taskDao = pm.TaskDao; 67 var projectDao = pm.ProjectDao; 64 68 pm.UseTransaction(() => { 65 69 var task = taskDao.GetById(taskId); 66 70 if (task == null) throw new SecurityException(TASK_NOT_EXISTENT); 71 72 // check if user is granted to administer a job-parenting project 73 var administrationGrantedProjects = projectDao 74 .GetAdministrationGrantedProjectsForUser(currentUserId) 75 .ToList(); 76 if (administrationGrantedProjects.Contains(task.Job.Project)) return; 77 67 78 AuthorizeJob(pm, task.JobId, requiredPermission); 68 79 }); … … 70 81 71 82 public void AuthorizeForJob(Guid jobId, DT.Permission requiredPermission) { 72 var pm = PersistenceManager; 73 pm.UseTransaction(() => { 83 if (ServiceLocator.Instance.RoleVerifier.IsInRole(HiveRoles.Administrator)) return; // administrator can access all jobs 84 var currentUserId = UserManager.CurrentUserId; 85 var pm = PersistenceManager; 86 var jobDao = pm.JobDao; 87 var projectDao = pm.ProjectDao; 88 pm.UseTransaction(() => { 89 var job = jobDao.GetById(jobId); 90 if(job == null) throw new SecurityException(JOB_NOT_EXISTENT); 91 92 // check if user is granted to administer a job-parenting project 93 var administrationGrantedProjects = projectDao 94 .GetAdministrationGrantedProjectsForUser(currentUserId) 95 .ToList(); 96 if (administrationGrantedProjects.Contains(job.Project)) return; 97 74 98 AuthorizeJob(pm, jobId, requiredPermission); 75 99 });
Note: See TracChangeset
for help on using the changeset viewer.