Skip to content
Extraits de code Groupes Projets
Valider 594c9b02 rédigé par Ilyaaaaaaaaaaaaa Zhitomirskiy's avatar Ilyaaaaaaaaaaaaa Zhitomirskiy
Parcourir les fichiers

A admin is now able to allow open invitations

parent ae8f75ea
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -12,7 +12,7 @@ class InvitationsController < Devise::InvitationsController ...@@ -12,7 +12,7 @@ class InvitationsController < Devise::InvitationsController
end end
def create def create
if current_user.invites == 0 if !AppConfig[:open_invitations] && current_user.invites == 0
flash[:error] = I18n.t 'invitations.create.no_more' flash[:error] = I18n.t 'invitations.create.no_more'
redirect_to :back redirect_to :back
return return
...@@ -34,7 +34,7 @@ class InvitationsController < Devise::InvitationsController ...@@ -34,7 +34,7 @@ class InvitationsController < Devise::InvitationsController
end end
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? if bad_emails.any?
flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ') 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 ...@@ -51,7 +51,7 @@ class ServicesController < ApplicationController
end end
def inviter def inviter
if current_user.invites == 0 if !AppConfig[:open_invitations] && current_user.invites == 0
flash[:error] = I18n.t 'invitations.create.no_more' flash[:error] = I18n.t 'invitations.create.no_more'
redirect_to :back redirect_to :back
return return
......
...@@ -82,14 +82,15 @@ ...@@ -82,14 +82,15 @@
%br= link_to service.titleize, "/auth/#{service}" %br= link_to service.titleize, "/auth/#{service}"
- if @invites > 0 - unless AppConfig[:invites_off]
.section .section
.title .title
= image_tag('/images/icons/plus.png') = image_tag('/images/icons/plus.png')
%h5 %h5
.right - unless AppConfig[:open_invitations]
= t('shared.invitations.invitations_left', :count => @invites) .right
= t('shared.invitations.invitations_left', :count => @invites)
= t('shared.invitations.invite_your_friends') = t('shared.invitations.invite_your_friends')
.content .content
= render "shared/invitations", :invites => @invites = render "shared/invitations", :invites => @invites
......
- if AppConfig[:invites_off] -if AppConfig[:open_invitations] || (invites > 0)
= t('.invites_closed') - if SERVICES['facebook']['app_id'] !=""
-else - if defined? remote
-if invites > 0 = link_to t('.from_facebook'), friend_finder_path('facebook', :remote => remote), :rel => 'facebox'
- if SERVICES['facebook']['app_id'] !="" -else
- if defined? remote = link_to t('.from_facebook'), friend_finder_path('facebook'), :rel => 'facebox'
= link_to t('.from_facebook'), friend_finder_path('facebook', :remote => remote), :rel => 'facebox' %br
-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' = 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'
- else - 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 ...@@ -14,6 +14,9 @@ defaults: &defaults
# Set this to true to prevent users from sending invitations. # Set this to true to prevent users from sending invitations.
invites_off: false invites_off: false
# Set this to true if you want users to invite as many people as they want
open_invitations: true
# #
# Logging setup # Logging setup
# #
...@@ -148,4 +151,6 @@ test: ...@@ -148,4 +151,6 @@ test:
pod_url: "http://localhost:9887" pod_url: "http://localhost:9887"
socket_port: 8081 socket_port: 8081
enable_splunk_logging: false enable_splunk_logging: false
open_invitations: false
...@@ -52,21 +52,33 @@ describe InvitationsController do ...@@ -52,21 +52,33 @@ describe InvitationsController do
it "doesn't invite anyone if you have 0 invites" do it "doesn't invite anyone if you have 0 invites" do
@user.invites = 0 @user.invites = 0
@user.save! @user.save!
lambda {
post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com") Resque.should_not_receive(:enqueue)
}.should_not change(User, :count) 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 end
it 'returns to the previous page on success' do it 'returns to the previous page on success' do
post :create, :user => @invite post :create, :user => @invite
response.should redirect_to("http://test.host/cats/foo") response.should redirect_to("http://test.host/cats/foo")
end end
it 'strips out your own email' do it 'strips out your own email' do
lambda { lambda {
post :create, :user => @invite.merge(:email => @user.email) post :create, :user => @invite.merge(:email => @user.email)
}.should_not change(User, :count) }.should_not change(User, :count)
Resque.should_receive(:enqueue).once Resque.should_receive(:enqueue).once
post :create, :user => @invite.merge(:email => "hello@example.org, #{@user.email}") post :create, :user => @invite.merge(:email => "hello@example.org, #{@user.email}")
end end
......
...@@ -140,5 +140,23 @@ describe ServicesController do ...@@ -140,5 +140,23 @@ describe ServicesController do
put :inviter, @invite_params put :inviter, @invite_params
}.should_not change(Invitation, :count) }.should_not change(Invitation, :count)
end 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
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter