Skip to content
Permalink
Browse files

FIX: Skip attachments in click track.

  • Loading branch information
nbianca committed May 8, 2019
1 parent f530048 commit 861023f0d64d1ba26c07d42d24ad55315e50ed1b
@@ -52,22 +52,26 @@ export default {
return true;
}

let href = ($link.attr("href") || $link.data("href") || "").trim();
if (!href || href.indexOf("mailto:") === 0) {
return true;
}

if ($link.hasClass("attachment")) {
// Warn the user if they cannot download the file.
if (
Discourse.SiteSettings.prevent_anons_from_downloading_files &&
!Discourse.User.current()
) {
bootbox.alert(I18n.t("post.errors.attachment_download_requires_login"));
return false;
} else if (wantsNewWindow(e)) {
const newWindow = window.open(href, "_blank");
newWindow.opener = null;
newWindow.focus();
} else {
DiscourseURL.redirectTo(href);
}

return true;
}

let href = ($link.attr("href") || $link.data("href") || "").trim();
if (!href || href.indexOf("mailto:") === 0) {
return true;
return false;
}

const $article = $link.closest(
@@ -70,13 +70,13 @@ QUnit.test("does not track elements with no href", async assert => {
});

QUnit.test("does not track attachments", async assert => {
assert.expect(1);
sandbox.stub(DiscourseURL, "origin").returns("http://discuss.domain.com");

/* global server */
server.post("/clicks/track", () => assert.ok(false));

assert.ok(track(generateClickEventOn(".attachment")));
assert.notOk(track(generateClickEventOn(".attachment")));
assert.ok(DiscourseURL.redirectTo.calledWith("http://discuss.domain.com/uploads/default/1234/1532357280.txt"));
});

QUnit.test("tracks external URLs", async assert => {

4 comments on commit 861023f

@discoursebot

This comment has been minimized.

Copy link

discoursebot replied May 8, 2019

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/subfolder-issue-with-pdf-uploads/116896/5

@discoursebot

This comment has been minimized.

Copy link

discoursebot replied May 8, 2019

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/file-attachment-download-link-returns-success-ok/117092/4

@SamSaffron

This comment has been minimized.

Copy link
Member

SamSaffron replied May 9, 2019

If we are already doing mail: here maybe just do any custom protocol? allowed href schemes Site Setting allows users to enter custom protocols.

@discoursereviewbot

This comment has been minimized.

Copy link

discoursereviewbot replied Jan 8, 2020

Régis Hanol posted:

Actually, we are not blacklisting any custom protocols other than mailto (since 2016) because it's breaking mail integration (I think?).

So I think we're fine here?

Please sign in to comment.
You can’t perform that action at this time.