- Timestamp:
- 07/25/12 14:12:47 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Hive/3.3/HiveService.cs
r8266 r8326 28 28 using DA = HeuristicLab.Services.Hive.DataAccess; 29 29 using DT = HeuristicLab.Services.Hive.DataTransfer; 30 using System.Transactions; 30 31 31 32 … … 63 64 public Guid AddTask(Task task, TaskData taskData, IEnumerable<Guid> resourceIds) { 64 65 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 66 Guid currentUserId = userManager.CurrentUserId; 65 67 return trans.UseTransaction(() => { 66 68 task.Id = dao.AddTask(task); … … 71 73 } 72 74 dao.AddTaskData(taskData); 73 dao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, userManager.CurrentUserId, null);75 dao.UpdateTaskState(task.Id, DA.TaskState.Waiting, null, currentUserId, null); 74 76 return taskData.TaskId; 75 77 }, false, true); … … 181 183 182 184 public Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception) { 183 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 184 author.AuthorizeForTask(taskId, Permission.Full); 185 using (var ts = new TransactionScope(TransactionScopeOption.Suppress)) { 186 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 187 author.AuthorizeForTask(taskId, Permission.Full); 188 } 185 189 return trans.UseTransaction(() => { 186 190 Task task = dao.UpdateTaskState(taskId, DataTransfer.Convert.ToEntity(taskState), slaveId, userId, exception); … … 245 249 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client, HiveRoles.Slave); 246 250 author.AuthorizeForTask(taskId, Permission.Full); 247 trans.UseTransaction(() => { 248 Task task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, userManager.CurrentUserId, string.Empty); 251 Guid currentUserId = userManager.CurrentUserId; 252 trans.UseTransaction(() => { 253 Task task = dao.UpdateTaskState(taskId, DA.TaskState.Waiting, null, currentUserId, string.Empty); 249 254 task.Command = null; 250 255 dao.UpdateTask(task); … … 320 325 public void GrantPermission(Guid jobId, Guid grantedUserId, Permission permission) { 321 326 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 327 Guid currentUserId = userManager.CurrentUserId; 322 328 trans.UseTransaction(() => { 323 329 Job job = dao.GetJob(jobId); 324 330 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 325 Permission perm = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, userManager.CurrentUserId));331 Permission perm = DT.Convert.ToDto(dao.GetPermissionForJob(job.Id, currentUserId)); 326 332 if (perm != Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 327 dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DT.Convert.ToEntity(permission));333 dao.SetJobPermission(jobId, currentUserId, grantedUserId, DT.Convert.ToEntity(permission)); 328 334 }); 329 335 } … … 331 337 public void RevokePermission(Guid jobId, Guid grantedUserId) { 332 338 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 339 Guid currentUserId = userManager.CurrentUserId; 333 340 trans.UseTransaction(() => { 334 341 Job job = dao.GetJob(jobId); 335 342 if (job == null) throw new FaultException<FaultReason>(new FaultReason("Could not find task with id " + jobId)); 336 DA.Permission perm = dao.GetPermissionForJob(job.Id, userManager.CurrentUserId);343 DA.Permission perm = dao.GetPermissionForJob(job.Id, currentUserId); 337 344 if (perm != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permissions for this experiment")); 338 dao.SetJobPermission(jobId, userManager.CurrentUserId, grantedUserId, DA.Permission.NotAllowed);345 dao.SetJobPermission(jobId, currentUserId, grantedUserId, DA.Permission.NotAllowed); 339 346 }); 340 347 } … … 342 349 public IEnumerable<JobPermission> GetJobPermissions(Guid jobId) { 343 350 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 344 return trans.UseTransaction(() => { 345 DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, userManager.CurrentUserId); 351 Guid currentUserId = userManager.CurrentUserId; 352 return trans.UseTransaction(() => { 353 DA.Permission currentUserPermission = dao.GetPermissionForJob(jobId, currentUserId); 346 354 if (currentUserPermission != DA.Permission.Full) throw new FaultException<FaultReason>(new FaultReason("Not allowed to list permissions for this experiment")); 347 355 return dao.GetJobPermissions(x => x.JobId == jobId); … … 421 429 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 422 430 return trans.UseTransaction(() => { 423 plugin.UserId = userManager.CurrentUserId; 431 using (var ts = new TransactionScope(TransactionScopeOption.Suppress)) { 432 plugin.UserId = userManager.CurrentUserId; 433 } 424 434 plugin.DateCreated = DateTime.Now; 425 435 … … 476 486 public void GrantResourcePermissions(Guid resourceId, Guid[] grantedUserIds) { 477 487 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 488 Guid currentUserId = userManager.CurrentUserId; 478 489 trans.UseTransaction(() => { 479 490 Resource resource = dao.GetResource(resourceId); 480 491 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 481 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permission for this resource"));492 if (resource.OwnerUserId != currentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to grant permission for this resource")); 482 493 foreach (Guid id in grantedUserIds) 483 dao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = userManager.CurrentUserId, GrantedUserId = id });494 dao.AddResourcePermission(new ResourcePermission { ResourceId = resourceId, GrantedByUserId = currentUserId, GrantedUserId = id }); 484 495 }); 485 496 } … … 487 498 public void RevokeResourcePermissions(Guid resourceId, Guid[] grantedUserIds) { 488 499 authen.AuthenticateForAnyRole(HiveRoles.Administrator, HiveRoles.Client); 500 Guid currentUserId = userManager.CurrentUserId; 489 501 trans.UseTransaction(() => { 490 502 Resource resource = dao.GetResource(resourceId); 491 503 if (resource == null) throw new FaultException<FaultReason>(new FaultReason("Could not find resource with id " + resourceId)); 492 if (resource.OwnerUserId != userManager.CurrentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to revoke permission for this resource"));504 if (resource.OwnerUserId != currentUserId && !authen.IsInRole(HiveRoles.Administrator)) throw new FaultException<FaultReason>(new FaultReason("Not allowed to revoke permission for this resource")); 493 505 foreach (Guid id in grantedUserIds) 494 506 dao.DeleteResourcePermission(resourceId, id);
Note: See TracChangeset
for help on using the changeset viewer.