Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions NEXT_RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## Breaking changes

- `ShareItem(...)` now returns `ItemShareResult` instead of `void`.
- The single-email `ShareItem(...)` overloads were removed. Use a collection of email addresses for restricted links, or omit the collection entirely for unrestricted links.

## Highlights

Expand All @@ -24,6 +23,6 @@ onePassword.ShareItem(item, vault, "recipient@example.com");
After:

```csharp
var restrictedShare = onePassword.ShareItem(item, vault, new[] { "recipient@example.com" });
var restrictedShare = onePassword.ShareItem(item, vault, "recipient@example.com");
var unrestrictedShare = onePassword.ShareItem(item, vault);
```
28 changes: 27 additions & 1 deletion OnePassword.NET.Tests/OnePasswordManagerCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,33 @@ public void ShareItemWithoutEmailsOmitsEmailsFlag()
}

[Test]
public void ShareItemWithSingleEmailUsesEmailsFlag()
public void ShareItemStringSingleEmailOverloadUsesEmailsFlag()
{
using var fakeCli = new FakeCli();
var manager = fakeCli.CreateManager();

var result = manager.ShareItem("item-id", "vault-id", "recipient@example.com");

Assert.Multiple(() =>
{
Assert.That(result.RawResponse, Is.EqualTo("{}"));
Assert.That(fakeCli.LastArguments, Does.Contain("--emails recipient@example.com"));
});
}

[Test]
public void ShareItemObjectSingleEmailOverloadUsesEmailsFlag()
{
using var fakeCli = new FakeCli();
var manager = fakeCli.CreateManager();

manager.ShareItem(new TestItem("item-id"), new TestVault("vault-id"), "recipient@example.com");

Assert.That(fakeCli.LastArguments, Does.Contain("--emails recipient@example.com"));
}

