Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6547: toggle depreciate revised #15383

Merged
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
26 changes: 20 additions & 6 deletions src/DynamoCoreWpf/ViewModels/PackageManager/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PackageViewModel : NotificationObject
private readonly DynamoViewModel dynamoViewModel;
private readonly PackageManagerClient packageManagerClient;
private readonly DynamoModel dynamoModel;
private readonly PackageManagerClientViewModel packageManagerClientViewModel;

public Package Model { get; private set; }

Expand Down Expand Up @@ -172,6 +173,7 @@ public PackageViewModel(DynamoViewModel dynamoViewModel, Package model)
{
this.dynamoViewModel = dynamoViewModel;
this.dynamoModel = dynamoViewModel.Model;
this.packageManagerClientViewModel = dynamoViewModel.PackageManagerClientViewModel;

var pmExtension = dynamoModel.GetPackageManagerExtension();
this.packageManagerClient = pmExtension.PackageManagerClient;
Expand Down Expand Up @@ -410,10 +412,9 @@ private bool IsOwner()

private bool CanDeprecate()
{
var packageInfo = new PackageInfo(Model.Name, Version.Parse(Model.VersionName));
var packageHeader = this.packageManagerClient.GetPackageHeader(packageInfo);
var isDeprecated = IsPackageDeprecated(Model.Name);

return IsOwner() && !packageHeader.deprecated;
return IsOwner() && !isDeprecated;
}

private void Undeprecate()
Expand All @@ -427,10 +428,9 @@ private void Undeprecate()

private bool CanUndeprecate()
{
var packageInfo = new PackageInfo(Model.Name, Version.Parse(Model.VersionName));
var packageHeader = this.packageManagerClient.GetPackageHeader(packageInfo);
var isDeprecated = IsPackageDeprecated(Model.Name);

return IsOwner() && packageHeader.deprecated;
return IsOwner() && isDeprecated;
}

private void PublishNewPackageVersion()
Expand Down Expand Up @@ -465,5 +465,19 @@ private void ExecuteWithTou(Action acceptanceCallback)

termsOfUseCheck.Execute(false);
}

private PackageManagerSearchElement GetPackageVersionInformationFromCached(string packageName)
{
var package = this.packageManagerClientViewModel.CachedPackageList.FirstOrDefault(x => x.Name == packageName);

return package;
}

private bool IsPackageDeprecated(string packageName)
{
var package = GetPackageVersionInformationFromCached(packageName);

return package != null ? package.IsDeprecated : false;
}
}
}
6 changes: 3 additions & 3 deletions src/DynamoPackages/PackageManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ void CleanPackagesWithWrongVersions(List<PackageHeader> packages)
}

/// <summary>
/// Get the package Header which contains all the relevant information to the Package
/// Gets maintainers for a specific package
/// </summary>
/// <param name="packageInfo"></param>
/// <returns></returns>
internal PackageHeader GetPackageHeader(IPackageInfo packageInfo)
internal PackageHeader GetPackageMaintainers(IPackageInfo packageInfo)
{
var header = FailFunc.TryExecute(() =>
{
Expand Down Expand Up @@ -314,7 +314,7 @@ internal bool DoesCurrentUserOwnPackage(Package package,string username)
return value;
}
var pkg = new PackageInfo(package.Name, new Version(package.VersionName));
var mnt = GetPackageHeader(pkg);
var mnt = GetPackageMaintainers(pkg);
value = (mnt != null) && (mnt.maintainers.Any(maintainer => maintainer.username.Equals(username)));
this.packageMaintainers[package.Name] = value;
return value;
Expand Down
Loading