Skip to content

Commit

Permalink
Merge pull request #14888 from iterate-ch/feature/GH-14197
Browse files Browse the repository at this point in the history
Fix #14197
  • Loading branch information
dkocher authored Aug 16, 2023
2 parents 7745657 + 0e43674 commit 21510f4
Show file tree
Hide file tree
Showing 139 changed files with 1,144 additions and 442 deletions.
11 changes: 2 additions & 9 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,18 @@
<PackageReference Update="Microsoft.Build.Utilities.Core" Version="17.1.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Update="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
<PackageReference Update="Microsoft.Windows.CsWin32" Version="0.1.647-beta" />
<PackageReference Update="Microsoft.Windows.SDK.Contracts" Version="10.0.22000.196" />
<PackageReference Update="NUnit" Version="3.13.3" />
<PackageReference Update="NUnit.Console" Version="3.16.0" />
<PackageReference Update="NUnit.ConsoleRunner" Version="3.16.0" GeneratePathProperty="true" />
<PackageReference Update="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Update="ObjectListView.Official" Version="2.9.1" />
<PackageReference Update="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.2.3" />
<PackageReference Update="ReactiveUI.WPF" Version="17.1.50" />
<PackageReference Update="StructureMap" Version="2.6.4.1" />
<PackageReference Update="System.Memory" Version="4.5.5" />

<!-- Build-Supports -->
<PackageReference Update="Microsoft.Windows.CsWin32" Version="0.1.647-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Update="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.2.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

<GlobalPackageReference Include="MSBuildTasks" Version="1.5.0.235" GeneratePathProperty="true" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import ch.cyberduck.core.URIEncoder;
import ch.cyberduck.core.UserDateFormatterFactory;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Share;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
Expand All @@ -38,7 +38,7 @@

import synapticloop.b2.exception.B2ApiException;

