mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 18:14:45 +08:00
FIX: Improvements to like button for archived topics (#17951)
* FIX: Do not allow to remove like if topic is archived * FIX: Always show like button The like button used to be hidden if the topic was archived and it had no likes. This commit changes that to always show the like button, but with a not-allowed cursor if the topic is archived.
This commit is contained in:
@ -255,12 +255,10 @@ export default function transformPost(
|
||||
if (likeAction) {
|
||||
postAtts.liked = likeAction.acted;
|
||||
postAtts.canToggleLike = likeAction.get("canToggle");
|
||||
postAtts.showLike = postAtts.liked || postAtts.canToggleLike;
|
||||
postAtts.showLike = true;
|
||||
postAtts.likeCount = likeAction.count;
|
||||
}
|
||||
|
||||
if (!currentUser) {
|
||||
postAtts.showLike = !topic.archived;
|
||||
} else if (!currentUser) {
|
||||
postAtts.showLike = true;
|
||||
}
|
||||
|
||||
if (postAtts.post_number === 1) {
|
||||
|
@ -147,7 +147,9 @@ function likeCount(attrs, state) {
|
||||
|
||||
registerButton("like-count", likeCount);
|
||||
|
||||
registerButton("like", (attrs) => {
|
||||
registerButton(
|
||||
"like",
|
||||
(attrs, _state, _siteSettings, _settings, currentUser) => {
|
||||
if (!attrs.showLike) {
|
||||
return likeCount(attrs);
|
||||
}
|
||||
@ -173,15 +175,17 @@ registerButton("like", (attrs) => {
|
||||
// this is important for accessibility.
|
||||
if (attrs.liked && !attrs.canToggleLike) {
|
||||
button.title = "post.controls.has_liked";
|
||||
button.disabled = true;
|
||||
} else {
|
||||
button.title = attrs.liked
|
||||
? "post.controls.undo_like"
|
||||
: "post.controls.like";
|
||||
}
|
||||
|
||||
if (currentUser && !attrs.canToggleLike) {
|
||||
button.disabled = true;
|
||||
}
|
||||
return button;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
registerButton("flag-count", (attrs) => {
|
||||
let className = "button-count";
|
||||
|
@ -315,7 +315,8 @@ class PostSerializer < BasicPostSerializer
|
||||
summary.delete(:count) if summary[:count] == 0
|
||||
|
||||
# Only include it if the user can do it or it has a count
|
||||
if summary[:can_act] || summary[:count]
|
||||
# If it is a like, we want to show it always (even for archived topic)
|
||||
if summary[:can_act] || summary[:count] || (sym == :like && object.user_id != scope.user&.id)
|
||||
result << summary
|
||||
end
|
||||
end
|
||||
|
@ -232,7 +232,7 @@ module PostGuardian
|
||||
def can_delete_post_action?(post_action)
|
||||
return false unless is_my_own?(post_action) && !post_action.is_private_message?
|
||||
|
||||
post_action.created_at > SiteSetting.post_undo_action_window_mins.minutes.ago
|
||||
post_action.created_at > SiteSetting.post_undo_action_window_mins.minutes.ago && !post_action.post.topic&.archived?
|
||||
end
|
||||
|
||||
def can_see_post?(post)
|
||||
|
@ -2235,6 +2235,12 @@ RSpec.describe Guardian do
|
||||
expect(Guardian.new(user).can_delete?(post_action)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false if topic is archived" do
|
||||
post.topic.update!(archived: true)
|
||||
|
||||
expect(Guardian.new(user).can_delete?(post_action)).to be_falsey
|
||||
end
|
||||
|
||||
it "returns true if it's yours" do
|
||||
expect(Guardian.new(user).can_delete?(post_action)).to be_truthy
|
||||
end
|
||||
|
@ -55,6 +55,14 @@ RSpec.describe PostSerializer do
|
||||
|
||||
expect(notify_user_action).to eq(nil)
|
||||
end
|
||||
|
||||
it "shows like for archived topics even if user cannot act" do
|
||||
post = Fabricate(:post)
|
||||
post.topic.update!(archived: true)
|
||||
|
||||
serializer = PostSerializer.new(post, scope: Guardian.new(actor), root: false)
|
||||
expect(serializer.as_json[:actions_summary].map { |a| a[:id] }).to include(PostActionType.types[:like])
|
||||
end
|
||||
end
|
||||
|
||||
context "with a post with reviewable content" do
|
||||
|
Reference in New Issue
Block a user