Skip to content

Commit

Permalink
add getusers in group, and LastAuthenticationTimestamp in user (#74)
Browse files Browse the repository at this point in the history
* add  getusers in group, and LastAuthenticationTimestamp in user

* code clean

Co-authored-by: Jorge Costa <jorge.costa@trimble.com>
  • Loading branch information
jmecosta and jmecosta authored Jan 20, 2021
1 parent e714e5f commit cab6371
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Atlassian.Stash/Api/Groups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Atlassian.Stash.Api
public class Groups
{
private const string MANY_GROUPS = "rest/api/1.0/admin/groups";
private const string USERS_IN_GROUP = "rest/api/1.0/admin/groups/more-members?context={0}";
private const string SINGLE_GROUP = MANY_GROUPS + "?name={0}";

private HttpCommunicationWorker _httpWorker;
Expand Down Expand Up @@ -35,6 +36,15 @@ public async Task<ResponseWrapper<Group>> Get(string filter, RequestOptions requ
return response;
}

public async Task<ResponseWrapper<User>> GetUsers(string name, RequestOptions requestOptions = null)
{
var requestUrl = UrlBuilder.FormatRestApiUrl(USERS_IN_GROUP, requestOptions, name);

var response = await _httpWorker.GetAsync<ResponseWrapper<User>>(requestUrl).ConfigureAwait(false);

return response;
}

public async Task<Group> Create(string name)
{
string requestUrl = UrlBuilder.FormatRestApiUrl(SINGLE_GROUP, null, name);
Expand Down
28 changes: 27 additions & 1 deletion src/Atlassian.Stash/Entities/Permission.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Newtonsoft.Json;
using System.Diagnostics;

using Newtonsoft.Json;

namespace Atlassian.Stash.Entities
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Permission
{
[JsonProperty("group")]
Expand All @@ -12,5 +15,28 @@ public class Permission

[JsonProperty("permission")]
public string permission { get; set; }

private string DebuggerDisplay
{
get
{
if (Group != null && User != null)
{
return $"User: {User.Email} : {Group.Name} => {permission}";
}

if (Group == null)
{
return $"User: {User.Name} : {User.Email} => {permission}";
}

if (User == null)
{
return $"Group: {Group.Name} => {permission}";
}

return $"Permission: {permission}";
}
}
}
}
3 changes: 3 additions & 0 deletions src/Atlassian.Stash/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ public class User

[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("lastAuthenticationTimestamp")]
public long LastAuthenticationTimestamp { get; set; }
}
}
11 changes: 11 additions & 0 deletions test/Atlassian.Stash.IntegrationTests/StashClientTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public async Task Can_GetAllProjects()
Assert.IsTrue(projects.Any());
}

[TestMethod]
public async Task Can_GetAllUsers()
{
var response = await stashClient.Groups.GetUsers(EXISTING_GROUP, new RequestOptions { Limit = 1, Start = 0 });
var projects = response.Values;

Assert.IsNotNull(projects);
Assert.IsInstanceOfType(projects, typeof(IEnumerable<User>));
Assert.IsTrue(projects.Any());
}

[TestMethod]
public async Task Can_GetAllProjects_WithRequestOptions()
{
Expand Down

0 comments on commit cab6371

Please sign in to comment.