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:
Régis Hanol 2015-04-06 11:11:42 +02:00
commit 50edad5fb2
6 changed files with 30 additions and 18 deletions

View file

@ -43,15 +43,19 @@ export default ObjectController.extend(ModalFunctionality, {
// Show Groups? (add invited user to private group) // Show Groups? (add invited user to private group)
showGroups: function() { 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'), }.property('isAdmin', 'emailOrUsername', 'isPrivateTopic', 'invitingToTopic'),
// Instructional text for the modal. // Instructional text for the modal.
inviteInstructions: function() { 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'); return I18n.t('topic.invite_private.email_or_username');
} else if (this.get('invitingToTopic')) { } 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')) { if (this.blank('emailOrUsername')) {
return I18n.t('topic.invite_reply.to_topic_blank'); return I18n.t('topic.invite_reply.to_topic_blank');
} else if (Discourse.Utilities.emailValid(this.get('emailOrUsername'))) { } 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'); return I18n.t('topic.invite_reply.to_topic_username');
} }
} else { } else {
// inviting to forum
return I18n.t('topic.invite_reply.to_forum'); return I18n.t('topic.invite_reply.to_forum');
} }
}.property('isMessage', 'invitingToTopic', 'emailOrUsername'), }.property('isMessage', 'invitingToTopic', 'emailOrUsername'),
@ -76,15 +81,25 @@ export default ObjectController.extend(ModalFunctionality, {
}, },
successMessage: function() { successMessage: function() {
return this.get('isMessage') ? if (this.get('isMessage')) {
I18n.t('topic.invite_private.success') : return I18n.t('topic.invite_private.success');
I18n.t('topic.invite_reply.success', { emailOrUsername: this.get('emailOrUsername') }); } 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'), }.property('isMessage', 'emailOrUsername'),
errorMessage: function() { errorMessage: function() {
return this.get('isMessage') ? I18n.t('topic.invite_private.error') : I18n.t('topic.invite_reply.error'); return this.get('isMessage') ? I18n.t('topic.invite_private.error') : I18n.t('topic.invite_reply.error');
}.property('isMessage'), }.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 the modal to allow a new user to be invited.
reset() { reset() {
this.setProperties({ this.setProperties({

View file

@ -10,7 +10,7 @@
{{else}} {{else}}
<label>{{inviteInstructions}}</label> <label>{{inviteInstructions}}</label>
{{#if allowExistingMembers}} {{#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}} {{else}}
{{text-field value=emailOrUsername placeholderKey="topic.invite_reply.email_placeholder"}} {{text-field value=emailOrUsername placeholderKey="topic.invite_reply.email_placeholder"}}
{{/if}} {{/if}}

View file

@ -66,7 +66,7 @@ class Invite < ActiveRecord::Base
if topic.private_message? if topic.private_message?
topic.grant_permission_to_user(user.email) topic.grant_permission_to_user(user.email)
elsif topic.category && topic.category.groups.any? 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) } (topic.category.groups - user.groups).each { |group| group.add(user) }
end end
end end

View file

@ -551,12 +551,12 @@ class Topic < ActiveRecord::Base
end end
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 # NOTE callers expect an invite object if an invite was sent via email
invite_by_email(invited_by, username_or_email, group_ids) invite_by_email(invited_by, username_or_email, group_ids)
else else
# invite existing member to a topic # 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) if user && topic_allowed_users.create!(user_id: user.id)
# Notify the user they've been invited # Notify the user they've been invited

View file

@ -1077,15 +1077,18 @@ en:
invite_reply: invite_reply:
title: 'Invite' title: 'Invite'
username_placeholder: "username"
action: 'Send Invite' action: 'Send Invite'
help: 'invite others to this topic via email or notifications' 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." 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_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_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." 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' 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)" error: "Sorry, we couldn't invite that person. Perhaps they have already been invited? (Invites are rate limited)"
login_reply: 'Log In to Reply' login_reply: 'Log In to Reply'

View file

@ -197,12 +197,6 @@ class Guardian
is_me?(user) is_me?(user)
end 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) def can_invite_to_forum?(groups=nil)
authenticated? && authenticated? &&
!SiteSetting.enable_sso && !SiteSetting.enable_sso &&
@ -216,7 +210,7 @@ class Guardian
def can_invite_to?(object, group_ids=nil) def can_invite_to?(object, group_ids=nil)
return false if ! authenticated? 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 true if is_admin?
return false if ! can_see?(object) return false if ! can_see?(object)