From 783d98745a1808a1d89188db68c375ea7e73abcb Mon Sep 17 00:00:00 2001 From: Diaspora Europe Date: Mon, 8 Apr 2013 16:50:33 +0200 Subject: [PATCH 1/2] added to admin section: which users are under the age of 13 #1283 --- app/controllers/admins_controller.rb | 4 +++- app/views/admins/user_search.html.haml | 5 ++++- config/locales/diaspora/en.yml | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index e8b0a0aa6..783d9bcd1 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -5,7 +5,9 @@ class AdminsController < ApplicationController def user_search params[:user] ||= {} params[:user].delete_if {|key, value| value.blank? } - @users = params[:user].empty? ? [] : User.where(params[:user]) + @users = User.joins(person: :profile).where("profiles.birthday > date_sub(now(), interval 13 year)") if params[:under13] + @users = (@users || User).where(params[:user]) if params[:user].present? + @users ||= [] end def admin_inviter diff --git a/app/views/admins/user_search.html.haml b/app/views/admins/user_search.html.haml index a667cf7bb..c5329f771 100644 --- a/app/views/admins/user_search.html.haml +++ b/app/views/admins/user_search.html.haml @@ -22,6 +22,9 @@ = t('email') = text_field_tag 'user[email]', params[:user][:email] + = t('.under_13') + = check_box_tag 'under13', params[:under13] + = submit_tag t('admins.stats.go') @@ -38,7 +41,7 @@ = user.person.profile.inspect %br = "invite token: #{invite_code_url(user.invited_by.invite_code)}" if user.invited_by.present? - = link_to "add_invites", add_invites_path(user.invitation_code) + = link_to t(".add_invites"), add_invites_path(user.invitation_code) %br %br %br diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 92984d995..98ede928c 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -96,6 +96,7 @@ en: you_currently: "you currently have %{user_invitation} invites left %{link}" add_invites: "add invites" email_to: "Email to Invite" + under_13: "Show users that are under 13 (COPPA)" users: zero: "%{count} users found" one: "%{count} user found" From 02be4a533589f982b8c198d81df2a114b901d182 Mon Sep 17 00:00:00 2001 From: Florian Staudacher Date: Sun, 23 Jun 2013 15:56:41 +0200 Subject: [PATCH 2/2] make age search postgres compatible, add spec, changelog --- Changelog.md | 1 + app/controllers/admins_controller.rb | 10 +++++----- spec/controllers/admins_controller_spec.rb | 23 ++++++++++++++++++---- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Changelog.md b/Changelog.md index f1a493079..58acad724 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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) * 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 diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index 28ee1d44f..593b31ddd 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -5,16 +5,16 @@ class AdminsController < ApplicationController def user_search params[:user] ||= {} 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 ||= [] end - def admin_inviter + def admin_inviter inviter = InvitationCode.default_inviter_or(current_user) email = params[:identifier] user = User.find_by_email(email) - + unless user EmailInviter.new(email, inviter).send! flash[:notice] = "invitation sent to #{email}" @@ -32,14 +32,14 @@ class AdminsController < ApplicationController def weekly_user_stats @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.find_each do |u| + @created_users.find_each do |u| unless u.nil? @created_users_by_week[u.created_at.beginning_of_week.strftime("%Y-%m-%d")].push("#{u.username}") end end 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}" else @counter = "" diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb index bf8526ef6..7c824ce6d 100644 --- a/spec/controllers/admins_controller_spec.rb +++ b/spec/controllers/admins_controller_spec.rb @@ -34,29 +34,44 @@ describe AdminsController do assigns[:users].should == [] end - it 'should search on username' do + it 'searches on username' do get :user_search, :user => {:username => @user.username} assigns[:users].should == [@user] end - it 'should search on email' do + it 'searches on email' do get :user_search, :user => {:email => @user.email} assigns[:users].should == [@user] end - it 'should search on invitation_identifier' do + it 'searches on invitation_identifier' do @user.invitation_identifier = "La@foo.com" @user.save! get :user_search, :user => {:invitation_identifier => @user.invitation_identifier} assigns[:users].should == [@user] end - it 'should search on invitation_token' do + it 'searches on invitation_token' do @user.invitation_token = "akjsdhflhasdf" @user.save get :user_search, :user => {:invitation_token => @user.invitation_token} assigns[:users].should == [@user] 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