Skip to content

Commit

Permalink
FEATURE: add user profile fields in user list export
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan committed Mar 21, 2017
1 parent 82c0f5f commit df246c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/jobs/regular/export_csv_file.rb
Expand Up @@ -12,6 +12,7 @@ class ExportCsvFile < Jobs::Base
user_archive: ['topic_title','category','sub_category','is_pm','post','like_count','reply_count','url','created_at'],
user_list: ['id','name','username','email','title','created_at','last_seen_at','last_posted_at','last_emailed_at','trust_level','approved','suspended_at','suspended_till','blocked','active','admin','moderator','ip_address'],
user_stats: ['topics_entered','posts_read_count','time_read','topic_count','post_count','likes_given','likes_received'],
user_profile: ['location','website','views'],
user_sso: ['external_id','external_email', 'external_username', 'external_name', 'external_avatar_url'],
staff_action: ['staff_user','action','subject','created_at','details', 'context'],
screened_email: ['email','action','match_count','last_match_at','created_at','ip_address'],
Expand Down Expand Up @@ -79,7 +80,7 @@ def user_list_export

if SiteSetting.enable_sso
# SSO enabled
User.where(condition).includes(:user_stat, :single_sign_on_record, :groups).find_each do |user|
User.where(condition).includes(:user_profile, :user_stat, :single_sign_on_record, :groups).find_each do |user|
user_info_array = get_base_user_array(user)
user_info_array = add_single_sign_on(user, user_info_array)
user_info_array = add_custom_fields(user, user_info_array, user_field_ids)
Expand All @@ -88,7 +89,7 @@ def user_list_export
end
else
# SSO disabled
User.where(condition).includes(:user_stat, :groups).find_each do |user|
User.where(condition).includes(:user_profile, :user_stat, :groups).find_each do |user|
user_info_array = get_base_user_array(user)
user_info_array = add_custom_fields(user, user_info_array, user_field_ids)
user_info_array = add_group_names(user, user_info_array)
Expand Down Expand Up @@ -152,7 +153,7 @@ def report_export

def get_header
if @entity == 'user_list'
header_array = HEADER_ATTRS_FOR['user_list'] + HEADER_ATTRS_FOR['user_stats']
header_array = HEADER_ATTRS_FOR['user_list'] + HEADER_ATTRS_FOR['user_stats'] + HEADER_ATTRS_FOR['user_profile']
header_array.concat(HEADER_ATTRS_FOR['user_sso']) if SiteSetting.enable_sso
user_custom_fields = UserField.all
if user_custom_fields.present?
Expand Down Expand Up @@ -180,7 +181,7 @@ def escape_comma(string)

def get_base_user_array(user)
user_array = []
user_array.push(user.id,escape_comma(user.name),user.username,user.email,escape_comma(user.title),user.created_at,user.last_seen_at,user.last_posted_at,user.last_emailed_at,user.trust_level,user.approved,user.suspended_at,user.suspended_till,user.blocked,user.active,user.admin,user.moderator,user.ip_address,user.user_stat.topics_entered,user.user_stat.posts_read_count,user.user_stat.time_read,user.user_stat.topic_count,user.user_stat.post_count,user.user_stat.likes_given,user.user_stat.likes_received)
user_array.push(user.id,escape_comma(user.name),user.username,user.email,escape_comma(user.title),user.created_at,user.last_seen_at,user.last_posted_at,user.last_emailed_at,user.trust_level,user.approved,user.suspended_at,user.suspended_till,user.blocked,user.active,user.admin,user.moderator,user.ip_address,user.user_stat.topics_entered,user.user_stat.posts_read_count,user.user_stat.time_read,user.user_stat.topic_count,user.user_stat.post_count,user.user_stat.likes_given,user.user_stat.likes_received,escape_comma(user.user_profile.location),user.user_profile.website,user.user_profile.views)
end

def add_single_sign_on(user, user_info_array)
Expand Down
4 changes: 3 additions & 1 deletion spec/jobs/export_csv_file_spec.rb
Expand Up @@ -9,7 +9,7 @@
end

let :user_list_header do
['id','name','username','email','title','created_at','last_seen_at','last_posted_at','last_emailed_at','trust_level','approved','suspended_at','suspended_till','blocked','active','admin','moderator','ip_address','topics_entered','posts_read_count','time_read','topic_count','post_count','likes_given','likes_received','external_id','external_email', 'external_username', 'external_name', 'external_avatar_url']
['id','name','username','email','title','created_at','last_seen_at','last_posted_at','last_emailed_at','trust_level','approved','suspended_at','suspended_till','blocked','active','admin','moderator','ip_address','topics_entered','posts_read_count','time_read','topic_count','post_count','likes_given','likes_received','location','website','views','external_id','external_email', 'external_username', 'external_name', 'external_avatar_url']
end

let :user_list_export do
Expand All @@ -23,10 +23,12 @@ def to_hash(row)
it 'exports sso data' do
SiteSetting.enable_sso = true
user = Fabricate(:user)
user.user_profile.update_column(:location, "La La Land")
user.create_single_sign_on_record(external_id: "123", last_payload: "xxx", external_email: 'test@test.com')

user = to_hash(user_list_export.find{|u| u[0].to_i == user.id})

expect(user["location"]).to eq("La La Land")
expect(user["external_id"]).to eq("123")
expect(user["external_email"]).to eq("test@test.com")
end
Expand Down

0 comments on commit df246c7

Please sign in to comment.