Files
discourse/spec/serializers/web_hook_post_serializer_spec.rb
Keegan George 6154fa6b45 FEATURE: Add translations to posts (#32564)
## 🔍 Overview
This update adds the ability for users to manually add translations to
specific posts. It adds a 🌐 icon on the post menu where you can click to
add translations for posts.

It also introduces a new site setting:
`content_localization_debug_allowed_groups` which is convenient when
debugging localized posts. It adds a globe icon in the post meta data
area along with a number of how many languages the post is translated
in. Hovering over the icon will show a tooltip with access to editing
and deleting the translated posts.

## 📸 Screenshots
<img width="1234" alt="Screenshot 2025-05-07 at 13 26 09"
src="https://github.com/user-attachments/assets/9d65374d-ee3e-4e8b-b171-b98db6f90f23"
/>
<img width="300" alt="Screenshot 2025-05-07 at 13 26 41"
src="https://github.com/user-attachments/assets/6ee9c5e6-16ed-4dab-97ec-9401804a4ac8"
/>
2025-05-08 10:40:36 -07:00

82 lines
1.9 KiB
Ruby

# frozen_string_literal: true
RSpec.describe WebHookPostSerializer do
fab!(:admin)
fab!(:post)
def serialized_for_user(u)
WebHookPostSerializer.new(post, scope: Guardian.new(u), root: false).as_json
end
it "should only include the required keys" do
expect(serialized_for_user(admin).keys).to contain_exactly(
:id,
:name,
:username,
:avatar_template,
:created_at,
:cooked,
:post_number,
:post_type,
:posts_count,
:updated_at,
:reply_count,
:reply_to_post_number,
:quote_count,
:incoming_link_count,
:reads,
:score,
:topic_id,
:topic_slug,
:topic_title,
:category_id,
:display_username,
:primary_group_name,
:flair_name,
:flair_group_id,
:version,
:user_title,
:bookmarked,
:raw,
:moderator,
:admin,
:staff,
:user_id,
:hidden,
:trust_level,
:deleted_at,
:user_deleted,
:edit_reason,
:wiki,
:reviewable_id,
:reviewable_score_count,
:reviewable_score_pending_count,
:post_url,
:topic_posts_count,
:topic_filtered_posts_count,
:topic_archetype,
:category_slug,
:has_post_localizations,
:post_localizations,
)
end
it "includes category_id" do
expect(serialized_for_user(admin)[:category_id]).to eq(post.topic.category_id)
end
it "should only include deleted topic title for staffs" do
topic = post.topic
PostDestroyer.new(Discourse.system_user, post, context: "Automated testing").destroy
post.reload
[nil, post.user, Fabricate(:user)].each do |user|
expect(serialized_for_user(user)[:topic_title]).to eq(nil)
end
[Fabricate(:moderator), admin].each do |user|
expect(serialized_for_user(user)[:topic_title]).to eq(topic.title)
end
end
end