Skip to content

FIX: Wrong link to groups in post-small-action widget #33099

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

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { i18n } from "discourse-i18n";

// TODO (glimmer-post-stream) remove the export after removing the legacy widget code
export const GROUP_ACTION_CODES = ["invited_group", "removed_group"];
const customGroupActionCodes = [];
export const customGroupActionCodes = [];

export const ICONS = {
"closed.enabled": "lock",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { computed } from "@ember/object";
import { htmlSafe } from "@ember/template";
import { h } from "virtual-dom";
import {
customGroupActionCodes,
GROUP_ACTION_CODES,
ICONS,
} from "discourse/components/post/small-action";
Expand All @@ -24,7 +25,10 @@ export function actionDescriptionHtml(actionCode, createdAt, username, path) {

let who = "";
if (username) {
if (GROUP_ACTION_CODES.includes(actionCode)) {
if (
GROUP_ACTION_CODES.includes(actionCode) ||
customGroupActionCodes.includes(actionCode)
) {
who = `<a class="mention-group" href="/g/${username}">@${username}</a>`;
} else {
who = `<a class="mention" href="${userPath(username)}">@${username}</a>`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { module, test } from "qunit";
import PostSmallAction from "discourse/components/post/small-action";
import { withPluginApi } from "discourse/lib/plugin-api";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import I18n from "discourse-i18n";

function renderComponent(post) {
return render(<template><PostSmallAction @post={{post}} /></template>);
Expand Down Expand Up @@ -100,6 +101,36 @@ module("Integration | Component | Post | PostSmallAction", function (hooks) {
.exists("the custom icon was rendered");
});

test("api.addGroupPostSmallActionCode", async function (assert) {
withPluginApi((api) => {
api.addGroupPostSmallActionCode("some_code");
});

this.post.action_code = "some_code";
this.post.action_code_who = "somegroup";

I18n.translations[I18n.locale].js.action_codes = {
some_code: "Some %{who} Code Action",
};

await renderComponent(this.post);

assert
.dom(".small-action")
.hasText(
"Some @somegroup Code Action",
"the action code text was rendered correctly"
);

assert
.dom("a.mention-group")
.hasAttribute(
"href",
"/g/somegroup",
"the group mention link has the correct href"
);
});

test("api.addPostSmallActionIcon", async function (assert) {
withPluginApi((api) => {
api.addPostSmallActionIcon("open_topic", "far-circle-check");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import MountWidget from "discourse/components/mount-widget";
import { withSilencedDeprecations } from "discourse/lib/deprecated";
import { withPluginApi } from "discourse/lib/plugin-api";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import I18n from "discourse-i18n";

// TODO (glimmer-post-stream) remove this test when removing the widget post stream code
module(
Expand Down Expand Up @@ -114,6 +115,42 @@ module(
.exists("adds the recover small action button");
});

test("`addGroupPostSmallActionCode` plugin api", async function (assert) {
const self = this;

withPluginApi("1.6.0", (api) => {
api.addGroupPostSmallActionCode("some_code");
});

this.set("args", {
id: 123,
actionCode: "some_code",
actionCodeWho: "somegroup",
});

I18n.translations[I18n.locale].js.action_codes = {
some_code: "Some %{who} Code Action",
};
await render(
<template>
<MountWidget @widget="post-small-action" @args={{self.args}} />
</template>
);
assert
.dom(".small-action")
.hasText(
"Some @somegroup Code Action",
"the action code text was rendered correctly"
);
assert
.dom("a.mention-group")
.hasAttribute(
"href",
"/g/somegroup",
"the group mention link has the correct href"
);
});

test("`addPostSmallActionClassesCallback` plugin api", async function (assert) {
const self = this;

Expand Down
Loading