Diff
Modified: trunk/app/controllers/application.rb (1892 => 1893)
--- trunk/app/controllers/application.rb 2008-10-28 15:50:48 UTC (rev 1892)
+++ trunk/app/controllers/application.rb 2008-10-28 16:35:07 UTC (rev 1893)
@@ -23,6 +23,22 @@
end
+ # if "referer" in the HTTP header contains "myexperiment", we know
+ # that current action was accessed from myExperiment website; if
+ # referer is not set OR doesn't contain the search string, access
+ # was initiated from other location
+ def accessed_from_website?
+ res = false
+
+ referer = request.env['HTTP_REFERER']
+ unless referer.nil?
+ res = referer.include?("myexperiment")
+ end
+
+ return res
+ end
+
+
# this method is only intended to check if entry
# in "viewings" or "downloads" table needs to be
# created for current access - and this is *only*
Modified: trunk/app/controllers/blobs_controller.rb (1892 => 1893)
--- trunk/app/controllers/blobs_controller.rb 2008-10-28 15:50:48 UTC (rev 1892)
+++ trunk/app/controllers/blobs_controller.rb 2008-10-28 16:35:07 UTC (rev 1893)
@@ -38,7 +38,7 @@
# GET /files/1;download
def download
if allow_statistics_logging(@blob)
- @download = Download.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'])
+ @download = Download.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
end
send_data(@blob.content_blob.data, :filename => @blob.local_name, :type => @blob.content_type)
@@ -74,7 +74,7 @@
# GET /files/1
def show
if allow_statistics_logging(@blob)
- @viewing = Viewing.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'])
+ @viewing = Viewing.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
end
respond_to do |format|
Modified: trunk/app/controllers/packs_controller.rb (1892 => 1893)
--- trunk/app/controllers/packs_controller.rb 2008-10-28 15:50:48 UTC (rev 1892)
+++ trunk/app/controllers/packs_controller.rb 2008-10-28 16:35:07 UTC (rev 1893)
@@ -49,7 +49,7 @@
# GET /packs/1
def show
if allow_statistics_logging(@pack)
- @viewing = Viewing.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'])
+ @viewing = Viewing.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
end
respond_to do |format|
@@ -76,7 +76,7 @@
@pack.create_zip(current_user, image_hash)
if allow_statistics_logging(@pack)
- @download = Download.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'])
+ @download = Download.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
end
send_file @pack.archive_file_path, :disposition => 'attachment'
Modified: trunk/app/controllers/workflows_controller.rb (1892 => 1893)
--- trunk/app/controllers/workflows_controller.rb 2008-10-28 15:50:48 UTC (rev 1892)
+++ trunk/app/controllers/workflows_controller.rb 2008-10-28 16:35:07 UTC (rev 1893)
@@ -158,7 +158,7 @@
# GET /workflows/1;download
def download
if allow_statistics_logging(@viewing_version)
- @download = Download.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'])
+ @download = Download.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
end
send_data(@viewing_version.content_blob.data, :filename => @workflow.filename(@viewing_version_number), :type => @workflow.content_type)
@@ -228,7 +228,7 @@
# GET /workflows/1
def show
if allow_statistics_logging(@viewing_version)
- @viewing = Viewing.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'])
+ @viewing = Viewing.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
end
respond_to do |format|
Added: trunk/db/migrate/070_add_accessed_from_site_to_viewings_and_downloads.rb (0 => 1893)
--- trunk/db/migrate/070_add_accessed_from_site_to_viewings_and_downloads.rb (rev 0)
+++ trunk/db/migrate/070_add_accessed_from_site_to_viewings_and_downloads.rb 2008-10-28 16:35:07 UTC (rev 1893)
@@ -0,0 +1,17 @@
+class AddAccessedFromSiteToViewingsAndDownloads < ActiveRecord::Migration
+
+ # a boolean field ("accessed_from_site") is added to "viewings" and "downloads" tables
+ # to record if viewing/download was initiated from myExperiment website - that is
+ # non-direct link was used and, therefore, 'referer' in the http header would contain
+ # "myexperiment" as a part of the link
+
+ def self.up
+ add_column :viewings, :accessed_from_site, :boolean, :default => false
+ add_column :downloads, :accessed_from_site, :boolean, :default => false
+ end
+
+ def self.down
+ remove_column :viewings, :accessed_from_site
+ remove_column :downloads, :accessed_from_site
+ end
+end