mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #3336 from techAPJ/patch-1
FEATURE: support inviting existing users to topic and message when SSO is enabled
This commit is contained in:
commit
50edad5fb2
6 changed files with 30 additions and 18 deletions
|
@ -43,15 +43,19 @@ export default ObjectController.extend(ModalFunctionality, {
|
|||
|
||||
// Show Groups? (add invited user to private group)
|
||||
showGroups: function() {
|
||||
return this.get('isAdmin') && (Discourse.Utilities.emailValid(this.get('emailOrUsername')) || this.get('isPrivateTopic') || !this.get('invitingToTopic'));
|
||||
return this.get('isAdmin') && (Discourse.Utilities.emailValid(this.get('emailOrUsername')) || this.get('isPrivateTopic') || !this.get('invitingToTopic')) && !Discourse.SiteSettings.enable_sso;
|
||||
}.property('isAdmin', 'emailOrUsername', 'isPrivateTopic', 'invitingToTopic'),
|
||||
|
||||
// Instructional text for the modal.
|
||||
inviteInstructions: function() {
|
||||
if (this.get('isMessage')) {
|
||||
if (Discourse.SiteSettings.enable_sso) {
|
||||
// inviting existing user when SSO enabled
|
||||
return I18n.t('topic.invite_reply.sso_enabled');
|
||||
} else if (this.get('isMessage')) {
|
||||
// inviting to a message
|
||||
return I18n.t('topic.invite_private.email_or_username');
|
||||
} else if (this.get('invitingToTopic')) {
|
||||
// display instructions based on provided entity
|
||||
// when inviting to topic, display instructions based on provided entity
|
||||
if (this.blank('emailOrUsername')) {
|
||||
return I18n.t('topic.invite_reply.to_topic_blank');
|
||||
} else if (Discourse.Utilities.emailValid(this.get('emailOrUsername'))) {
|
||||
|
@ -60,6 +64,7 @@ export default ObjectController.extend(ModalFunctionality, {
|
|||
return I18n.t('topic.invite_reply.to_topic_username');
|
||||
}
|
||||
} else {
|
||||
// inviting to forum
|
||||
return I18n.t('topic.invite_reply.to_forum');
|
||||
}
|
||||
}.property('isMessage', 'invitingToTopic', 'emailOrUsername'),
|
||||
|
@ -76,15 +81,25 @@ export default ObjectController.extend(ModalFunctionality, {
|
|||
},
|
||||
|
||||
successMessage: function() {
|
||||
return this.get('isMessage') ?
|
||||
I18n.t('topic.invite_private.success') :
|
||||
I18n.t('topic.invite_reply.success', { emailOrUsername: this.get('emailOrUsername') });
|
||||
if (this.get('isMessage')) {
|
||||
return I18n.t('topic.invite_private.success');
|
||||
} else if ( Discourse.Utilities.emailValid(this.get('emailOrUsername')) ) {
|
||||
return I18n.t('topic.invite_reply.success_email', { emailOrUsername: this.get('emailOrUsername') });
|
||||
} else {
|
||||
return I18n.t('topic.invite_reply.success_username');
|
||||
}
|
||||
}.property('isMessage', 'emailOrUsername'),
|
||||
|
||||
errorMessage: function() {
|
||||
return this.get('isMessage') ? I18n.t('topic.invite_private.error') : I18n.t('topic.invite_reply.error');
|
||||
}.property('isMessage'),
|
||||
|
||||
placeholderKey: function() {
|
||||
return Discourse.SiteSettings.enable_sso ?
|
||||
'topic.invite_reply.username_placeholder' :
|
||||
'topic.invite_private.email_or_username_placeholder';
|
||||
}.property(),
|
||||
|
||||
// Reset the modal to allow a new user to be invited.
|
||||
reset() {
|
||||
this.setProperties({
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{{else}}
|
||||
<label>{{inviteInstructions}}</label>
|
||||
{{#if allowExistingMembers}}
|
||||
{{user-selector single="true" allowAny=true usernames=emailOrUsername includeGroups="true" placeholderKey="topic.invite_private.email_or_username_placeholder"}}
|
||||
{{user-selector single="true" allowAny=true usernames=emailOrUsername includeGroups="true" placeholderKey=placeholderKey}}
|
||||
{{else}}
|
||||
{{text-field value=emailOrUsername placeholderKey="topic.invite_reply.email_placeholder"}}
|
||||
{{/if}}
|
||||
|
|
|
@ -66,7 +66,7 @@ class Invite < ActiveRecord::Base
|
|||
if topic.private_message?
|
||||
topic.grant_permission_to_user(user.email)
|
||||
elsif topic.category && topic.category.groups.any?
|
||||
if Guardian.new(invited_by).can_invite_to?(topic)
|
||||
if Guardian.new(invited_by).can_invite_to?(topic) && !SiteSetting.enable_sso
|
||||
(topic.category.groups - user.groups).each { |group| group.add(user) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -551,12 +551,12 @@ class Topic < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
if username_or_email =~ /^.+@.+$/
|
||||
if username_or_email =~ /^.+@.+$/ && !SiteSetting.enable_sso
|
||||
# NOTE callers expect an invite object if an invite was sent via email
|
||||
invite_by_email(invited_by, username_or_email, group_ids)
|
||||
else
|
||||
# invite existing member to a topic
|
||||
user = User.find_by_username_or_email(username_or_email)
|
||||
user = User.find_by_username(username_or_email)
|
||||
if user && topic_allowed_users.create!(user_id: user.id)
|
||||
|
||||
# Notify the user they've been invited
|
||||
|
|
|
@ -1077,15 +1077,18 @@ en:
|
|||
|
||||
invite_reply:
|
||||
title: 'Invite'
|
||||
username_placeholder: "username"
|
||||
action: 'Send Invite'
|
||||
help: 'invite others to this topic via email or notifications'
|
||||
to_forum: "We'll send a brief email allowing your friend to immediately join by clicking a link, no login required."
|
||||
sso_enabled: "Enter the username of the person you'd like to invite to this topic."
|
||||
to_topic_blank: "Enter the username or email address of the person you'd like to invite to this topic."
|
||||
to_topic_email: "You've entered an email address. We'll email an invitation that allows your friend to immediately reply to this topic."
|
||||
to_topic_username: "You've entered a username. We'll send a notification to that user with a link inviting them to this topic."
|
||||
|
||||
email_placeholder: 'name@example.com'
|
||||
success: "We mailed out an invitation to <b>{{emailOrUsername}}</b>. We'll notify you when the invitation is redeemed. Check the invitations tab on your user page to keep track of your invites."
|
||||
success_email: "We mailed out an invitation to <b>{{emailOrUsername}}</b>. We'll notify you when the invitation is redeemed. Check the invitations tab on your user page to keep track of your invites."
|
||||
success_username: "We've invited that user to participate in this topic."
|
||||
error: "Sorry, we couldn't invite that person. Perhaps they have already been invited? (Invites are rate limited)"
|
||||
|
||||
login_reply: 'Log In to Reply'
|
||||
|
|
|
@ -197,12 +197,6 @@ class Guardian
|
|||
is_me?(user)
|
||||
end
|
||||
|
||||
def invitations_allowed?
|
||||
!SiteSetting.enable_sso &&
|
||||
SiteSetting.enable_local_logins &&
|
||||
(!SiteSetting.must_approve_users? || is_staff?)
|
||||
end
|
||||
|
||||
def can_invite_to_forum?(groups=nil)
|
||||
authenticated? &&
|
||||
!SiteSetting.enable_sso &&
|
||||
|
@ -216,7 +210,7 @@ class Guardian
|
|||
|
||||
def can_invite_to?(object, group_ids=nil)
|
||||
return false if ! authenticated?
|
||||
return false if ! invitations_allowed?
|
||||
return false unless ( SiteSetting.enable_local_logins && (!SiteSetting.must_approve_users? || is_staff?) )
|
||||
return true if is_admin?
|
||||
return false if ! can_see?(object)
|
||||
|
||||
|
|
Loading…
Reference in a new issue