Skip to content

Commit

Permalink
Auth.GetUsersForShare: use the latest API
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-keeper committed Nov 19, 2024
1 parent 4047242 commit 0106d67
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
6 changes: 3 additions & 3 deletions KeeperSdk/KeeperSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
<LangVersion>7.1</LangVersion>
<Version>1.0.6</Version>
<Version>1.0.7-beta01</Version>
<Authors>Keeper Security Inc.</Authors>
<Product>.NET Keeper Sdk</Product>
<PackageTags>keeper password manager</PackageTags>
Expand All @@ -13,8 +13,8 @@
<RepositoryType>Github</RepositoryType>
<PackageProjectUrl>https://github.com/Keeper-Security/keeper-sdk-dotnet</PackageProjectUrl>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>1.0.6.41</AssemblyVersion>
<FileVersion>1.0.6.41</FileVersion>
<AssemblyVersion>1.0.7.42</AssemblyVersion>
<FileVersion>1.0.7.42</FileVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<IncludeSymbols>true</IncludeSymbols>
Expand Down
34 changes: 0 additions & 34 deletions KeeperSdk/vault/VaultCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,40 +412,6 @@ public class GetAvailableTeamsResponse : KeeperApiResponse
public AvailableTeam[] teams;
}

/// <exclude/>
[DataContract]
public class GetShareAutoCompleteCommand : AuthenticatedCommand
{
public GetShareAutoCompleteCommand() : base("get_share_auto_complete")
{
}

[DataMember(Name = "starts_with", EmitDefaultValue = false)]
public string StartsWith { get; set; }
}

/// <exclude/>
[DataContract]
public class ShareUserInfo
{
[DataMember(Name = "email")]
public string Email { get; set; }
}

/// <exclude/>
[DataContract]
public class GetShareAutoCompleteResponse : KeeperApiResponse
{
[DataMember(Name = "shares_from_users")]
public ShareUserInfo[] SharesFromUsers;

[DataMember(Name = "shares_with_users")]
public ShareUserInfo[] SharesWithUsers;

[DataMember(Name = "group_users ")]
public ShareUserInfo[] GroupUsers;
}

/// <exclude/>
[DataContract]
public class PublicKeysCommand : AuthenticatedCommand
Expand Down
33 changes: 25 additions & 8 deletions KeeperSdk/vault/VaultOnline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Google.Protobuf;
using KeeperSecurity.Authentication;
Expand Down Expand Up @@ -337,14 +338,30 @@ public async Task<IEnumerable<TeamInfo>> GetTeamsForShare()
/// <inheritdoc/>
public async Task<ShareWithUsers> GetUsersForShare()
{
var request = new GetShareAutoCompleteCommand();
var response = await Auth.ExecuteAuthCommand<GetShareAutoCompleteCommand, GetShareAutoCompleteResponse>(request);
return new ShareWithUsers
{
SharesWith = response.SharesWithUsers?.Select(x => x.Email).ToArray() ?? new string [0],
SharesFrom = response.SharesFromUsers?.Select(x => x.Email).ToArray() ?? new string[0],
GroupUsers = response.GroupUsers?.Select(x => x.Email).ToArray() ?? new string[0]
};
var rs = await Auth.ExecuteAuthRest<GetShareObjectsRequest, GetShareObjectsResponse>("vault/get_share_objects", new GetShareObjectsRequest());

var response = new ShareWithUsers();
var directUsers = new HashSet<string>();
directUsers.UnionWith(rs.ShareRelationships.Where(x => x.Status == ShareStatus.Active).Select(x => x.Username));
response.SharesWith = directUsers.ToArray();

var familyUsers = new HashSet<string>();
familyUsers.UnionWith(rs.ShareFamilyUsers.Where(x => x.Status == ShareStatus.Active).Select(x => x.Username));
familyUsers.ExceptWith(directUsers);
familyUsers.Remove(Auth.Username);
response.SharesFrom = familyUsers.ToArray();

var uniqueUsers = new HashSet<string>();
uniqueUsers.UnionWith(rs.ShareEnterpriseUsers.Where(x => x.Status == ShareStatus.Active).Select(x => x.Username));
uniqueUsers.ExceptWith(directUsers);
uniqueUsers.ExceptWith(familyUsers);
uniqueUsers.Remove(Auth.Username);
response.GroupUsers = uniqueUsers.ToArray();

uniqueUsers.Clear();
uniqueUsers.UnionWith(rs.ShareRelationships.Where(x => x.Status == ShareStatus.Active).Select(x => x.Username));

return response;
}

/// <inheritdoc/>
Expand Down

0 comments on commit 0106d67

Please sign in to comment.