Skip to content

Commit 9e21b38

Browse files
authored
Merge pull request #97 from jscarle/feature/restore-share-email-overloads
Restore the single-email share overloads
2 parents 64a31ad + 64c0b44 commit 9e21b38

6 files changed

Lines changed: 105 additions & 7 deletions

File tree

NEXT_RELEASE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## Breaking changes
44

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

87
## Highlights
98

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

2625
```csharp
27-
var restrictedShare = onePassword.ShareItem(item, vault, new[] { "recipient@example.com" });
26+
var restrictedShare = onePassword.ShareItem(item, vault, "recipient@example.com");
2827
var unrestrictedShare = onePassword.ShareItem(item, vault);
2928
```

OnePassword.NET.Tests/OnePasswordManagerCommandTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,33 @@ public void ShareItemWithoutEmailsOmitsEmailsFlag()
8484
}
8585

8686
[Test]
87-
public void ShareItemWithSingleEmailUsesEmailsFlag()
87+
public void ShareItemStringSingleEmailOverloadUsesEmailsFlag()
88+
{
89+
using var fakeCli = new FakeCli();
90+
var manager = fakeCli.CreateManager();
91+
92+
var result = manager.ShareItem("item-id", "vault-id", "recipient@example.com");
93+
94+
Assert.Multiple(() =>
95+
{
96+
Assert.That(result.RawResponse, Is.EqualTo("{}"));
97+
Assert.That(fakeCli.LastArguments, Does.Contain("--emails recipient@example.com"));
98+
});
99+
}
100+
101+
[Test]
102+
public void ShareItemObjectSingleEmailOverloadUsesEmailsFlag()
103+
{
104+
using var fakeCli = new FakeCli();
105+
var manager = fakeCli.CreateManager();
106+
107+
manager.ShareItem(new TestItem("item-id"), new TestVault("vault-id"), "recipient@example.com");
108+
109+
Assert.That(fakeCli.LastArguments, Does.Contain("--emails recipient@example.com"));
110+
}
111+
112+
[Test]
113+
public void ShareItemWithSingleEmailCollectionUsesEmailsFlag()
88114
{
89115
using var fakeCli = new FakeCli();
90116
var manager = fakeCli.CreateManager();

OnePassword.NET/IOnePasswordManager.Items.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ public ImmutableList<Item> SearchForItems(string? vaultId = null, bool? includeA
145145
/// <exception cref="ArgumentException">Thrown when there is an invalid argument.</exception>
146146
public void MoveItem(string itemId, string currentVaultId, string destinationVaultId);
147147

148+
/// <summary>Shares an item.</summary>
149+
/// <param name="item">The item to share.</param>
150+
/// <param name="vault">The vault that contains the item to share.</param>
151+
/// <param name="emailAddress">The recipient email address.</param>
152+
/// <param name="expiresIn">The delay before the link expires.</param>
153+
/// <param name="viewOnce">Expires the link after a single view.</param>
154+
/// <returns>The created share result.</returns>
155+
/// <exception cref="ArgumentException">Thrown when there is an invalid argument.</exception>
156+
public ItemShareResult ShareItem(IItem item, IVault vault, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null);
157+
158+
/// <summary>Shares an item.</summary>
159+
/// <param name="itemId">The ID of the item to share.</param>
160+
/// <param name="vaultId">The ID of the vault that contains the item to share.</param>
161+
/// <param name="emailAddress">The recipient email address.</param>
162+
/// <param name="expiresIn">The delay before the link expires.</param>
163+
/// <param name="viewOnce">Expires the link after a single view.</param>
164+
/// <returns>The created share result.</returns>
165+
/// <exception cref="ArgumentException">Thrown when there is an invalid argument.</exception>
166+
public ItemShareResult ShareItem(string itemId, string vaultId, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null);
167+
148168
/// <summary>Shares an item.</summary>
149169
/// <param name="item">The item to share.</param>
150170
/// <param name="vault">The vault that contains the item to share.</param>

OnePassword.NET/OnePasswordManager.Items.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,38 @@ public void MoveItem(string itemId, string currentVaultId, string destinationVau
249249
Op(command);
250250
}
251251

252+
/// <inheritdoc />
253+
public ItemShareResult ShareItem(IItem item, IVault vault, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null)
254+
{
255+
if (item is null || item.Id.Length == 0)
256+
throw new ArgumentException($"{nameof(item.Id)} cannot be empty.", nameof(item));
257+
if (vault is null || vault.Id.Length == 0)
258+
throw new ArgumentException($"{nameof(vault.Id)} cannot be empty.", nameof(vault));
259+
if (emailAddress is null || emailAddress.Length == 0)
260+
throw new ArgumentException($"{nameof(emailAddress)} cannot be empty.", nameof(emailAddress));
261+
var trimmedEmailAddress = emailAddress.Trim();
262+
if (trimmedEmailAddress.Length == 0)
263+
throw new ArgumentException($"{nameof(trimmedEmailAddress)} cannot be empty.", nameof(emailAddress));
264+
265+
return ShareItem(item.Id, vault.Id, trimmedEmailAddress, expiresIn, viewOnce);
266+
}
267+
268+
/// <inheritdoc />
269+
public ItemShareResult ShareItem(string itemId, string vaultId, string emailAddress, TimeSpan? expiresIn = null, bool? viewOnce = null)
270+
{
271+
if (itemId is null || itemId.Length == 0)
272+
throw new ArgumentException($"{nameof(itemId)} cannot be empty.", nameof(itemId));
273+
if (vaultId is null || vaultId.Length == 0)
274+
throw new ArgumentException($"{nameof(vaultId)} cannot be empty.", nameof(vaultId));
275+
if (emailAddress is null || emailAddress.Length == 0)
276+
throw new ArgumentException($"{nameof(emailAddress)} cannot be empty.", nameof(emailAddress));
277+
var trimmedEmailAddress = emailAddress.Trim();
278+
if (trimmedEmailAddress.Length == 0)
279+
throw new ArgumentException($"{nameof(trimmedEmailAddress)} cannot be empty.", nameof(emailAddress));
280+
281+
return ShareItem(itemId, vaultId, new[] { trimmedEmailAddress }, expiresIn, viewOnce);
282+
}
283+
252284
/// <inheritdoc />
253285
public ItemShareResult ShareItem(IItem item, IVault vault, IReadOnlyCollection<string>? emailAddresses = null, TimeSpan? expiresIn = null, bool? viewOnce = null)
254286
{

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ This library has no dependencies.
2020
## Breaking changes for the next x.x.x release
2121

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

2524
## Quick start
2625

@@ -144,13 +143,24 @@ Console.WriteLine(share.Url);
144143
var share = onePassword.ShareItem(
145144
item,
146145
vault,
147-
new[] { "recipient@example.com" },
146+
"recipient@example.com",
148147
expiresIn: TimeSpan.FromDays(7),
149148
viewOnce: true);
150149

151150
Console.WriteLine(share.Url);
152151
```
153152

153+
### Sharing an item with multiple email restrictions
154+
155+
```csharp
156+
var share = onePassword.ShareItem(
157+
item,
158+
vault,
159+
new[] { "recipient1@example.com", "recipient2@example.com" });
160+
161+
Console.WriteLine(share.Url);
162+
```
163+
154164
### Archiving an item
155165

156166
```csharp

docfx/docs/quick-start.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Quick start
22

3-
> 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.
3+
> Starting with the next x.x.x release, `ShareItem(...)` returns `ItemShareResult` instead of `void`.
44
55
### Creating an instance of the manager
66

@@ -122,13 +122,24 @@ Console.WriteLine(share.Url);
122122
var share = onePassword.ShareItem(
123123
item,
124124
vault,
125-
new[] { "recipient@example.com" },
125+
"recipient@example.com",
126126
expiresIn: TimeSpan.FromDays(7),
127127
viewOnce: true);
128128

129129
Console.WriteLine(share.Url);
130130
```
131131

132+
### Sharing an item with multiple email restrictions
133+
134+
```csharp
135+
var share = onePassword.ShareItem(
136+
item,
137+
vault,
138+
new[] { "recipient1@example.com", "recipient2@example.com" });
139+
140+
Console.WriteLine(share.Url);
141+
```
142+
132143
### Archiving an item
133144

134145
```csharp

0 commit comments

Comments
 (0)