[13860] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[13847] | 22 | using HeuristicLab.Clients.Hive.WebJobManager.Models;
|
---|
[13862] | 23 | using HeuristicLab.Clients.Hive.WebJobManager.Services.Imports;
|
---|
[13741] | 24 | using System;
|
---|
[13740] | 25 | using System.Collections.Generic;
|
---|
| 26 | using System.Linq;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Clients.Hive.WebJobManager.ViewModels.User
|
---|
| 29 | {
|
---|
[13805] | 30 | /// <summary>
|
---|
| 31 | /// ViewModel containing User/Group/Role data
|
---|
| 32 | /// </summary>
|
---|
[13862] | 33 | public class UserViewModel : MasterVM
|
---|
[13740] | 34 | {
|
---|
[13741] | 35 | public AccessAdministrationClient accessClient { get; set; }
|
---|
| 36 | public List<Access.User> users { get; set; }
|
---|
| 37 | public List<Access.Role> roles { get; set; }
|
---|
| 38 | public List<Access.UserGroup> ugroups { get; set; }
|
---|
[13740] | 39 |
|
---|
[13741] | 40 | public Access.User SelectedUser { get; set; }
|
---|
[13742] | 41 | public List<Access.UserGroup> SelectedUserSubscriptions { get; set; }
|
---|
[13754] | 42 | public List<Access.Role> SelectedUserRoles { get; set; }
|
---|
[13742] | 43 | public Access.UserGroup SelectedGroup { get; set; }
|
---|
| 44 | public List<Access.UserGroupBase> SelectedGroupMembers { get; set; }
|
---|
[13754] | 45 | public Access.Role SelectedRole { get; set; }
|
---|
| 46 | public List<Access.UserGroupBase> SelectedRoleEnrolled { get; set; }
|
---|
[13740] | 47 |
|
---|
[13805] | 48 | /// <summary>
|
---|
| 49 | /// Initialize viewmodel and set up connection
|
---|
| 50 | /// </summary>
|
---|
| 51 | /// <param name="ac">AccessAdminClient for connection</param>
|
---|
[13862] | 52 | public UserViewModel(AccessAdministrationClient ac, HiveWebUser hwu) : base(hwu)
|
---|
[13740] | 53 | {
|
---|
[13741] | 54 | users = new List<Access.User>();
|
---|
| 55 | accessClient = ac;
|
---|
[13754] | 56 |
|
---|
[13741] | 57 | SelectedUser = new Access.User();
|
---|
[13742] | 58 | SelectedGroup = new Access.UserGroup();
|
---|
[13754] | 59 | SelectedRole = new Access.Role();
|
---|
| 60 | SelectedRole.Name = "";
|
---|
| 61 |
|
---|
[13742] | 62 | SelectedUserSubscriptions = new List<Access.UserGroup>();
|
---|
[13754] | 63 | SelectedUserRoles = new List<Access.Role>();
|
---|
[13742] | 64 | SelectedGroupMembers = new List<Access.UserGroupBase>();
|
---|
[13741] | 65 |
|
---|
[13742] | 66 |
|
---|
[13740] | 67 | }
|
---|
[13805] | 68 | /// <summary>
|
---|
| 69 | /// Refreshes Users, Groups and Roles
|
---|
| 70 | /// </summary>
|
---|
| 71 | /// <returns></returns>
|
---|
[13754] | 72 | public UserViewModel refreshAll()
|
---|
| 73 | {
|
---|
| 74 | refreshUsers();
|
---|
| 75 | refreshGroups();
|
---|
| 76 | refreshRoles();
|
---|
| 77 | return this;
|
---|
| 78 | }
|
---|
[13805] | 79 | /// <summary>
|
---|
| 80 | /// Refreshes only the Users
|
---|
| 81 | /// </summary>
|
---|
| 82 | /// <returns></returns>
|
---|
[13741] | 83 | public UserViewModel refreshUsers()
|
---|
| 84 | {
|
---|
| 85 | accessClient.RefreshUsers();
|
---|
| 86 | users = accessClient.Users.ToList();
|
---|
| 87 | return this;
|
---|
| 88 | }
|
---|
[13805] | 89 | /// <summary>
|
---|
| 90 | /// Refreshes only the Roles
|
---|
| 91 | /// </summary>
|
---|
| 92 | /// <returns></returns>
|
---|
[13741] | 93 | public UserViewModel refreshRoles()
|
---|
| 94 | {
|
---|
| 95 | accessClient.RefreshRoles();
|
---|
| 96 | roles = accessClient.Roles.ToList();
|
---|
| 97 | return this;
|
---|
| 98 | }
|
---|
[13805] | 99 | /// <summary>
|
---|
| 100 | /// Refreshes only the User Groups
|
---|
| 101 | /// </summary>
|
---|
| 102 | /// <returns></returns>
|
---|
[13741] | 103 | public UserViewModel refreshGroups()
|
---|
| 104 | {
|
---|
| 105 | accessClient.RefreshUserGroups();
|
---|
| 106 | ugroups= accessClient.Groups.ToList();
|
---|
| 107 | return this;
|
---|
| 108 | }
|
---|
[13805] | 109 | /// <summary>
|
---|
| 110 | /// Returns a user by its Id
|
---|
| 111 | /// </summary>
|
---|
| 112 | /// <param name="id">User Id</param>
|
---|
| 113 | /// <returns></returns>
|
---|
[13741] | 114 | public Access.User getUserById(Guid id)
|
---|
| 115 | {
|
---|
| 116 | return users.Find(x => x.Id == id);
|
---|
| 117 | }
|
---|
[13805] | 118 | /// <summary>
|
---|
| 119 | /// Returns a group by its Id
|
---|
| 120 | /// </summary>
|
---|
| 121 | /// <param name="id">Group id</param>
|
---|
| 122 | /// <returns></returns>
|
---|
[13742] | 123 | public Access.UserGroup getGroupById(Guid id)
|
---|
| 124 | {
|
---|
| 125 | return ugroups.Find(x => x.Id == id);
|
---|
| 126 | }
|
---|
[13805] | 127 | /// <summary>
|
---|
| 128 | /// Returns a role by its name
|
---|
| 129 | /// </summary>
|
---|
| 130 | /// <param name="name">Role name</param>
|
---|
| 131 | /// <returns></returns>
|
---|
[13754] | 132 | public Access.Role getRoleByName(string name)
|
---|
| 133 | {
|
---|
| 134 | return roles.Find(x => x.Name == name);
|
---|
| 135 | }
|
---|
[13740] | 136 | }
|
---|
| 137 | }
|
---|