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

@ -635,6 +635,39 @@ class TopicsController < ApplicationController
end
end
def invite_notify
topic = Topic.find_by(id: params[:topic_id])
guardian.ensure_can_see!(topic)
usernames = params[:usernames]
raise Discourse::InvalidParameters.new(:usernames) if !usernames.kind_of?(Array) || (!current_user.staff? && usernames.size > 1)
users = User.where(username_lower: usernames.map(&:downcase))
raise Discourse::InvalidParameters.new(:usernames) if usernames.size != users.size
topic.rate_limit_topic_invitation(current_user)
users.find_each do |user|
if !user.guardian.can_see_topic?(topic)
return render json: failed_json.merge(error: I18n.t('topic_invite.user_cannot_see_topic', username: user.username)), status: 422
end
end
users.find_each do |user|
last_notification = user.notifications
.where(notification_type: Notification.types[:invited_to_topic])
.where(topic_id: topic.id)
.where(post_number: 1)
.where('created_at > ?', 1.hour.ago)
if !last_notification.exists?
topic.create_invite_notification!(user, Notification.types[:invited_to_topic], current_user.username)
end
end
render json: success_json
end
def invite_group
group = Group.find_by(name: params[:group])
raise Discourse::NotFound unless group