Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: anon access, git workflow branch #88

Merged
merged 14 commits into from
Feb 1, 2024
2 changes: 1 addition & 1 deletion .github/workflows/discourse-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Discourse Plugin
on:
push:
branches:
- main
- master
pull_request:

jobs:
Expand Down
40 changes: 23 additions & 17 deletions assets/javascripts/discourse/initializers/retort-init.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,35 @@ function initializePlugin(api) {
}

api.decorateWidget("post-menu:before-extra-controls", (helper) => {
let retort = api.container.lookup("service:retort");
let postId = helper.getModel().id;
let post = retort.postFor(postId);
let currentUser = api.container.lookup("service:currentUser");

if (retort.disabledFor(postId)) {
return;
}
if (currentUser) {
let retort = api.container.lookup("service:retort");
let postId = helper.getModel().id;
let post = retort.postFor(postId);

retort.storeWidget(helper);
if (retort.disabledFor(postId)) {
return;
}

if (!post.retorts) {
return;
}
retort.storeWidget(helper);

if (!post.retorts) {
return;
}

const retorts = post.retorts.map(({ usernames, emoji }) => {
return helper.attach("retort-toggle", {
post,
usernames,
emoji,
const retorts = post.retorts.map(({ usernames, emoji }) => {
return helper.attach("retort-toggle", {
post,
usernames,
emoji,
});
});
});

return helper.h("div.post-retort-container", retorts);
return helper.h("div.post-retort-container", retorts);
} else {
return "";
}
});

api.addPostClassesCallback((attrs) => {
Expand Down
27 changes: 16 additions & 11 deletions assets/javascripts/discourse/services/retort.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default class RetortService extends Service {
@service siteSettings;
@service messageBus;
@service router;
@service currentUser;
@tracked picker;
@tracked model;
@tracked widgets;
Expand All @@ -20,19 +21,20 @@ export default class RetortService extends Service {
if (this.model.id) {
this.messageBus.unsubscribe(`/retort/topics/${this.model.id}`);
}
if (this.currentUser) {
this.messageBus.subscribe(
`/retort/topics/${this.model.id}`,
({ id, retorts }) => {
const post = this.postFor(id);
if (!post) {
return;
}

this.messageBus.subscribe(
`/retort/topics/${this.model.id}`,
({ id, retorts }) => {
const post = this.postFor(id);
if (!post) {
return;
post.setProperties({ retorts });
this.get(`widgets.${id}`).scheduleRerender();
}

post.setProperties({ retorts });
this.get(`widgets.${id}`).scheduleRerender();
}
);
);
}
}

postFor(id) {
Expand All @@ -59,6 +61,9 @@ export default class RetortService extends Service {
}

disabledFor(postId) {
if (!this.currentUser) {
return true;
}
const post = this.postFor(postId);
if (!post) {
return true;
Expand Down
21 changes: 21 additions & 0 deletions test/javascripts/acceptance/retort-anon-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { default as RetortTopics } from "../fixtures/retort-topic-fixtures";

acceptance("Retort - Anon", function (needs) {
needs.settings({
retort_enabled: true,
});

needs.pretender((server, helper) => {
const topicPath = "/t/56.json";
server.get(topicPath, () => helper.response(RetortTopics[topicPath]));
});

test("It does not show retort controls", async (assert) => {
await visit("/t/slug/56");

assert.notOk(exists("button.retort"), "retort controls are not available");
});
});