first proof of concept, security still missing

This commit is contained in:
Sam 2015-05-19 16:26:22 +10:00
parent 43f40c9825
commit a4e9ee4552
4 changed files with 28 additions and 6 deletions

View File

@ -1,5 +1,5 @@
{{#if topic.accepted_answer}}
<p class="solved">
<i class='fa-check-square fa accepted'></i> Solved by <a data-user-card="{{topic.accepted_answer.username}}">{{topic.accepted_answer.username}}</a> in <a href="{{acceptedAnswerPath}}">post #{{topic.accepted_answer.post_number}}</a>
{{{topic.acceptedAnswerHtml}}}
</p>
{{/if}}

View File

@ -2,16 +2,31 @@ import PostMenuView from 'discourse/views/post-menu';
import PostView from 'discourse/views/post';
import { Button } from 'discourse/views/post-menu';
import Topic from 'discourse/models/topic';
import User from 'discourse/models/user';
export default {
name: 'extend-for-solved-button',
initialize: function() {
Topic.reopen({
// keeping this here cause there is complex localization
acceptedAnswerHtml: function(){
return I18n.t("")
}.property('accepted_answer')
var username = this.get('accepted_answer.username');
var postNumber = this.get('accepted_answer.post_number');
if (!username || !postNumber) {
return "";
}
return I18n.t("accepted_answer.accepted_html", {
username_lower: username.toLowerCase(),
username: username,
post_path: this.get('url') + "/" + postNumber,
post_number: postNumber,
user_path: User.create({username: username}).get('path')
});
}.property('accepted_answer', 'id')
});
PostView.reopen({
@ -35,7 +50,8 @@ export default {
clickUnacceptAnswer: function(){
this.set('post.can_accept_answer', true);
this.set('post.can_unaccept_answer', false);
this.set('post.topic.has_accepted_answer', false);
this.set('post.accepted_answer', false);
this.set('post.topic.accepted_answer', undefined);
Discourse.ajax("/solution/unaccept", {
type: 'POST',

View File

@ -0,0 +1,6 @@
en:
js:
accepted_answer:
accept_answer: "Accept answer"
unaccept_answer: "Unaccept answer"
accepted_html: "<i class='fa-check-square fa accepted'></i> Solved by <a href data-user-card='{{username_lower}}'>{{username}}</a> in <a href='{{post_path}}'>post #{{post_number}}</a>"

View File

@ -22,8 +22,8 @@ after_initialize do
post = Post.find(params[:id].to_i)
accepted_id = post.topic.custom_fields["has_accepted_answer"].to_i
if accepted_id
accepted_id = post.topic.custom_fields["accepted_answer_post_id"].to_i
if accepted_id > 0
if p2 = Post.find_by(id: accepted_id)
p2.custom_fields["is_accepted_answer"] = nil
p2.save!