From 9f8d6b6088912295421ebd04cf865677868a45ab Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 30 Oct 2015 11:28:05 +0530 Subject: [PATCH] FIX: allow exisiting users to be invited to topic/message when enable_local_logins is disabled --- app/assets/javascripts/discourse/controllers/invite.js.es6 | 6 +++--- app/models/topic.rb | 2 +- lib/guardian.rb | 2 +- spec/components/guardian_spec.rb | 6 ------ 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/invite.js.es6 b/app/assets/javascripts/discourse/controllers/invite.js.es6 index 7befba51c2f..ffaaab94d1d 100644 --- a/app/assets/javascripts/discourse/controllers/invite.js.es6 +++ b/app/assets/javascripts/discourse/controllers/invite.js.es6 @@ -68,12 +68,12 @@ export default Ember.Controller.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')) && !Discourse.SiteSettings.enable_sso && !this.get('isMessage'); + return this.get('isAdmin') && (Discourse.Utilities.emailValid(this.get('emailOrUsername')) || this.get('isPrivateTopic') || !this.get('invitingToTopic')) && !Discourse.SiteSettings.enable_sso && Discourse.SiteSettings.enable_local_logins && !this.get('isMessage'); }.property('isAdmin', 'emailOrUsername', 'isPrivateTopic', 'isMessage', 'invitingToTopic'), // Instructional text for the modal. inviteInstructions: function() { - if (Discourse.SiteSettings.enable_sso) { + if (Discourse.SiteSettings.enable_sso || !Discourse.SiteSettings.enable_local_logins) { // inviting existing user when SSO enabled return I18n.t('topic.invite_reply.sso_enabled'); } else if (this.get('isMessage')) { @@ -128,7 +128,7 @@ export default Ember.Controller.extend(ModalFunctionality, { }.property('isMessage'), placeholderKey: function() { - return Discourse.SiteSettings.enable_sso ? + return (Discourse.SiteSettings.enable_sso || !Discourse.SiteSettings.enable_local_logins) ? 'topic.invite_reply.username_placeholder' : 'topic.invite_private.email_or_username_placeholder'; }.property(), diff --git a/app/models/topic.rb b/app/models/topic.rb index 37f9ebb331f..ea884ec19ca 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -585,7 +585,7 @@ class Topic < ActiveRecord::Base end end - if username_or_email =~ /^.+@.+$/ && !SiteSetting.enable_sso + if username_or_email =~ /^.+@.+$/ && !SiteSetting.enable_sso && SiteSetting.enable_local_logins # rate limit topic invite RateLimiter.new(invited_by, "topic-invitations-per-day", SiteSetting.max_topic_invitations_per_day, 1.day.to_i).performed! diff --git a/lib/guardian.rb b/lib/guardian.rb index 3896a02c12e..78dcee9cd50 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -212,7 +212,7 @@ class Guardian def can_invite_to?(object, group_ids=nil) return false if ! authenticated? - return false unless ( SiteSetting.enable_local_logins && (!SiteSetting.must_approve_users? || is_staff?) ) + return false unless (!SiteSetting.must_approve_users? || is_staff?) return true if is_admin? return false if (SiteSetting.max_invites_per_day.to_i == 0 && !is_staff?) return false if ! can_see?(object) diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 92318aada55..5d12ef0f198 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -316,12 +316,6 @@ describe Guardian do expect(Guardian.new(coding_horror).can_invite_to?(topic)).to be_falsey end - it 'returns false when local logins are disabled' do - SiteSetting.stubs(:enable_local_logins).returns(false) - expect(Guardian.new(moderator).can_invite_to?(topic)).to be_falsey - expect(Guardian.new(user).can_invite_to?(topic)).to be_falsey - end - it 'returns false for normal user on private topic' do expect(Guardian.new(user).can_invite_to?(private_topic)).to be_falsey end