mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-05-03 20:55:05 +00:00
FEATURE: Add setting to show who marked as solved
This commit is contained in:
parent
d88ea600b9
commit
1797ffe20c
@ -1,4 +1,5 @@
|
|||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
|
import { htmlSafe } from "@ember/template";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import DButton from "discourse/components/d-button";
|
import DButton from "discourse/components/d-button";
|
||||||
@ -6,6 +7,7 @@ import icon from "discourse/helpers/d-icon";
|
|||||||
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 { i18n } from "discourse-i18n";
|
import { i18n } from "discourse-i18n";
|
||||||
|
import DTooltip from "float-kit/components/d-tooltip";
|
||||||
|
|
||||||
export function unacceptAnswer(post, appEvents) {
|
export function unacceptAnswer(post, appEvents) {
|
||||||
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
|
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
|
||||||
@ -41,23 +43,52 @@ function unacceptPost(post) {
|
|||||||
|
|
||||||
export default class SolvedUnacceptAnswerButton extends Component {
|
export default class SolvedUnacceptAnswerButton extends Component {
|
||||||
@service appEvents;
|
@service appEvents;
|
||||||
|
@service siteSettings;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
unacceptAnswer() {
|
unacceptAnswer() {
|
||||||
unacceptAnswer(this.args.post, this.appEvents);
|
unacceptAnswer(this.args.post, this.appEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get solvedBy() {
|
||||||
|
const username = this.args.post.topic.accepted_answer.accepter_username
|
||||||
|
if (this.siteSettings.show_who_marked_solved && this.args.post.topic.accepted_answer.accepter_username) {
|
||||||
|
return i18n("solved.marked_solved_by", {
|
||||||
|
username,
|
||||||
|
username_lower: username,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<span class="extra-buttons">
|
<span class="extra-buttons">
|
||||||
{{#if @post.can_unaccept_answer}}
|
{{#if @post.can_unaccept_answer}}
|
||||||
<DButton
|
{{#if this.solvedBy}}
|
||||||
class="post-action-menu__solved-accepted accepted fade-out"
|
<DTooltip @identifier="post-action-menu__solved-accepted-tooltip">
|
||||||
...attributes
|
<:trigger>
|
||||||
@action={{this.unacceptAnswer}}
|
<DButton
|
||||||
@icon="square-check"
|
class="post-action-menu__solved-accepted accepted fade-out"
|
||||||
@label="solved.solution"
|
...attributes
|
||||||
@title="solved.unaccept_answer"
|
@action={{this.unacceptAnswer}}
|
||||||
/>
|
@icon="square-check"
|
||||||
|
@label="solved.solution"
|
||||||
|
@title="solved.unaccept_answer"
|
||||||
|
/>
|
||||||
|
</:trigger>
|
||||||
|
<:content>
|
||||||
|
{{htmlSafe this.solvedBy}}
|
||||||
|
</:content>
|
||||||
|
</DTooltip>
|
||||||
|
{{else}}
|
||||||
|
<DButton
|
||||||
|
class="post-action-menu__solved-accepted accepted fade-out"
|
||||||
|
...attributes
|
||||||
|
@action={{this.unacceptAnswer}}
|
||||||
|
@icon="square-check"
|
||||||
|
@label="solved.solution"
|
||||||
|
@title="solved.unaccept_answer"
|
||||||
|
/>
|
||||||
|
{{/if}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<span
|
<span
|
||||||
class="accepted-text"
|
class="accepted-text"
|
||||||
|
@ -193,6 +193,9 @@ export default {
|
|||||||
accepterHtml: computed("accepted_answer", function () {
|
accepterHtml: computed("accepted_answer", function () {
|
||||||
const username = this.get("accepted_answer.accepter_username");
|
const username = this.get("accepted_answer.accepter_username");
|
||||||
const name = this.get("accepted_answer.accepter_name");
|
const name = this.get("accepted_answer.accepter_name");
|
||||||
|
if (!this.siteSettings.show_who_marked_solved) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
const formattedUsername =
|
const formattedUsername =
|
||||||
this.siteSettings.display_name_on_posts && name
|
this.siteSettings.display_name_on_posts && name
|
||||||
? name
|
? name
|
||||||
|
@ -98,3 +98,7 @@ aside.quote.accepted-answer {
|
|||||||
.user-card-metadata-outlet.accepted-answers {
|
.user-card-metadata-outlet.accepted-answers {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-action-menu__solved-accepted-tooltip-content .fk-d-tooltip__inner-content {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
@ -19,6 +19,7 @@ en:
|
|||||||
solved_add_schema_markup: "Add QAPage schema markup to HTML."
|
solved_add_schema_markup: "Add QAPage schema markup to HTML."
|
||||||
enable_solved_tags: "Tags that will allow users to select solutions."
|
enable_solved_tags: "Tags that will allow users to select solutions."
|
||||||
prioritize_solved_topics_in_search: "Prioritize solved topics in search results."
|
prioritize_solved_topics_in_search: "Prioritize solved topics in search results."
|
||||||
|
show_who_marked_solved: "Show who marked the topic as solved. This is indicated in the topic's first post, and the answer post in a tooltip."
|
||||||
|
|
||||||
keywords:
|
keywords:
|
||||||
accept_all_solutions_allowed_groups: "accept_all_solutions_trust_level"
|
accept_all_solutions_allowed_groups: "accept_all_solutions_trust_level"
|
||||||
|
@ -2,6 +2,9 @@ discourse_solved:
|
|||||||
solved_enabled:
|
solved_enabled:
|
||||||
default: true
|
default: true
|
||||||
client: true
|
client: true
|
||||||
|
show_who_marked_solved:
|
||||||
|
default: false
|
||||||
|
client: true
|
||||||
allow_solved_on_all_topics:
|
allow_solved_on_all_topics:
|
||||||
default: false
|
default: false
|
||||||
client: true
|
client: true
|
||||||
|
@ -36,11 +36,14 @@ module DiscourseSolved::TopicViewSerializerExtension
|
|||||||
post_number: answer_post.post_number,
|
post_number: answer_post.post_number,
|
||||||
username: answer_post_user.username,
|
username: answer_post_user.username,
|
||||||
name: answer_post_user.name,
|
name: answer_post_user.name,
|
||||||
accepter_username: accepter.username,
|
|
||||||
accepter_name: accepter.name,
|
|
||||||
excerpt:,
|
excerpt:,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if SiteSetting.show_who_marked_solved
|
||||||
|
accepted_answer[:accepter_name] = accepter.name
|
||||||
|
accepted_answer[:accepter_username] = accepter.username
|
||||||
|
end
|
||||||
|
|
||||||
if !SiteSetting.enable_names || !SiteSetting.display_name_on_posts
|
if !SiteSetting.enable_names || !SiteSetting.display_name_on_posts
|
||||||
accepted_answer[:name] = nil
|
accepted_answer[:name] = nil
|
||||||
accepted_answer[:accepter_name] = nil
|
accepted_answer[:accepter_name] = nil
|
||||||
|
@ -65,6 +65,7 @@ RSpec.describe TopicsController do
|
|||||||
|
|
||||||
it "should include user name in output with the corresponding site setting" do
|
it "should include user name in output with the corresponding site setting" do
|
||||||
SiteSetting.display_name_on_posts = true
|
SiteSetting.display_name_on_posts = true
|
||||||
|
SiteSetting.show_who_marked_solved = true
|
||||||
accepter = Fabricate(:user)
|
accepter = Fabricate(:user)
|
||||||
Fabricate(:solved_topic, topic: topic, answer_post: p2, accepter:)
|
Fabricate(:solved_topic, topic: topic, answer_post: p2, accepter:)
|
||||||
|
|
||||||
@ -75,6 +76,11 @@ RSpec.describe TopicsController do
|
|||||||
expect(response.parsed_body["accepted_answer"]["accepter_name"]).to eq(accepter.name)
|
expect(response.parsed_body["accepted_answer"]["accepter_name"]).to eq(accepter.name)
|
||||||
expect(response.parsed_body["accepted_answer"]["accepter_username"]).to eq(accepter.username)
|
expect(response.parsed_body["accepted_answer"]["accepter_username"]).to eq(accepter.username)
|
||||||
|
|
||||||
|
SiteSetting.show_who_marked_solved = false
|
||||||
|
get "/t/#{topic.slug}/#{topic.id}.json"
|
||||||
|
expect(response.parsed_body["accepted_answer"]["accepter_name"]).to eq(nil)
|
||||||
|
expect(response.parsed_body["accepted_answer"]["accepter_username"]).to eq(nil)
|
||||||
|
|
||||||
# enable_names is default ON, this ensures disabling it also disables names here
|
# enable_names is default ON, this ensures disabling it also disables names here
|
||||||
SiteSetting.enable_names = false
|
SiteSetting.enable_names = false
|
||||||
get "/t/#{topic.slug}/#{topic.id}.json"
|
get "/t/#{topic.slug}/#{topic.id}.json"
|
||||||
|
@ -12,6 +12,7 @@ describe "About page", type: :system do
|
|||||||
SiteSetting.solved_enabled = true
|
SiteSetting.solved_enabled = true
|
||||||
SiteSetting.allow_solved_on_all_topics = true
|
SiteSetting.allow_solved_on_all_topics = true
|
||||||
SiteSetting.accept_all_solutions_allowed_groups = Group::AUTO_GROUPS[:everyone]
|
SiteSetting.accept_all_solutions_allowed_groups = Group::AUTO_GROUPS[:everyone]
|
||||||
|
SiteSetting.show_who_marked_solved = true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "accepts post as solution and shows in OP" do
|
it "accepts post as solution and shows in OP" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user