myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [1893] trunk: Viewings/donwloads tables now have


From: noreply
Subject: [myexperiment-hackers] [1893] trunk: Viewings/donwloads tables now have a new field - " accessed_from_site" which stores a boolean value indicating whether this viewing/ download was initiated from myExperiment website (in which case "referer" in HTTP header will contain "myexperiment" - this can also happen as a side effect if the external link to the resource would contain the search string in it , but is unlikely).
Date: Tue, 28 Oct 2008 12:35:08 -0400 (EDT)

Revision
1893
Author
alekses6
Date
2008-10-28 12:35:07 -0400 (Tue, 28 Oct 2008)

Log Message

Viewings/donwloads tables now have a new field - "accessed_from_site" which stores a boolean value indicating whether this viewing/download was initiated from myExperiment website (in which case "referer" in HTTP header will contain "myexperiment" - this can also happen as a side effect if the external link to the resource would contain the search string in it, but is unlikely).

show() / download() actions for files/workflows/packs updated accordingly.

Modified Paths

Added Paths

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]