public class B2AuthorizedUrlProvider implements PromptUrlProvider<Void, Void> {
public class B2AuthorizedUrlProvider implements Share<Void, Void> {
private static final Logger log = LogManager.getLogger(B2AuthorizedUrlProvider.class);

private final PathContainerService containerService
Expand All @@ -62,10 +62,10 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final Void none, final PasswordCallback callback) throws BackgroundException {
final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(),
URIEncoder.encode(containerService.getContainer(file).getName()),
URIEncoder.encode(containerService.getKey(file)));
URIEncoder.encode(containerService.getContainer(file).getName()),
URIEncoder.encode(containerService.getKey(file)));
try {
if(log.isDebugEnabled()) {
log.debug(String.format("Create download authorization for %s", file));
Expand All @@ -91,7 +91,7 @@ public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final Pass
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Void none, final PasswordCallback callback) throws BackgroundException {
return DescriptiveUrl.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public <T> T _getFeature(final Class<T> type) {
if(type == UrlProvider.class) {
return (T) new B2UrlProvider(this);
}
if(type == PromptUrlProvider.class) {
if(type == Share.class) {
return (T) new B2AuthorizedUrlProvider(this, fileid);
}
if(type == Find.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import ch.cyberduck.core.DisabledPasswordCallback;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Share;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;

Expand All @@ -43,8 +43,8 @@ public void testToUrl() throws Exception {
final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
new B2TouchFeature(session, fileid).touch(test, new TransferStatus());
final B2AuthorizedUrlProvider provider = new B2AuthorizedUrlProvider(session, fileid);
assertFalse(provider.isSupported(bucket, PromptUrlProvider.Type.download));
final DescriptiveUrl url = provider.toDownloadUrl(test, null, new DisabledPasswordCallback());
assertFalse(provider.isSupported(bucket, Share.Type.download));
final DescriptiveUrl url = provider.toDownloadUrl(test, Share.Sharee.world, null, new DisabledPasswordCallback());
assertNotEquals(DescriptiveUrl.EMPTY, url);
assertNotNull(url.getUrl());
new B2DeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
Expand Down
4 changes: 2 additions & 2 deletions box/src/main/java/ch/cyberduck/core/box/BoxSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Move;
import ch.cyberduck.core.features.MultipartWrite;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Share;
import ch.cyberduck.core.features.Read;
import ch.cyberduck.core.features.Touch;
import ch.cyberduck.core.features.Upload;
Expand Down Expand Up @@ -136,7 +136,7 @@ public <T> T _getFeature(final Class<T> type) {
if(type == AttributesFinder.class) {
return (T) new BoxAttributesFinderFeature(this, fileid);
}
if(type == PromptUrlProvider.class) {
if(type == Share.class) {
return (T) new BoxShareFeature(this, fileid);
}
return super._getFeature(type);
Expand Down
8 changes: 4 additions & 4 deletions box/src/main/java/ch/cyberduck/core/box/BoxShareFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.exception.LoginCanceledException;
import ch.cyberduck.core.exception.UnsupportedException;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Share;

import java.net.URI;
import java.text.MessageFormat;

public class BoxShareFeature implements PromptUrlProvider {
public class BoxShareFeature implements Share {

private final BoxSession session;
private final BoxFileidProvider fileid;
Expand All @@ -60,15 +60,15 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
if(file.isDirectory()) {
return this.createFolderSharedLink(file, callback);
}
return this.createFileSharedLink(file, callback);
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
throw new UnsupportedException();
}

Expand Down
14 changes: 7 additions & 7 deletions box/src/test/java/ch/cyberduck/core/box/BoxShareFeatureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Home;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Share;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;

Expand All @@ -41,9 +41,9 @@ public void testFolder() throws Exception {
final Path directory = new BoxDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(),
EnumSet.of(Path.Type.directory)), new TransferStatus());
final BoxShareFeature feature = new BoxShareFeature(session, fileid);
assertTrue(feature.isSupported(directory, PromptUrlProvider.Type.download));
assertFalse(feature.isSupported(directory, PromptUrlProvider.Type.upload));
assertNotNull(feature.toDownloadUrl(directory, null, new DisabledPasswordCallback()).getUrl());
assertTrue(feature.isSupported(directory, Share.Type.download));
assertFalse(feature.isSupported(directory, Share.Type.upload));
assertNotNull(feature.toDownloadUrl(directory, Share.Sharee.world, null, new DisabledPasswordCallback()).getUrl());
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(directory), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}

Expand All @@ -53,9 +53,9 @@ public void testFile() throws Exception {
final Path test = new BoxTouchFeature(session, fileid).touch(
new Path(Home.ROOT, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final BoxShareFeature feature = new BoxShareFeature(session, fileid);
assertTrue(feature.isSupported(test, PromptUrlProvider.Type.download));
assertFalse(feature.isSupported(test, PromptUrlProvider.Type.upload));
assertNotNull(feature.toDownloadUrl(test, null, new DisabledPasswordCallback()).getUrl());
assertTrue(feature.isSupported(test, Share.Type.download));
assertFalse(feature.isSupported(test, Share.Type.upload));
assertNotNull(feature.toDownloadUrl(test, Share.Sharee.world, null, new DisabledPasswordCallback()).getUrl());
new BoxDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}
}
4 changes: 2 additions & 2 deletions brick/src/main/java/ch/cyberduck/core/brick/BrickSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import ch.cyberduck.core.features.Lock;
import ch.cyberduck.core.features.Move;
import ch.cyberduck.core.features.MultipartWrite;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Share;
import ch.cyberduck.core.features.Read;
import ch.cyberduck.core.features.Timestamp;
import ch.cyberduck.core.features.Touch;
Expand Down Expand Up @@ -236,7 +236,7 @@ public <T> T _getFeature(final Class<T> type) {
if(type == Lock.class) {
return (T) new BrickLockFeature(this);
}
if(type == PromptUrlProvider.class) {
if(type == Share.class) {
return (T) new BrickShareFeature(this);
}
return super._getFeature(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
import ch.cyberduck.core.brick.io.swagger.client.api.BundlesApi;
import ch.cyberduck.core.brick.io.swagger.client.model.BundlesBody;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Share;

import org.apache.commons.lang3.StringUtils;

import java.net.URI;
import java.text.MessageFormat;
import java.util.Collections;

public class BrickShareFeature implements PromptUrlProvider {
public class BrickShareFeature implements Share {

private final BrickSession session;

Expand All @@ -47,7 +47,7 @@ public boolean isSupported(final Path file, final Type type) {
}

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toDownloadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
try {
final Credentials password = callback.prompt(session.getHost(),
LocaleFactory.localizedString("Passphrase", "Cryptomator"),
Expand All @@ -63,7 +63,7 @@ public DescriptiveUrl toDownloadUrl(final Path file, final Object options, final
}

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Object options, final PasswordCallback callback) throws BackgroundException {
public DescriptiveUrl toUploadUrl(final Path file, final Sharee sharee, final Object options, final PasswordCallback callback) throws BackgroundException {
return DescriptiveUrl.EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.cyberduck.core.DisabledPasswordCallback;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Share;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;

Expand All @@ -39,7 +40,7 @@ public void toDownloadUrl() throws Exception {
EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
final Path test = new BrickTouchFeature(session).touch(
new Path(directory, String.format("%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)), new TransferStatus());
assertNotNull(new BrickShareFeature(session).toDownloadUrl(test, null, new DisabledPasswordCallback()).getUrl());
assertNotNull(new BrickShareFeature(session).toDownloadUrl(test, Share.Sharee.world, null, new DisabledPasswordCallback()).getUrl());
new BrickDeleteFeature(session).delete(Collections.singletonList(directory), new DisabledPasswordCallback(), new Delete.DisabledCallback());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

<ItemGroup>
<PackageReference Include="DotNetProjects.Extended.Wpf.Toolkit" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" />
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ReactiveUI.WPF" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using ch.cyberduck.core;
using ch.cyberduck.core.exception;
using ch.cyberduck.core.features;
using ch.cyberduck.core.threading;
using Ch.Cyberduck.Core.Refresh.Splat;
using Ch.Cyberduck.Core.Refresh.ViewModels.Dialogs;
using java.util;
using Splat;
using System.Windows;

namespace Ch.Cyberduck.Core.Refresh.Interactivity;

public class DialogPromptShareeCallback : Share.ShareeCallback
{
private readonly Controller controller;
private readonly Host host;
private readonly nint parent;

public DialogPromptShareeCallback(Host host, nint parent, Controller controller)
{
(
this.controller,
this.host,
this.parent) = (controller, host, parent);
}

public Share.Sharee prompt(Share.Type type, Set sharees)
{
var viewModel = new PromptShareeViewModel(host.getProtocol(), sharees);
var action = new PromptShareeAction(viewModel, parent);
controller.invoke(action, true);
if (action.Result != true)
{
throw new ConnectionCanceledException();
}

return viewModel.SelectedSharee;
}

private class PromptShareeAction : DefaultMainAction
{
private readonly nint parent;
private readonly PromptShareeViewModel viewModel;

public bool? Result { get; private set; }

public PromptShareeAction(PromptShareeViewModel viewModel, nint parent)
{
this.parent = parent;
this.viewModel = viewModel;
}

public override void run()
{
var factory = Locator.Current.GetService<IWindowFactory<PromptShareeViewModel>>();
var window = factory.Create(viewModel);
Result = window.ShowWithOwnerDialog(parent);
}
}
}
8 changes: 8 additions & 0 deletions core/native/refresh/src/main/csharp/Splat/IWindowFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Windows;

namespace Ch.Cyberduck.Core.Refresh.Splat;

public interface IWindowFactory<TViewModel> where TViewModel : class
{
Window Create(TViewModel model);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace System.Collections
{
public static class DictionaryExtensions
{
public static TValue Lookup<TValue, TKey>(this IDictionary<TKey, TValue> dictionary, TKey key)
{
return dictionary[key];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Windows.Interop;

namespace System.Windows;

public static class WindowExtensions
{
public static bool? ShowWithOwnerDialog(this Window window, in nint? owner)
{
if (owner is nint ownerLocal)
{
_ = new WindowInteropHelper(window)
{
Owner = ownerLocal
};
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
}

return window.ShowDialog();
}
}
Loading

0 comments on commit 21510f4

Please sign in to comment.