mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-05-03 04:35:20 +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 { htmlSafe } from "@ember/template";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
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 { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import { i18n } from "discourse-i18n";
|
||||
import DTooltip from "float-kit/components/d-tooltip";
|
||||
|
||||
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
|
||||
@ -41,23 +43,52 @@ function unacceptPost(post) {
|
||||
|
||||
export default class SolvedUnacceptAnswerButton extends Component {
|
||||
@service appEvents;
|
||||
@service siteSettings;
|
||||
|
||||
@action
|
||||
unacceptAnswer() {
|
||||
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>
|
||||
<span class="extra-buttons">
|
||||
{{#if @post.can_unaccept_answer}}
|
||||
<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 this.solvedBy}}
|
||||
<DTooltip @identifier="post-action-menu__solved-accepted-tooltip">
|
||||
<:trigger>
|
||||
<DButton
|
||||
class="post-action-menu__solved-accepted accepted fade-out"
|
||||
...attributes
|
||||
@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}}
|
||||
<span
|
||||
class="accepted-text"
|
||||
|
@ -193,6 +193,9 @@ export default {
|
||||
accepterHtml: computed("accepted_answer", function () {
|
||||
const username = this.get("accepted_answer.accepter_username");
|
||||
const name = this.get("accepted_answer.accepter_name");
|
||||
if (!this.siteSettings.show_who_marked_solved) {
|
||||
return "";
|
||||
}
|
||||
const formattedUsername =
|
||||
this.siteSettings.display_name_on_posts && name
|
||||
? name
|
||||
|
@ -98,3 +98,7 @@ aside.quote.accepted-answer {
|
||||
.user-card-metadata-outlet.accepted-answers {
|
||||
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."
|
||||
enable_solved_tags: "Tags that will allow users to select solutions."
|
||||
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:
|
||||
accept_all_solutions_allowed_groups: "accept_all_solutions_trust_level"
|
||||
|
@ -2,6 +2,9 @@ discourse_solved:
|
||||
solved_enabled:
|
||||
default: true
|
||||
client: true
|
||||
show_who_marked_solved:
|
||||
default: false
|
||||
client: true
|
||||
allow_solved_on_all_topics:
|
||||
default: false
|
||||
client: true
|
||||
|
@ -36,11 +36,14 @@ module DiscourseSolved::TopicViewSerializerExtension
|
||||
post_number: answer_post.post_number,
|
||||
username: answer_post_user.username,
|
||||
name: answer_post_user.name,
|
||||
accepter_username: accepter.username,
|
||||
accepter_name: accepter.name,
|
||||
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
|
||||
accepted_answer[: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
|
||||
SiteSetting.display_name_on_posts = true
|
||||
SiteSetting.show_who_marked_solved = true
|
||||
accepter = Fabricate(:user)
|
||||
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_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
|
||||
SiteSetting.enable_names = false
|
||||
get "/t/#{topic.slug}/#{topic.id}.json"
|
||||
|
@ -12,6 +12,7 @@ describe "About page", type: :system do
|
||||
SiteSetting.solved_enabled = true
|
||||
SiteSetting.allow_solved_on_all_topics = true
|
||||
SiteSetting.accept_all_solutions_allowed_groups = Group::AUTO_GROUPS[:everyone]
|
||||
SiteSetting.show_who_marked_solved = true
|
||||
end
|
||||
|
||||
it "accepts post as solution and shows in OP" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user