diff --git a/app/controllers/admin/digitals_controller.rb b/app/controllers/admin/digitals_controller.rb deleted file mode 100644 index f30d3a6..0000000 --- a/app/controllers/admin/digitals_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Admin::DigitalsController < Spree::Admin::ResourceController - - index.before do - @product = Product.find_by_permalink(params[:product_id]) - end - - create.wants.html { redirect_to admin_product_digitals_url(@product) } - destroy.wants.html { redirect_to admin_product_digitals_url(@product) } - -end diff --git a/app/controllers/digitals_controller.rb b/app/controllers/digitals_controller.rb deleted file mode 100644 index 4a42470..0000000 --- a/app/controllers/digitals_controller.rb +++ /dev/null @@ -1,16 +0,0 @@ -class DigitalsController < Spree::BaseController - - ssl_required :show - - def show - link = DigitalLink.find_by_secret(params[:secret]) - if link.present? and link.digital.attachment.present? - attachment = link.digital.attachment - if link.authorize! and File.file?(attachment.path) - send_file attachment.path :filename => attachment.original_filename, :type => attachment.content_type and return - end - end - render :unauthorized - end - -end diff --git a/app/controllers/spree/admin/digitals_controller.rb b/app/controllers/spree/admin/digitals_controller.rb new file mode 100644 index 0000000..56d79f7 --- /dev/null +++ b/app/controllers/spree/admin/digitals_controller.rb @@ -0,0 +1,15 @@ +module Spree + class Admin::DigitalsController < Spree::Admin::ResourceController + belongs_to "spree/product", find_by: :permalink + + def load_resource + @object = @product = Product.find_by_permalink(params[:product_id]) + end + + + protected + def location_after_save + admin_product_digitals_url(@product) + end + end +end \ No newline at end of file diff --git a/app/controllers/spree/digitals_controller.rb b/app/controllers/spree/digitals_controller.rb new file mode 100644 index 0000000..8e9d55d --- /dev/null +++ b/app/controllers/spree/digitals_controller.rb @@ -0,0 +1,18 @@ +module Spree + class DigitalsController < Spree::BaseController + + ssl_required :show + + def show + link = DigitalLink.find_by_secret(params[:secret]) + if link.present? and link.digital.attachment.present? + attachment = link.digital.attachment + if link.authorize! and File.file?(attachment.path) + send_file attachment.path :filename => attachment.original_filename, :type => attachment.content_type and return + end + end + render :unauthorized + end + + end +end \ No newline at end of file diff --git a/app/models/digital.rb b/app/models/digital.rb deleted file mode 100644 index 79d8c0d..0000000 --- a/app/models/digital.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Digital < ActiveRecord::Base - - belongs_to :variant - has_many :digital_links, :dependent => :destroy - - has_attached_file :attachment, :path => ":rails_root/private/digitals/:id/:basename.:extension" - - # TODO: Limit the attachment to one single file. Paperclip supports many by default :/ - -end \ No newline at end of file diff --git a/app/models/digital_link.rb b/app/models/digital_link.rb deleted file mode 100644 index 813ae00..0000000 --- a/app/models/digital_link.rb +++ /dev/null @@ -1,27 +0,0 @@ -class DigitalLink < ActiveRecord::Base - - belongs_to :digital - belongs_to :line_item - - before_validation :set_defaults, :on => :create - - # Can this link stil be used? It is valid if it's less than 24 hours old and was not accessed more than 3 times - def authorizable? - self.created_at > 1.day.ago and self.access_counter < 3 - end - - # This method should be called when a download is initiated. - # It returns +true+ or +false+ depending on whether the authorization is granted. - def authorize! - authorizable? && increment!(:access_counter) ? true : false - end - - private - - # Populating the secret automatically and zero'ing the access_counter (otherwise it might turn out to be NULL) - def set_defaults - self.secret = SecureRandom.hex(15) - self.access_counter = 0 - end - -end \ No newline at end of file diff --git a/app/models/spree/digital.rb b/app/models/spree/digital.rb new file mode 100644 index 0000000..d1d4bd1 --- /dev/null +++ b/app/models/spree/digital.rb @@ -0,0 +1,11 @@ +module Spree + class Digital < ActiveRecord::Base + belongs_to :variant + has_many :digital_links, :dependent => :destroy + + has_attached_file :attachment, :path => ":rails_root/private/digitals/:id/:basename.:extension" + + # TODO: Limit the attachment to one single file. Paperclip supports many by default :/ + + end +end \ No newline at end of file diff --git a/app/models/spree/digital_link.rb b/app/models/spree/digital_link.rb new file mode 100644 index 0000000..797d9ba --- /dev/null +++ b/app/models/spree/digital_link.rb @@ -0,0 +1,29 @@ +module Spree + class DigitalLink < ActiveRecord::Base + + belongs_to :digital + belongs_to :line_item + + before_validation :set_defaults, :on => :create + + # Can this link stil be used? It is valid if it's less than 24 hours old and was not accessed more than 3 times + def authorizable? + self.created_at > 1.day.ago and self.access_counter < 3 + end + + # This method should be called when a download is initiated. + # It returns +true+ or +false+ depending on whether the authorization is granted. + def authorize! + authorizable? && increment!(:access_counter) ? true : false + end + + private + + # Populating the secret automatically and zero'ing the access_counter (otherwise it might turn out to be NULL) + def set_defaults + self.secret = SecureRandom.hex(15) + self.access_counter = 0 + end + + end +end \ No newline at end of file diff --git a/app/models/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb similarity index 100% rename from app/models/line_item_decorator.rb rename to app/models/spree/line_item_decorator.rb diff --git a/app/models/order_decorator.rb b/app/models/spree/order_decorator.rb similarity index 100% rename from app/models/order_decorator.rb rename to app/models/spree/order_decorator.rb diff --git a/app/models/variant_decorator.rb b/app/models/spree/variant_decorator.rb similarity index 100% rename from app/models/variant_decorator.rb rename to app/models/spree/variant_decorator.rb diff --git a/app/views/admin/digitals/_digital.html.erb b/app/views/spree/admin/digitals/_digital.html.erb similarity index 100% rename from app/views/admin/digitals/_digital.html.erb rename to app/views/spree/admin/digitals/_digital.html.erb diff --git a/app/views/admin/digitals/_form.html.erb b/app/views/spree/admin/digitals/_form.html.erb similarity index 91% rename from app/views/admin/digitals/_form.html.erb rename to app/views/spree/admin/digitals/_form.html.erb index 9a90456..09662da 100644 --- a/app/views/admin/digitals/_form.html.erb +++ b/app/views/spree/admin/digitals/_form.html.erb @@ -2,7 +2,7 @@
<%= form_for(:digital, :url => { :controller => 'digitals', :action => 'create' }, :html => { :multipart => true }) do |f| %>
- <%= Variant.model_name.human %> "<%= variant.options_text %>" + <%= Spree::Variant.model_name.human %> "<%= variant.options_text %>" <%= f.field_container :current_file do %> <%=t 'current_file' %>:
diff --git a/app/views/admin/digitals/index.html.erb b/app/views/spree/admin/digitals/index.html.erb similarity index 68% rename from app/views/admin/digitals/index.html.erb rename to app/views/spree/admin/digitals/index.html.erb index 2fca15b..a7d7004 100644 --- a/app/views/admin/digitals/index.html.erb +++ b/app/views/spree/admin/digitals/index.html.erb @@ -1,5 +1,5 @@ -<%= render :partial => 'admin/shared/product_sub_menu' %> -<%= render :partial => 'admin/shared/product_tabs', :locals => {:current => "Digital Versions"} %> +<%= render :partial => 'spree/admin/shared/product_sub_menu' %> +<%= render :partial => 'spree/admin/shared/product_tabs', :locals => {:current => "Digital Versions"} %> <% if @product.has_variants? %> diff --git a/app/views/checkout/_delivery.html.erb b/app/views/spree/checkout/_delivery.html.erb similarity index 100% rename from app/views/checkout/_delivery.html.erb rename to app/views/spree/checkout/_delivery.html.erb diff --git a/app/views/checkout/_delivery_digital.html.erb b/app/views/spree/checkout/_delivery_digital.html.erb similarity index 100% rename from app/views/checkout/_delivery_digital.html.erb rename to app/views/spree/checkout/_delivery_digital.html.erb diff --git a/app/views/checkout/_delivery_original.html.erb b/app/views/spree/checkout/_delivery_original.html.erb similarity index 100% rename from app/views/checkout/_delivery_original.html.erb rename to app/views/spree/checkout/_delivery_original.html.erb diff --git a/app/views/order_mailer/confirm_email.text.erb b/app/views/spree/order_mailer/confirm_email.text.erb similarity index 100% rename from app/views/order_mailer/confirm_email.text.erb rename to app/views/spree/order_mailer/confirm_email.text.erb diff --git a/config/routes.rb b/config/routes.rb index 71c0385..4c65727 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,4 @@ -Rails.application.routes.draw do - +Spree::Core::Engine.routes.draw do namespace :admin do resources :products do resources :digitals diff --git a/db/migrate/20111207121840_rename_digital_to_namespace.rb b/db/migrate/20111207121840_rename_digital_to_namespace.rb new file mode 100644 index 0000000..b45b8c0 --- /dev/null +++ b/db/migrate/20111207121840_rename_digital_to_namespace.rb @@ -0,0 +1,6 @@ +class RenameDigitalToNamespace < ActiveRecord::Migration + def change + rename_table :digitals, :spree_digitals + rename_table :digital_links, :spree_digital_links + end +end diff --git a/lib/spree_digital_hooks.rb b/lib/spree_digital_hooks.rb index 5f1fbec..1034edf 100644 --- a/lib/spree_digital_hooks.rb +++ b/lib/spree_digital_hooks.rb @@ -1,5 +1,5 @@ class SpreeDigitalHooks < Spree::ThemeSupport::HookListener - Deface::Override.new(:virtual_path => "admin/shared/_product_tabs", + Deface::Override.new(:virtual_path => "spree/admin/shared/_product_tabs", :name => "converted_admin_product_tabs_986577829", :insert_bottom => "[data-hook='admin_product_tabs'], #admin_product_tabs[data-hook]", :text => " >