Skip to content

Commit

Permalink
Suspicious users detection
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgronlund committed Dec 10, 2015
1 parent 1aaee0f commit d97b66d
Show file tree
Hide file tree
Showing 24 changed files with 25,586 additions and 27,931 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/fake_users.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/fake_users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin/fake_users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
10 changes: 10 additions & 0 deletions app/controllers/admin/fake_users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::FakeUsersController < ApplicationController

before_action :admin_only
before_action :set_user, only: [:show, :update, :destroy]

def index
@users = User.where( "created_at < ?", Time.now - 24.hours ).where(confirmed_at: nil).page(params[:page]).per(100)

end
end
2 changes: 2 additions & 0 deletions app/helpers/admin/fake_users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::FakeUsersHelper
end
19 changes: 17 additions & 2 deletions app/services/user_completeness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def self.process user
default_name = User.create_uniq_user_name_from_email(user.email)

# user user_name is still default name
completeness += 1 unless user.user_name == default_name
nr_required_params += 1
#completeness += 1 unless user.user_name == default_name
#nr_required_params += 1

completeness += 1 unless user.profile.to_s == ''
nr_required_params += 1
Expand All @@ -29,6 +29,21 @@ def self.process user

completeness += 1 unless user.image_url.include?('5GA3Zk1C_avatar_')
nr_required_params += 1

completeness += 1 if user.has_recordings
nr_required_params += 1

completeness += 1 if user.follow_other_users
nr_required_params += 1

completeness += 1 if user.has_liked_recordings
nr_required_params += 1

completeness += 1 if user.has_liked_a_user
nr_required_params += 1

completeness += 1 if user.user_configuration_configured
nr_required_params += 1

user.completeness = (completeness / nr_required_params * 100).to_i
user.uniq_completeness = user.completeness.to_uniq
Expand Down
112 changes: 112 additions & 0 deletions app/views/admin/fake_users/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#wrapper
.full-width-top
== render 'shared/navigationbar', page: 'home'


.admin-account
#sidebar-wrapper
ul class="sidebar-nav"
== render 'admin/shared/sidebar', selected: 'user'

#page-content-wrapper
.container-fluid
== render 'shared/breadcrumbs', breadcrumbs: { links: { admin: admin_index_path }, current: ''}
.row
.col-sm-7
h2 Suspicious users
.col-sm-5
.pull-right.pull-down-10
= link_to admin_users_path do
.btn.btn-default
i.fa.fa-chevron-left
'&nbsp;Back




.pull-down-10
.users
.table-responsive
table class="table table-hover"
thead
tr
th
th Email
th Compleness
th Created
th Name

/th Role
/th Admin
th Id
tbody
- @users.each do |user|
tr id="delete_user_#{user.id.to_s}"
/td = debug user
td
- if user.role == 'Super'
.btn.btn-danger.btn-xs disabled="disabled"
i class="fa fa-times"
- else
=> link_to admin_user_path( user), data: { confirm: 'Are you sure?.' } , :method => :delete, remote: true do
.btn.btn-danger.btn-xs
i class="fa fa-times"

=> link_to admin_user_path( user, blacklist: true), data: { confirm: '!WARNING if you blacklist this user no other users from the users domain will be able to signup' } , :method => :delete, remote: true do
.btn.btn-default.btn-xs
'Blacklist

/=> link_to edit_admin_user_path( user) do
/ .btn.btn-default.btn-xs
/ i class="fa fa-pencil edit-user-#{user.id.to_s}"
/
/- if account = user.account
/ => link_to edit_admin_account_path( account) do
/ .btn.btn-default.btn-xs
/ i class="fa fa-gear"
/
/ => link_to account_account_path(account) do
/ div class="btn btn-default btn-xs #{ disabled ='disabled' if account.account_type == 'Social'}"
/ i.fa.fa-tachometer
/ '&nbsp;
/ 'Pro
/
/-else
/ .btn.btn-warning.btn-xs
/ i.fa.fa-frown-o
/ '&nbsp;
/ 'Err
td
= link_to user_path(user) do
.btn.btn-default.btn-xs style="width: 250px; text-align: left; text-overflow: ellipsis;"
- if user.confirmed_at
'&nbsp;&nbsp;
- else user.confirmed_at
'&nbsp;-&nbsp;
= user.email

td = user.completeness
td = time_ago_in_words(user.created_at)
td = user.user_name
/td
/ - if user.featured
/ i.fa.fa-star&nbsp;Featured
/
/td
/ -if user.account
/ = user.account_type
/td = user.created_at.strftime("%Y-%m-%d")
/td = user.role
/td
/ - if user.administrator
/ 'Administrator
td
= user.id

.pull-down-10
== paginate(@users)
== render 'shared/site_footer'

43 changes: 24 additions & 19 deletions app/views/admin/users/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@
.container-fluid
== render 'shared/breadcrumbs', breadcrumbs: { links: { admin: admin_index_path }, current: ''}
.row
.col-sm-5

.col-sm-6
h2 Users
.col-sm-6
.pull-right.pull-down-10
= link_to 'Suspicious users', admin_fake_users_path, class: 'btn btn-default'

.row
.col-sm-5
.col-sm-7
.pull-down-10
= simple_form_for [ @user ], :url => url_for(:action => 'index', \
:controller => 'users'), \
:method => 'get',
turboboost: true do |f|

.input-group
span class="input-group-addon"
i class= 'fa fa-search'
= text_field_tag "query", "", :class => 'search-query form-control', \
:placeholder => 'Search for user', \
value: params[:query], autofocus: true
.input-group-btn
= f.submit 'Search', class: "btn btn-info"
'&nbsp;
= link_to 'Clear', admin_users_path, class: 'btn btn-default'

.pull-right
.pull-down-10
= simple_form_for [ @user ], :url => url_for(:action => 'index', \
:controller => 'users'), \
:method => 'get',
turboboost: true do |f|

.input-group
span class="input-group-addon"
i class= 'fa fa-search'
= text_field_tag "query", "", :class => 'search-query form-control', \
:placeholder => 'Search for user', \
value: params[:query], autofocus: true
.input-group-btn
= f.submit 'Search', class: "btn btn-info"
'&nbsp;
= link_to 'Clear', admin_users_path, class: 'btn btn-default'


.pull-down-10
.users
Expand Down
4 changes: 2 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

# working with stripe
# config.action_dispatch.perform_deep_munge = false !dont use
config.cache_classes = true
#config.cache_classes = true


# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
#config.cache_classes = false
config.cache_classes = false


# Do not eager load code on boot.
Expand Down
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@





get 'facebook_import/index'

get "/invites/:provider/contact_callback" => "invites#index"
Expand Down Expand Up @@ -154,6 +152,7 @@
resources :digiramp_emails
resources :email_recipients
end
resources :fake_users, only: [:index]
get 'features_and_values/index'
resources :front_end_contents, only: [:edit, :update]
resources :helps
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20151208161921_update_user_completeness.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UpdateUserCompleteness < ActiveRecord::Migration
def change

User.find_each do |user|
UserCompleteness.process user
user.save(validate: false)
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20151210131408_fix_user_completeness.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class FixUserCompleteness < ActiveRecord::Migration
def change

User.find_each do |user|
UserCompleteness.process user
user.save(validate: false)
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151204174539) do
ActiveRecord::Schema.define(version: 20151210131408) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down
Loading

0 comments on commit d97b66d

Please sign in to comment.