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

Commit

Permalink
#6 import by user type
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoerger committed Jul 25, 2012
1 parent c5481bc commit 7ec158e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def find

def import
#initialize
@user_type = params[:user_type]
file = params[:csv_upload]
# the rails CSV class only handles filepaths and not file objects
location = file.tempfile.path
Expand All @@ -122,6 +123,17 @@ def import
@user_temp = User.csv_data_formatting(user,data)
@user = User.new(@user_temp)

# assign user type
if @user_type == 'admin'
@user.is_admin = 1
elsif @user_type == 'checkout'
@user.is_checkout_person = 1
elsif @user_type == 'normal'
# add something if we change how type is stored in the database
elsif @user_type == 'banned'
@user.is_banned = 1
end

# check validations
if @user.valid?
# save
Expand Down Expand Up @@ -150,6 +162,17 @@ def import
@user.email = data[4] unless data[4].blank?
@user.affiliation = data[5] unless data[5].blank?

# assign user type
if @user_type == 'admin'
@user.is_admin = 1
elsif @user_type == 'checkout'
@user.is_checkout_person = 1
elsif @user_type == 'normal'
# add something if we change how type is stored in the database
elsif @user_type == 'banned'
@user.is_banned = 1
end

if @user.valid?
@user.save
@users_added_set << @user
Expand All @@ -165,6 +188,7 @@ def import
end

def import_page
@select_options = [['Normal Users','normal'],['Checkout Persons','checkout'],['Admins','admin'],['Banned Users','banned']]
render 'import'
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class User < ActiveRecord::Base
:deleted_at, :requirement_ids, :user_ids, :terms_of_service_accepted,
:created_by_admin

attr_accessor :full_query, :created_by_admin
attr_accessor :full_query, :created_by_admin, :user_type

validates :login, :presence => true,
:uniqueness => true
Expand Down
1 change: 1 addition & 0 deletions app/views/users/import.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<p><h4>Login, First Name, Last Name, Nickname, Phone, Email, Affiliation</h4></p>

<%= form_tag csv_import_path, :multipart => true do %>
<%= select_tag :user_type, options_for_select(@select_options) %>
<p>
<%= file_field_tag 'csv_upload' %>
</p>
Expand Down

0 comments on commit 7ec158e

Please sign in to comment.