Skip to content

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

FIX: Append /all to URL if default list is 'none' (#15460)

Dan Ungureanuc0d72ec3d616
diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js
index 441d6b8d1c7..94a015236ec 100644
--- a/app/assets/javascripts/discourse/app/lib/url.js
+++ b/app/assets/javascripts/discourse/app/lib/url.js
@@ -507,7 +507,9 @@ export function getCategoryAndTagUrl(category, subcategories, tag) {
if (category) {
url = category.path;
- if (!subcategories) {
+ if (subcategories && category.default_list_filter === "none") {
+ url += "/all";
+ } else if (!subcategories && category.default_list_filter === "all") {
url += "/none";
}
}
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/url-test.js b/app/assets/javascripts/discourse/tests/unit/lib/url-test.js
index b9b1a35b962..cc11a7d6cbe 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/url-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/url-test.js
@@ -1,4 +1,8 @@
-import DiscourseURL, { prefixProtocol, userPath } from "discourse/lib/url";
+import DiscourseURL, {
+ getCategoryAndTagUrl,
+ prefixProtocol,
+ userPath,
+} from "discourse/lib/url";
import { module, test } from "qunit";
import User from "discourse/models/user";
import { logIn } from "discourse/tests/helpers/qunit-helpers";
@@ -100,6 +104,40 @@ module("Unit | Utility | url", function () {
);
});
+ test("getCategoryAndTagUrl", function (assert) {
+ assert.strictEqual(
+ getCategoryAndTagUrl(
+ { path: "/c/foo/1", default_list_filter: "all" },
+ true
+ ),
+ "/c/foo/1"
+ );
+
+ assert.strictEqual(
+ getCategoryAndTagUrl(
+ { path: "/c/foo/1", default_list_filter: "all" },
+ false
+ ),
+ "/c/foo/1/none"
+ );
+
+ assert.strictEqual(
+ getCategoryAndTagUrl(
+ { path: "/c/foo/1", default_list_filter: "none" },
+ true
+ ),
+ "/c/foo/1/all"
+ );
+
+ assert.strictEqual(
+ getCategoryAndTagUrl(
+ { path: "/c/foo/1", default_list_filter: "none" },
+ false
+ ),
+ "/c/foo/1"
+ );
+ });
+
test("routeTo redirects secure media URLS because they are server side only", async function (assert) {
sinon.stub(DiscourseURL, "redirectTo");
sinon.stub(DiscourseURL, "handleURL");