[Test]
public void ShareItemWithSingleEmailCollectionUsesEmailsFlag()
{
using var fakeCli = new FakeCli();
var manager = fakeCli.CreateManager();
Expand Down
20 changes: 20 additions & 0 deletions OnePassword.NET/IOnePasswordManager.Items.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ public ImmutableList<Item> SearchForItems(string? vaultId = null, bool? includeA
/// <exception cref="ArgumentException">Thrown when there is an invalid argument.</exception>
public void MoveItem(string itemId, string currentVaultId, string destinationVaultId);

/// <summary>Shares an item.</summary>
/// <param name="item">The item to share.</param>
/// <param name="vault">The vault that contains the item to share.</param>
/// <param name="emailAddress">The recipient email address.</param>
/// <param name="expiresIn">The delay before the link expires.</param>
/// <param name="viewOnce">Expires the link after a single view.</param>
/// <returns>The created share result.</returns>
/// <exception cref="ArgumentException">Thrown when there is an invalid argument.</exception>
public ItemShareResult ShareItem(IItem item, IVault vault, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null);

/// <summary>Shares an item.</summary>
/// <param name="itemId">The ID of the item to share.</param>
/// <param name="vaultId">The ID of the vault that contains the item to share.</param>
/// <param name="emailAddress">The recipient email address.</param>
/// <param name="expiresIn">The delay before the link expires.</param>
/// <param name="viewOnce">Expires the link after a single view.</param>
/// <returns>The created share result.</returns>
/// <exception cref="ArgumentException">Thrown when there is an invalid argument.</exception>
public ItemShareResult ShareItem(string itemId, string vaultId, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null);

/// <summary>Shares an item.</summary>
/// <param name="item">The item to share.</param>
/// <param name="vault">The vault that contains the item to share.</param>
Expand Down
32 changes: 32 additions & 0 deletions OnePassword.NET/OnePasswordManager.Items.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,38 @@ public void MoveItem(string itemId, string currentVaultId, string destinationVau
Op(command);
}

/// <inheritdoc />
public ItemShareResult ShareItem(IItem item, IVault vault, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null)
{
if (item is null || item.Id.Length == 0)
throw new ArgumentException($"{nameof(item.Id)} cannot be empty.", nameof(item));
if (vault is null || vault.Id.Length == 0)
throw new ArgumentException($"{nameof(vault.Id)} cannot be empty.", nameof(vault));
if (emailAddress is null || emailAddress.Length == 0)
throw new ArgumentException($"{nameof(emailAddress)} cannot be empty.", nameof(emailAddress));
var trimmedEmailAddress = emailAddress.Trim();
if (trimmedEmailAddress.Length == 0)
throw new ArgumentException($"{nameof(trimmedEmailAddress)} cannot be empty.", nameof(emailAddress));

return ShareItem(item.Id, vault.Id, trimmedEmailAddress, expiresIn, viewOnce);
}

/// <inheritdoc />
public ItemShareResult ShareItem(string itemId, string vaultId, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null)
{
if (itemId is null || itemId.Length == 0)
throw new ArgumentException($"{nameof(itemId)} cannot be empty.", nameof(itemId));
if (vaultId is null || vaultId.Length == 0)
throw new ArgumentException($"{nameof(vaultId)} cannot be empty.", nameof(vaultId));
if (emailAddress is null || emailAddress.Length == 0)
throw new ArgumentException($"{nameof(emailAddress)} cannot be empty.", nameof(emailAddress));
var trimmedEmailAddress = emailAddress.Trim();
if (trimmedEmailAddress.Length == 0)
throw new ArgumentException($"{nameof(trimmedEmailAddress)} cannot be empty.", nameof(emailAddress));

return ShareItem(itemId, vaultId, new[] { trimmedEmailAddress }, expiresIn, viewOnce);
}

/// <inheritdoc />
public ItemShareResult ShareItem(IItem item, IVault vault, IReadOnlyCollection<string>? emailAddresses = null, TimeSpan? expiresIn = null, bool? viewOnce = null)
{
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ This library has no dependencies.
## Breaking changes for the next x.x.x release

- `ShareItem(...)` now returns `ItemShareResult` instead of `void`.
- The single-email `ShareItem(...)` overloads were removed. Pass a collection of email addresses for restricted links, or omit the collection entirely for unrestricted links.

## Quick start

Expand Down Expand Up @@ -144,13 +143,24 @@ Console.WriteLine(share.Url);
var share = onePassword.ShareItem(
item,
vault,
new[] { "recipient@example.com" },
"recipient@example.com",
expiresIn: TimeSpan.FromDays(7),
viewOnce: true);

Console.WriteLine(share.Url);
```

### Sharing an item with multiple email restrictions

```csharp
var share = onePassword.ShareItem(
item,
vault,
new[] { "recipient1@example.com", "recipient2@example.com" });

Console.WriteLine(share.Url);
```

### Archiving an item

```csharp
Expand Down
15 changes: 13 additions & 2 deletions docfx/docs/quick-start.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Quick start

> Starting with the next x.x.x release, `ShareItem(...)` returns `ItemShareResult` and the single-email overloads are removed. Pass a collection of email addresses for restricted links, or omit the collection entirely for unrestricted links.
> Starting with the next x.x.x release, `ShareItem(...)` returns `ItemShareResult` instead of `void`.

### Creating an instance of the manager

Expand Down Expand Up @@ -122,13 +122,24 @@ Console.WriteLine(share.Url);
var share = onePassword.ShareItem(
item,
vault,
new[] { "recipient@example.com" },
"recipient@example.com",
expiresIn: TimeSpan.FromDays(7),
viewOnce: true);

Console.WriteLine(share.Url);
```

### Sharing an item with multiple email restrictions

```csharp
var share = onePassword.ShareItem(
item,
vault,
new[] { "recipient1@example.com", "recipient2@example.com" });

Console.WriteLine(share.Url);
```

### Archiving an item

```csharp
Expand Down
Loading