FEATURE: New share topic modal (#12804)

The old share modal used to host both share and invite functionality,
under two tabs. The new "Share Topic" modal can be used only for
sharing, but has a link to the invite modal.

Among the sharing methods, there is also "Notify" which points out
that existing users will simply be notified (this was not clear
before). Staff members can notify as many users as they want, but
regular users are restricted to one at a time, no more than
max_topic_invitations_per_day. The user will not receive another
notification if they have been notified of the same topic in past hour.

The "Create Invite" modal also suffered some changes: the two radio
boxes for selecting the type (invite or email) have been replaced by a
single checkbox (is email?) and then the two labels about emails have
been replaced by a single one, some fields were reordered and the
advanced options toggle was moved to the bottom right of the modal.
This commit is contained in:
Dan Ungureanu
2021-04-23 19:18:23 +03:00
committed by GitHub
parent e3b1d1a718
commit cfee2728ce
16 changed files with 444 additions and 274 deletions

View File

@ -1683,6 +1683,27 @@ class Topic < ActiveRecord::Base
email_addresses.to_a
end
def create_invite_notification!(target_user, notification_type, username)
target_user.notifications.create!(
notification_type: notification_type,
topic_id: self.id,
post_number: 1,
data: {
topic_title: self.title,
display_username: username
}.to_json
)
end
def rate_limit_topic_invitation(invited_by)
RateLimiter.new(
invited_by,
"topic-invitations-per-day",
SiteSetting.max_topic_invitations_per_day,
1.day.to_i
).performed!
end
private
def invite_to_private_message(invited_by, target_user, guardian)
@ -1711,7 +1732,7 @@ class Topic < ActiveRecord::Base
Topic.transaction do
rate_limit_topic_invitation(invited_by)
if group_ids
if group_ids.present?
(
self.category.groups.where(id: group_ids).where(automatic: false) -
target_user.groups.where(automatic: false)
@ -1743,29 +1764,6 @@ class Topic < ActiveRecord::Base
def apply_per_day_rate_limit_for(key, method_name)
RateLimiter.new(user, "#{key}-per-day", SiteSetting.get(method_name), 1.day.to_i)
end
def create_invite_notification!(target_user, notification_type, username)
target_user.notifications.create!(
notification_type: notification_type,
topic_id: self.id,
post_number: 1,
data: {
topic_title: self.title,
display_username: username
}.to_json
)
end
def rate_limit_topic_invitation(invited_by)
RateLimiter.new(
invited_by,
"topic-invitations-per-day",
SiteSetting.max_topic_invitations_per_day,
1.day.to_i
).performed!
true
end
end
# == Schema Information