Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
#6 cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoerger committed Jul 26, 2012
1 parent efbd320 commit 6269ee3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
13 changes: 7 additions & 6 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def import
file = params[:csv_upload]
@users_added_set = []
@users_updated_set = []
@users_not_updated_set = {}
@users_not_added_set = {}
@users_not_updated_set = {}
@users_conflict_set = {}
flash[:errors] = ''

Expand Down Expand Up @@ -147,15 +147,15 @@ def import
next
else
# attempt LDAP rescue
@user_temp = User.search_ldap(user)
if @user_temp.nil?
ldap_hash = User.search_ldap(user)
if ldap_hash.nil?
data << 'Incomplete user information. Unable to find user in online directory (LDAP).'
@users_not_updated_set[user] = data
next
end

# redeclare what LDAP overwrote
@user_formatted = User.import_ldap_fix(@user_temp,user,data,@user_type)
@user_formatted = User.import_ldap_fix(ldap_hash,user,data,@user_type)
@user.csv_import = true

# re-attempt save
Expand All @@ -177,10 +177,10 @@ def import
@users_added_set << @user
next
else # if validations fail
# check LDAP
# attempt LDAP rescue
ldap_hash = User.search_ldap(user)
if ldap_hash.nil?
data << 'Missing data. Unable to find user in online directory (LDAP).'
data << 'Incomplete user information. Unable to find user in online directory (LDAP).'
@users_not_added_set[user] = data
next
end
Expand All @@ -198,6 +198,7 @@ def import
else
error_temp = process_all_error_messages_to_string(@user)
if error_temp == 'Login has already been taken. '
data << 'User already exists.'
@users_conflict_set[user] = data
else
data << error_temp
Expand Down
5 changes: 3 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def self.csv_data_formatting(user,data,user_type)
hash[:phone] = data[3]
hash[:email] = data[4]
hash[:affiliation] = data[5]
hash[:csv_import] = true # attr_accessor defined above
# hash[:csv_import] = true # attr_accessor defined above

if user_type == 'admin'
hash[:is_admin] = 1
elsif user_type == 'checkout'
Expand Down Expand Up @@ -181,7 +182,7 @@ def self.import_ldap_fix(ldap_hash,user,data,user_type)
ldap_hash[:phone] = data[3] # LDAP doesn't fetch phone number
ldap_hash[:email] = data[4] unless data[4].blank?
ldap_hash[:affiliation] = data[5] unless data[5].blank?
ldap_hash[:csv_import] = true # attr_accessor defined above
# ldap_hash[:csv_import] = true # attr_accessor defined above

if user_type == 'admin'
ldap_hash[:is_admin] = 1
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/import_success.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% unless @users_conflict_set.empty? %>
<h2>Users not successfully imported (already in database)</h2>
<p>
<%= link_to 'Update!', {:action => 'import', :users_hash => @users_conflict_set, :overwrite => '1', :user_type => @user_type }, :method => :post, :class => 'btn btn-primary' %> Clicking this button will attempt to update these existing users with the data provided in your CSV file.
<%= link_to 'Update!', {:action => 'import', :users_hash => @users_conflict_set, :overwrite => '1', :user_type => @user_type }, :method => :post, :class => 'btn btn-primary' %> Clicking this button will update these existing users with the data provided in your CSV file.
</p>
<%= render :partial => 'table_of_errors', :locals => {:users => @users_conflict_set} %>
<% unless @users_not_added_set.empty? and @users_added_set.empty? and @users_updated_set.empty? %>
Expand Down

0 comments on commit 6269ee3

Please sign in to comment.