- Timestamp:
- 04/12/16 15:28:19 (9 years ago)
- Location:
- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/JobController.cs
r13740 r13754 45 45 /// initializes the connection for the right user. Not constructor because httpcontext is needed. 46 46 /// </summary> 47 private voidinit()47 private bool init() 48 48 { 49 49 var u = HttpContext.Session.GetString("UserId"); 50 50 if (u == null || u == "" || Guid.Parse(u) == Guid.Empty) 51 51 { 52 userId = Guid.Empty; 53 serviceLocator = new HiveServiceLocatorWeb(); 54 serviceClient = serviceLocator.getHiveServiceClient(); 55 clientWeb = new HiveClientWeb(serviceLocator, userId); 52 return false; 56 53 } 57 54 else … … 61 58 serviceClient = serviceLocator.getHiveServiceClient(); 62 59 clientWeb = weblog.getClientWeb(userId); 60 return serviceLocator.CheckLogin(); 63 61 } 64 62 } … … 71 69 public IActionResult Index() 72 70 { 73 try 74 { 75 init(); 71 if (init()) 72 { 76 73 clientWeb.Refresh(); 77 74 vm.userJobs = clientWeb.Jobs.ToList(); 78 } 79 catch (Exception e) 80 { 81 if (e is MessageSecurityException || e is InvalidOperationException) 82 { 83 return RedirectToAction("Index", "Home"); 84 } 85 throw; 86 } 87 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 88 ViewBag.Title = "Jobs"; 89 return View(vm); 75 76 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 77 ViewBag.Title = "Jobs"; 78 return View(vm); 79 } 80 else 81 { 82 return RedirectToAction("Index", "Home"); 83 } 90 84 } 91 85 /// <summary> … … 96 90 public IActionResult Selected(Guid id) 97 91 { 98 init(); 99 if (serviceLocator.CheckLogin()) 92 if (init()) 100 93 { 101 94 clientWeb.Refresh(); … … 129 122 public IActionResult Delete(Guid id) 130 123 { 131 init(); 132 if (serviceLocator.CheckLogin()) 124 if (init()) 133 125 { 134 126 … … 155 147 public IActionResult Uploads() 156 148 { 157 init(); 158 if (serviceLocator.CheckLogin()) 149 if (init()) 159 150 { 160 151 UploadedJobViewModel upper = new UploadedJobViewModel(); … … 176 167 public IActionResult UploadDir(int index) 177 168 { 178 init(); 179 if (serviceLocator.CheckLogin()) 169 if (init()) 180 170 { 181 171 UploadedJobViewModel upper = new UploadedJobViewModel(); 182 172 fillUploadsPaths(upper, index); 183 if (index != -1)173 if (index != -1) 184 174 ViewBag.Title = upper.DisplayDatePaths[index] + " - Uploads"; 185 175 else … … 209 199 tempdex = -1; 210 200 } 211 else { 201 else 202 { 212 203 vm.FullDatePaths.Add(dir); 213 204 var temp = dir.Split('\\'); … … 235 226 public IActionResult DeleteFile(int index, int filedex) 236 227 { 237 init(); 238 if (serviceLocator.CheckLogin()) 228 if (init()) 239 229 { 240 230 UploadedJobViewModel upper = new UploadedJobViewModel(); … … 263 253 public IActionResult OpenFile(int index, int filedex) 264 254 { 265 init(); 266 if (serviceLocator.CheckLogin()) 255 if (init()) 267 256 { 268 257 UploadedJobViewModel upper = new UploadedJobViewModel(); … … 305 294 public IActionResult AddToHive() 306 295 { 307 init(); 308 if (serviceLocator.CheckLogin()) 296 if (init()) 309 297 { 310 298 var job = weblog.getFileOpener(userId).AddCurrentModelToHive(); … … 364 352 public async Task<IActionResult> Uploader(ICollection<IFormFile> files, string directory) 365 353 { 366 init(); 367 UploadedJobViewModel upper = new UploadedJobViewModel(); 368 var uploads = Path.Combine(_environment.WebRootPath, "uploads", serviceClient.ClientCredentials.UserName.UserName, 369 directory); 370 Directory.CreateDirectory(uploads); 371 foreach (var file in files) 372 { 373 if (file.Length > 0) 374 { 375 var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); 376 await file.SaveAsAsync(Path.Combine(uploads, fileName)); 377 // var ioptimizer = ContentManager.Load(Path.Combine(uploads, fileName)); 378 //OptimizerHiveTask task = new OptimizerHiveTask((IOptimizer)ioptimizer); 379 //upper.Tasks.Add(task); 380 } 381 } 382 ViewBag.Title = "Upload complete - Uploads"; 383 return RedirectToAction("Uploads", "Job"); 384 354 if (init()) 355 { 356 UploadedJobViewModel upper = new UploadedJobViewModel(); 357 var uploads = Path.Combine(_environment.WebRootPath, "uploads", serviceClient.ClientCredentials.UserName.UserName, 358 directory); 359 Directory.CreateDirectory(uploads); 360 foreach (var file in files) 361 { 362 if (file.Length > 0) 363 { 364 var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); 365 await file.SaveAsAsync(Path.Combine(uploads, fileName)); 366 // var ioptimizer = ContentManager.Load(Path.Combine(uploads, fileName)); 367 //OptimizerHiveTask task = new OptimizerHiveTask((IOptimizer)ioptimizer); 368 //upper.Tasks.Add(task); 369 } 370 } 371 ViewBag.Title = "Upload complete - Uploads"; 372 return RedirectToAction("Uploads", "Job"); 373 } 374 else 375 { 376 return RedirectToAction("Index", "Home"); 377 } 385 378 } 386 379 #endregion -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/ResourceController.cs
r13740 r13754 1 using HeuristicLab.Clients.Hive.WebJobManager.Services; 1 using HeuristicLab.Clients.Access.Administration; 2 using HeuristicLab.Clients.Hive.WebJobManager.Services; 2 3 using Microsoft.AspNet.Hosting; 3 4 using Microsoft.AspNet.Http; … … 15 16 private WebLoginService weblog; 16 17 private HiveServiceLocatorWeb serviceLocator; 17 private HiveServiceClient serviceClient; 18 private HiveClientWeb clientWeb; 18 private AccessAdministrationClient accessClient; 19 19 private Guid userId; 20 20 … … 26 26 _environment = env; 27 27 } 28 private voidinit()28 private bool init() 29 29 { 30 30 var u = HttpContext.Session.GetString("UserId"); 31 31 if (u == null || u == "" || Guid.Parse(u) == Guid.Empty) 32 32 { 33 userId = Guid.Empty; 34 serviceLocator = new HiveServiceLocatorWeb(); 35 serviceClient = serviceLocator.getHiveServiceClient(); 36 clientWeb = new HiveClientWeb(serviceLocator, userId); 33 return false; 37 34 } 38 35 else … … 40 37 userId = Guid.Parse(u); 41 38 serviceLocator = weblog.getServiceLocator(userId); 42 serviceClient = serviceLocator.getHiveServiceClient(); 43 clientWeb = weblog.getClientWeb(userId); 39 accessClient = weblog.getAccessAdminClient(userId); 40 return serviceLocator.CheckLogin(); 41 44 42 } 45 43 } 46 44 public IActionResult Index() 47 45 { 48 init();49 if ( serviceLocator.CheckLogin())46 47 if (init()) 50 48 { 51 49 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 52 50 ViewBag.Title = "Resources"; 53 51 return View("Index"); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Controllers/UserController.cs
r13742 r13754 27 27 _environment = env; 28 28 } 29 private voidinit()29 private bool init() 30 30 { 31 31 var u = HttpContext.Session.GetString("UserId"); 32 32 if (u == null || u == "" || Guid.Parse(u) == Guid.Empty) 33 33 { 34 userId = Guid.Empty; 35 serviceLocator = new HiveServiceLocatorWeb(); 34 return false; 36 35 } 37 36 else … … 40 39 serviceLocator = weblog.getServiceLocator(userId); 41 40 accessClient = weblog.getAccessAdminClient(userId); 41 return serviceLocator.CheckLogin(); 42 42 43 } 43 44 } … … 46 47 public IActionResult Index() 47 48 { 48 init(); 49 if (serviceLocator.CheckLogin()) 50 { 51 49 if (init()) 50 { 52 51 ViewBag.Title = "Users"; 53 UserViewModel vm = new UserViewModel(accessClient).refresh Users();52 UserViewModel vm = new UserViewModel(accessClient).refreshAll() ; 54 53 ViewBag.SessionId = HttpContext.Session.GetString("UserId"); 55 54 return View("Index", vm); … … 63 62 public IActionResult SelectUser(string id) 64 63 { 65 init();66 if ( serviceLocator.CheckLogin())64 ; 65 if (init()) 67 66 { 68 67 Guid curr = Guid.Parse(id); 69 70 UserViewModel vm = new UserViewModel(accessClient).refresh Users();68 69 UserViewModel vm = new UserViewModel(accessClient).refreshAll(); 71 70 if (curr == Guid.Empty) 72 71 { … … 77 76 vm.SelectedUser = vm.getUserById(curr); 78 77 vm.SelectedUserSubscriptions = accessClient.getSubscribedGroups(curr); 78 vm.SelectedUserRoles = accessClient.getRoles(vm.SelectedUser); 79 79 ViewBag.title = vm.SelectedUser.UserName; 80 80 } … … 89 89 } 90 90 [HttpPost] 91 public IActionResult saveUser(string inpusername, string inpfullname, string inpemail, string u) 92 { 93 init(); 94 var uid = Guid.Parse(u); 95 Access.User user; 96 if (uid == Guid.Empty) 97 user = new Access.User(); 98 else 91 public IActionResult saveUser(string inpusername, string inpfullname, string inpemail, string u, string[] rolestoadd, string[] groupstoadd) 92 { 93 94 if (init()) 95 { 96 var uid = Guid.Parse(u); 97 Access.User user; 98 if (uid == Guid.Empty) 99 user = new Access.User(); 100 else 101 user = accessClient.Users.Find(x => x.Id == uid); 102 103 104 user.FullName = inpfullname; 105 user.Email = inpemail; 106 107 108 if (uid == Guid.Empty) 109 { 110 user.UserName = inpusername; 111 uid = accessClient.addUser(user); 112 ViewBag.Title = user.UserName + " added - User"; 113 } 114 else 115 { 116 accessClient.updateUser(user); 117 ViewBag.Title = user.UserName + " updated - User"; 118 } 119 accessClient.RefreshUsers(); 99 120 user = accessClient.Users.Find(x => x.Id == uid); 100 101 102 user.FullName = inpfullname;103 user.Email = inpemail; 104 105 106 if (uid == Guid.Empty)107 {108 user.UserName = inpusername;109 uid = accessClient.addUser(user);110 ViewBag.Title = user.UserName + " added - User";111 }112 else113 {114 accessClient.updateUser(user);115 ViewBag.Title = user.UserName + " updated - User";116 }117 118 return RedirectToAction( "SelectUser", new { id = uid.ToString()});121 foreach (var s in rolestoadd) 122 { 123 var role = accessClient.Roles.Find(x => x.Name == s); 124 125 accessClient.addRoleToUser(user, role); 126 } 127 accessClient.RefreshUserGroups(); 128 foreach(var g in groupstoadd) 129 { 130 var gid = Guid.Parse(g); 131 var group = accessClient.Groups.Find(x => x.Id == gid); 132 accessClient.addMember(user, group); 133 } 134 return RedirectToAction("SelectUser", new { id = uid.ToString() }); 135 } 136 else 137 { 138 return RedirectToAction("Index", "Home"); 139 } 119 140 120 141 } 121 142 public IActionResult deleteUser(string id) 122 143 { 123 init(); 124 var uid = Guid.Parse(id); 125 UserViewModel vm = new UserViewModel(accessClient).refreshUsers(); 126 127 if (uid == Guid.Empty) 128 { 129 vm.message = "Something went wrong, user is not deleted"; 130 return View("Index", vm); 131 } 132 else 133 { 144 if (init()) 145 { 146 var uid = Guid.Parse(id); 147 UserViewModel vm = new UserViewModel(accessClient).refreshUsers(); 148 149 if (uid == Guid.Empty) 150 { 151 vm.message = "Something went wrong, user is not deleted"; 152 return View("Index", vm); 153 } 154 else 155 { 156 var user = vm.getUserById(uid); 157 vm.message = user.UserName + " (" + user.FullName + ") has been deleted"; 158 accessClient.DeleteUser(user); 159 vm.refreshAll(); 160 ViewBag.Title = "Users"; 161 return View("Index", vm); 162 } 163 } 164 else 165 { 166 return RedirectToAction("Index", "Home"); 167 } 168 169 } 170 171 public IActionResult deleteUserRole(string id, string role) 172 { 173 if (init()) 174 { 175 var uid = Guid.Parse(id); 176 UserViewModel vm = new UserViewModel(accessClient).refreshAll(); 177 134 178 var user = vm.getUserById(uid); 135 vm.message = user.UserName + " ("+user.FullName+") has been deleted"; 136 accessClient.DeleteUser(user); 137 vm.refreshUsers(); 138 return View("Index", vm); 139 } 140 141 } 142 179 var r = vm.getRoleByName(role); 180 accessClient.deleteUserRole(user, r); 181 return RedirectToAction("SelectUser", new { id = id }); 182 } 183 else 184 { 185 return RedirectToAction("Index", "Home"); 186 } 187 } 188 public IActionResult deleteUserGroup(string id, string group) 189 { 190 if (init()) 191 { 192 var gid = Guid.Parse(group); 193 var mid = Guid.Parse(id); 194 UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers(); 195 196 var user = vm.getUserById(mid); 197 var gr = vm.getGroupById(gid); 198 accessClient.deleteMember(user, gr); 199 return RedirectToAction("SelectUser", new { id = id}); 200 } 201 else 202 { 203 return RedirectToAction("Index", "Home"); 204 } 205 206 } 143 207 #endregion 144 208 … … 146 210 public IActionResult Groups() 147 211 { 148 init(); 149 if (serviceLocator.CheckLogin()) 212 if (init()) 150 213 { 151 214 … … 161 224 public IActionResult SelectGroup(string id) 162 225 { 163 init(); 164 if (serviceLocator.CheckLogin()) 226 if (init()) 165 227 { 166 228 Guid curr = Guid.Parse(id); … … 190 252 public IActionResult saveGroup(string inpgroupname, string u, string[] userstoadd, string[] groupstoadd) 191 253 { 192 init(); 193 var uid = Guid.Parse(u); 194 var vm = new UserViewModel(accessClient).refreshGroups().refreshUsers(); 195 196 Access.UserGroup group; 197 198 if (uid == Guid.Empty) 199 group = new Access.UserGroup(); 200 else 201 group = accessClient.Groups.Find(x => x.Id == uid); 202 203 group.Name = inpgroupname; 204 205 if (uid == Guid.Empty) 206 { 207 uid = accessClient.addGroup(group); 208 ViewBag.Title = group.Name + " added - Group"; 209 } 210 else 211 { 212 accessClient.updateGroup(group); 213 ViewBag.Title = group.Name + " updated - Group"; 214 } 215 vm.refreshGroups(); 216 group = vm.getGroupById(uid); 217 foreach(var s in userstoadd) 218 { 219 var tempid = Guid.Parse(s); 220 var member = vm.getUserById(tempid); 221 accessClient.addMember(member, group); 222 } 223 foreach (var g in groupstoadd) 224 { 225 var tempid = Guid.Parse(g); 226 var member = vm.getGroupById(tempid); 227 accessClient.addMember(member, group); 228 } 229 230 return RedirectToAction("SelectGroup", new { id = uid.ToString() }); 231 254 if (init()) 255 { 256 var uid = Guid.Parse(u); 257 var vm = new UserViewModel(accessClient).refreshGroups().refreshUsers(); 258 259 Access.UserGroup group; 260 261 if (uid == Guid.Empty) 262 group = new Access.UserGroup(); 263 else 264 group = accessClient.Groups.Find(x => x.Id == uid); 265 266 group.Name = inpgroupname; 267 268 if (uid == Guid.Empty) 269 { 270 uid = accessClient.addGroup(group); 271 ViewBag.Title = group.Name + " added - Group"; 272 } 273 else 274 { 275 accessClient.updateGroup(group); 276 ViewBag.Title = group.Name + " updated - Group"; 277 } 278 vm.refreshGroups(); 279 group = vm.getGroupById(uid); 280 foreach (var s in userstoadd) 281 { 282 var tempid = Guid.Parse(s); 283 var member = vm.getUserById(tempid); 284 accessClient.addMember(member, group); 285 } 286 foreach (var g in groupstoadd) 287 { 288 var tempid = Guid.Parse(g); 289 var member = vm.getGroupById(tempid); 290 accessClient.addMember(member, group); 291 } 292 293 return RedirectToAction("SelectGroup", new { id = uid.ToString() }); 294 } 295 else 296 { 297 return RedirectToAction("Index", "Home"); 298 } 232 299 } 233 300 public IActionResult deleteGroup(string id) 234 301 { 235 init(); 236 var uid = Guid.Parse(id); 237 UserViewModel vm = new UserViewModel(accessClient).refreshGroups(); 238 239 if (uid == Guid.Empty) 240 { 241 vm.message = "Something went wrong, group is not deleted"; 242 return View("Groups", vm); 243 } 244 else 245 { 246 var group = vm.getGroupById(uid); 247 vm.message = group.Name + " has been deleted"; 248 accessClient.deleteUserGroup(group); 249 vm.refreshGroups(); 250 return View("Groups", vm); 302 if (init()) 303 { 304 var uid = Guid.Parse(id); 305 UserViewModel vm = new UserViewModel(accessClient).refreshGroups(); 306 307 if (uid == Guid.Empty) 308 { 309 vm.message = "Something went wrong, group is not deleted"; 310 return View("Groups", vm); 311 } 312 else 313 { 314 var group = vm.getGroupById(uid); 315 vm.message = group.Name + " has been deleted"; 316 accessClient.deleteUserGroup(group); 317 vm.refreshGroups(); 318 return View("Groups", vm); 319 } 320 } 321 else 322 { 323 return RedirectToAction("Index", "Home"); 251 324 } 252 325 … … 254 327 public IActionResult deleteMember(string g, string m) 255 328 { 256 init(); 257 var gid = Guid.Parse(g); 258 var mid = Guid.Parse(m); 259 UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers() ; 260 261 if (gid == Guid.Empty || mid == Guid.Empty) 262 { 263 vm.message = "Something went wrong, member is not deleted"; 264 return View("Groups", vm); 265 } 266 else 267 { 268 var group = vm.getGroupById(gid); 269 Access.UserGroupBase member = vm.getUserById(mid); 270 if(member == null) 271 { 272 member = vm.getGroupById(mid); 273 } 274 vm.message = " Member deleted"; 275 accessClient.deleteMember(member,group); 276 vm.refreshGroups(); 277 return RedirectToAction("SelectGroup", new { id = g }); 329 if (init()) 330 { 331 var gid = Guid.Parse(g); 332 var mid = Guid.Parse(m); 333 UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers(); 334 335 if (gid == Guid.Empty || mid == Guid.Empty) 336 { 337 vm.message = "Something went wrong, member is not deleted"; 338 return View("Groups", vm); 339 } 340 else 341 { 342 var group = vm.getGroupById(gid); 343 Access.UserGroupBase member = vm.getUserById(mid); 344 if (member == null) 345 { 346 member = vm.getGroupById(mid); 347 } 348 vm.message = " Member deleted"; 349 accessClient.deleteMember(member, group); 350 vm.refreshGroups(); 351 return RedirectToAction("SelectGroup", new { id = g }); 352 } 353 } 354 else 355 { 356 return RedirectToAction("Index", "Home"); 278 357 } 279 358 … … 284 363 public IActionResult Roles() 285 364 { 286 init(); 287 if (serviceLocator.CheckLogin()) 365 if (init()) 288 366 { 289 367 290 368 ViewBag.Title = "Roles"; 291 // accessClient.RefreshUsers(); 292 293 return View("Roles"); 369 UserViewModel vm = new UserViewModel(accessClient).refreshRoles(); 370 371 return View("Roles", vm); 372 } 373 else 374 { 375 return RedirectToAction("Index", "Home"); 376 } 377 } 378 public IActionResult SelectRole(string name) 379 { 380 if (init()) 381 { 382 383 UserViewModel vm = new UserViewModel(accessClient).refreshRoles(); 384 if (name == "" || name == null) 385 { 386 ViewBag.Title = "Add Role"; 387 } 388 else 389 { 390 vm.SelectedRole = vm.getRoleByName(name); 391 vm.SelectedRoleEnrolled = accessClient.getEnrolled(vm.SelectedRole); 392 393 ViewBag.title = vm.SelectedRole.Name; 394 } 395 ViewBag.Title += " - Roles"; 396 return View("Roles", vm); 397 } 398 else 399 { 400 return RedirectToAction("Index", "Home"); 401 } 402 } 403 [HttpPost] 404 public IActionResult saveRole(string inprolename) 405 { 406 if (init()) 407 { 408 Access.Role role = accessClient.Roles.Find(x => x.Name == inprolename); 409 if (role == null) 410 { 411 role = new Access.Role(); 412 role.Name = inprolename; 413 accessClient.addRole(role); 414 } 415 416 accessClient.RefreshRoles(); 417 return RedirectToAction("SelectRole", new { name = inprolename }); 418 } 419 else 420 { 421 return RedirectToAction("Index", "Home"); 422 } 423 } 424 public IActionResult deleteRole(string name) 425 { 426 if (init()) 427 { 428 accessClient.deleteRole(name); 429 return RedirectToAction("Roles"); 430 } 431 else 432 { 433 return RedirectToAction("Index", "Home"); 434 } 435 } 436 public IActionResult deleteRoleUser(string id, string role) 437 { 438 if (init()) 439 { 440 var uid = Guid.Parse(id); 441 UserViewModel vm = new UserViewModel(accessClient).refreshAll(); 442 443 var user = vm.getUserById(uid); 444 var r = vm.getRoleByName(role); 445 vm.message = role + " role has been deleted from " + user.FullName; 446 accessClient.deleteUserRole(user, r); 447 return RedirectToAction("SelectRole", new { name = role }); 294 448 } 295 449 else
Note: See TracChangeset
for help on using the changeset viewer.