mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 02:30:57 +08:00
DEV: don't add username to share links when badges are disabled (#10730)
Context: https://meta.discourse.org/t/stop-appending-username-to-url-when-badge-system-disabled/164904 Share links for topics and posts have the current username appended to them when the user is logged in. If badges are disabled, those added usernames are not beneficial since they're only used to track progress towards certain badges. This PR makes two change. 1. it moves the logic for the share link url to a centralized helper because it's shared in both topic and post models. 2. it stops username params from being added to share links when badges are disabled.
This commit is contained in:
parent
f7940b1d20
commit
72361738d0
|
@ -0,0 +1,8 @@
|
||||||
|
import { helperContext } from "discourse-common/lib/helpers";
|
||||||
|
|
||||||
|
export function resolveShareUrl(url, user) {
|
||||||
|
const badgesEnabled = helperContext().siteSettings.enable_badges;
|
||||||
|
const userSuffix = user && badgesEnabled ? `?u=${user.username_lower}` : "";
|
||||||
|
|
||||||
|
return url + userSuffix;
|
||||||
|
}
|
|
@ -17,18 +17,13 @@ import Site from "discourse/models/site";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
import { fancyTitle } from "discourse/lib/topic-fancy-title";
|
import { fancyTitle } from "discourse/lib/topic-fancy-title";
|
||||||
|
import { resolveShareUrl } from "discourse/helpers/share-url";
|
||||||
|
|
||||||
const Post = RestModel.extend({
|
const Post = RestModel.extend({
|
||||||
@discourseComputed("url")
|
@discourseComputed("url")
|
||||||
shareUrl(url) {
|
shareUrl(url) {
|
||||||
const user = User.current();
|
const user = User.current();
|
||||||
const userSuffix = user ? `?u=${user.username_lower}` : "";
|
return resolveShareUrl(url, user);
|
||||||
|
|
||||||
if (this.firstPost) {
|
|
||||||
return this.get("topic.url") + userSuffix;
|
|
||||||
} else {
|
|
||||||
return url + userSuffix;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
new_user: equal("trust_level", 0),
|
new_user: equal("trust_level", 0),
|
||||||
|
|
|
@ -24,6 +24,7 @@ import Site from "discourse/models/site";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import bootbox from "bootbox";
|
import bootbox from "bootbox";
|
||||||
import { deepMerge } from "discourse-common/lib/object";
|
import { deepMerge } from "discourse-common/lib/object";
|
||||||
|
import { resolveShareUrl } from "discourse/helpers/share-url";
|
||||||
|
|
||||||
export function loadTopicView(topic, args) {
|
export function loadTopicView(topic, args) {
|
||||||
const data = deepMerge({}, args);
|
const data = deepMerge({}, args);
|
||||||
|
@ -242,8 +243,7 @@ const Topic = RestModel.extend({
|
||||||
@discourseComputed("url")
|
@discourseComputed("url")
|
||||||
shareUrl(url) {
|
shareUrl(url) {
|
||||||
const user = User.current();
|
const user = User.current();
|
||||||
const userQueryString = user ? `?u=${user.get("username_lower")}` : "";
|
return resolveShareUrl(url, user);
|
||||||
return `${url}${userQueryString}`;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
printUrl: fmt("url", "%@/print"),
|
printUrl: fmt("url", "%@/print"),
|
||||||
|
|
|
@ -70,3 +70,25 @@ QUnit.test("Post date link", async (assert) => {
|
||||||
|
|
||||||
assert.ok(exists("#share-link"), "it shows the share modal");
|
assert.ok(exists("#share-link"), "it shows the share modal");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
acceptance("Share url with badges disabled - desktop", {
|
||||||
|
loggedIn: true,
|
||||||
|
settings: {
|
||||||
|
enable_badges: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test(
|
||||||
|
"topic footer button - badges disabled - desktop",
|
||||||
|
async (assert) => {
|
||||||
|
await visit("/t/internationalization-localization/280");
|
||||||
|
await click("#topic-footer-button-share-and-invite");
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
|
||||||
|
.val()
|
||||||
|
.includes("?u=eviltrout"),
|
||||||
|
"it doesn't add the username param when badges are disabled"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -60,3 +60,26 @@ QUnit.test("Post date link", async (assert) => {
|
||||||
|
|
||||||
assert.ok(exists("#share-link"), "it shows the share modal");
|
assert.ok(exists("#share-link"), "it shows the share modal");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
acceptance("Share url with badges disabled - mobile", {
|
||||||
|
loggedIn: true,
|
||||||
|
mobileView: true,
|
||||||
|
settings: {
|
||||||
|
enable_badges: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test("topic footer button - badges disabled - mobile", async (assert) => {
|
||||||
|
await visit("/t/internationalization-localization/280");
|
||||||
|
|
||||||
|
const subject = selectKit(".topic-footer-mobile-dropdown");
|
||||||
|
await subject.expand();
|
||||||
|
await subject.selectRowByValue("share-and-invite");
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
find(".share-and-invite.modal .modal-panel.share .topic-share-url")
|
||||||
|
.val()
|
||||||
|
.includes("?u=eviltrout"),
|
||||||
|
"it doesn't add the username param when badges are disabled"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user