mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 13:43:16 +08:00
FIX: Show membership requests link just for group owners. (#7543)
This commit is contained in:
parent
4ae8065f2c
commit
b60b2a342f
|
@ -443,20 +443,12 @@ class GroupsController < ApplicationController
|
||||||
.pluck("users.username")
|
.pluck("users.username")
|
||||||
)
|
)
|
||||||
|
|
||||||
raw = <<~EOF
|
|
||||||
#{reason}
|
|
||||||
|
|
||||||
---
|
|
||||||
<a href="#{Discourse.base_uri}/g/#{group.name}/requests">
|
|
||||||
#{I18n.t('groups.request_membership_pm.handle')}
|
|
||||||
</a>
|
|
||||||
EOF
|
|
||||||
|
|
||||||
post = PostCreator.new(current_user,
|
post = PostCreator.new(current_user,
|
||||||
title: I18n.t('groups.request_membership_pm.title', group_name: group.name),
|
title: I18n.t('groups.request_membership_pm.title', group_name: group.name),
|
||||||
raw: raw,
|
raw: params[:reason],
|
||||||
archetype: Archetype.private_message,
|
archetype: Archetype.private_message,
|
||||||
target_usernames: usernames.join(','),
|
target_usernames: usernames.join(','),
|
||||||
|
custom_fields: { requested_group_id: group.id },
|
||||||
skip_validations: true
|
skip_validations: true
|
||||||
).create!
|
).create!
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,27 @@ class BasicPostSerializer < ApplicationSerializer
|
||||||
I18n.t('flagging.user_must_edit')
|
I18n.t('flagging.user_must_edit')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
object.filter_quotes(@parent_post)
|
cooked = object.filter_quotes(@parent_post)
|
||||||
|
|
||||||
|
if scope&.user
|
||||||
|
group = Group
|
||||||
|
.joins('JOIN group_users ON groups.id = group_users.group_id')
|
||||||
|
.find_by(
|
||||||
|
id: object.custom_fields['requested_group_id'].to_i,
|
||||||
|
group_users: { user_id: scope.user.id, owner: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
if group
|
||||||
|
cooked << <<~EOF
|
||||||
|
<hr />
|
||||||
|
<a href="#{Discourse.base_uri}/g/#{group.name}/requests">
|
||||||
|
#{I18n.t('groups.request_membership_pm.handle')}
|
||||||
|
</a>
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cooked
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class TopicView
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.default_post_custom_fields
|
def self.default_post_custom_fields
|
||||||
@default_post_custom_fields ||= ["action_code_who", "notice_type", "notice_args"]
|
@default_post_custom_fields ||= ["action_code_who", "notice_type", "notice_args", "requested_group_id"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.post_custom_fields_whitelisters
|
def self.post_custom_fields_whitelisters
|
||||||
|
|
|
@ -1351,6 +1351,7 @@ describe GroupsController do
|
||||||
body = JSON.parse(response.body)
|
body = JSON.parse(response.body)
|
||||||
|
|
||||||
expect(body['relative_url']).to eq(topic.relative_url)
|
expect(body['relative_url']).to eq(topic.relative_url)
|
||||||
|
expect(post.custom_fields['requested_group_id'].to_i).to eq(group.id)
|
||||||
expect(post.user).to eq(user)
|
expect(post.user).to eq(user)
|
||||||
|
|
||||||
expect(topic.title).to eq(I18n.t('groups.request_membership_pm.title',
|
expect(topic.title).to eq(I18n.t('groups.request_membership_pm.title',
|
||||||
|
|
|
@ -24,4 +24,27 @@ describe BasicPostSerializer do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "cooked" do
|
||||||
|
it "includes membership requests" do
|
||||||
|
user = Fabricate(:user)
|
||||||
|
member = Fabricate(:user)
|
||||||
|
owner = Fabricate(:user)
|
||||||
|
|
||||||
|
group = Fabricate(:group)
|
||||||
|
group.add(member)
|
||||||
|
group.add_owner(owner)
|
||||||
|
|
||||||
|
post = Fabricate(:post, custom_fields: { requested_group_id: group.id })
|
||||||
|
|
||||||
|
json = BasicPostSerializer.new(post, scope: Guardian.new(user), root: false).as_json
|
||||||
|
expect(json[:cooked]).not_to include(I18n.t('groups.request_membership_pm.handle'))
|
||||||
|
|
||||||
|
json = BasicPostSerializer.new(post, scope: Guardian.new(member), root: false).as_json
|
||||||
|
expect(json[:cooked]).not_to include(I18n.t('groups.request_membership_pm.handle'))
|
||||||
|
|
||||||
|
json = BasicPostSerializer.new(post, scope: Guardian.new(owner), root: false).as_json
|
||||||
|
expect(json[:cooked]).to include(I18n.t('groups.request_membership_pm.handle'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user