Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit d14fd7a

Browse files
committed
Add UserApi.
1 parent 575cb79 commit d14fd7a

File tree

4 files changed

+445
-0
lines changed

4 files changed

+445
-0
lines changed
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
// Licensed to the Symphony Software Foundation (SSF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SSF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
namespace SymphonyOSS.RestApiClient.Api.PodApi
19+
{
20+
using System.Collections.Generic;
21+
using Authentication;
22+
using Generated.OpenApi.PodApi.Client;
23+
using Generated.OpenApi.PodApi.Model;
24+
25+
/// <summary>
26+
/// Provides methods for managing pod users, by encapsulating
27+
/// <see cref="Generated.OpenApi.PodApi.Api.UserApi"/>,
28+
/// adding authentication token management and a custom execution strategy.
29+
/// </summary>
30+
public class UserApi
31+
{
32+
private readonly Generated.OpenApi.PodApi.Api.IUserApi _userApi;
33+
34+
private readonly IAuthTokens _authTokens;
35+
36+
private readonly IApiExecutor _apiExecutor;
37+
38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="UserApi" /> class.
40+
/// See <see cref="Factories.PodApiFactory"/> for conveniently constructing
41+
/// an instance.
42+
/// </summary>
43+
/// <param name="authTokens">Authentication tokens.</param>
44+
/// <param name="configuration">Api configuration.</param>
45+
/// <param name="apiExecutor">Execution strategy.</param>
46+
public UserApi(IAuthTokens authTokens, Configuration configuration, IApiExecutor apiExecutor)
47+
{
48+
_userApi = new Generated.OpenApi.PodApi.Api.UserApi(configuration);
49+
_authTokens = authTokens;
50+
_apiExecutor = apiExecutor;
51+
}
52+
53+
/// <summary>
54+
/// Create a new user.
55+
/// </summary>
56+
/// <param name="payload"></param>
57+
/// <returns>User details.</returns>
58+
public UserDetail CreateUser(UserCreate payload)
59+
{
60+
return _apiExecutor.Execute(_userApi.V1AdminUserCreatePost, _authTokens.SessionToken, payload);
61+
}
62+
63+
/// <summary>
64+
/// Find a user based on attributes.
65+
/// </summary>
66+
/// <param name="payload"></param>
67+
/// <returns>List of users.</returns>
68+
public UserList FindUser(UserFilter payload)
69+
{
70+
return _apiExecutor.Execute(_userApi.V1AdminUserFindPost, _authTokens.SessionToken, payload);
71+
}
72+
73+
/// <summary>
74+
/// Retreive a list of all users in the company (pod).
75+
/// </summary>
76+
/// <returns>The list of user IDs.</returns>
77+
public UserIdList GetAllUsers()
78+
{
79+
return _apiExecutor.Execute(_userApi.V1AdminUserListGet, _authTokens.SessionToken);
80+
}
81+
82+
/// <summary>
83+
/// Send a password reset email to the email address of a particular user.
84+
/// </summary>
85+
/// <param name="uid">User ID.</param>
86+
/// <returns>Success response.</returns>
87+
public SuccessResponse ResetPassword(long uid)
88+
{
89+
return _apiExecutor.Execute(
90+
_userApi.V1AdminUserUidActionPasswordResetPost,
91+
_authTokens.SessionToken,
92+
(long?)uid,
93+
new PasswordReset(PasswordReset.TypeEnum.Email));
94+
}
95+
96+
/// <summary>
97+
/// Get the URL of the avatar of a particular user.
98+
/// </summary>
99+
/// <param name="uid">User ID.</param>
100+
/// <returns>List of avatars.</returns>
101+
public AvatarList GetAvatar(long uid)
102+
{
103+
return _apiExecutor.Execute(_userApi.V1AdminUserUidAvatarGet, _authTokens.SessionToken, (long?)uid);
104+
}
105+
106+
/// <summary>
107+
/// Update the avatar of a particular user.
108+
/// </summary>
109+
/// <param name="uid">User ID.</param>
110+
/// <param name="image">Base64 encoded image.</param>
111+
/// <returns>Success response.</returns>
112+
public SuccessResponse UpdateAvatar(long uid, string image)
113+
{
114+
return _apiExecutor.Execute(_userApi.V1AdminUserUidAvatarUpdatePost, _authTokens.SessionToken, (long?)uid, new AvatarUpdate(image));
115+
}
116+
117+
/// <summary>
118+
/// Get the delegates assigned to a user.
119+
/// </summary>
120+
/// <param name="uid">User ID.</param>
121+
/// <returns>List of delegates.</returns>
122+
public IntegerList GetDelegates(long uid)
123+
{
124+
return _apiExecutor.Execute(_userApi.V1AdminUserUidDelegatesGet, _authTokens.SessionToken, (long?)uid);
125+
}
126+
127+
/// <summary>
128+
/// Update the delegates assigned to a user.
129+
/// </summary>
130+
/// <param name="uid">User ID.</param>
131+
/// <param name="payload"></param>
132+
/// <returns>Success response.</returns>
133+
public SuccessResponse UpdateDelegates(long uid, DelegateAction payload)
134+
{
135+
return _apiExecutor.Execute(_userApi.V1AdminUserUidDelegatesUpdatePost, _authTokens.SessionToken, (long?)uid, payload);
136+
}
137+
138+
/// <summary>
139+
/// Get the disclaimer assigned to a user.
140+
/// </summary>
141+
/// <param name="uid">User ID.</param>
142+
/// <returns>The disclaimer.</returns>
143+
public Disclaimer GetDisclaimer(long uid)
144+
{
145+
return _apiExecutor.Execute(_userApi.V1AdminUserUidDisclaimerGet, _authTokens.SessionToken, (long?)uid);
146+
}
147+
148+
/// <summary>
149+
/// Assign a disclaimer to a user.
150+
/// </summary>
151+
/// <param name="uid">User ID.</param>
152+
/// <param name="disclaimer">The disclaimer.</param>
153+
/// <returns>Success response.</returns>
154+
public SuccessResponse UpdateDisclaimer(long uid, string disclaimer)
155+
{
156+
return _apiExecutor.Execute(_userApi.V1AdminUserUidDisclaimerUpdatePost, _authTokens.SessionToken, (long?)uid, new StringId(disclaimer));
157+
}
158+
159+
/// <summary>
160+
/// Get the list of feature entitlements enabled for a particular user.
161+
/// </summary>
162+
/// <param name="uid">User ID.</param>
163+
/// <returns>List of features.</returns>
164+
public FeatureList GetFeatures(long uid)
165+
{
166+
return _apiExecutor.Execute(_userApi.V1AdminUserUidFeaturesGet, _authTokens.SessionToken, (long?)uid);
167+
}
168+
169+
/// <summary>
170+
/// Update the list of feature entitlements for a particular user.
171+
/// </summary>
172+
/// <param name="uid">User ID.</param>
173+
/// <param name="features">List of features.</param>
174+
/// <returns>Success response.</returns>
175+
public SuccessResponse UpdateFeatures(long uid, List<Feature> features)
176+
{
177+
var payload = new FeatureList();
178+
payload.AddRange(features);
179+
return _apiExecutor.Execute(_userApi.V1AdminUserUidFeaturesUpdatePost, _authTokens.SessionToken, (long?)uid, payload);
180+
}
181+
182+
/// <summary>
183+
/// Retreive user details for a particular user.
184+
/// </summary>
185+
/// <param name="uid">User ID.</param>
186+
/// <returns>User details.</returns>
187+
public UserDetail GetDetails(long uid)
188+
{
189+
return _apiExecutor.Execute(_userApi.V1AdminUserUidGet, _authTokens.SessionToken, (long?)uid);
190+
}
191+
192+
/// <summary>
193+
/// Get the list of roles assigned to a user.
194+
/// </summary>
195+
/// <param name="uid">User ID.</param>
196+
/// <returns>List of roles.</returns>
197+
public RoleList GetRoles(long uid)
198+
{
199+
return _apiExecutor.Execute(_userApi.V1AdminUserUidRolesGet, _authTokens.SessionToken, (long?)uid);
200+
}
201+
202+
/// <summary>
203+
/// Update the list of roles assigned to a user.
204+
/// </summary>
205+
/// <param name="uid">User ID.</param>
206+
/// <param name="roles">List of roles.</param>
207+
/// <returns>Success response.</returns>
208+
public SuccessResponse UpdateRoles(long uid, List<string> roles)
209+
{
210+
var payload = new StringList();
211+
payload.AddRange(roles);
212+
return _apiExecutor.Execute(_userApi.V1AdminUserUidRolesUpdatePost, _authTokens.SessionToken, (long?)uid, payload);
213+
}
214+
215+
/// <summary>
216+
/// Get the status, active or inactive, for a particular user.
217+
/// </summary>
218+
/// <param name="uid">User ID.</param>
219+
/// <returns>User status.</returns>
220+
public UserStatus GetStatus(long uid)
221+
{
222+
return _apiExecutor.Execute(_userApi.V1AdminUserUidStatusGet, _authTokens.SessionToken, (long?)uid);
223+
}
224+
225+
/// <summary>
226+
/// Update the status of a particular user.
227+
/// </summary>
228+
/// <param name="uid">User ID.</param>
229+
/// <param name="payload"></param>
230+
/// <returns>Success response.</returns>
231+
public SuccessResponse UpdateStatus(long uid, UserStatus payload)
232+
{
233+
return _apiExecutor.Execute(_userApi.V1AdminUserUidStatusUpdatePost, _authTokens.SessionToken, (long?)uid, payload);
234+
}
235+
236+
/// <summary>
237+
/// Update an existing user.
238+
/// </summary>
239+
/// <param name="uid">User ID.</param>
240+
/// <param name="payload"></param>
241+
/// <returns>User details.</returns>
242+
public UserDetail UpdateUser(long uid, UserAttributes payload)
243+
{
244+
return _apiExecutor.Execute(_userApi.V1AdminUserUidUpdatePost, _authTokens.SessionToken, (long?)uid, payload);
245+
}
246+
}
247+
}

src/SymphonyOSS.RestApiClient/SymphonyOSS.RestApiClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<Compile Include="Api\IRetryStrategy.cs" />
5858
<Compile Include="Api\PodApi\RoomMembershipApi.cs" />
5959
<Compile Include="Api\PodApi\SecurityApi.cs" />
60+
<Compile Include="Api\PodApi\UserApi.cs" />
6061
<Compile Include="Api\RefreshTokensRetryStrategy.cs" />
6162
<Compile Include="Api\PodApi\MessageSuppressionApi.cs" />
6263
<Compile Include="Api\PodApi\SessionApi.cs" />

test/SymphonyOSS.RestApiClient.Tests/SymphonyOSS.RestApiClient.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<Compile Include="SessionManagerTest.cs" />
105105
<Compile Include="StreamsApiTest.cs" />
106106
<Compile Include="SystemApiTest.cs" />
107+
<Compile Include="UserApiTest.cs" />
107108
<Compile Include="UsersApiTest.cs" />
108109
<Compile Include="UtilApiTest.cs" />
109110
</ItemGroup>

0 commit comments

Comments
 (0)