Permalink
Browse files

Bug fixes, adding user.mailed and user.printed.

Now mails from whichever uploader finished last.
  • Loading branch information...
1 parent f8ffbdd commit ab74c1485d500095b1bcfb206023e96891ef906e @jherrm committed Sep 28, 2012
View
12 scanbooth_web/app/jobs/ftp_upload.rb
@@ -12,12 +12,20 @@ def self.perform(user_id)
filename = user.scan_file_with_ext
path = [ScanBooth::Application.config.scans_path, filename].join('/')
- ftp = Net::FTP.new(server)
- ftp.login(username, password)
+ ftp = Net::FTP.new(FTP_SERVER)
+ ftp.login(FTP_USERNAME, FTP_PASSWORD)
ftp.putbinaryfile(path, File.basename( path ))
ftp.quit()
user.external_download_id = filename
user.save!
+
+ if !user.mailed && ScanBooth::Application.config.scan_viewer_enabled && !user.external_view_id.blank?
+ puts 'mailing user from ftp'
+ UserMailer.scan_email(user).deliver
+ user.mailed = true
+ user.save!
+ end
+
end
end
View
8 scanbooth_web/app/jobs/sketchfab_upload.rb
@@ -49,7 +49,13 @@ def self.perform(user_id)
if data['success']
user.external_view_id = data['id']
user.save!
- UserMailer.scan_email(user).deliver
+
+ if !user.mailed && ScanBooth::Application.config.scan_download_enabled && !user.external_download_id.blank?
+ puts 'mailing user from sketchfab'
+ UserMailer.scan_email(user).deliver
+ user.mailed = true
+ user.save!
+ end
p "https://sketchfab.com/show/#{data['id']}"
else
p "Upload to sketchfab failed: #{response.body}"
View
2 scanbooth_web/app/mailers/user_mailer.rb
@@ -2,7 +2,7 @@ class UserMailer < ActionMailer::Base
default from: ScanBooth::Application.config.scan_mail[:from]
def scan_email(user)
@user = user
- @scan_view_url = [ScanBooth::Application.config, @user.external_view_id].join
+ @scan_view_url = [ScanBooth::Application.config.scan_view_url, @user.external_view_id].join
@scan_download_url = [ScanBooth::Application.config.scan_download_url, @user.external_download_id].join
mail(:to => @user.email, :subject => ScanBooth::Application.config.scan_mail[:subject])
end
View
4 scanbooth_web/app/models/user.rb
@@ -1,11 +1,11 @@
class User < ActiveRecord::Base
- attr_accessible :name, :email, :scan_file, :external_view_id, :external_download_id
+ attr_accessible :name, :email, :scan_file, :mailed, :printed, :external_view_id, :external_download_id
before_create :generate_filename
after_create :async_upload_model
def generate_filename
self.scan_file = self.name.gsub(/[^a-z0-9\\-]/i,'')
- self.scan_file =
+ self.scan_file = self.id if self.scan_file.blank?;
end
def scan_file_with_ext
View
2 scanbooth_web/app/views/user_mailer/scan_email.html.erb
@@ -27,7 +27,7 @@
<p>
Sincerely,<br/>
- <a href="mailto:<%=ScanBooth::Application.config.contact[:email]%>?subject=<%=u ScanBooth::Application.config.scan_mail[:subject]%>"><%=ScanBooth::Application.config.contact[:name]%></a>
+ <a href="mailto:<%=ScanBooth::Application.config.contact_info[:email]%>?subject=<%=u ScanBooth::Application.config.scan_mail[:subject]%>"><%=ScanBooth::Application.config.contact_info[:name]%></a>
</p>
</body>
</html>
View
4 scanbooth_web/app/views/user_mailer/scan_email.text.erb
@@ -16,5 +16,5 @@ Please note: Your scan will only be viewable on sketchfab for 3 months.
<%= ScanBooth::Application.config.scan_mail[:thanks_message] %>
Sincerely,
-<%=ScanBooth::Application.config.contact[:name]%>
-<%=ScanBooth::Application.config.contact[:email]%>
+<%=ScanBooth::Application.config.contact_info[:name]%>
+<%=ScanBooth::Application.config.contact_info[:email]%>
View
8 scanbooth_web/app/views/users/_form.html.erb
@@ -19,6 +19,14 @@
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
+ <div class="field">
+ <%= f.label :printed %><br />
+ <%= f.check_box :printed %>
+ </div>
+ <div class="field">
+ <%= f.label :mailed %><br />
+ <%= f.check_box :mailed %>
+ </div>
<div class="actions">
<%= f.submit "Submit" %>
</div>
View
8 scanbooth_web/app/views/users/index.html.erb
@@ -5,7 +5,10 @@
<th>Name</th>
<th>Email</th>
<th>Scan file</th>
- <th>External</th>
+ <th>External View Id</th>
+ <th>External Download Id</th>
+ <th>Printed</th>
+ <th>Mailed</th>
<th></th>
<th></th>
<th></th>
@@ -17,6 +20,9 @@
<td><%= user.email %></td>
<td><%= user.scan_file %></td>
<td><%= user.external_view_id %></td>
+ <td><%= user.external_download_id %></td>
+ <td><%= user.printed %></td>
+ <td><%= user.mailed %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
View
5 scanbooth_web/db/migrate/20120923184415_add_external_download_id_to_user.rb
@@ -0,0 +1,5 @@
+class AddExternalDownloadIdToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :external_download_id, :string
+ end
+end
View
5 scanbooth_web/db/migrate/20120923184455_rename_user_external_id_to_external_view_id.rb
@@ -0,0 +1,5 @@
+class RenameUserExternalIdToExternalViewId < ActiveRecord::Migration
+ def change
+ rename_column :users, :external_id, :external_view_id
+ end
+end
View
6 scanbooth_web/db/migrate/20120923205345_add_status_bools_to_user.rb
@@ -0,0 +1,6 @@
+class AddStatusBoolsToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :printed, :boolean, :default => false
+ add_column :users, :mailed, :boolean, :default => false
+ end
+end
View
11 scanbooth_web/db/schema.rb
@@ -11,15 +11,18 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120921172401) do
+ActiveRecord::Schema.define(:version => 20120923205345) do
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.string "scan_file"
- t.string "external_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.string "external_view_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "external_download_id"
+ t.boolean "printed", :default => false
+ t.boolean "mailed", :default => false
end
end

0 comments on commit ab74c14

Please sign in to comment.