mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Various invite system fixes (#13003)
* FIX: Ensure the same email cannot be invited twice When creating a new invite with a duplicated email, the old invite will be updated and returned. When updating an invite with a duplicated email address, an error will be returned. * FIX: not Ember helper does not exist * FIX: Sync can_invite_to_forum? and can_invite_to? The two methods should perform the same basic set of checks, such as check must_approve_users site setting. Ideally, one of the methods would call the other one or be merged and that will happen in the future. * FIX: Show invite to group if user is group owner
This commit is contained in:
@@ -151,6 +151,11 @@ export default Controller.extend(
|
||||
});
|
||||
},
|
||||
|
||||
@discourseComputed("currentUser.staff", "currentUser.groups")
|
||||
canInviteToGroup(staff, groups) {
|
||||
return staff || groups.any((g) => g.owner);
|
||||
},
|
||||
|
||||
@discourseComputed("type", "buffered.email")
|
||||
disabled(type, email) {
|
||||
if (type === "email") {
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
{{/if}}
|
||||
|
||||
{{#if showAdvanced}}
|
||||
{{#if currentUser.staff}}
|
||||
{{#if canInviteToGroup}}
|
||||
<div class="input-group invite-to-groups">
|
||||
<label>{{i18n "user.invited.invite.add_to_groups"}}</label>
|
||||
{{group-chooser
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
{{d-button
|
||||
icon="check"
|
||||
class="btn-primary"
|
||||
disabled=(not users)
|
||||
disabled=(if users false true)
|
||||
action=(action "notifyUsers")
|
||||
}}
|
||||
</div>
|
||||
|
||||
@@ -71,10 +71,6 @@ class InvitesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:email].present? && Invite.exists?(email: params[:email])
|
||||
return render json: failed_json, status: 422
|
||||
end
|
||||
|
||||
if params[:topic_id].present?
|
||||
topic = Topic.find_by(id: params[:topic_id])
|
||||
raise Discourse::InvalidParameters.new(:topic_id) if topic.blank?
|
||||
@@ -153,6 +149,12 @@ class InvitesController < ApplicationController
|
||||
old_email = invite.email.presence
|
||||
new_email = params[:email].presence
|
||||
|
||||
if new_email
|
||||
if Invite.where.not(id: invite.id).find_by(email: new_email.downcase, invited_by_id: current_user.id)&.redeemable?
|
||||
return render_json_error(I18n.t("invite.invite_exists", email: new_email), status: 409)
|
||||
end
|
||||
end
|
||||
|
||||
if old_email != new_email
|
||||
invite.emailed_status = if new_email && !params[:skip_email]
|
||||
Invite.emailed_status_types[:pending]
|
||||
|
||||
@@ -65,7 +65,12 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||
:can_review,
|
||||
|
||||
def groups
|
||||
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name } }
|
||||
owned_group_ids = GroupUser.where(user_id: id, owner: true).pluck(:group_id).to_set
|
||||
object.visible_groups.pluck(:id, :name).map do |id, name|
|
||||
group = { id: id, name: name }
|
||||
group[:owner] = true if owned_group_ids.include?(id)
|
||||
group
|
||||
end
|
||||
end
|
||||
|
||||
def link_posting_access
|
||||
|
||||
Reference in New Issue
Block a user