Skip to content

Commit

Permalink
7919: The Alias UI links for sites using UrlPrefix are broken (#7930)
Browse files Browse the repository at this point in the history
* AliasUI: removing UrlPrefix addition to url. Fixing issue in Href() that strips first / in urls for sites using UrlPrefix

* Simplifying fix for WebViewPage.Href for tenants with URL prefix

* Code styling WebViewPage

---------

Co-authored-by: Benedek Farkas <[email protected]>
  • Loading branch information
Hazzamanic and BenedekFarkas authored Apr 11, 2024
1 parent fb1aa73 commit 8086c01
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@using Orchard.Utility.Extensions

@{
var urlPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix;

Layout.Title = T("Manage Aliases").Text;
var aliasService = WorkContext.Resolve<IAliasService>();
AdminIndexOptions options = Model.Options;
Expand Down Expand Up @@ -59,10 +57,10 @@
<tr>
<td>
<input type="hidden" value="@alias.Path" name="@Html.FieldNameFor(m => Model.AliasEntries[index].Alias.Path)" />
@Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path))
@Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + alias.Path))
</td>
<td>
@Html.Link(url, Href("~/" + urlPrefix + "/" + url))
@Html.Link(url, Href("~/" + url))
</td>
</tr>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@using Orchard.Utility.Extensions

@{
var urlPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix;

Layout.Title = T("Manage Aliases").Text;
var aliasService = WorkContext.Resolve<IAliasService>();
AdminIndexOptions options = Model.Options;
Expand Down Expand Up @@ -73,10 +71,10 @@
<input type="checkbox" value="true" name="@Html.FieldNameFor(m => Model.AliasEntries[index].IsChecked)" />
</td>
<td>
@Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + urlPrefix + alias.Path))
@Html.Link(alias.Path == String.Empty ? "/" : alias.Path, Href("~/" + alias.Path))
</td>
<td>
@Html.Link(url, Href("~/" + urlPrefix + "/" + url))
@Html.Link(url, Href("~/" + url))
</td>
<td>
@Html.ActionLink(T("Edit").Text, "Edit", new { path = alias.Path == String.Empty ? "/" : alias.Path })@T(" | ")
Expand Down
31 changes: 15 additions & 16 deletions src/Orchard/Mvc/ViewEngines/Razor/WebViewPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ public abstract class WebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel>,
private object _display;
private object _layout;

public Localizer T {
public Localizer T {
get {
// first time used, create it
if(_localizer == NullLocalizer.Instance) {
if (_localizer == NullLocalizer.Instance) {

// if the Model is a shape, get localization scopes from binding sources
// e.g., Logon.cshtml in a theme, overriging Users/Logon.cshtml, needs T to
// fallback to the one in Users
var shape = Model as IShape;
if(shape != null && shape.Metadata.BindingSources.Count > 1) {
if (shape != null && shape.Metadata.BindingSources.Count > 1) {
var localizers = shape.Metadata.BindingSources.Reverse().Select(scope => LocalizationUtilities.Resolve(ViewContext, scope)).ToList();
_localizer = (text, args) => {
foreach(var localizer in localizers) {
_localizer = (text, args) => {
foreach (var localizer in localizers) {
var hint = localizer(text, args);
// if not localized using this scope, use next scope
if(hint.Text != text) {
if (hint.Text != text) {
return hint;
}
}
Expand All @@ -54,7 +54,7 @@ public Localizer T {
}

return _localizer;
}
}
}

public dynamic Display { get { return _display; } }
Expand All @@ -79,7 +79,7 @@ public IShapeFactory ShapeFactory {
}

private IAuthorizer _authorizer;
public IAuthorizer Authorizer {
public IAuthorizer Authorizer {
get {
return _authorizer ?? (_authorizer = WorkContext.Resolve<IAuthorizer>());
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public ResourceRegister Style {
}

private string[] _commonLocations;
public string[] CommonLocations { get { return _commonLocations ?? (_commonLocations = WorkContext.Resolve<ExtensionLocations>().CommonLocations); } }
public string[] CommonLocations { get { return _commonLocations ?? (_commonLocations = WorkContext.Resolve<ExtensionLocations>().CommonLocations); } }

public void RegisterImageSet(string imageSet, string style = "", int size = 16) {
// hack to fake the style "alternate" for now so we don't have to change stylesheet names when this is hooked up
Expand Down Expand Up @@ -150,7 +150,7 @@ public override void InitHelpers() {
base.InitHelpers();

WorkContext = ViewContext.GetWorkContext();

_display = DisplayHelperFactory.CreateHelper(ViewContext, this);
_layout = WorkContext.Layout;
}
Expand Down Expand Up @@ -190,11 +190,10 @@ public override string Href(string path, params object[] pathParts) {
_tenantPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix ?? "";
}

if (!String.IsNullOrEmpty(_tenantPrefix)
&& path.StartsWith("~/")
&& !CommonLocations.Any(gpp=>path.StartsWith(gpp, StringComparison.OrdinalIgnoreCase))
) {
return base.Href("~/" + _tenantPrefix + path.Substring(2), pathParts);
if (!string.IsNullOrWhiteSpace(_tenantPrefix)
&& path.StartsWith("~/")
&& !CommonLocations.Any(gpp => path.StartsWith(gpp, StringComparison.OrdinalIgnoreCase))) {
return base.Href("~/" + _tenantPrefix + path.Substring(1), pathParts);
}

return base.Href(path, pathParts);
Expand Down

0 comments on commit 8086c01

Please sign in to comment.