Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

FIX: Guardian can_rebake? was breaking core post rebake endpoint #680

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/chat_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def restore
end

def rebake
guardian.ensure_can_rebake!(@message)
guardian.ensure_can_rebake_chat_message!(@message)
@message.rebake!(invalidate_oneboxes: true)
render json: success_json
end
Expand Down
2 changes: 1 addition & 1 deletion lib/guardian_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def can_move_chat_to_topic?(chat_channel)
is_staff? && can_modify_channel_message?(chat_channel)
end

def can_rebake?(message)
def can_rebake_chat_message?(message)
return false if !can_modify_channel_message?(message.chat_channel)
is_staff? || @user.has_trust_level?(TrustLevel[4])
end
Expand Down
9 changes: 9 additions & 0 deletions spec/requests/chat_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,15 @@
end
end

it "does not interfere with core's guardian can_rebake? for posts" do
sign_in(Fabricate(:admin))
put "/chat/#{chat_channel.id}/#{chat_message.id}/rebake.json"
expect(response.status).to eq(200)
post = Fabricate(:post)
put "/posts/#{post.id}/rebake.json"
expect(response.status).to eq(200)
end

it "does not rebake the post when channel is read_only" do
chat_message.chat_channel.update!(status: :read_only)
sign_in(Fabricate(:admin))
Expand Down