FIX: Remove social sharing icons from private contexts (#10213)

This commit is contained in:
Penar Musaraj 2020-07-13 14:35:39 -04:00 committed by GitHub
parent e0f97c707e
commit c02e358146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 11 deletions

View File

@ -14,9 +14,10 @@ export default Component.extend({
topic: alias("panel.model.topic"), topic: alias("panel.model.topic"),
@discourseComputed @discourseComputed("topic.isPrivateMessage")
sources() { sources(isPM) {
return Sharing.activeSources(this.siteSettings.share_links); const privateContext = this.siteSettings.login_required || isPM;
return Sharing.activeSources(this.siteSettings.share_links, privateContext);
}, },
@discourseComputed("type", "topic.title") @discourseComputed("type", "topic.title")

View File

@ -14,9 +14,10 @@ export default Component.extend({
link: null, link: null,
visible: null, visible: null,
@discourseComputed @discourseComputed("topic.isPrivateMessage")
sources() { sources(isPM) {
return Sharing.activeSources(this.siteSettings.share_links); const privateContext = this.siteSettings.login_required || isPM;
return Sharing.activeSources(this.siteSettings.share_links, privateContext);
}, },
@discourseComputed("type", "postNumber") @discourseComputed("type", "postNumber")

View File

@ -40,6 +40,7 @@ export default {
id: "email", id: "email",
icon: "envelope-square", icon: "envelope-square",
title: I18n.t("share.email"), title: I18n.t("share.email"),
showInPrivateContext: true,
generateUrl: function(link, title) { generateUrl: function(link, title) {
return ( return (
"mailto:?to=&subject=" + "mailto:?to=&subject=" +

View File

@ -11,7 +11,7 @@
// The icon that will be displayed, choose between icon name `icon` and custom HTML `htmlIcon`. // The icon that will be displayed, choose between icon name `icon` and custom HTML `htmlIcon`.
// When both provided, prefer `icon` // When both provided, prefer `icon`
icon: 'twitter-square' icon: 'twitter-square',
htmlIcon: '<img src="example.com/example.jpg">', htmlIcon: '<img src="example.com/example.jpg">',
// A callback for generating the remote link from the `link` and `title` // A callback for generating the remote link from the `link` and `title`
@ -22,11 +22,14 @@
// If provided, handle by custom javascript rather than default url open // If provided, handle by custom javascript rather than default url open
clickHandler: function(link, title){ clickHandler: function(link, title){
alert("Hello!") alert("Hello!")
} },
// If true, opens in a popup of `popupHeight` size. If false it's opened in a new tab // If true, opens in a popup of `popupHeight` size. If false it's opened in a new tab
shouldOpenInPopup: true, shouldOpenInPopup: true,
popupHeight: 265 popupHeight: 265,
// If true, will show the sharing service in PMs and login_required sites
showInPrivateContext: false
}); });
``` ```
**/ **/
@ -77,12 +80,16 @@ export default {
} }
}, },
activeSources(linksSetting = "") { activeSources(linksSetting = "", privateContext = false) {
return linksSetting const sources = linksSetting
.split("|") .split("|")
.concat(_customSharingIds) .concat(_customSharingIds)
.map(s => _sources[s]) .map(s => _sources[s])
.compact(); .compact();
return privateContext
? sources.filter(s => s.showInPrivateContext)
: sources;
}, },
_reset() { _reset() {

View File

@ -39,4 +39,29 @@ QUnit.test("addSharingId", assert => {
1, 1,
"it adds sharing id to existing sharing settings" "it adds sharing id to existing sharing settings"
); );
const privateContext = true;
Sharing.addSource({
id: "another-source"
});
Sharing.addSharingId("another-source");
assert.equal(
Sharing.activeSources(sharingSettings, privateContext).length,
0,
"it does not add a regular source to sources in a private context"
);
Sharing.addSource({
id: "a-private-friendly-source",
showInPrivateContext: true
});
Sharing.addSharingId("a-private-friendly-source");
assert.equal(
Sharing.activeSources(sharingSettings, privateContext).length,
1,
"it does not add a regular source to sources in a private context"
);
}); });