FIX: Update transcript handling following core updates (#179)

This commit is contained in:
David Taylor 2023-11-27 12:04:54 +00:00 committed by GitHub
parent a6dfc289a4
commit 3860d82625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 23 deletions

View File

@ -1,32 +1,31 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { next } from "@ember/runloop"; import { inject as service } from "@ember/service";
export default class Trascript extends DiscourseRoute { export default class Trascript extends DiscourseRoute {
model(params) { @service currentUser;
if (this.currentUser) { @service composer;
@service router;
async model(params) {
if (!this.currentUser) {
this.session.set("shouldRedirectToUrl", window.location.href);
this.router.replaceWith("login");
return;
}
const secret = params.secret; const secret = params.secret;
this.replaceWith("discovery.latest").then((e) => { await this.router.replaceWith("discovery.latest").followRedirects();
if (this.controllerFor("navigation/default").get("canCreateTopic")) {
next(() => { try {
ajax(`chat-transcript/${secret}`).then((result) => { const result = await ajax(`/chat-transcript/${secret}`);
e.send( this.composer.openNewTopic({
"createNewTopicViaParams", body: result.content,
null,
result["content"],
null,
null,
null
);
}, popupAjaxError);
}); });
} } catch (e) {
}); popupAjaxError(e);
} else {
this.session.set("shouldRedirectToUrl", window.location.href);
this.replaceWith("login");
} }
} }
} }

View File

@ -0,0 +1,37 @@
import { settled, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
/**
* Workaround for https://github.com/tildeio/router.js/pull/335
*/
async function visitWithRedirects(url) {
try {
await visit(url);
} catch (error) {
const { message } = error;
if (message !== "TransitionAborted") {
throw error;
}
await settled();
}
}
acceptance("Chat Integration - slack transcript", function (needs) {
needs.user({
can_create_topic: true,
});
needs.pretender((server, helper) => {
server.get("/chat-transcript/abcde", () => {
return helper.response({
content: "This is a chat transcript",
});
});
});
test("Can open composer with transcript", async function (assert) {
await visitWithRedirects("/chat-transcript/abcde");
assert.dom(".d-editor-input").hasValue("This is a chat transcript");
});
});