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 |
|
---|
22 | using HeuristicLab.Clients.Access.Administration;
|
---|
23 | using HeuristicLab.Clients.Hive.WebJobManager.Models;
|
---|
24 | using System;
|
---|
25 | using System.Collections.Generic;
|
---|
26 | using System.Linq;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Clients.Hive.WebJobManager.ViewModels.User
|
---|
29 | {
|
---|
30 | /// <summary>
|
---|
31 | /// ViewModel containing User/Group/Role data
|
---|
32 | /// </summary>
|
---|
33 | public class UserViewModel
|
---|
34 | {
|
---|
35 | public HiveWebUser currentUser { get; set; }
|
---|
36 | public string message { get; set; }
|
---|
37 | public AccessAdministrationClient accessClient { get; set; }
|
---|
38 | public List<Access.User> users { get; set; }
|
---|
39 | public List<Access.Role> roles { get; set; }
|
---|
40 | public List<Access.UserGroup> ugroups { get; set; }
|
---|
41 |
|
---|
42 | public Access.User SelectedUser { get; set; }
|
---|
43 | public List<Access.UserGroup> SelectedUserSubscriptions { get; set; }
|
---|
44 | public List<Access.Role> SelectedUserRoles { get; set; }
|
---|
45 | public Access.UserGroup SelectedGroup { get; set; }
|
---|
46 | public List<Access.UserGroupBase> SelectedGroupMembers { get; set; }
|
---|
47 | public Access.Role SelectedRole { get; set; }
|
---|
48 | public List<Access.UserGroupBase> SelectedRoleEnrolled { get; set; }
|
---|
49 |
|
---|
50 | /// <summary>
|
---|
51 | /// Initialize viewmodel and set up connection
|
---|
52 | /// </summary>
|
---|
53 | /// <param name="ac">AccessAdminClient for connection</param>
|
---|
54 | public UserViewModel(AccessAdministrationClient ac, HiveWebUser hwu)
|
---|
55 | {
|
---|
56 | currentUser = hwu;
|
---|
57 | users = new List<Access.User>();
|
---|
58 | accessClient = ac;
|
---|
59 |
|
---|
60 | SelectedUser = new Access.User();
|
---|
61 | SelectedGroup = new Access.UserGroup();
|
---|
62 | SelectedRole = new Access.Role();
|
---|
63 | SelectedRole.Name = "";
|
---|
64 |
|
---|
65 | SelectedUserSubscriptions = new List<Access.UserGroup>();
|
---|
66 | SelectedUserRoles = new List<Access.Role>();
|
---|
67 | SelectedGroupMembers = new List<Access.UserGroupBase>();
|
---|
68 |
|
---|
69 |
|
---|
70 | }
|
---|
71 | /// <summary>
|
---|
72 | /// Refreshes Users, Groups and Roles
|
---|
73 | /// </summary>
|
---|
74 | /// <returns></returns>
|
---|
75 | public UserViewModel refreshAll()
|
---|
76 | {
|
---|
77 | refreshUsers();
|
---|
78 | refreshGroups();
|
---|
79 | refreshRoles();
|
---|
80 | return this;
|
---|
81 | }
|
---|
82 | /// <summary>
|
---|
83 | /// Refreshes only the Users
|
---|
84 | /// </summary>
|
---|
85 | /// <returns></returns>
|
---|
86 | public UserViewModel refreshUsers()
|
---|
87 | {
|
---|
88 | accessClient.RefreshUsers();
|
---|
89 | users = accessClient.Users.ToList();
|
---|
90 | return this;
|
---|
91 | }
|
---|
92 | /// <summary>
|
---|
93 | /// Refreshes only the Roles
|
---|
94 | /// </summary>
|
---|
95 | /// <returns></returns>
|
---|
96 | public UserViewModel refreshRoles()
|
---|
97 | {
|
---|
98 | accessClient.RefreshRoles();
|
---|
99 | roles = accessClient.Roles.ToList();
|
---|
100 | return this;
|
---|
101 | }
|
---|
102 | /// <summary>
|
---|
103 | /// Refreshes only the User Groups
|
---|
104 | /// </summary>
|
---|
105 | /// <returns></returns>
|
---|
106 | public UserViewModel refreshGroups()
|
---|
107 | {
|
---|
108 | accessClient.RefreshUserGroups();
|
---|
109 | ugroups= accessClient.Groups.ToList();
|
---|
110 | return this;
|
---|
111 | }
|
---|
112 | /// <summary>
|
---|
113 | /// Returns a user by its Id
|
---|
114 | /// </summary>
|
---|
115 | /// <param name="id">User Id</param>
|
---|
116 | /// <returns></returns>
|
---|
117 | public Access.User getUserById(Guid id)
|
---|
118 | {
|
---|
119 | return users.Find(x => x.Id == id);
|
---|
120 | }
|
---|
121 | /// <summary>
|
---|
122 | /// Returns a group by its Id
|
---|
123 | /// </summary>
|
---|
124 | /// <param name="id">Group id</param>
|
---|
125 | /// <returns></returns>
|
---|
126 | public Access.UserGroup getGroupById(Guid id)
|
---|
127 | {
|
---|
128 | return ugroups.Find(x => x.Id == id);
|
---|
129 | }
|
---|
130 | /// <summary>
|
---|
131 | /// Returns a role by its name
|
---|
132 | /// </summary>
|
---|
133 | /// <param name="name">Role name</param>
|
---|
134 | /// <returns></returns>
|
---|
135 | public Access.Role getRoleByName(string name)
|
---|
136 | {
|
---|
137 | return roles.Find(x => x.Name == name);
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|