Skip to content

A platform for community discussion. Free, open, simple.

FIX: Prefix hardcoded URLs with subfolder base path (#39728)

Renato Atilio4b7c6f21da8a
diff --git a/app/controllers/nested_topics_controller.rb b/app/controllers/nested_topics_controller.rb
index 0378318f612..a3e43981cfe 100644
--- a/app/controllers/nested_topics_controller.rb
+++ b/app/controllers/nested_topics_controller.rb
@@ -200,7 +200,7 @@ class NestedTopicsController < ApplicationController
end
def topic_route_url(post_number = nil)
- url = +"/t/#{@topic.slug}/#{@topic.id}"
+ url = +path("/t/#{@topic.slug}/#{@topic.id}")
post_number = post_number.to_i
url << "/#{post_number}" if post_number > 0
@@ -218,7 +218,7 @@ class NestedTopicsController < ApplicationController
return unless @topic.private_message?
if request.get?
- url = "/t/#{@topic.slug}/#{@topic.id}"
+ url = +path("/t/#{@topic.slug}/#{@topic.id}")
post_number = params[:post_number].to_i
url << "/#{post_number}" if post_number > 0
redirect_to url, status: :found
diff --git a/app/services/problem_check/unreachable_themes.rb b/app/services/problem_check/unreachable_themes.rb
index 8ebd3f3b4b9..c56aa6dc2b9 100644
--- a/app/services/problem_check/unreachable_themes.rb
+++ b/app/services/problem_check/unreachable_themes.rb
@@ -24,7 +24,7 @@ class ProblemCheck::UnreachableThemes < ProblemCheck
<ul>#{
unreachable_themes
.map do |name, id|
- "<li><a href=\"/admin/customize/themes/#{id}\">#{CGI.escapeHTML(name)}</a></li>"
+ "<li><a href=\"#{Discourse.base_path}/admin/customize/themes/#{id}\">#{CGI.escapeHTML(name)}</a></li>"
end
.join("\n")
}</ul>
diff --git a/frontend/discourse/admin/components/modal/badge-preview.gjs b/frontend/discourse/admin/components/modal/badge-preview.gjs
index 0cc9cf4167a..d0517519145 100644
--- a/frontend/discourse/admin/components/modal/badge-preview.gjs
+++ b/frontend/discourse/admin/components/modal/badge-preview.gjs
@@ -1,5 +1,6 @@
import Component from "@glimmer/component";
import { trustHTML } from "@ember/template";
+import getURL from "discourse/lib/get-url";
import { escapeExpression } from "discourse/lib/utilities";
import DModal from "discourse/ui-kit/d-modal";
import dIcon from "discourse/ui-kit/helpers/d-icon";
@@ -13,7 +14,7 @@ export default class BadgePreview extends Component {
if (grant.post_id) {
i18nKey += "_post";
- i18nParams.link = `<a href="/p/${grant.post_id}" data-auto-route="true">
+ i18nParams.link = `<a href="${getURL(`/p/${grant.post_id}`)}" data-auto-route="true">
${escapeExpression(grant.title)}
</a>`;
}
diff --git a/frontend/discourse/admin/controllers/admin-user/index.js b/frontend/discourse/admin/controllers/admin-user/index.js
index e83c2bd2dbb..0c6ffa290c6 100644
--- a/frontend/discourse/admin/controllers/admin-user/index.js
+++ b/frontend/discourse/admin/controllers/admin-user/index.js
@@ -11,7 +11,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import CanCheckEmailsHelper from "discourse/lib/can-check-emails-helper";
import getURL from "discourse/lib/get-url";
import { deepEqual } from "discourse/lib/object";
-import DiscourseURL, { userPath } from "discourse/lib/url";
+import DiscourseURL, { groupPath, userPath } from "discourse/lib/url";
import { i18n } from "discourse-i18n";
import DeletePostsConfirmationModal from "../../components/modal/delete-posts-confirmation";
import MergeUsersConfirmationModal from "../../components/modal/merge-users-confirmation";
@@ -89,7 +89,7 @@ export default class AdminUserIndexController extends Controller {
return this.model.automaticGroups
.map((group) => {
const name = trustHTML(group.name);
- return `<a href="/g/${name}">${name}</a>`;
+ return `<a href="${groupPath(name)}">${name}</a>`;
})
.join(", ");
}
diff --git a/frontend/discourse/admin/models/staff-action-log.js b/frontend/discourse/admin/models/staff-action-log.js
index 7f33f923593..f9aad6a1a1a 100644
--- a/frontend/discourse/admin/models/staff-action-log.js
+++ b/frontend/discourse/admin/models/staff-action-log.js
@@ -1,6 +1,7 @@
import { computed } from "@ember/object";
import AdminUser from "discourse/admin/models/admin-user";
import { ajax } from "discourse/lib/ajax";
+import getURL from "discourse/lib/get-url";
import { escapeExpression } from "discourse/lib/utilities";
import RestModel from "discourse/models/rest";
import { i18n } from "discourse-i18n";
@@ -67,7 +68,7 @@ export default class StaffActionLog extends RestModel {
: null;
const reviewableLink = this.reviewable_id
- ? `<a href="/review/${this.reviewable_id}">${this.reviewable_id}</a>`
+ ? `<a href="${getURL(`/review/${this.reviewable_id}`)}">${this.reviewable_id}</a>`
: null;
let lines = [
diff --git a/frontend/discourse/admin/templates/admin-user/index.gjs b/frontend/discourse/admin/templates/admin-user/index.gjs
index e0ead0f74b9..47b5369c4ea 100644
--- a/frontend/discourse/admin/templates/admin-user/index.gjs
+++ b/frontend/discourse/admin/templates/admin-user/index.gjs
@@ -8,6 +8,7 @@ import PluginOutlet from "discourse/components/plugin-outlet";
import i18nYesNo from "discourse/helpers/i18n-yes-no";
import lazyHash from "discourse/helpers/lazy-hash";
import routeAction from "discourse/helpers/route-action";
+import getURL from "discourse/lib/get-url";
import ComboBox from "discourse/select-kit/components/combo-box";
import DropdownSelectBox from "discourse/select-kit/components/dropdown-select-box";
import GroupChooser from "discourse/select-kit/components/group-chooser";
@@ -409,7 +410,7 @@ export default <template>
</div>
<div class="controls">
<DButton
- @href="/admin/api/keys"
+ @href={{getURL "/admin/api/keys"}}
@label="admin.api.manage_keys"
class="btn-default"
/>
diff --git a/frontend/discourse/app/components/about-page-extra-groups.gjs b/frontend/discourse/app/components/about-page-extra-groups.gjs
index 067332c27a5..c6987848165 100644
--- a/frontend/discourse/app/components/about-page-extra-groups.gjs
+++ b/frontend/discourse/app/components/about-page-extra-groups.gjs
@@ -5,6 +5,7 @@ import { service } from "@ember/service";
import { trustHTML } from "@ember/template";
import AboutPageUsers from "discourse/components/about-page-users";
import { ajax } from "discourse/lib/ajax";
+import { groupPath } from "discourse/lib/url";
import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner";
export default class AboutPageExtraGroups extends Component {
@@ -117,7 +118,7 @@ export default class AboutPageExtraGroups extends Component {
{{if this.showGroupDescription '--has-description'}}"
>
<h3>
- <a href="/g/{{group.name}}">{{this.groupName group}}</a>
+ <a href={{groupPath group.name}}>{{this.groupName group}}</a>
</h3>
{{#if this.showGroupDescription}}
<p>{{trustHTML group.bio_cooked}}</p>
diff --git a/frontend/discourse/app/components/composer-messages.gjs b/frontend/discourse/app/components/composer-messages.gjs
index 179fface329..4d82a754eb2 100644
--- a/frontend/discourse/app/components/composer-messages.gjs
+++ b/frontend/discourse/app/components/composer-messages.gjs
@@ -15,6 +15,7 @@ import {
import { debounce } from "discourse/lib/decorators";
import { INPUT_DELAY } from "discourse/lib/environment";
import LinkLookup from "discourse/lib/link-lookup";
+import { userPath } from "discourse/lib/url";
import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
import { i18n } from "discourse-i18n";
import { autoTrackedArray } from "../lib/tracked-tools";
@@ -198,7 +199,7 @@ export default class ComposerMessages extends Component {
let usernames = [];
response.usernames.forEach((username, index) => {
usernames[index] =
- `<a class='mention' href='/u/${username}'>@${username}</a>`;
+ `<a class='mention' href='${userPath(username)}'>@${username}</a>`;
});
let body_key;
diff --git a/frontend/discourse/app/components/modal/nested-activity-log/item.gjs b/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
index 537801f8521..eb517c2cabc 100644
--- a/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
+++ b/frontend/discourse/app/components/modal/nested-activity-log/item.gjs
@@ -8,7 +8,7 @@ import {
} from "discourse/components/post/small-action";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
import getURL from "discourse/lib/get-url";
-import { userPath } from "discourse/lib/url";
+import { groupPath, userPath } from "discourse/lib/url";
import { escapeExpression } from "discourse/lib/utilities";
import DUserAvatar from "discourse/ui-kit/d-user-avatar";
import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";
@@ -39,7 +39,7 @@ function mentionLinkFor(code, who) {
GROUP_ACTION_CODES.includes(code) ||
customGroupActionCodes.includes(code)
) {
- return `<a class="mention-group" href="/g/${encodeURIComponent(who)}">@${escaped}</a>`;
+ return `<a class="mention-group" href="${groupPath(encodeURIComponent(who))}">@${escaped}</a>`;
}
return `<a class="mention" href="${userPath(who)}">@${escaped}</a>`;
}
diff --git a/frontend/discourse/app/components/post-action-description.gjs b/frontend/discourse/app/components/post-action-description.gjs
index 02df2736092..b6147ecd2f7 100644
--- a/frontend/discourse/app/components/post-action-description.gjs
+++ b/frontend/discourse/app/components/post-action-description.gjs
@@ -5,7 +5,7 @@ import {
GROUP_ACTION_CODES,
} from "discourse/components/post/small-action";
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
-import { userPath } from "discourse/lib/url";
+import { groupPath, userPath } from "discourse/lib/url";
import { escapeExpression } from "discourse/lib/utilities";
import { i18n } from "discourse-i18n";
@@ -23,7 +23,7 @@ export function actionDescriptionHtml(actionCode, createdAt, username, path) {
GROUP_ACTION_CODES.includes(actionCode) ||
customGroupActionCodes.includes(actionCode)
) {
- who = `<a class="mention-group" href="/g/${encodeURIComponent(username)}">@${escapedUsername}</a>`;
+ who = `<a class="mention-group" href="${groupPath(encodeURIComponent(username))}">@${escapedUsername}</a>`;
} else {
who = `<a class="mention" href="${userPath(encodeURIComponent(username))}">@${escapedUsername}</a>`;
}
diff --git a/frontend/discourse/app/components/post/small-action.gjs b/frontend/discourse/app/components/post/small-action.gjs
index 61ffaab6213..d116ae739b8 100644
--- a/frontend/discourse/app/components/post/small-action.gjs
+++ b/frontend/discourse/app/components/post/small-action.gjs
@@ -8,7 +8,7 @@ import PostCookedHtml from "discourse/components/post/cooked-html";
import { autoUpdatingRelativeAge, relativeAge } from "discourse/lib/formatter";
import getURL from "discourse/lib/get-url";
import { applyValueTransformer } from "discourse/lib/transformer";
-import { userPath } from "discourse/lib/url";
+import { groupPath, userPath } from "discourse/lib/url";
import { escapeExpression } from "discourse/lib/utilities";
import DButton from "discourse/ui-kit/d-button";
import DUserAvatar from "discourse/ui-kit/d-user-avatar";
@@ -112,7 +112,7 @@ export default class PostSmallAction extends Component {
if (this.who) {
const escapedWho = escapeExpression(this.who);
if (this.isGroupAction) {
- who = `<a class="mention-group" href="/g/${encodeURIComponent(this.who)}">@${escapedWho}</a>`;
+ who = `<a class="mention-group" href="${groupPath(encodeURIComponent(this.who))}">@${escapedWho}</a>`;
} else {
who = `<a class="mention" href="${userPath(this.who)}">@${escapedWho}</a>`;
}
diff --git a/frontend/discourse/app/components/reviewable/insights.gjs b/frontend/discourse/app/components/reviewable/insights.gjs
index f1702c06f3c..002923fa721 100644
--- a/frontend/discourse/app/components/reviewable/insights.gjs
+++ b/frontend/discourse/app/components/reviewable/insights.gjs
@@ -2,6 +2,7 @@ import Component from "@glimmer/component";
import { trustHTML } from "@ember/template";
import IpLookup from "discourse/components/reviewable/ip-lookup";
import { shortDate } from "discourse/lib/formatter";
+import { userPath } from "discourse/lib/url";
import { i18n } from "discourse-i18n";
/**
@@ -71,7 +72,7 @@ export default class ReviewableInsights extends Component {
if (postCount > 0 && user?.username) {
activities.push(
- `<a href="/u/${user.username}/activity">${postsText}</a>`
+ `<a href="${userPath(`${user.username}/activity`)}">${postsText}</a>`
);
} else {
activities.push(postsText);
diff --git a/frontend/discourse/app/components/tag-settings.gjs b/frontend/discourse/app/components/tag-settings.gjs
index f1e0c39857c..23a42f760aa 100644
--- a/frontend/discourse/app/components/tag-settings.gjs
+++ b/frontend/discourse/app/components/tag-settings.gjs
@@ -9,6 +9,7 @@ import AddSynonymsConfirmation from "discourse/components/tag-settings/add-synon
import TagSettingsLocalizations from "discourse/components/tag-settings/localizations";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
+import getURL from "discourse/lib/get-url";
import { slugify } from "discourse/lib/utilities";
import MiniTagChooser from "discourse/select-kit/components/mini-tag-chooser";
import TagDropdown from "discourse/select-kit/components/tag-dropdown";
@@ -100,7 +101,9 @@ export default class TagSettings extends Component {
? i18n("tagging.tag_groups_info_prefix.one")
: i18n("tagging.tag_groups_info_prefix.other");
const groups = (this.args.tag.tag_groups || [])
- .map((tg) => `<a href="/tag_groups/${tg.id}">${tg.name}</a>`)
+ .map(
+ (tg) => `<a href="${getURL(`/tag_groups/${tg.id}`)}">${tg.name}</a>`
+ )
.join(", ");
parts.push(`${prefix}${groups}.`);
}
diff --git a/frontend/discourse/app/components/topic-drafts-dropdown.gjs b/frontend/discourse/app/components/topic-drafts-dropdown.gjs
index 9656096ab76..cd5e4d1dd6c 100644
--- a/frontend/discourse/app/components/topic-drafts-dropdown.gjs
+++ b/frontend/discourse/app/components/topic-drafts-dropdown.gjs
@@ -3,6 +3,7 @@ import { tracked } from "@glimmer/tracking";
import { fn } from "@ember/helper";
import { action } from "@ember/object";
import { service } from "@ember/service";
+import getURL from "discourse/lib/get-url";
import DiscourseURL from "discourse/lib/url";
import {
NEW_PRIVATE_MESSAGE_KEY,
@@ -143,7 +144,7 @@ export default class TopicDraftsDropdown extends Component {
<dropdown.item>
<DButton
- @href="/my/activity/drafts"
+ @href={{getURL "/my/activity/drafts"}}
@model={{this.currentUser}}
class="btn-link view-all-drafts"
>
diff --git a/frontend/discourse/app/components/welcome-banner.gjs b/frontend/discourse/app/components/welcome-banner.gjs
index 5c6024fe6cf..763fbeb076f 100644
--- a/frontend/discourse/app/components/welcome-banner.gjs
+++ b/frontend/discourse/app/components/welcome-banner.gjs
@@ -7,6 +7,7 @@ import { modifier } from "ember-modifier";
import PluginOutlet from "discourse/components/plugin-outlet";
import SearchMenu from "discourse/components/search-menu";
import bodyClass from "discourse/helpers/body-class";
+import getURL from "discourse/lib/get-url";
import { headerOffset } from "discourse/lib/offset-calculator";
import { prioritizeNameFallback } from "discourse/lib/settings";
import { sanitize } from "discourse/lib/text";
@@ -276,7 +277,7 @@ export default class WelcomeBanner extends Component {
<DButton
@icon="magnifying-glass"
@title="search.open_advanced"
- @href="/search?expanded=true"
+ @href={{getURL "/search?expanded=true"}}
class="search-icon"
/>
<SearchMenu
diff --git a/frontend/discourse/app/templates/user-api-key-new.gjs b/frontend/discourse/app/templates/user-api-key-new.gjs
index 9648ca9b58d..29c67d34c3e 100644
--- a/frontend/discourse/app/templates/user-api-key-new.gjs
+++ b/frontend/discourse/app/templates/user-api-key-new.gjs
@@ -1,6 +1,7 @@
import { on } from "@ember/modifier";
import hideApplicationFooter from "discourse/helpers/hide-application-footer";
import hideApplicationSidebar from "discourse/helpers/hide-application-sidebar";
+import getURL from "discourse/lib/get-url";
import DButton from "discourse/ui-kit/d-button";
import { i18n } from "discourse-i18n";
@@ -115,7 +116,11 @@ export default <template>
type="submit"
class="btn-primary"
/>
- <DButton @href="/" @label="user_api_key.deny" class="btn-default" />
+ <DButton
+ @href={{getURL "/"}}
+ @label="user_api_key.deny"
+ class="btn-default"
+ />
</div>
</form>
{{/if}}
diff --git a/frontend/discourse/app/templates/user-invited/show.gjs b/frontend/discourse/app/templates/user-invited/show.gjs
index 98e97048fff..e216b56447c 100644
--- a/frontend/discourse/app/templates/user-invited/show.gjs
+++ b/frontend/discourse/app/templates/user-invited/show.gjs
@@ -5,6 +5,7 @@ import SvgEnvelopeZero from "discourse/components/svg/envelope-zero";
import DMenu from "discourse/float-kit/components/d-menu";
import bodyClass from "discourse/helpers/body-class";
import rawDate from "discourse/helpers/raw-date";
+import { groupPath } from "discourse/lib/url";
import DButton from "discourse/ui-kit/d-button";
import DConditionalLoadingSpinner from "discourse/ui-kit/d-conditional-loading-spinner";
import DCopyButton from "discourse/ui-kit/d-copy-button";
@@ -258,7 +259,7 @@ export default <template>
{{#each invite.groups as |g|}}
<span class="invite-extra">
<a
- href="/g/{{g.name}}"
+ href={{groupPath g.name}}
class="invite-extra-item-link"
>{{dIcon "users"}}
{{g.name}}
diff --git a/frontend/discourse/tests/integration/components/post-action-description-test.gjs b/frontend/discourse/tests/integration/components/post-action-description-test.gjs
index 478a655d77c..e67a311f889 100644
--- a/frontend/discourse/tests/integration/components/post-action-description-test.gjs
+++ b/frontend/discourse/tests/integration/components/post-action-description-test.gjs
@@ -1,6 +1,7 @@
import { render } from "@ember/test-helpers";
import { module, test } from "qunit";
import PostActionDescription from "discourse/components/post-action-description";
+import { setPrefix } from "discourse/lib/get-url";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
module("Integration | Component | PostActionDescription", function (hooks) {
@@ -25,4 +26,22 @@ module("Integration | Component | PostActionDescription", function (hooks) {
.dom(".excerpt .mention")
.hasText(`@${this.username}`, "shows the actor name as text");
});
+
+ test("prefixes mention links with the subfolder base path", async function (assert) {
+ setPrefix("/forum");
+ this.username = "discourse";
+
+ await render(
+ <template>
+ <PostActionDescription
+ @actionCode="invited_group"
+ @username={{this.username}}
+ />
+ </template>
+ );
+
+ assert
+ .dom(".excerpt .mention-group")
+ .hasAttribute("href", "/forum/g/discourse");
+ });
});
diff --git a/plugins/chat/lib/chat/onebox_handler.rb b/plugins/chat/lib/chat/onebox_handler.rb
index 4f6cf0d4c20..272434f0663 100644
--- a/plugins/chat/lib/chat/onebox_handler.rb
+++ b/plugins/chat/lib/chat/onebox_handler.rb
@@ -40,6 +40,7 @@ module Chat
{
channel_id: chat_channel.id,
channel_name: chat_channel.name,
+ base_path: Discourse.base_path,
color: chat_channel.chatable.color,
channel_badge: build_channel_badge(chat_channel),
}
diff --git a/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache b/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache
index ceb95d6029a..b05f5621501 100644
--- a/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache
+++ b/plugins/chat/lib/onebox/templates/discourse_chat_channel.mustache
@@ -1,7 +1,7 @@
<aside class="onebox chat-onebox">
<article class="onebox-body chat-onebox-body">
<h3 class="chat-onebox-title">
- <a href="/chat/c/-/{{channel_id}}">
+ <a href="{{base_path}}/chat/c/-/{{channel_id}}">
{{{channel_badge}}}
<span class="clear-badge">{{channel_name}}</span>
</a>
diff --git a/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache b/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache
index 04549f94093..a6c1587ffc0 100644
--- a/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache
+++ b/plugins/chat/lib/onebox/templates/discourse_chat_message.mustache
@@ -8,19 +8,19 @@
<div class="chat-transcript-username">{{username}}</div>
<div class="chat-transcript-datetime">
{{#thread_id}}
- <a href="/chat/c/-/{{channel_id}}/t/{{thread_id}}/{{message_id}}" title="{{created_at}}">{{created_at}}</a>
+ <a href="{{base_path}}/chat/c/-/{{channel_id}}/t/{{thread_id}}/{{message_id}}" title="{{created_at}}">{{created_at}}</a>
{{/thread_id}}
{{^thread_id}}
- <a href="/chat/c/-/{{channel_id}}/{{message_id}}" title="{{created_at}}">{{created_at}}</a>
+ <a href="{{base_path}}/chat/c/-/{{channel_id}}/{{message_id}}" title="{{created_at}}">{{created_at}}</a>
{{/thread_id}}
</div>
- <a class="chat-transcript-channel" href="/chat/c/-/{{channel_id}}">
+ <a class="chat-transcript-channel" href="{{base_path}}/chat/c/-/{{channel_id}}">
{{{channel_badge}}}
{{channel_name}}
</a>
{{#thread_id}}
<span class="chat-transcript-separator">&#124</span>
- <a class="chat-transcript-thread" href="/chat/c/-/{{channel_id}}/t/{{thread_id}}">
+ <a class="chat-transcript-thread" href="{{base_path}}/chat/c/-/{{channel_id}}/t/{{thread_id}}">
<span class="topic-thread-icon">
<svg class="fa d-icon d-icon-discourse-threads svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#discourse-threads"></use></svg>
</span>
diff --git a/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache b/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache
index 1386cf5a7d0..acf4cb7caed 100644
--- a/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache
+++ b/plugins/chat/lib/onebox/templates/discourse_chat_thread.mustache
@@ -2,7 +2,7 @@
<article class="onebox-body chat-onebox-body">
<div class="chat-transcript-user">
<h3 class="chat-onebox-title">
- <a href="/chat/c/-/{{channel_id}}/t/{{thread_id}}">
+ <a href="{{base_path}}/chat/c/-/{{channel_id}}/t/{{thread_id}}">
<span class="category-chat-badge" style="color: #{{color}}">
<svg class="fa d-icon d-icon-discourse-threads svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#discourse-threads"></use></svg>
</span>
@@ -10,7 +10,7 @@
</a>
</h3>
<span class="thread-title-connector">{{thread_title_connector}}</span>
- <a href="/chat/c/-/{{channel_id}}">
+ <a href="{{base_path}}/chat/c/-/{{channel_id}}">
{{{channel_badge}}}
<span class="clear-badge">{{channel_name}}</span>
</a>
diff --git a/plugins/chat/spec/lib/chat/onebox_handler_spec.rb b/plugins/chat/spec/lib/chat/onebox_handler_spec.rb
index f7890a98098..d287d9efb35 100644
--- a/plugins/chat/spec/lib/chat/onebox_handler_spec.rb
+++ b/plugins/chat/spec/lib/chat/onebox_handler_spec.rb
@@ -245,4 +245,72 @@ describe Chat::OneboxHandler do
end
end
end
+
+ context "when Discourse is installed in a subfolder" do
+ before { set_subfolder "/forum" }
+
+ fab!(:message) do
+ Fabricate(:chat_message, chat_channel: public_channel, user: user, message: "Hello world!")
+ end
+ fab!(:thread_original_message) do
+ Fabricate(:chat_message, chat_channel: public_channel, user: user, message: "Thread starter")
+ end
+ fab!(:thread) do
+ Fabricate(:chat_thread, channel: public_channel, original_message: thread_original_message)
+ end
+
+ it "prefixes channel onebox links with the subfolder" do
+ onebox_html = Chat::OneboxHandler.handle(public_chat_url, { channel_id: public_channel.id })
+
+ expect(onebox_html).to include(%(href="/forum/chat/c/-/#{public_channel.id}"))
+ expect(onebox_html).not_to include(%(href="/chat/c/))
+ end
+
+ it "prefixes message onebox links with the subfolder" do
+ onebox_html =
+ Chat::OneboxHandler.handle(
+ "#{public_chat_url}/#{message.id}",
+ { channel_id: public_channel.id, message_id: message.id },
+ )
+
+ expect(onebox_html).to include(%(href="/forum/chat/c/-/#{public_channel.id}/#{message.id}"))
+ expect(onebox_html).to include(%(href="/forum/chat/c/-/#{public_channel.id}"))
+ expect(onebox_html).not_to include(%(href="/chat/c/))
+ end
+
+ it "prefixes threaded-message onebox links with the subfolder" do
+ threaded_message =
+ Fabricate(
+ :chat_message,
+ chat_channel: public_channel,
+ user: user,
+ thread: thread,
+ message: "In the thread",
+ )
+
+ onebox_html =
+ Chat::OneboxHandler.handle(
+ "#{public_chat_url}/#{threaded_message.id}",
+ { channel_id: public_channel.id, message_id: threaded_message.id },
+ )
+
+ expect(onebox_html).to include(
+ %(href="/forum/chat/c/-/#{public_channel.id}/t/#{thread.id}/#{threaded_message.id}"),
+ )
+ expect(onebox_html).to include(%(href="/forum/chat/c/-/#{public_channel.id}/t/#{thread.id}"))
+ expect(onebox_html).not_to include(%(href="/chat/c/))
+ end
+
+ it "prefixes thread onebox links with the subfolder" do
+ onebox_html =
+ Chat::OneboxHandler.handle(
+ "#{public_chat_url}/t/#{thread.id}",
+ { channel_id: public_channel.id, thread_id: thread.id },
+ )
+
+ expect(onebox_html).to include(%(href="/forum/chat/c/-/#{public_channel.id}/t/#{thread.id}"))
+ expect(onebox_html).to include(%(href="/forum/chat/c/-/#{public_channel.id}"))
+ expect(onebox_html).not_to include(%(href="/chat/c/))
+ end
+ end
end
diff --git a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_mcp_servers_controller.rb b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_mcp_servers_controller.rb
index 406bc83ea5a..ee38abe6cb2 100644
--- a/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_mcp_servers_controller.rb
+++ b/plugins/discourse-ai/app/controllers/discourse_ai/admin/ai_mcp_servers_controller.rb
@@ -104,7 +104,7 @@ module DiscourseAi
"discourse_ai.mcp_servers.errors.oauth_callback_failed",
message: e.message,
)
- redirect_to "/admin/plugins/discourse-ai/ai-tools"
+ redirect_to path("/admin/plugins/discourse-ai/ai-tools")
end
end
diff --git a/plugins/discourse-ai/spec/requests/admin/ai_mcp_servers_controller_spec.rb b/plugins/discourse-ai/spec/requests/admin/ai_mcp_servers_controller_spec.rb
index fff60c5f759..f1563134a54 100644
--- a/plugins/discourse-ai/spec/requests/admin/ai_mcp_servers_controller_spec.rb
+++ b/plugins/discourse-ai/spec/requests/admin/ai_mcp_servers_controller_spec.rb
@@ -334,6 +334,20 @@ RSpec.describe DiscourseAi::Admin::AiMcpServersController do
I18n.t("discourse_ai.mcp_servers.errors.oauth_callback_failed", message: "invalid state"),
)
end
+
+ context "when Discourse is installed in a subfolder" do
+ before { set_subfolder "/forum" }
+
+ it "prefixes the tools-page fallback redirect with the subfolder" do
+ DiscourseAi::Mcp::OAuthFlow.expects(:complete!).raises(
+ DiscourseAi::Mcp::OAuthFlow::OAuthError.new("invalid state"),
+ )
+
+ get "/admin/plugins/discourse-ai/ai-mcp-servers/oauth/callback", params: { state: "bad" }
+
+ expect(response).to redirect_to("/forum/admin/plugins/discourse-ai/ai-tools")
+ end
+ end
end
describe "DELETE #oauth_disconnect" do
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/result-types/post.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/result-types/post.gjs
index f53f2f32687..99e075c42b9 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/result-types/post.gjs
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/result-types/post.gjs
@@ -12,7 +12,7 @@ const Post = <template>
<div class="quote-controls">
{{! eslint-disable ember/template-no-invalid-link-text }}
<a
- href="/t/via-quote/{{@ctx.post.topic_id}}/{{@ctx.post.post_number}}"
+ href="{{@ctx.baseuri}}/t/via-quote/{{@ctx.post.topic_id}}/{{@ctx.post.post_number}}"
title="go to the quoted post"
class="quote-other-topic"
>
@@ -21,7 +21,7 @@ const Post = <template>
<a
class="result-post-link"
- href="/t/{{@ctx.post.topic_id}}/{{@ctx.post.post_number}}"
+ href="{{@ctx.baseuri}}/t/{{@ctx.post.topic_id}}/{{@ctx.post.post_number}}"
>
{{dAvatar @ctx.post imageSize="tiny"}}{{@ctx.post.username}}:
</a>
diff --git a/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs b/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs
index 2ad02340224..ef305071481 100644
--- a/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs
+++ b/plugins/discourse-gamification/assets/javascripts/discourse/components/gamification-leaderboard.gjs
@@ -6,6 +6,7 @@ import { service } from "@ember/service";
import { tagName } from "@ember-decorators/component";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
+import getURL from "discourse/lib/get-url";
import PeriodChooser from "discourse/select-kit/components/period-chooser";
import { or } from "discourse/truth-helpers";
import DButton from "discourse/ui-kit/d-button";
@@ -165,7 +166,10 @@ export default class GamificationLeaderboard extends Component {
class="leaderboard__period-chooser"
/>
{{#if this.currentUser.staff}}
- <a href="/admin/plugins/gamification" class="leaderboard__settings">
+ <a
+ href={{getURL "/admin/plugins/gamification"}}
+ class="leaderboard__settings"
+ >
{{dIcon "gear"}}
{{unless
this.site.mobileView
diff --git a/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjs b/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjs
index c11269b9480..a4edfa9cf46 100644
--- a/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjs
+++ b/plugins/discourse-topic-voting/assets/javascripts/discourse/components/vote-button.gjs
@@ -5,6 +5,7 @@ import { service } from "@ember/service";
import DMenu from "discourse/float-kit/components/d-menu";
import DTooltip from "discourse/float-kit/components/d-tooltip";
import { deferAnonymousAction } from "discourse/lib/anonymous-action";
+import getURL from "discourse/lib/get-url";
import { NotificationLevels } from "discourse/lib/notification-levels";
import { applyBehaviorTransformer } from "discourse/lib/transformer";
import { eq } from "discourse/truth-helpers";
@@ -170,7 +171,7 @@ export default class VoteButton extends Component {
count=this.currentUser.votes_left
max=this.currentUser.vote_limit
}}
- @href="/my/activity/votes"
+ @href={{getURL "/my/activity/votes"}}
@icon="check-to-slot"
class="btn-transparent see-votes topic-voting-menu__row-btn"
/>
diff --git a/spec/requests/nested_topics_controller_spec.rb b/spec/requests/nested_topics_controller_spec.rb
index 4010a1451a5..bf351bd23e0 100644
--- a/spec/requests/nested_topics_controller_spec.rb
+++ b/spec/requests/nested_topics_controller_spec.rb
@@ -100,6 +100,35 @@ RSpec.describe NestedTopicsController, type: :request do
expect(response).to redirect_to("/t/#{pm.slug}/#{pm.id}/5")
expect(response.status).to eq(302)
end
+
+ context "when Discourse is installed in a subfolder" do
+ before { set_subfolder "/forum" }
+
+ it "prefixes the crawler redirect target with the subfolder" do
+ get "/n/#{topic.slug}/#{topic.id}", headers: { "HTTP_USER_AGENT" => "Googlebot" }
+
+ expect(response).to redirect_to("/forum/t/#{topic.slug}/#{topic.id}")
+ expect(response.status).to eq(301)
+ end
+
+ it "prefixes the browser redirect target with the subfolder" do
+ get "/n/#{topic.slug}/#{topic.id}/5"
+
+ expect(response).to redirect_to("/forum/t/#{topic.slug}/#{topic.id}/5")
+ expect(response.status).to eq(302)
+ end
+
+ it "prefixes the private-message fallback redirect with the subfolder" do
+ pm = Fabricate(:private_message_topic, user: user)
+ Fabricate(:post, topic: pm, user: user, post_number: 1)
+
+ sign_in(user)
+ get "/n/#{pm.slug}/#{pm.id}/5"
+
+ expect(response).to redirect_to("/forum/t/#{pm.slug}/#{pm.id}/5")
+ expect(response.status).to eq(302)
+ end
+ end
end
describe "GET show" do