Skip to content
Extraits de code Groupes Projets
Valider 02be4a53 rédigé par Florian Staudacher's avatar Florian Staudacher
Parcourir les fichiers

make age search postgres compatible, add spec, changelog

parent 44fbb647
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* Deleting a post that was shared to Twitter now deletes it from Twitter too [#4156](https://github.com/diaspora/diaspora/pull/4156) * Deleting a post that was shared to Twitter now deletes it from Twitter too [#4156](https://github.com/diaspora/diaspora/pull/4156)
* Improvement on how participants are displayed on each conversation without opening it [#4149](https://github.com/diaspora/diaspora/pull/4149) * Improvement on how participants are displayed on each conversation without opening it [#4149](https://github.com/diaspora/diaspora/pull/4149)
* Admin: add option to find users under 13 (COPPA) [#4252](https://github.com/diaspora/diaspora/pull/4252)
## Gem updates ## Gem updates
......
...@@ -5,16 +5,16 @@ class AdminsController < ApplicationController ...@@ -5,16 +5,16 @@ class AdminsController < ApplicationController
def user_search def user_search
params[:user] ||= {} params[:user] ||= {}
params[:user].delete_if {|key, value| value.blank? } params[:user].delete_if {|key, value| value.blank? }
@users = User.joins(person: :profile).where("profiles.birthday > date_sub(now(), interval 13 year)") if params[:under13] @users = User.joins(person: :profile).where(["profiles.birthday > ?", Date.today - 13.years]) if params[:under13]
@users = (@users || User).where(params[:user]) if params[:user].present? @users = (@users || User).where(params[:user]) if params[:user].present?
@users ||= [] @users ||= []
end end
def admin_inviter def admin_inviter
inviter = InvitationCode.default_inviter_or(current_user) inviter = InvitationCode.default_inviter_or(current_user)
email = params[:identifier] email = params[:identifier]
user = User.find_by_email(email) user = User.find_by_email(email)
unless user unless user
EmailInviter.new(email, inviter).send! EmailInviter.new(email, inviter).send!
flash[:notice] = "invitation sent to #{email}" flash[:notice] = "invitation sent to #{email}"
...@@ -32,14 +32,14 @@ class AdminsController < ApplicationController ...@@ -32,14 +32,14 @@ class AdminsController < ApplicationController
def weekly_user_stats def weekly_user_stats
@created_users = User.where("username IS NOT NULL and created_at IS NOT NULL") @created_users = User.where("username IS NOT NULL and created_at IS NOT NULL")
@created_users_by_week = Hash.new{ |h,k| h[k] = [] } @created_users_by_week = Hash.new{ |h,k| h[k] = [] }
@created_users.find_each do |u| @created_users.find_each do |u|
unless u.nil? unless u.nil?
@created_users_by_week[u.created_at.beginning_of_week.strftime("%Y-%m-%d")].push("#{u.username}") @created_users_by_week[u.created_at.beginning_of_week.strftime("%Y-%m-%d")].push("#{u.username}")
end end
end end
unless(params[:week]).nil? unless(params[:week]).nil?
# @segment = "#{@created_users_by_week[(params[:week])]}" # @segment = "#{@created_users_by_week[(params[:week])]}"
@counter = "#{@created_users_by_week[(params[:week])].count}" @counter = "#{@created_users_by_week[(params[:week])].count}"
else else
@counter = "" @counter = ""
......
...@@ -34,29 +34,44 @@ describe AdminsController do ...@@ -34,29 +34,44 @@ describe AdminsController do
assigns[:users].should == [] assigns[:users].should == []
end end
it 'should search on username' do it 'searches on username' do
get :user_search, :user => {:username => @user.username} get :user_search, :user => {:username => @user.username}
assigns[:users].should == [@user] assigns[:users].should == [@user]
end end
it 'should search on email' do it 'searches on email' do
get :user_search, :user => {:email => @user.email} get :user_search, :user => {:email => @user.email}
assigns[:users].should == [@user] assigns[:users].should == [@user]
end end
it 'should search on invitation_identifier' do it 'searches on invitation_identifier' do
@user.invitation_identifier = "La@foo.com" @user.invitation_identifier = "La@foo.com"
@user.save! @user.save!
get :user_search, :user => {:invitation_identifier => @user.invitation_identifier} get :user_search, :user => {:invitation_identifier => @user.invitation_identifier}
assigns[:users].should == [@user] assigns[:users].should == [@user]
end end
it 'should search on invitation_token' do it 'searches on invitation_token' do
@user.invitation_token = "akjsdhflhasdf" @user.invitation_token = "akjsdhflhasdf"
@user.save @user.save
get :user_search, :user => {:invitation_token => @user.invitation_token} get :user_search, :user => {:invitation_token => @user.invitation_token}
assigns[:users].should == [@user] assigns[:users].should == [@user]
end end
it 'searches on age < 13 (COPPA)' do
u_13 = FactoryGirl.create(:user)
u_13.profile.birthday = 10.years.ago.to_date
u_13.profile.save!
o_13 = FactoryGirl.create(:user)
o_13.profile.birthday = 20.years.ago.to_date
o_13.profile.save!
get :user_search, under13: true
assigns[:users].should include(u_13)
assigns[:users].should_not include(o_13)
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