adds ability to return hidden packages since we need this for starter kits that are hidden
This commit is contained in:
@@ -99,8 +99,9 @@ namespace OurUmbraco.Repository.Controllers
|
||||
/// <param name="id"></param>
|
||||
/// <param name="version">The umbraco version requesting the details, if null than the ZipUrl will be the latest package zip</param>
|
||||
/// <param name="asFile">pass in true to get the package file otherwise leave blank or set to false to retreive the package details</param>
|
||||
/// <param name="includeHidden">Some packages are hidden (i.e. projectLive), set to true to ignore this switch (i.e. for starter kits)</param>
|
||||
/// <returns></returns>
|
||||
public HttpResponseMessage Get(Guid id, string version = null, bool? asFile = false)
|
||||
public HttpResponseMessage Get(Guid id, string version = null, bool? asFile = false, bool? includeHidden = false)
|
||||
{
|
||||
SemVersion parsed = null;
|
||||
if (version.IsNullOrWhiteSpace() == false)
|
||||
@@ -123,11 +124,11 @@ namespace OurUmbraco.Repository.Controllers
|
||||
var v = new System.Version(parsed.Major, parsed.Minor, parsed.Patch);
|
||||
|
||||
return asFile.HasValue && asFile.Value
|
||||
? GetPackageFile(id, v)
|
||||
: GetDetails(id, v);
|
||||
? GetPackageFile(id, v, includeHidden != null && includeHidden.Value)
|
||||
: GetDetails(id, v, includeHidden != null && includeHidden.Value);
|
||||
}
|
||||
|
||||
private HttpResponseMessage GetDetails(Guid id, System.Version currUmbracoVersion)
|
||||
private HttpResponseMessage GetDetails(Guid id, System.Version currUmbracoVersion, bool includeHidden)
|
||||
{
|
||||
//return the results, but cache for 1 minute
|
||||
var key = string.Format("PackageRepositoryController.GetDetails.{0}.{1}", id, currUmbracoVersion.ToString(3));
|
||||
@@ -137,7 +138,7 @@ namespace OurUmbraco.Repository.Controllers
|
||||
(key,
|
||||
() =>
|
||||
{
|
||||
var details = Service.GetDetails(id, currUmbracoVersion);
|
||||
var details = Service.GetDetails(id, currUmbracoVersion, includeHidden);
|
||||
|
||||
if (details == null)
|
||||
throw new InvalidOperationException("No package found with id " + id);
|
||||
@@ -163,11 +164,11 @@ namespace OurUmbraco.Repository.Controllers
|
||||
|
||||
}
|
||||
|
||||
private HttpResponseMessage GetPackageFile(Guid packageId, System.Version currUmbracoVersion)
|
||||
private HttpResponseMessage GetPackageFile(Guid packageId, System.Version currUmbracoVersion, bool includeHidden)
|
||||
{
|
||||
var pckRepoService = new PackageRepositoryService(Umbraco, Members, DatabaseContext);
|
||||
|
||||
var details = pckRepoService.GetDetails(packageId, currUmbracoVersion);
|
||||
var details = pckRepoService.GetDetails(packageId, currUmbracoVersion, includeHidden);
|
||||
if (details == null)
|
||||
throw new InvalidOperationException("No package found with id " + packageId);
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace OurUmbraco.Repository.Services
|
||||
/// <param name="query"></param>
|
||||
/// <param name="version"></param>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="includeHidden">Some packages are hidden (i.e. projectLive), set to true to ignore this switch (i.e. for starter kits)</param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// This caches each query for 2 minutes (non-sliding)
|
||||
@@ -79,12 +80,18 @@ namespace OurUmbraco.Repository.Services
|
||||
string category = null,
|
||||
string query = null,
|
||||
string version = null,
|
||||
PackageSortOrder order = PackageSortOrder.Default)
|
||||
PackageSortOrder order = PackageSortOrder.Default,
|
||||
bool? includeHidden = false)
|
||||
{
|
||||
var filters = new List<SearchFilters>();
|
||||
var searchFilters = new SearchFilters(BooleanOperation.And);
|
||||
//MUST be live
|
||||
searchFilters.Filters.Add(new SearchFilter("projectLive", "1"));
|
||||
|
||||
if (includeHidden == false)
|
||||
{
|
||||
//MUST be live
|
||||
searchFilters.Filters.Add(new SearchFilter("projectLive", "1"));
|
||||
}
|
||||
|
||||
filters.Add(searchFilters);
|
||||
if (version.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
@@ -151,17 +158,20 @@ namespace OurUmbraco.Repository.Services
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="version">The umbraco version requesting the details, if null than the ZipUrl will be the latest package zip</param>
|
||||
/// <param name="includeHidden">Some packages are hidden (i.e. projectLive), set to true to ignore this switch (i.e. for starter kits)</param>
|
||||
/// <returns>
|
||||
/// If the current umbraco version is not compatible with any package files, the ZipUrl and ZipFileId will be empty
|
||||
/// </returns>
|
||||
public PackageDetails GetDetails(Guid id, System.Version version)
|
||||
public PackageDetails GetDetails(Guid id, System.Version version, bool includeHidden)
|
||||
{
|
||||
if (version == null) throw new ArgumentNullException("version");
|
||||
|
||||
// [LK:2016-06-13@CGRT16] We're using XPath as we experienced issues with query Examine for GUIDs,
|
||||
// (it might worth but we were up against the clock).
|
||||
// The XPath 'translate' is being used to force the 'packageGuid' to be lowercase for comparison.
|
||||
var xpath = string.Format("//Project[@isDoc and projectLive = 1 and translate(packageGuid,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = '{0}']", id.ToString("D").ToLowerInvariant());
|
||||
var xpath = includeHidden
|
||||
? string.Format("//Project[@isDoc and translate(packageGuid,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = '{0}']", id.ToString("D").ToLowerInvariant())
|
||||
: string.Format("//Project[@isDoc and projectLive = 1 and translate(packageGuid,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = '{0}']", id.ToString("D").ToLowerInvariant());
|
||||
var item = UmbracoHelper.TypedContentSingleAtXPath(xpath);
|
||||
|
||||
if (item == null)
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace OurUmbraco.Repository.webservices
|
||||
throw new InvalidOperationException("Could not parse the version specified " + umbracoVersion);
|
||||
|
||||
var guid = new Guid(packageGuid);
|
||||
var details = pckRepoService.GetDetails(guid, currUmbracoVersion);
|
||||
var details = pckRepoService.GetDetails(guid, currUmbracoVersion, true);
|
||||
if (details == null)
|
||||
throw new InvalidOperationException("No package found with id " + packageGuid);
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace OurUmbraco.Repository.webservices
|
||||
//This doesn't matter what we set it to so long as it's below 7.5 since that is the version we introduce strict dependencies
|
||||
var currUmbracoVersion = new System.Version(4, 0, 0);
|
||||
var guid = new Guid(packageGuid);
|
||||
var details = pckRepoService.GetDetails(guid, currUmbracoVersion);
|
||||
var details = pckRepoService.GetDetails(guid, currUmbracoVersion ,true);
|
||||
if (details == null)
|
||||
throw new InvalidOperationException("No package found with id " + packageGuid);
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace OurUmbraco.Repository.webservices
|
||||
// requests the file, well it won't get it because this will only return non strict packages.
|
||||
var currUmbracoVersion = new System.Version(4, 0, 0);
|
||||
var guid = new Guid(packageGuid);
|
||||
var details = pckRepoService.GetDetails(guid, currUmbracoVersion);
|
||||
var details = pckRepoService.GetDetails(guid, currUmbracoVersion, true);
|
||||
if (details == null)
|
||||
return new byte[0];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user