A admin is now able to allow open invitations
This commit is contained in:
parent
ae8f75eae9
commit
594c9b02b1
7 changed files with 58 additions and 25 deletions
|
|
@ -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(', ')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue