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 | var newpass = accessClient.resetPassword(uid);
|
---|
135 | sendPassmail(accessClient.Users.Find(x => x.Id == uid), newpass);
|
---|
136 | //password received through mail
|
---|
137 | ViewBag.Title = user.UserName + " added - User";
|
---|
138 | }
|
---|
139 | else
|
---|
140 | {//Existing user
|
---|
141 | accessClient.updateUser(user);
|
---|
142 | ViewBag.Title = user.UserName + " updated - User";
|
---|
143 | }
|
---|
144 | accessClient.RefreshUsers();//Refresh data from user
|
---|
145 | user = accessClient.Users.Find(x => x.Id == uid);
|
---|
146 | foreach (var s in rolestoadd)
|
---|
147 | {//Loop to add roles
|
---|
148 | var role = accessClient.Roles.Find(x => x.Name == s);
|
---|
149 |
|
---|
150 | accessClient.addRoleToUser(user, role);
|
---|
151 | }
|
---|
152 | accessClient.RefreshUserGroups();
|
---|
153 | foreach(var g in groupstoadd)
|
---|
154 | {//loop to subscribe to groups
|
---|
155 | var gid = Guid.Parse(g);
|
---|
156 | var group = accessClient.Groups.Find(x => x.Id == gid);
|
---|
157 | accessClient.addMember(user, group);
|
---|
158 | }
|
---|
159 | return RedirectToAction("SelectUser", new { id = uid.ToString() });
|
---|
160 | }
|
---|
161 | else
|
---|
162 | {
|
---|
163 | return RedirectToAction("Index", "Home");
|
---|
164 | }
|
---|
165 |
|
---|
166 | }
|
---|
167 | /// <summary>
|
---|
168 | /// Sends email for a specific user, containg a password
|
---|
169 | /// </summary>
|
---|
170 | /// <param name="u">User to mail</param>
|
---|
171 | /// <param name="pass">Password to send</param>
|
---|
172 | public static void sendPassmail(Access.User u, string pass)
|
---|
173 | {/*
|
---|
174 | SmtpClient smtpClient = new SmtpClient("mail.MyWebsiteDomainName.com", 25);
|
---|
175 |
|
---|
176 | smtpClient.Credentials = new System.Net.NetworkCredential("info@MyWebsiteDomainName.com", "myIDPassword");
|
---|
177 | smtpClient.UseDefaultCredentials = true;
|
---|
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("info@MyWebsiteDomainName", "MyWeb Site");
|
---|
184 | mail.Subject = "Password changed - HeuristicLab Hive";
|
---|
185 | mail.Body = "Hello " + u.FullName + ", " +
|
---|
186 | "Your password was changed through the HeuristicLab Hive web application." +
|
---|
187 | "The new password for " + u.UserName + " is '" + pass + "'.";
|
---|
188 | mail.To.Add(new MailAddress(u.Email));
|
---|
189 |
|
---|
190 | smtpClient.Send(mail);
|
---|
191 | */
|
---|
192 | }
|
---|
193 | /// <summary>
|
---|
194 | /// Delete a user
|
---|
195 | /// </summary>
|
---|
196 | /// <param name="id">User ID to delete</param>
|
---|
197 | /// <returns></returns>
|
---|
198 | public IActionResult deleteUser(string id)
|
---|
199 | {
|
---|
200 | if (init())
|
---|
201 | {
|
---|
202 | var uid = Guid.Parse(id);
|
---|
203 | UserViewModel vm = new UserViewModel(accessClient).refreshUsers();
|
---|
204 |
|
---|
205 | if (uid == Guid.Empty)
|
---|
206 | {//check for empty Guid, should not happen but still
|
---|
207 | vm.message = "Something went wrong, user is not deleted";
|
---|
208 | return View("Index", vm);
|
---|
209 | }
|
---|
210 | else
|
---|
211 | {
|
---|
212 | var user = vm.getUserById(uid);
|
---|
213 | vm.message = user.UserName + " (" + user.FullName + ") has been deleted";
|
---|
214 | accessClient.DeleteUser(user);
|
---|
215 | vm.refreshAll();//refreshAll for index view
|
---|
216 | ViewBag.Title = "Users";
|
---|
217 | return View("Index", vm);//No redirect to save the viewbag message
|
---|
218 | }
|
---|
219 | }
|
---|
220 | else
|
---|
221 | {
|
---|
222 | return RedirectToAction("Index", "Home");
|
---|
223 | }
|
---|
224 |
|
---|
225 | }
|
---|
226 | /// <summary>
|
---|
227 | /// Deletes a role from a user
|
---|
228 | /// </summary>
|
---|
229 | /// <param name="id">User Id</param>
|
---|
230 | /// <param name="role">Role name</param>
|
---|
231 | /// <returns></returns>
|
---|
232 | public IActionResult deleteUserRole(string id, string role)
|
---|
233 | {
|
---|
234 | if (init())
|
---|
235 | {
|
---|
236 | var uid = Guid.Parse(id);
|
---|
237 | UserViewModel vm = new UserViewModel(accessClient).refreshAll();
|
---|
238 |
|
---|
239 | var user = vm.getUserById(uid);
|
---|
240 | var r = vm.getRoleByName(role);
|
---|
241 |
|
---|
242 | accessClient.deleteUserRole(user, r);
|
---|
243 | return RedirectToAction("SelectUser", new { id = id });
|
---|
244 | }
|
---|
245 | else
|
---|
246 | {
|
---|
247 | return RedirectToAction("Index", "Home");
|
---|
248 | }
|
---|
249 | }
|
---|
250 | /// <summary>
|
---|
251 | /// Delete user from a group
|
---|
252 | /// </summary>
|
---|
253 | /// <param name="id">User Id</param>
|
---|
254 | /// <param name="group">Group Id</param>
|
---|
255 | /// <returns></returns>
|
---|
256 | public IActionResult deleteUserGroup(string id, string group)
|
---|
257 | {
|
---|
258 | if (init())
|
---|
259 | {
|
---|
260 | var gid = Guid.Parse(group);
|
---|
261 | var mid = Guid.Parse(id);
|
---|
262 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
263 |
|
---|
264 | var user = vm.getUserById(mid);
|
---|
265 | var gr = vm.getGroupById(gid);
|
---|
266 |
|
---|
267 | accessClient.deleteMember(user, gr);
|
---|
268 | return RedirectToAction("SelectUser", new { id = id});
|
---|
269 | }
|
---|
270 | else
|
---|
271 | {
|
---|
272 | return RedirectToAction("Index", "Home");
|
---|
273 | }
|
---|
274 |
|
---|
275 | }
|
---|
276 | #endregion
|
---|
277 |
|
---|
278 | #region Groups
|
---|
279 | /// <summary>
|
---|
280 | /// Shows the groups overview, opening up with "Add group"
|
---|
281 | /// </summary>
|
---|
282 | /// <returns></returns>
|
---|
283 | public IActionResult Groups()
|
---|
284 | {
|
---|
285 | if (init())
|
---|
286 | {
|
---|
287 |
|
---|
288 | ViewBag.Title = "Groups";
|
---|
289 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
290 | return View("Groups", vm);
|
---|
291 | }
|
---|
292 | else
|
---|
293 | {
|
---|
294 | return RedirectToAction("Index", "Home");
|
---|
295 | }
|
---|
296 | }
|
---|
297 | /// <summary>
|
---|
298 | /// Show information for a specific group (Guid.empty = new group)
|
---|
299 | /// </summary>
|
---|
300 | /// <param name="id">Group ID</param>
|
---|
301 | /// <returns></returns>
|
---|
302 | public IActionResult SelectGroup(string id)
|
---|
303 | {
|
---|
304 | if (init())
|
---|
305 | {
|
---|
306 | Guid curr = Guid.Parse(id);
|
---|
307 |
|
---|
308 | UserViewModel vm = new UserViewModel(accessClient)
|
---|
309 | .refreshGroups()
|
---|
310 | .refreshUsers();
|
---|
311 | if (curr == Guid.Empty)
|
---|
312 | {//Add group
|
---|
313 | ViewBag.Title = "Add group";
|
---|
314 | }
|
---|
315 | else
|
---|
316 | {//Show existing group info and possibility to edit
|
---|
317 | vm.SelectedGroup = vm.getGroupById(curr);
|
---|
318 | vm.SelectedGroupMembers = accessClient.getGroupMembers(curr);
|
---|
319 | ViewBag.title = vm.SelectedGroup.Name;
|
---|
320 | }
|
---|
321 | ViewBag.Title += " - Group";
|
---|
322 | return View("Groups", vm);
|
---|
323 | }
|
---|
324 | else
|
---|
325 | {
|
---|
326 | return RedirectToAction("Index", "Home");
|
---|
327 | }
|
---|
328 | }
|
---|
329 | /// <summary>
|
---|
330 | /// Saves an exisiting group or adds a new one.
|
---|
331 | /// </summary>
|
---|
332 | /// <param name="inpgroupname">Group name</param>
|
---|
333 | /// <param name="u">Group id (empty for new)</param>
|
---|
334 | /// <param name="userstoadd">Users to add to group</param>
|
---|
335 | /// <param name="groupstoadd">Groups to add to group</param>
|
---|
336 | /// <returns></returns>
|
---|
337 | [HttpPost]
|
---|
338 | public IActionResult saveGroup(string inpgroupname, string u, string[] userstoadd, string[] groupstoadd)
|
---|
339 | {
|
---|
340 | if (init())
|
---|
341 | {
|
---|
342 | var uid = Guid.Parse(u);
|
---|
343 | var vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
344 |
|
---|
345 | Access.UserGroup group;
|
---|
346 |
|
---|
347 | if (uid == Guid.Empty)//Create new group
|
---|
348 | group = new Access.UserGroup();
|
---|
349 | else//Find existing group
|
---|
350 | group = accessClient.Groups.Find(x => x.Id == uid);
|
---|
351 |
|
---|
352 | group.Name = inpgroupname;
|
---|
353 |
|
---|
354 | if (uid == Guid.Empty)
|
---|
355 | {//New Group add
|
---|
356 | uid = accessClient.addGroup(group);
|
---|
357 | ViewBag.Title = group.Name + " added - Group";
|
---|
358 | }
|
---|
359 | else
|
---|
360 | {//Existing group update
|
---|
361 | accessClient.updateGroup(group);
|
---|
362 | ViewBag.Title = group.Name + " updated - Group";
|
---|
363 | }
|
---|
364 | vm.refreshGroups();
|
---|
365 | group = vm.getGroupById(uid);
|
---|
366 | //refresh group info
|
---|
367 | foreach (var s in userstoadd)
|
---|
368 | {//Subscribes members to group
|
---|
369 | var tempid = Guid.Parse(s);
|
---|
370 | var member = vm.getUserById(tempid);
|
---|
371 | accessClient.addMember(member, group);
|
---|
372 | }
|
---|
373 | foreach (var g in groupstoadd)
|
---|
374 | {//Subscribes groups to group
|
---|
375 | var tempid = Guid.Parse(g);
|
---|
376 | var member = vm.getGroupById(tempid);
|
---|
377 | accessClient.addMember(member, group);
|
---|
378 | }
|
---|
379 |
|
---|
380 | return RedirectToAction("SelectGroup", new { id = uid.ToString() });
|
---|
381 | }
|
---|
382 | else
|
---|
383 | {
|
---|
384 | return RedirectToAction("Index", "Home");
|
---|
385 | }
|
---|
386 | }
|
---|
387 | /// <summary>
|
---|
388 | /// Delete an existing group
|
---|
389 | /// </summary>
|
---|
390 | /// <param name="id">Group to delete</param>
|
---|
391 | /// <returns></returns>
|
---|
392 | public IActionResult deleteGroup(string id)
|
---|
393 | {
|
---|
394 | if (init())
|
---|
395 | {
|
---|
396 | var uid = Guid.Parse(id);
|
---|
397 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups();
|
---|
398 |
|
---|
399 | if (uid == Guid.Empty)
|
---|
400 | {//Check for empty ID, should not happen but still..
|
---|
401 | vm.message = "Something went wrong, group is not deleted";
|
---|
402 | return View("Groups", vm);
|
---|
403 | }
|
---|
404 | else
|
---|
405 | {//Deletes the user group
|
---|
406 | var group = vm.getGroupById(uid);
|
---|
407 | vm.message = group.Name + " has been deleted";
|
---|
408 | accessClient.deleteUserGroup(group);
|
---|
409 | vm.refreshGroups();
|
---|
410 | return View("Groups", vm);
|
---|
411 | }
|
---|
412 | }
|
---|
413 | else
|
---|
414 | {
|
---|
415 | return RedirectToAction("Index", "Home");
|
---|
416 | }
|
---|
417 |
|
---|
418 | }
|
---|
419 | /// <summary>
|
---|
420 | /// Delete a member from a group
|
---|
421 | /// </summary>
|
---|
422 | /// <param name="g">Group id</param>
|
---|
423 | /// <param name="m">User id</param>
|
---|
424 | /// <returns>Group selected</returns>
|
---|
425 | public IActionResult deleteMember(string g, string m)
|
---|
426 | {
|
---|
427 | if (init())
|
---|
428 | {
|
---|
429 | var gid = Guid.Parse(g);
|
---|
430 | var mid = Guid.Parse(m);
|
---|
431 | UserViewModel vm = new UserViewModel(accessClient).refreshGroups().refreshUsers();
|
---|
432 |
|
---|
433 | if (gid == Guid.Empty || mid == Guid.Empty)
|
---|
434 | {//Should not be empty but still..
|
---|
435 | vm.message = "Something went wrong, member is not deleted";
|
---|
436 | return View("Groups", vm);
|
---|
437 | }
|
---|
438 | else
|
---|
439 | {//Deletes the member
|
---|
440 | var group = vm.getGroupById(gid);
|
---|
441 | Access.UserGroupBase member = vm.getUserById(mid);
|
---|
442 | if (member == null)
|
---|
443 | {
|
---|
444 | member = vm.getGroupById(mid);
|
---|
445 | }
|
---|
446 | vm.message = " Member deleted";
|
---|
447 | accessClient.deleteMember(member, group);
|
---|
448 | vm.refreshGroups();
|
---|
449 | return RedirectToAction("SelectGroup", new { id = g });
|
---|
450 | }
|
---|
451 | }
|
---|
452 | else
|
---|
453 | {
|
---|
454 | return RedirectToAction("Index", "Home");
|
---|
455 | }
|
---|
456 |
|
---|
457 | }
|
---|
458 | #endregion
|
---|
459 |
|
---|
460 | #region Roles
|
---|
461 | /// <summary>
|
---|
462 | /// Shows roles overview, opening with "Add role"
|
---|
463 | /// </summary>
|
---|
464 | /// <returns></returns>
|
---|
465 | public IActionResult Roles()
|
---|
466 | {
|
---|
467 | if (init())
|
---|
468 | {
|
---|
469 |
|
---|
470 | ViewBag.Title = "Roles";
|
---|
471 | UserViewModel vm = new UserViewModel(accessClient).refreshRoles();
|
---|
472 |
|
---|
473 | return View("Roles", vm);
|
---|
474 | }
|
---|
475 | else
|
---|
476 | {
|
---|
477 | return RedirectToAction("Index", "Home");
|
---|
478 | }
|
---|
479 | }
|
---|
480 | /// <summary>
|
---|
481 | /// Shows information for a specific role
|
---|
482 | /// </summary>
|
---|
483 | /// <param name="name">Role name</param>
|
---|
484 | /// <returns></returns>
|
---|
485 | public IActionResult SelectRole(string name)
|
---|
486 | {
|
---|
487 | if (init())
|
---|
488 | {
|
---|
489 |
|
---|
490 | UserViewModel vm = new UserViewModel(accessClient).refreshRoles();
|
---|
491 | if (name == "" || name == null)
|
---|
492 | {//Add role
|
---|
493 | ViewBag.Title = "Add Role";
|
---|
494 | }
|
---|
495 | else
|
---|
496 | {//Edit/view role
|
---|
497 | vm.SelectedRole = vm.getRoleByName(name);
|
---|
498 | vm.SelectedRoleEnrolled = accessClient.getEnrolled(vm.SelectedRole);
|
---|
499 |
|
---|
500 | ViewBag.title = vm.SelectedRole.Name;
|
---|
501 | }
|
---|
502 | ViewBag.Title += " - Roles";
|
---|
503 | return View("Roles", vm);
|
---|
504 | }
|
---|
505 | else
|
---|
506 | {
|
---|
507 | return RedirectToAction("Index", "Home");
|
---|
508 | }
|
---|
509 | }
|
---|
510 | /// <summary>
|
---|
511 | /// Saves a role or adds a new one
|
---|
512 | /// </summary>
|
---|
513 | /// <param name="inprolename">Role name</param>
|
---|
514 | /// <returns></returns>
|
---|
515 | [HttpPost]
|
---|
516 | public IActionResult saveRole(string inprolename)
|
---|
517 | {
|
---|
518 | if (init())
|
---|
519 | {
|
---|
520 | Access.Role role = accessClient.Roles.Find(x => x.Name == inprolename);
|
---|
521 | if (role == null)
|
---|
522 | {
|
---|
523 | role = new Access.Role();
|
---|
524 | role.Name = inprolename;
|
---|
525 | accessClient.addRole(role);
|
---|
526 | }
|
---|
527 |
|
---|
528 | accessClient.RefreshRoles();
|
---|
529 | return RedirectToAction("SelectRole", new { name = inprolename });
|
---|
530 | }
|
---|
531 | else
|
---|
532 | {
|
---|
533 | return RedirectToAction("Index", "Home");
|
---|
534 | }
|
---|
535 | }
|
---|
536 | /// <summary>
|
---|
537 | /// Delete a role
|
---|
538 | /// </summary>
|
---|
539 | /// <param name="name">Role name</param>
|
---|
540 | /// <returns></returns>
|
---|
541 | public IActionResult deleteRole(string name)
|
---|
542 | {
|
---|
543 | if (init())
|
---|
544 | {
|
---|
545 | accessClient.deleteRole(name);
|
---|
546 | return RedirectToAction("Roles");
|
---|
547 | }
|
---|
548 | else
|
---|
549 | {
|
---|
550 | return RedirectToAction("Index", "Home");
|
---|
551 | }
|
---|
552 | }
|
---|
553 | /// <summary>
|
---|
554 | /// Deletes a user from a role
|
---|
555 | /// </summary>
|
---|
556 | /// <param name="id">User id</param>
|
---|
557 | /// <param name="role">Role name</param>
|
---|
558 | /// <returns></returns>
|
---|
559 | public IActionResult deleteRoleUser(string id, string role)
|
---|
560 | {
|
---|
561 | if (init())
|
---|
562 | {
|
---|
563 | var uid = Guid.Parse(id);
|
---|
564 | UserViewModel vm = new UserViewModel(accessClient).refreshAll();
|
---|
565 |
|
---|
566 | var user = vm.getUserById(uid);
|
---|
567 | var r = vm.getRoleByName(role);
|
---|
568 | vm.message = role + " role has been deleted from " + user.FullName;
|
---|
569 | accessClient.deleteUserRole(user, r);
|
---|
570 | return RedirectToAction("SelectRole", new { name = role });
|
---|
571 | }
|
---|
572 | else
|
---|
573 | {
|
---|
574 | return RedirectToAction("Index", "Home");
|
---|
575 | }
|
---|
576 | }
|
---|
577 | #endregion
|
---|
578 | }
|
---|
579 | }
|
---|