FEATURE: Show error if invite to topic is invalid (#15959)

This can happen if the topic to which a user is invited is in a private
category and the user was not invited to one of the groups that can see
that specific category.

This used to be a warning and this commit makes it an error.
This commit is contained in:
Dan Ungureanu
2022-02-16 18:35:02 +02:00
committed by GitHub
parent 34e2ed6d76
commit effbd6d3e4
8 changed files with 60 additions and 66 deletions

View File

@@ -138,6 +138,11 @@ class InvitesController < ApplicationController
guardian.ensure_can_invite_to_forum!(groups)
if !groups_can_see_topic?(groups, topic)
editable_topic_groups = topic.category.groups.filter { |g| guardian.can_edit_group?(g) }
return render_json_error(I18n.t("invite.requires_groups", groups: editable_topic_groups.pluck(:name).join(", ")))
end
begin
invite = Invite.generate(current_user,
email: params[:email],
@@ -201,6 +206,11 @@ class InvitesController < ApplicationController
groups.each { |group| invite.invited_groups.find_or_create_by!(group_id: group.id) } if groups.present?
end
if !groups_can_see_topic?(invite.groups, invite.topics.first)
editable_topic_groups = invite.topics.first.category.groups.filter { |g| guardian.can_edit_group?(g) }
return render_json_error(I18n.t("invite.requires_groups", groups: editable_topic_groups.pluck(:name).join(", ")))
end
if params.has_key?(:email)
old_email = invite.email.presence
new_email = params[:email].presence
@@ -448,6 +458,15 @@ class InvitesController < ApplicationController
end
end
def groups_can_see_topic?(groups, topic)
if topic&.read_restricted_category?
topic_groups = topic.category.groups
return false if (groups & topic_groups).blank?
end
true
end
def post_process_invite(user)
user.enqueue_welcome_message('welcome_invite') if user.send_welcome_message