FIX: don't allow inviting more than max_allowed_message_recipients

* FIX: don't allow inviting more than `max_allowed_message_recipients` setting allows

* add specs for guardian

* user preferences for auto track shouldn't be applicable to PMs (it auto watches on visit)

Execlude PMs from "Automatically track topics I enter..." and "When I post in a topic, set that topic to..." user preferences

* groups take only 1 slot in PM

* just return if topic is a PM
This commit is contained in:
Osama Sayegh
2018-08-23 07:36:49 +03:00
committed by Sam
parent b2ce33be26
commit 2711f173dc
10 changed files with 133 additions and 2 deletions

View File

@ -523,6 +523,12 @@ class TopicsController < ApplicationController
topic = Topic.find_by(id: params[:topic_id])
unless pm_has_slots?(topic)
return render_json_error(I18n.t("pm_reached_recipients_limit",
recipients_limit: SiteSetting.max_allowed_message_recipients
))
end
if topic.private_message?
guardian.ensure_can_invite_group_to_private_message!(group, topic)
topic.invite_group(current_user, group)
@ -543,6 +549,12 @@ class TopicsController < ApplicationController
group_names: params[:group_names]
)
unless pm_has_slots?(topic)
return render_json_error(I18n.t("pm_reached_recipients_limit",
recipients_limit: SiteSetting.max_allowed_message_recipients
))
end
guardian.ensure_can_invite_to!(topic, groups)
group_ids = groups.map(&:id)
@ -880,4 +892,7 @@ class TopicsController < ApplicationController
params[:email]
end
def pm_has_slots?(pm)
guardian.is_staff? || !pm.reached_recipients_limit?
end
end