diff --git a/src/Atlassian.Stash/Api/Groups.cs b/src/Atlassian.Stash/Api/Groups.cs index 28c73d9..3a47c15 100644 --- a/src/Atlassian.Stash/Api/Groups.cs +++ b/src/Atlassian.Stash/Api/Groups.cs @@ -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; @@ -35,6 +36,15 @@ public async Task> Get(string filter, RequestOptions requ return response; } + public async Task> GetUsers(string name, RequestOptions requestOptions = null) + { + var requestUrl = UrlBuilder.FormatRestApiUrl(USERS_IN_GROUP, requestOptions, name); + + var response = await _httpWorker.GetAsync>(requestUrl).ConfigureAwait(false); + + return response; + } + public async Task Create(string name) { string requestUrl = UrlBuilder.FormatRestApiUrl(SINGLE_GROUP, null, name); diff --git a/src/Atlassian.Stash/Entities/Permission.cs b/src/Atlassian.Stash/Entities/Permission.cs index 1b5ffbd..12d2c26 100644 --- a/src/Atlassian.Stash/Entities/Permission.cs +++ b/src/Atlassian.Stash/Entities/Permission.cs @@ -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")] @@ -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}"; + } + } } } diff --git a/src/Atlassian.Stash/Entities/User.cs b/src/Atlassian.Stash/Entities/User.cs index f51dc58..364bc79 100644 --- a/src/Atlassian.Stash/Entities/User.cs +++ b/src/Atlassian.Stash/Entities/User.cs @@ -21,5 +21,8 @@ public class User [JsonProperty("type")] public string Type { get; set; } + + [JsonProperty("lastAuthenticationTimestamp")] + public long LastAuthenticationTimestamp { get; set; } } } diff --git a/test/Atlassian.Stash.IntegrationTests/StashClientTester.cs b/test/Atlassian.Stash.IntegrationTests/StashClientTester.cs index 85a48a6..b276c40 100644 --- a/test/Atlassian.Stash.IntegrationTests/StashClientTester.cs +++ b/test/Atlassian.Stash.IntegrationTests/StashClientTester.cs @@ -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)); + Assert.IsTrue(projects.Any()); + } + [TestMethod] public async Task Can_GetAllProjects_WithRequestOptions() {