Skip to content
Merged
10 changes: 4 additions & 6 deletions src/Umbraco.Cms.Api.Management/Factories/DocumentUrlFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<IEnumerable<DocumentUrlInfo>> CreateUrlsAsync(IContent content
{
ISet<UrlInfo> urlInfos = await _publishedUrlInfoProvider.GetAllAsync(content);
return urlInfos
.Select(urlInfo => CreateDocumentUrlInfo(urlInfo, false))
.Select(CreateDocumentUrlInfo)
.ToArray();
}

Expand Down Expand Up @@ -89,18 +89,16 @@ public async Task<IEnumerable<DocumentUrlInfoResponseModel>> CreateUrlSetsAsync(
}
}

return CreateDocumentUrlInfo(previewUrlInfo, previewUrlInfo.IsExternal is false);
return CreateDocumentUrlInfo(previewUrlInfo);
}

private DocumentUrlInfo CreateDocumentUrlInfo(UrlInfo urlInfo, bool ensureAbsoluteUrl)
private DocumentUrlInfo CreateDocumentUrlInfo(UrlInfo urlInfo)
{
var url = urlInfo.Url?.ToString();
return new DocumentUrlInfo
{
Culture = urlInfo.Culture,
Url = ensureAbsoluteUrl && url is not null
? _absoluteUrlBuilder.ToAbsoluteUrl(url).ToString()
: url,
Url = url,
Message = urlInfo.Message,
Provider = urlInfo.Provider,
};
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Routing/NewDefaultUrlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public virtual IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
public Task<UrlInfo?> GetPreviewUrlAsync(IContent content, string? culture, string? segment)
=> Task.FromResult<UrlInfo?>(
UrlInfo.AsUrl(
$"/{Constants.System.UmbracoPathSegment}/preview?id={content.Key}&culture={culture}&segment={segment}",
$"/preview?id={content.Key}&culture={culture}&segment={segment}",
Alias,
culture,
isExternal: false));
Expand Down Expand Up @@ -182,7 +182,7 @@ private string GetLegacyRouteFormatById(Guid key, string? culture)
// We have the published content now, so we can check if the culture is published, and thus avoid the DB hit.
string route;
var isDraft = _umbracoContextAccessor.GetRequiredUmbracoContext().InPreviewMode;
if(isDraft is false && string.IsNullOrWhiteSpace(culture) is false && content.Cultures.Any() && content.IsInvariantOrHasCulture(culture) is false)
if (isDraft is false && string.IsNullOrWhiteSpace(culture) is false && content.Cultures.Any() && content.IsInvariantOrHasCulture(culture) is false)
{
route = "#";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity';
import type { UmbVariantPropertyGuardRule } from '@umbraco-cms/backoffice/property';
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
import { UMB_SERVER_CONTEXT } from '@umbraco-cms/backoffice/server';

type ContentModel = UmbDocumentDetailModel;
type ContentTypeModel = UmbDocumentTypeDetailModel;
Expand Down Expand Up @@ -344,7 +345,16 @@
);

if (previewUrlData.url) {
const previewWindow = window.open(previewUrlData.url, `umbpreview-${unique}`);
let previewUrl = previewUrlData.url;

const serverContext = await this.getContext(UMB_SERVER_CONTEXT);
const backofficePath = serverContext?.getBackofficePath() ?? '/';

if (!previewUrlData.url.startsWith(backofficePath)) {
previewUrl = `${backofficePath}${previewUrlData.url}`;
}

const previewWindow = window.open(previewUrl, `umbpreview-${unique}`);

Check warning on line 357 in src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (release/17.0)

❌ Getting worse: Complex Method

UmbDocumentWorkspaceContext.handleSaveAndPreview increases in cyclomatic complexity from 10 to 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
previewWindow?.focus();
return;
}
Expand Down
Loading