diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb index 02899e36928ffd4e3074efcc4a50058243d2b41d..5e8423ae480b4b45caf0aca8fb0d5972bf125d8a 100644 --- a/app/controllers/invitations_controller.rb +++ b/app/controllers/invitations_controller.rb @@ -12,7 +12,7 @@ class InvitationsController < Devise::InvitationsController end def create - if current_user.invites == 0 + if !AppConfig[:open_invitations] && current_user.invites == 0 flash[:error] = I18n.t 'invitations.create.no_more' redirect_to :back return @@ -34,7 +34,7 @@ class InvitationsController < Devise::InvitationsController end end - good_emails.each{|e| Resque.enqueue(Job::InviteUserByEmail, current_user.id, e, aspect, message)} + good_emails.each{|e| pp Resque.enqueue(Job::InviteUserByEmail, current_user.id, e, aspect, message)} if bad_emails.any? flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ') diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index ae855f4aeb95e2df7d51776c641ee68e3a38e9d1..b9ea7f3d6a639749f5f0c37b7dd9d1358fa05c51 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -51,7 +51,7 @@ class ServicesController < ApplicationController end def inviter - if current_user.invites == 0 + if !AppConfig[:open_invitations] && current_user.invites == 0 flash[:error] = I18n.t 'invitations.create.no_more' redirect_to :back return diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 32d910cbad7fae35d1122389f89fa915413eb050..aa6a26ca6bb6d1b6c12e9404fed1dd49cf3c7d95 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -82,14 +82,15 @@ %br= link_to service.titleize, "/auth/#{service}" - - if @invites > 0 + - unless AppConfig[:invites_off] .section .title = image_tag('/images/icons/plus.png') %h5 - .right - = t('shared.invitations.invitations_left', :count => @invites) + - unless AppConfig[:open_invitations] + .right + = t('shared.invitations.invitations_left', :count => @invites) = t('shared.invitations.invite_your_friends') .content = render "shared/invitations", :invites => @invites diff --git a/app/views/shared/_invitations.haml b/app/views/shared/_invitations.haml index dc536f143f83582e7a6a02b9b730ec877115b74a..6ebe21c52ae52cdb0d221a935dad74167a3042f1 100644 --- a/app/views/shared/_invitations.haml +++ b/app/views/shared/_invitations.haml @@ -1,16 +1,13 @@ -- if AppConfig[:invites_off] - = t('.invites_closed') --else - -if invites > 0 - - if SERVICES['facebook']['app_id'] !="" - - if defined? remote - = link_to t('.from_facebook'), friend_finder_path('facebook', :remote => remote), :rel => 'facebox' - -else - = link_to t('.from_facebook'), friend_finder_path('facebook'), :rel => 'facebox' - %br +-if AppConfig[:open_invitations] || (invites > 0) + - if SERVICES['facebook']['app_id'] !="" + - if defined? remote + = link_to t('.from_facebook'), friend_finder_path('facebook', :remote => remote), :rel => 'facebox' + -else + = link_to t('.from_facebook'), friend_finder_path('facebook'), :rel => 'facebox' + %br - = link_to t('.by_email'), new_user_invitation_path, :title => t('.invite_someone'), :rel => 'facebox' - - else - = link_to t('.by_email'), new_user_invitation_path, :title => t('.invite_someone'), :rel => 'facebox' + = link_to t('.by_email'), new_user_invitation_path, :title => t('.invite_someone'), :rel => 'facebox' - else - = t('.dont_have_now') + = link_to t('.by_email'), new_user_invitation_path, :title => t('.invite_someone'), :rel => 'facebox' +- else + = t('.dont_have_now') diff --git a/config/application.yml.example b/config/application.yml.example index 68692de60d28e36a486a39f03a1ca0e91b92f159..0be3aa125871be12a84d4344eded482536b11bfd 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -14,6 +14,9 @@ defaults: &defaults # Set this to true to prevent users from sending invitations. invites_off: false + # Set this to true if you want users to invite as many people as they want + open_invitations: true + # # Logging setup # @@ -148,4 +151,6 @@ test: pod_url: "http://localhost:9887" socket_port: 8081 enable_splunk_logging: false + open_invitations: false + diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 920290a1bde6b6c0ea09022cffb216ae1d7a6ef2..6bcb9d23c7226cc800c7aeadeab240d35ed37b01 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -52,21 +52,33 @@ describe InvitationsController do it "doesn't invite anyone if you have 0 invites" do @user.invites = 0 @user.save! - lambda { - post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com") - }.should_not change(User, :count) + + Resque.should_not_receive(:enqueue) + post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com") + end + + it "allows invitations without limit if invitations are open" do + open_bit = AppConfig[:open_invitations] + AppConfig[:open_invitations] = true + @user.invites = 0 + @user.save! + + Resque.should_receive(:enqueue).once + post :create, :user => @invite + + AppConfig[:open_invitations] = open_bit end it 'returns to the previous page on success' do post :create, :user => @invite response.should redirect_to("http://test.host/cats/foo") end - + it 'strips out your own email' do lambda { post :create, :user => @invite.merge(:email => @user.email) }.should_not change(User, :count) - + Resque.should_receive(:enqueue).once post :create, :user => @invite.merge(:email => "hello@example.org, #{@user.email}") end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 45b0ffbd1daa3994a7a94b0e42ef0e63e2354043..06cd95ed814eca5f0a6a20bdd81290de2d8127af 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -140,5 +140,23 @@ describe ServicesController do put :inviter, @invite_params }.should_not change(Invitation, :count) end + + it' does not crete an invitation if the user has no invitations' do + @user.invites = 0 + lambda { + put :inviter, @invite_params + }.should_not change(Invitation, :count) + end + + it 'disregares the amount of invites if open_invitations are anabled' do + open_bit = AppConfig[:open_invitations] + AppConfig[:open_invitations] = true + @user.invites = 0 + + lambda { + put :inviter, @invite_params + }.should change(Invitation, :count).by(1) + AppConfig[:open_invitations] = open_bit + end end end