UX: Group membership PMs thread (#26974)
Instead of creating two separate Topics when a user (1) requests to join a group and (2) gets accepted in, this makes the acceptance message into a Post under the origin group request Topic.
This commit is contained in:
parent
0012d9626f
commit
e42ba6e90a
|
@ -480,6 +480,17 @@ class GroupsController < ApplicationController
|
||||||
user = User.find_by(id: params[:user_id])
|
user = User.find_by(id: params[:user_id])
|
||||||
raise Discourse::InvalidParameters.new(:user_id) if user.blank?
|
raise Discourse::InvalidParameters.new(:user_id) if user.blank?
|
||||||
|
|
||||||
|
# find original membership request PM
|
||||||
|
request_topic =
|
||||||
|
Topic.find_by(
|
||||||
|
title:
|
||||||
|
(
|
||||||
|
I18n.t "groups.request_membership_pm.title", group_name: group.name, locale: user.locale
|
||||||
|
),
|
||||||
|
archetype: "private_message",
|
||||||
|
user_id: user.id,
|
||||||
|
)
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
if params[:accept]
|
if params[:accept]
|
||||||
group.add(user)
|
group.add(user)
|
||||||
|
@ -492,9 +503,11 @@ class GroupsController < ApplicationController
|
||||||
if params[:accept]
|
if params[:accept]
|
||||||
PostCreator.new(
|
PostCreator.new(
|
||||||
current_user,
|
current_user,
|
||||||
title: I18n.t("groups.request_accepted_pm.title", group_name: group.name),
|
post_type: Post.types[:regular],
|
||||||
raw: I18n.t("groups.request_accepted_pm.body", group_name: group.name),
|
topic_id: request_topic.id,
|
||||||
archetype: Archetype.private_message,
|
raw:
|
||||||
|
(I18n.t "groups.request_accepted_pm.body", group_name: group.name, locale: user.locale),
|
||||||
|
reply_to_post_number: 1,
|
||||||
target_usernames: user.username,
|
target_usernames: user.username,
|
||||||
skip_validations: true,
|
skip_validations: true,
|
||||||
).create!
|
).create!
|
||||||
|
|
|
@ -638,7 +638,6 @@ en:
|
||||||
request_membership_pm:
|
request_membership_pm:
|
||||||
title: "Membership Request for @%{group_name}"
|
title: "Membership Request for @%{group_name}"
|
||||||
request_accepted_pm:
|
request_accepted_pm:
|
||||||
title: "You've been accepted into @%{group_name}"
|
|
||||||
body: |
|
body: |
|
||||||
Your request to enter @%{group_name} has been accepted and you are now a member.
|
Your request to enter @%{group_name} has been accepted and you are now a member.
|
||||||
|
|
||||||
|
|
|
@ -2267,21 +2267,83 @@ RSpec.describe GroupsController do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sends a private message when accepted" do
|
it "sends a reply to the request membership topic when accepted" do
|
||||||
GroupRequest.create!(group: group, user: other_user)
|
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),
|
||||||
|
raw: "*British accent* Please, sir, may I have some group?",
|
||||||
|
archetype: Archetype.private_message,
|
||||||
|
target_usernames: "#{user.username}",
|
||||||
|
skip_validations: true,
|
||||||
|
).create!
|
||||||
|
|
||||||
|
topic = Topic.last
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
put "/groups/#{group.id}/handle_membership_request.json",
|
put "/groups/#{group.id}/handle_membership_request.json",
|
||||||
params: {
|
params: {
|
||||||
user_id: other_user.id,
|
user_id: other_user.id,
|
||||||
accept: true,
|
accept: true,
|
||||||
}
|
}
|
||||||
}.to change { Topic.count }.by(1).and change { Post.count }.by(1)
|
}.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
|
||||||
|
|
||||||
|
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
|
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.archetype).to eq(Archetype.private_message)
|
||||||
expect(topic.title).to eq(I18n.t("groups.request_accepted_pm.title", group_name: group.name))
|
expect(Topic.first.title).to eq(
|
||||||
expect(topic.first_post.raw).to eq(
|
I18n.t("groups.request_membership_pm.title", group_name: group.name, locale: "fr"),
|
||||||
I18n.t("groups.request_accepted_pm.body", group_name: group.name).strip,
|
)
|
||||||
|
|
||||||
|
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, locale: "fr").strip,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue