I edited the discourse-solved plugin code to hide the correct checkbox if you are not the OP but it kinda broke my badges. Can somebody help me see what part of the code I should update on my badges in order for it to work again? Thank you.
Edited code on the discourse-solved plugin:
api.addPostMenuButton('solved', attrs => {
const canAccept = attrs.can_accept_answer;
const canUnaccept = attrs.can_unaccept_answer;
const accepted = attrs.accepted_answer;
const isOp = currentUser && currentUser.id === attrs.topicCreatedById;
const position = (!accepted && canAccept && !isOp) ? 'second-last-hidden' : 'first';
if (canAccept) {
return {
action: 'acceptAnswer',
icon: 'check-square-o',
className: 'unaccepted',
title: 'solved.accept_answer',
position
};
} else if (canUnaccept) {
const title = canUnaccept ? 'solved.unaccept_answer' : '';
return {
action: 'unacceptAnswer',
icon: 'check-square',
title,
className: 'accepted fade-out',
position,
beforeButton(h) {
return h('span.accepted-text', I18n.t('solved.solution'));
}
};
} else if (accepted) {
const title = accepted ? 'solved.accepted_answer' : '';
return {
icon: '',
title,
className: 'not-op-accepted fade-out',
position,
beforeButton(h) {
return h('span.accepted-text', I18n.t('solved.solution'));
}
};
}
});
For Badge: This code is the example from discourse forum:
SELECT p.user_id, p.id post_id, p.updated_at granted_at
FROM badge_posts p
WHERE p.post_number > 1 AND
p.id IN (
SELECT post_id FROM (
SELECT pc.post_id, row_number()
OVER (PARTITION BY p1.user_id ORDER BY pc.created_at) as rnum
FROM post_custom_fields pc
JOIN badge_posts p1 ON p1.id = pc.post_id
JOIN topics t1 ON p1.topic_id = t1.id
WHERE name = 'is_accepted_answer' AND
value IS NOT NULL AND
p1.user_id <> t1.user_id AND
(
:backfill OR
p1.user_id IN (
select user_id from posts where p1.id IN (:post_ids)
)
)
) X WHERE rnum = 1)