FIX: Show membership requests link just for group owners. (#7543)

This commit is contained in:
Bianca Nenciu
2019-08-06 13:28:22 +03:00
committed by GitHub
parent 4ae8065f2c
commit b60b2a342f
5 changed files with 48 additions and 12 deletions
+2 -10
View File
@@ -443,20 +443,12 @@ class GroupsController < ApplicationController
.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,
title: I18n.t('groups.request_membership_pm.title', group_name: group.name),
raw: raw,
raw: params[:reason],
archetype: Archetype.private_message,
target_usernames: usernames.join(','),
custom_fields: { requested_group_id: group.id },
skip_validations: true
).create!
+21 -1
View File
@@ -38,7 +38,27 @@ class BasicPostSerializer < ApplicationSerializer
I18n.t('flagging.user_must_edit')
end
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