Skip to content

Commit

Permalink
Handles different locales
Browse files Browse the repository at this point in the history
  • Loading branch information
brrusselburg committed May 17, 2024
1 parent a4df064 commit b9dc9cc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ def handle_membership_request
# find original membership request PM
request_topic =
Topic.find_by(
title: I18n.t("groups.request_membership_pm.title", group_name: group.name),
title:
(
I18n.t "groups.request_membership_pm.title", group_name: group.name, locale: user.locale
),
archetype: "private_message",
user_id: user.id,
)
Expand All @@ -479,7 +482,8 @@ def handle_membership_request
current_user,
post_type: Post.types[:regular],
topic_id: request_topic.id,
raw: I18n.t("groups.request_accepted_pm.body", group_name: group.name),
raw:
(I18n.t "groups.request_accepted_pm.body", group_name: group.name, locale: user.locale),
reply_to_post_number: 1,
target_usernames: user.username,
skip_validations: true,
Expand Down
44 changes: 44 additions & 0 deletions spec/requests/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,50 @@ def expect_type_to_return_right_groups(type, expected_group_ids)
I18n.t("groups.request_accepted_pm.body", group_name: group.name).strip,
)
end

it "sends accepted membership request reply even if request is in another language" do
SiteSetting.allow_user_locale = true
other_user.update!(locale: "fr")

GroupRequest.create!(group: group, user: other_user)

# send the initial request PM
PostCreator.new(
other_user,
title:
(
I18n.t "groups.request_membership_pm.title",
group_name: group.name,
locale: other_user.locale
),
raw: "*French accent* Please let me in!",
archetype: Archetype.private_message,
target_usernames: "#{user.username}",
skip_validations: true,
).create!

topic = Topic.last

expect {
put "/groups/#{group.id}/handle_membership_request.json",
params: {
user_id: other_user.id,
accept: true,
}
}.to_not change { Topic.count }

expect(topic.archetype).to eq(Archetype.private_message)
expect(Topic.first.title).to eq(
I18n.t("groups.request_membership_pm.title", group_name: group.name),
)

post = Post.last
expect(post.topic_id).to eq(Topic.last.id)
expect(topic.posts.count).to eq(2)
expect(post.raw).to eq(
I18n.t("groups.request_accepted_pm.body", group_name: group.name).strip,
)
end
end

describe "#histories" do
Expand Down

0 comments on commit b9dc9cc

Please sign in to comment.