1 | using HeuristicLab.Clients.Access.Administration;
|
---|
2 | using HeuristicLab.Clients.Hive.WebJobManager.Services;
|
---|
3 | using HeuristicLab.Clients.Hive.WebJobManager.ViewModels.User;
|
---|
4 | using Microsoft.AspNet.Hosting;
|
---|
5 | using Microsoft.AspNet.Http;
|
---|
6 | using Microsoft.AspNet.Mvc;
|
---|
7 | using System;
|
---|
8 | using System.Collections.Generic;
|
---|
9 | using System.Linq;
|
---|
10 | using System.Net.Mail;
|
---|
11 | using System.ServiceModel.Security;
|
---|
12 | using System.Threading.Tasks;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.Clients.Hive.WebJobManager.Controllers
|
---|
15 | {
|
---|
16 | /// <summary>
|
---|
17 | /// Handles all the actions for user management
|
---|
18 | /// </summary>
|
---|
19 | public class UserController : Controller
|
---|
20 | {
|
---|
21 | private WebLoginService weblog;
|
---|
22 | private HiveServiceLocatorWeb serviceLocator;
|
---|
23 | private AccessAdministrationClient accessClient;
|
---|
24 | private Guid userId;
|
---|
25 |
|
---|
26 | private IHostingEnvironment _environment;
|
---|
27 |
|
---|
28 | public UserController(IHostingEnvironment env)
|
---|
29 | {
|
---|
30 | weblog = WebLoginService.Instance;
|
---|
31 | _environment = env;
|
---|
32 | }
|
---|
33 | /// <summary>
|
---|
34 | /// Init required services and checks login
|
---|
35 | /// </summary>
|
---|
36 | /// <returns></returns>
|
---|
37 | private bool init()
|
---|
38 | {
|
---|
39 | var u = HttpContext.Session.GetString("UserId");
|
---|
40 | if (u == null || u == "" || Guid.Parse(u) == Guid.Empty)
|
---|
41 | {
|
---|
42 | return false;
|
---|
43 | }
|
---|
44 | else
|
---|
45 | {
|
---|
46 | userId = Guid.Parse(u);
|
---|
47 | serviceLocator = weblog.getServiceLocator(userId);
|
---|
48 | accessClient = weblog.getAccessAdminClient(userId);
|
---|
49 | return serviceLocator.CheckLogin();
|
---|
50 |
|
---|
51 | }
|
---|
52 | }
|
---|
53 | #region Users
|
---|
54 | /// <summary>
|
---|
55 | /// Show users page
|
---|
56 | /// </summary>
|
---|
57 | /// <returns></returns>
|
---|
58 | public IActionResult Index()
|
---|
59 | {
|
---|
60 | if (init())
|
---|
61 | {
|
---|
62 | ViewBag.Title = "Users";
|
---|
63 | UserViewModel vm = new UserViewModel(accessClient).refreshAll() ;
|
---|
64 | //Refreshall for users, groups and roles
|
---|
65 | ViewBag.SessionId = HttpContext.Session.GetString("UserId");
|
---|
66 | return View("Index", vm);
|
---|
67 | }
|
---|
68 | else
|
---|
69 | {
|
---|
70 | return RedirectToAction("Index", "Home");
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | public IActionResult SelectUser(string id)
|
---|
75 | {
|
---|
76 | if (init())
|
---|
77 | {
|
---|
78 | Guid curr = Guid.Parse(id);
|
---|
79 |
|
---|
80 | UserViewModel vm = new UserViewModel(accessClient).refreshAll();
|
---|
81 | if (curr == Guid.Empty)
|
---|
82 | {//new user
|
---|
83 | ViewBag.Title = "Add User";
|
---|
84 | }
|
---|
85 | else
|
---|
86 | {//View an existing user
|
---|
87 | vm.SelectedUser = vm.getUserById(curr);
|
---|
88 | vm.SelectedUserSubscriptions = accessClient.getSubscribedGroups(curr);
|
---|
89 | vm.SelectedUserRoles = accessClient.getRoles(vm.SelectedUser);
|
---|
90 | ViewBag.title = vm.SelectedUser.UserName;
|
---|
91 | }
|
---|
92 | ViewBag.Title += " - Users";
|
---|
93 | ViewBag.SessionId = HttpContext.Session.GetString("UserId");
|
---|
94 | return View("Index", vm);
|
---|
95 | //Uses Index page too, with the additional info in the Viewmodel
|
---|
96 | }
|
---|
97 | else
|
---|
98 | {
|
---|
99 | return RedirectToAction("Index", "Home");
|
---|
100 | }
|
---|
101 | }
|
---|
102 | /// <summary>
|
---|
103 | /// Saves an existing user or adds a new user
|
---|
104 | /// </summary>
|
---|
105 | /// <param name="inpusername">Username</param>
|
---|
106 | /// <param name="inpfullname">Full name </param>
|
---|
107 | /// <param name="inpemail">Email</param>
|
---|
108 | /// <param name="u">User ID</param>
|
---|
109 | /// <param name="rolestoadd">Roles to add to the user</param>
|
---|
110 | /// <param name="groupstoadd">Groups to subscribe the user to</param>
|
---|
111 | /// <returns></returns>
|
---|
112 | [HttpPost]
|
---|
113 | public IActionResult saveUser(string inpusername, string inpfullname, string inpemail, string u, string[] rolestoadd, string[] groupstoadd)
|
---|
114 | {
|
---|
115 |
|
---|
116 | if (init())
|
---|
117 | {
|
---|
118 | var uid = Guid.Parse(u);
|
---|
119 | Access.User user;
|
---|
120 | if (uid == Guid.Empty)//checks if user is new or exists
|
---|
121 | user = new Access.User();
|
---|
122 | else
|
---|
123 | user = accessClient.Users.Find(x => x.Id == uid);
|
---|
124 |
|
---|
125 |
|
---|
126 | user.FullName = inpfullname;
|
---|
127 | user.Email = inpemail;
|
---|
128 |
|
---|
129 |
|
---|
130 | if (uid == Guid.Empty)
|
---|
131 | {//New user
|
---|
132 | user.UserName = inpusername;
|
---|
133 | uid = accessClient.addUser(user);
|
---|
134 | accessClient.RefreshUsers();
|
---|
135 | var newpass = accessClient.resetPassword(uid);
|
---|
136 | sendPassmail(accessClient.Users.Find(x => x.Id == uid), newpass);
|
---|
137 | //password received through mail
|
---|
138 | ViewBag.Title = user.UserName + " added - User";
|
---|
139 | }
|
---|
140 | else
|
---|
141 | {//Existing user
|
---|
142 | accessClient.updateUser(user);
|
---|
143 | ViewBag.Title = user.UserName + " updated - User";
|
---|
144 | }
|
---|
145 | accessClient.RefreshUsers();//Refresh data from user
|
---|
146 | user = accessClient.Users.Find(x => x.Id == uid);
|
---|
147 | foreach (var s in rolestoadd)
|
---|
148 | {//Loop to add roles
|
---|
149 | var role = accessClient.Roles.Find(x => x.Name == s);
|
---|
150 |
|
---|
151 | accessClient.addRoleToUser(user, role);
|
---|
152 | }
|
---|
153 | accessClient.RefreshUserGroups();
|
---|
154 | foreach(var g in groupstoadd)
|
---|
155 | {//loop to subscribe to groups
|
---|
156 | var gid = Guid.Parse(g);
|
---|
157 | var group = accessClient.Groups.Find(x => x.Id == gid);
|
---|
158 | accessClient.addMember(user, group);
|
---|
159 | }
|
---|
160 | return RedirectToAction("SelectUser", new { id = uid.ToString() });
|
---|
161 | }
|
---|
162 | else
|
---|
163 | {
|
---|
164 | return RedirectToAction("Index", "Home");
|
---|
165 | }
|
---|
166 |
|
---|
167 | }
|
---|
168 | /// <summary>
|
---|
169 | /// Sends email for a specific user, containg a password
|
---|
170 | /// </summary>
|
---|
171 | /// <param name="u">User to mail</param>
|
---|
172 | /// <param name="pass">Password to send</param>
|
---|
173 | public static void sendPassmail(Access.User u, string pass)
|
---|
174 | {/*
|
---|
175 | SmtpClient smtpClient = new SmtpClient("smtp.gmail.com",587);
|
---|
176 | smtpClient.UseDefaultCredentials = true;
|
---|
177 | smtpClient.Credentials = new System.Net.NetworkCredential("trac.heuristiclab@gmail.com", "||||||||||||");
|
---|
178 | smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
---|
179 | smtpClient.EnableSsl = true;
|
---|
180 | MailMessage mail = new MailMessage();
|
---|
181 |
|
---|
182 | //Setting From , To and CC
|
---|
183 | mail.From = new MailAddress("trac.heuristiclab@gmail.com", "HeuristicLab");
|
---|
184 | mail.Subject = "Password changed - HeuristicLab Hive";
|
---|
185 | mail.Body = "Hello " + u.FullName + ", " + Environment.NewLine + Environment.NewLine+
|
---|
186 | "Your password was changed through the HeuristicLab Hive web application." + Environment.NewLine+
|
---|
187 | "The new password for " + u.UserName + " is ' " + pass + " '." + Environment.NewLine + Environment.NewLine +
|
---|
188 | "HeuristicLab Hive";
|
---|
189 | mail.To.Add(new MailAddress(u.Email));
|
---|
190 |
|
---|
191 | smtpClient.Send(mail);
|
---|
192 | */
|
---|
193 | }
|
---|
194 | /// <summary>
|
---|
195 | /// Delete a user
|
---|
196 | /// </summary>
|
---|
197 | /// <param name="id">User ID to delete</param>
|
---|
198 | /// <returns></returns>
|
---|
199 | public IActionResult deleteUser(string id)
|
---|
200 | {
|
---|
201 | if (init())
|
---|
202 | {
|
---|
203 | var uid = Guid.Parse(id);
|
---|
204 | UserViewModel vm = new UserViewModel(accessClient).refreshUsers();
|
---|
205 |
|
---|
206 | if (uid == Guid.Empty)
|
---|
207 | {//check for empty Guid, should not happen but still
|
---|
208 | vm.message = "Something went wrong, user is not deleted";
|
---|
209 | return View("Index", vm);
|
---|
210 | }
|
---|
211 | else
|
---|
212 | {
|
---|
213 | var user = vm.getUserById(uid);
|
---|
214 | vm.message = user.UserName + " (" + user.FullName + ") has been deleted";
|
---|
215 | accessClient.DeleteUser(user);
|
---|
216 | vm.refreshAll();//refreshAll for index view
|
---|
217 | ViewBag.Title = "Users";
|
---|
218 | return View("Index", vm);//No redirect to save the viewbag message
|
---|
219 | }
|
---|
220 | }
|
---|
221 | else
|
---|
222 | {
|
---|
223 | return RedirectToAction("Index", "Home");
|
---|
224 | }
|
---|
225 |
|
---|
226 | }
|
---|
227 | /// <summary>
|
---|
228 | /// Deletes a role from a user
|
---|
229 | /// </summary>
|
---|
230 | /// <param name="id">User Id</param>
|
---|
231 | /// <param name="role">Role name</param>
|
---|
232 | /// <returns></returns>
|
---|
233 | public IActionResult deleteUserRole(string id, string role)
|
---|
234 | {
|
---|
235 | if (init())
|
---|
236 | {
|
---|
237 | var uid = Guid.Parse(id);
|
---|
238 | UserViewModel vm = new UserViewModel(accessClient).refreshAll();
|
---|
239 |
|
---|
240 | var user = vm.getUserById(uid);
|
---|
241 | var r = vm.getRoleByName(role);
|
---|
242 |
|
---|
243 | accessClient.deleteUserRole(user, r);
|
---|
244 | return RedirectToAction("SelectUser", new { id = id });
|
---|
245 | }
|
---|
246 | else
|
---|
247 | {
|
---|
248 | return RedirectToAction("Index", "Home");
|
---|
249 | }
|
---|
250 | }
|
---|
251 | /// <summary>
|
---|
252 | /// Delete user from a group
|
---|
253 | /// </summary>
|
---|
254 | /// <param name="id">User Id</param>
|
---|
255 | /// <param name="group">Group Id</param>
|
---|
256 | /// <returns></returns>
|
---|
257 | public IActionResult deleteUserGroup(string id, string group)
|
---|
258 | {
|
---|
259 | if (init())
|
---|
260 | {
|
---|
261 | var gid = Guid.Parse(group);
|
---|
262 | var mid = Guid.Parse(id);
|
---|
263 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
264 |
|
---|
265 | var user = vm.getUserById(mid);
|
---|
266 | var gr = vm.getGroupById(gid);
|
---|
267 |
|
---|
268 | accessClient.deleteMember(user, gr);
|
---|
269 | return RedirectToAction("SelectUser", new { id = id});
|
---|
270 | }
|
---|
271 | else
|
---|
272 | {
|
---|
273 | return RedirectToAction("Index", "Home");
|
---|
274 | }
|
---|
275 |
|
---|
276 | }
|
---|
277 | #endregion
|
---|
278 |
|
---|
279 | #region Groups
|
---|
280 | /// <summary>
|
---|
281 | /// Shows the groups overview, opening up with "Add group"
|
---|
282 | /// </summary>
|
---|
283 | /// <returns></returns>
|
---|
284 | public IActionResult Groups()
|
---|
285 | {
|
---|
286 | if (init())
|
---|
287 | {
|
---|
288 |
|
---|
289 | ViewBag.Title = "Groups";
|
---|
290 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
291 | return View("Groups", vm);
|
---|
292 | }
|
---|
293 | else
|
---|
294 | {
|
---|
295 | return RedirectToAction("Index", "Home");
|
---|
296 | }
|
---|
297 | }
|
---|
298 | /// <summary>
|
---|
299 | /// Show information for a specific group (Guid.empty = new group)
|
---|
300 | /// </summary>
|
---|
301 | /// <param name="id">Group ID</param>
|
---|
302 | /// <returns></returns>
|
---|
303 | public IActionResult SelectGroup(string id)
|
---|
304 | {
|
---|
305 | if (init())
|
---|
306 | {
|
---|
307 | Guid curr = Guid.Parse(id);
|
---|
308 |
|
---|
309 | UserViewModel vm = new UserViewModel(accessClient)
|
---|
310 | .refreshGroups()
|
---|
311 | .refreshUsers();
|
---|
312 | if (curr == Guid.Empty)
|
---|
313 | {//Add group
|
---|
314 | ViewBag.Title = "Add group";
|
---|
315 | }
|
---|
316 | else
|
---|
317 | {//Show existing group info and possibility to edit
|
---|
318 | vm.SelectedGroup = vm.getGroupById(curr);
|
---|
319 | vm.SelectedGroupMembers = accessClient.getGroupMembers(curr);
|
---|
320 | ViewBag.title = vm.SelectedGroup.Name;
|
---|
321 | }
|
---|
322 | ViewBag.Title += " - Group";
|
---|
323 | return View("Groups", vm);
|
---|
324 | }
|
---|
325 | else
|
---|
326 | {
|
---|
327 | return RedirectToAction("Index", "Home");
|
---|
328 | }
|
---|
329 | }
|
---|
330 | /// <summary>
|
---|
331 | /// Saves an exisiting group or adds a new one.
|
---|
332 | /// </summary>
|
---|
333 | /// <param name="inpgroupname">Group name</param>
|
---|
334 | /// <param name="u">Group id (empty for new)</param>
|
---|
335 | /// <param name="userstoadd">Users to add to group</param>
|
---|
336 | /// <param name="groupstoadd">Groups to add to group</param>
|
---|
337 | /// <returns></returns>
|
---|
338 | [HttpPost]
|
---|
339 | public IActionResult saveGroup(string inpgroupname, string u, string[] userstoadd, string[] groupstoadd)
|
---|
340 | {
|
---|
341 | if (init())
|
---|
342 | {
|
---|
343 | var uid = Guid.Parse(u);
|
---|
344 | var vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
345 |
|
---|
346 | Access.UserGroup group;
|
---|
347 |
|
---|
348 | if (uid == Guid.Empty)//Create new group
|
---|
349 | group = new Access.UserGroup();
|
---|
350 | else//Find existing group
|
---|
351 | group = accessClient.Groups.Find(x => x.Id == uid);
|
---|
352 |
|
---|
353 | group.Name = inpgroupname;
|
---|
354 |
|
---|
355 | if (uid == Guid.Empty)
|
---|
356 | {//New Group add
|
---|
357 | uid = accessClient.addGroup(group);
|
---|
358 | ViewBag.Title = group.Name + " added - Group";
|
---|
359 | }
|
---|
360 | else
|
---|
361 | {//Existing group update
|
---|
362 | accessClient.updateGroup(group);
|
---|
363 | ViewBag.Title = group.Name + " updated - Group";
|
---|
364 | }
|
---|
365 | vm.refreshGroups();
|
---|
366 | group = vm.getGroupById(uid);
|
---|
367 | //refresh group info
|
---|
368 | foreach (var s in userstoadd)
|
---|
369 | {//Subscribes members to group
|
---|
370 | var tempid = Guid.Parse(s);
|
---|
371 | var member = vm.getUserById(tempid);
|
---|
372 | accessClient.addMember(member, group);
|
---|
373 | }
|
---|
374 | foreach (var g in groupstoadd)
|
---|
375 | {//Subscribes groups to group
|
---|
376 | var tempid = Guid.Parse(g);
|
---|
377 | var member = vm.getGroupById(tempid);
|
---|
378 | accessClient.addMember(member, group);
|
---|
379 | }
|
---|
380 |
|
---|
381 | return RedirectToAction("SelectGroup", new { id = uid.ToString() });
|
---|
382 | }
|
---|
383 | else
|
---|
384 | {
|
---|
385 | return RedirectToAction("Index", "Home");
|
---|
386 | }
|
---|
387 | }
|
---|
388 | /// <summary>
|
---|
389 | /// Delete an existing group
|
---|
390 | /// </summary>
|
---|
391 | /// <param name="id">Group to delete</param>
|
---|
392 | /// <returns></returns>
|
---|
393 | public IActionResult deleteGroup(string id)
|
---|
394 | {
|
---|
395 | if (init())
|
---|
396 | {
|
---|
397 | var uid = Guid.Parse(id);
|
---|
398 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups();
|
---|
399 |
|
---|
400 | if (uid == Guid.Empty)
|
---|
401 | {//Check for empty ID, should not happen but still..
|
---|
402 | vm.message = "Something went wrong, group is not deleted";
|
---|
403 | return View("Groups", vm);
|
---|
404 | }
|
---|
405 | else
|
---|
406 | {//Deletes the user group
|
---|
407 | var group = vm.getGroupById(uid);
|
---|
408 | vm.message = group.Name + " has been deleted";
|
---|
409 | accessClient.deleteUserGroup(group);
|
---|
410 | vm.refreshGroups();
|
---|
411 | return View("Groups", vm);
|
---|
412 | }
|
---|
413 | }
|
---|
414 | else
|
---|
415 | {
|
---|
416 | return RedirectToAction("Index", "Home");
|
---|
417 | }
|
---|
418 |
|
---|
419 | }
|
---|
420 | /// <summary>
|
---|
421 | /// Delete a member from a group
|
---|
422 | /// </summary>
|
---|
423 | /// <param name="g">Group id</param>
|
---|
424 | /// <param name="m">User id</param>
|
---|
425 | /// <returns>Group selected</returns>
|
---|
426 | public IActionResult deleteMember(string g, string m)
|
---|
427 | {
|
---|
428 | if (init())
|
---|
429 | {
|
---|
430 | var gid = Guid.Parse(g);
|
---|
431 | var mid = Guid.Parse(m);
|
---|
432 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
433 |
|
---|
434 | if (gid == Guid.Empty || mid == Guid.Empty)
|
---|
435 | {//Should not be empty but still..
|
---|
436 | vm.message = "Something went wrong, member is not deleted";
|
---|
437 | return View("Groups", vm);
|
---|
438 | }
|
---|
439 | else
|
---|
440 | {//Deletes the member
|
---|
441 | var group = vm.getGroupById(gid);
|
---|
442 | Access.UserGroupBase member = vm.getUserById(mid);
|
---|
443 | if (member == null)
|
---|
444 | {
|
---|
445 | member = vm.getGroupById(mid);
|
---|
446 | }
|
---|
447 | vm.message = " Member deleted";
|
---|
448 | accessClient.deleteMember(member, group);
|
---|
449 | vm.refreshGroups();
|
---|
450 | return RedirectToAction("SelectGroup", new { id = g });
|
---|
451 | }
|
---|
452 | }
|
---|
453 | else
|
---|
454 | {
|
---|
455 | return RedirectToAction("Index", "Home");
|
---|
456 | }
|
---|
457 |
|
---|
458 | }
|
---|
459 | #endregion
|
---|
460 |
|
---|
461 | #region Roles
|
---|
462 | /// <summary>
|
---|
463 | /// Shows roles overview, opening with "Add role"
|
---|
464 | /// </summary>
|
---|
465 | /// <returns></returns>
|
---|
466 | public IActionResult Roles()
|
---|
467 | {
|
---|
468 | if (init())
|
---|
469 | {
|
---|
470 |
|
---|
471 | ViewBag.Title = "Roles";
|
---|
472 | UserViewModel vm = new UserViewModel(accessClient).refreshRoles();
|
---|
473 |
|
---|
474 | return View("Roles", vm);
|
---|
475 | }
|
---|
476 | else
|
---|
477 | {
|
---|
478 | return RedirectToAction("Index", "Home");
|
---|
479 | }
|
---|
480 | }
|
---|
481 | /// <summary>
|
---|
482 | /// Shows information for a specific role
|
---|
483 | /// </summary>
|
---|
484 | /// <param name="name">Role name</param>
|
---|
485 | /// <returns></returns>
|
---|
486 | public IActionResult SelectRole(string name)
|
---|
487 | {
|
---|
488 | if (init())
|
---|
489 | {
|
---|
490 |
|
---|
491 | UserViewModel vm = new UserViewModel(accessClient).refreshRoles();
|
---|
492 | if (name == "" || name == null)
|
---|
493 | {//Add role
|
---|
494 | ViewBag.Title = "Add Role";
|
---|
495 | }
|
---|
496 | else
|
---|
497 | {//Edit/view role
|
---|
498 | vm.SelectedRole = vm.getRoleByName(name);
|
---|
499 | vm.SelectedRoleEnrolled = accessClient.getEnrolled(vm.SelectedRole);
|
---|
500 |
|
---|
501 | ViewBag.title = vm.SelectedRole.Name;
|
---|
502 | }
|
---|
503 | ViewBag.Title += " - Roles";
|
---|
504 | return View("Roles", vm);
|
---|
505 | }
|
---|
506 | else
|
---|
507 | {
|
---|
508 | return RedirectToAction("Index", "Home");
|
---|
509 | }
|
---|
510 | }
|
---|
511 | /// <summary>
|
---|
512 | /// Saves a role or adds a new one
|
---|
513 | /// </summary>
|
---|
514 | /// <param name="inprolename">Role name</param>
|
---|
515 | /// <returns></returns>
|
---|
516 | [HttpPost]
|
---|
517 | public IActionResult saveRole(string inprolename)
|
---|
518 | {
|
---|
519 | if (init())
|
---|
520 | {
|
---|
521 | Access.Role role = accessClient.Roles.Find(x => x.Name == inprolename);
|
---|
522 | if (role == null)
|
---|
523 | {
|
---|
524 | role = new Access.Role();
|
---|
525 | role.Name = inprolename;
|
---|
526 | accessClient.addRole(role);
|
---|
527 | }
|
---|
528 |
|
---|
529 | accessClient.RefreshRoles();
|
---|
530 | return RedirectToAction("SelectRole", new { name = inprolename });
|
---|
531 | }
|
---|
532 | else
|
---|
533 | {
|
---|
534 | return RedirectToAction("Index", "Home");
|
---|
535 | }
|
---|
536 | }
|
---|
537 | /// <summary>
|
---|
538 | /// Delete a role
|
---|
539 | /// </summary>
|
---|
540 | /// <param name="name">Role name</param>
|
---|
541 | /// <returns></returns>
|
---|
542 | public IActionResult deleteRole(string name)
|
---|
543 | {
|
---|
544 | if (init())
|
---|
545 | {
|
---|
546 | accessClient.deleteRole(name);
|
---|
547 | return RedirectToAction("Roles");
|
---|
548 | }
|
---|
549 | else
|
---|
550 | {
|
---|
551 | return RedirectToAction("Index", "Home");
|
---|
552 | }
|
---|
553 | }
|
---|
554 | /// <summary>
|
---|
555 | /// Deletes a user from a role
|
---|
556 | /// </summary>
|
---|
557 | /// <param name="id">User id</param>
|
---|
558 | /// <param name="role">Role name</param>
|
---|
559 | /// <returns></returns>
|
---|
560 | public IActionResult deleteRoleUser(string id, string role)
|
---|
561 | {
|
---|
562 | if (init())
|
---|
563 | {
|
---|
564 | var uid = Guid.Parse(id);
|
---|
565 | UserViewModel vm = new UserViewModel(accessClient).refreshAll();
|
---|
566 |
|
---|
567 | var user = vm.getUserById(uid);
|
---|
568 | var r = vm.getRoleByName(role);
|
---|
569 | vm.message = role + " role has been deleted from " + user.FullName;
|
---|
570 | accessClient.deleteUserRole(user, r);
|
---|
571 | return RedirectToAction("SelectRole", new { name = role });
|
---|
572 | }
|
---|
573 | else
|
---|
574 | {
|
---|
575 | return RedirectToAction("Index", "Home");
|
---|
576 | }
|
---|
577 | }
|
---|
578 | #endregion
|
---|
579 | }
|
---|
580 | }
|
---|