myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2551] branches/neiss: svn merge -r2547:2550 svn+


From: noreply
Subject: [myexperiment-hackers] [2551] branches/neiss: svn merge -r2547:2550 svn+ssh://address@hidden/ var/svn/myexperiment/trunk
Date: Thu, 13 Jan 2011 09:46:44 -0500 (EST)

Revision
2551
Author
dgc
Date
2011-01-13 09:46:43 -0500 (Thu, 13 Jan 2011)

Log Message

svn merge -r2547:2550 svn+ssh://address@hidden/var/svn/myexperiment/trunk

Modified Paths

Added Paths

Removed Paths

Diff

Modified: branches/neiss/config/tables.xml


(Binary files differ)

Copied: branches/neiss/db/migrate/089_remove_network_relationships.rb (from rev 2550, trunk/db/migrate/089_remove_network_relationships.rb) (0 => 2551)


--- branches/neiss/db/migrate/089_remove_network_relationships.rb	                        (rev 0)
+++ branches/neiss/db/migrate/089_remove_network_relationships.rb	2011-01-13 14:46:43 UTC (rev 2551)
@@ -0,0 +1,16 @@
+class RemoveNetworkRelationships < ActiveRecord::Migration
+  def self.up
+    drop_table :relationships
+  end
+
+  def self.down
+    create_table "relationships", :force => true do |t|
+      t.column "network_id",  :integer
+      t.column "relation_id", :integer
+      t.column "created_at",  :datetime
+      t.column "accepted_at", :datetime
+    end
+  end
+end
+
+

Modified: branches/neiss/lib/account_management.rb (2550 => 2551)


--- branches/neiss/lib/account_management.rb	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/lib/account_management.rb	2011-01-13 14:46:43 UTC (rev 2551)
@@ -48,7 +48,6 @@
     :policies                   => { :owner => :contributor },
     :profiles                   => { :owner => :user_id, :skip_on_merge => true },
     :ratings                    => { :owner => :user_id },
-    :relationships              => { :ignore => :true },
     :remote_workflows           => { :owner => :unknown },
     :reviews                    => { :owner => :user_id },
     :schema_info                => { :ignore => :true },

Modified: branches/neiss/lib/authorization.rb (2550 => 2551)


--- branches/neiss/lib/authorization.rb	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/lib/authorization.rb	2011-01-13 14:46:43 UTC (rev 2551)
@@ -186,6 +186,19 @@
       return true
     end
     
+    # Rating permissions
+
+    if (object_type == 'Rating') && (action == 'create')
+
+      # Ratings can only be created by authenticated users
+      return false if user.nil?
+
+      # Ratings can only be set on things that a user can view
+      return Authorization.is_authorized?('view', nil, context, user) if context
+
+      return true
+    end
+    
     # Bookmark permissions
 
     if (object_type == 'Bookmark') && (action == 'create')

Modified: branches/neiss/lib/maintenance/GeneratePublicData.php (2550 => 2551)


--- branches/neiss/lib/maintenance/GeneratePublicData.php	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/lib/maintenance/GeneratePublicData.php	2011-01-13 14:46:43 UTC (rev 2551)
@@ -337,14 +337,6 @@
   PRIMARY KEY  (id),
   KEY fk_ratings_user (user_id)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
-	$createtable['relationships']="CREATE TABLE relationships (
-  id int(11) NOT NULL auto_increment,
-  network_id int(11) default NULL,
-  relation_id int(11) default NULL,
-  created_at datetime default NULL,
-  accepted_at datetime default NULL,
-  PRIMARY KEY  (id)
-) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
 	$createtable['remote_workflows']="CREATE TABLE remote_workflows (
   id int(11) NOT NULL auto_increment,
   workflow_id int(11) default NULL,
@@ -496,7 +488,6 @@
 	$publicsql['policies']="select * from policies where view_public=1";
 	$publicsql['profiles']="select * from profiles";
         $publicsql['ratings']="select ratings.* from ratings inner join contributions on ratings.rateable_id=contributions.contributable_id and ratings.rateable_type=contributions.contributable_type inner join policies on contributions.policy_id=policies.id where policies.view_public=1";
-        $publicsql['relationships']="select * from relationships";
 	$publicsql['remote_workflows']="select remote_workflows.* from remote_workflows inner join contributions on remote_workflows.workflow_id=contributions.contributable_id and contributions.contributable_type='Workflow' inner join policies on contributions.policy_id=policies.id where policies.view_public=1 and 1=0";
 
         $publicsql['reviews']="select reviews.* from reviews inner join contributions on reviews.reviewable_id=contributions.contributable_id and reviews.reviewable_type=contributions.contributable_type inner join policies on contributions.policy_id=policies.id where policies.view_public=1";

Modified: branches/neiss/lib/maintenance/backup.rb (2550 => 2551)


--- branches/neiss/lib/maintenance/backup.rb	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/lib/maintenance/backup.rb	2011-01-13 14:46:43 UTC (rev 2551)
@@ -155,7 +155,6 @@
       table(:model => Policy,                 :filter  => true)
       table(:model => Profile)
       table(:model => Rating,                 :filter  => true, :auth_object => "rateable")
-      table(:name  => "relationships",        :no_data => true)
       table(:model => RemoteWorkflow,         :no_data => true)
       table(:model => Review,                 :filter  => true, :auth_object => "reviewable")
       table(:name  => "schema_info")

Modified: branches/neiss/lib/rest.rb (2550 => 2551)


--- branches/neiss/lib/rest.rb	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/lib/rest.rb	2011-01-13 14:46:43 UTC (rev 2551)
@@ -1846,6 +1846,62 @@
   favourite_aux('destroy', opts)
 end
 
+# Ratings
+
+def rating_aux(action, opts)
+
+  # Obtain object
+
+  case action
+    when 'create':
+      return rest_response(401) unless Authorization.is_authorized_for_type?('create', 'Rating', opts[:user], nil)
+
+      ob = Rating.new(:user => opts[:user])
+    when 'read', 'update', 'destroy':
+      ob = obtain_rest_resource('Rating', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+    else
+      raise "Invalid action '#{action}'"
+  end
+
+  return if ob.nil? # appropriate rest response already given
+
+  if action == "destroy"
+
+    ob.destroy
+
+  else
+
+    data = ""
+
+    rating  = parse_element(data, :text,     '/rating/rating')
+    subject = parse_element(data, :resource, '/rating/subject')
+
+    ob.rating = rating if rating
+
+    if subject
+      return rest_response(400) unless [Blob, Network, Pack, Workflow].include?(subject.class)
+      return rest_response(401) unless Authorization.is_authorized_for_type?(action, 'Rating', opts[:user], subject)
+      ob.rateable = subject
+    end
+
+    return rest_response(400, :object => ob) unless ob.save
+  end
+
+  rest_get_request(ob, "rating", opts[:user], rest_resource_uri(ob), "rating", { "id" => ob.id.to_s })
+end
+
+def post_rating(opts)
+  rating_aux('create', opts)
+end
+
+def put_rating(opts)
+  rating_aux('update', opts)
+end
+
+def delete_rating(opts)
+  rating_aux('destroy', opts)
+end
+
 # Maps
 
 def map_aux(action, req_uri, rules, user, query)

Deleted: branches/neiss/test/fixtures/relationships.yml (2550 => 2551)


--- branches/neiss/test/fixtures/relationships.yml	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/test/fixtures/relationships.yml	2011-01-13 14:46:43 UTC (rev 2551)
@@ -1,13 +0,0 @@
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-one:
-  id: 1
-  network_id: 1
-  relation_id: 1
-  created_at: 2007-07-30 14:09:26
-  accepted_at: 2007-07-30 14:09:26
-two:
-  id: 2
-  network_id: 1
-  relation_id: 1
-  created_at: 2007-07-30 14:09:26
-  accepted_at: 2007-07-30 14:09:26

Modified: branches/neiss/test/functional/api_controller_test.rb (2550 => 2551)


--- branches/neiss/test/functional/api_controller_test.rb	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/test/functional/api_controller_test.rb	2011-01-13 14:46:43 UTC (rev 2551)
@@ -488,6 +488,82 @@
     assert_response(:not_found)
   end
 
+  def test_ratings
+
+    login_as(:john)
+
+    # post a workflow to test with
+
+    content = Base64.encode64(File.read('test/fixtures/files/workflow_dilbert.xml'))
+
+    existing_workflows = Workflow.find(:all)
+
+    rest_request(:post, 'workflow', "<?xml version='1.0'?>
+      <workflow>
+        <title>Unique tags</title>
+        <description>A workflow description.</description>
+        <license-type>by-sa</license-type>
+        <content-type>application/vnd.taverna.scufl+xml</content-type>
+        <content>#{content}</content>
+      </workflow>")
+
+    assert_response(:success)
+
+    extra_workflows = Workflow.find(:all) - existing_workflows
+
+    assert_equal(extra_workflows.length, 1)
+
+    workflow = extra_workflows.first
+    workflow_url = rest_resource_uri(workflow)
+
+    # post a rating
+
+    existing_ratings = Rating.find(:all)
+
+    rest_request(:post, 'rating', "<?xml version='1.0'?>
+      <rating>
+        <rating>4</rating>
+        <subject resource='#{workflow_url}'/>
+      </rating>")
+
+    assert_response(:success)
+
+    extra_ratings = Rating.find(:all) - existing_ratings 
+    
+    assert_equal(extra_ratings.length, 1)
+
+    rating = extra_ratings.first
+
+    assert_equal(rating.user, users(:john));
+    assert_equal(rating.rateable, workflow);
+    assert_equal(rating.rating, 4);
+
+    # update the rating (which should fail)
+
+    rest_request(:put, 'rating', "<?xml version='1.0'?>
+      <rating>
+        <rating>3</rating>
+      </rating>", "id" => rating.id)
+
+    assert_response(:success)
+    
+    rating.reload
+
+    assert_equal(rating.rating, 3);
+
+    # delete the rating
+
+    rest_request(:delete, 'rating', nil, "id" => rating.id)
+
+    assert_response(:success)
+
+    # try to get the deleted rating
+
+    rest_request(:get, 'rating', nil, "id" => rating.id)
+
+    assert_response(:not_found)
+  end
+
   def test_favourites
 
     login_as(:john)

Deleted: branches/neiss/test/unit/relationship_test.rb (2550 => 2551)


--- branches/neiss/test/unit/relationship_test.rb	2011-01-13 12:54:58 UTC (rev 2550)
+++ branches/neiss/test/unit/relationship_test.rb	2011-01-13 14:46:43 UTC (rev 2551)
@@ -1,10 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class RelationshipTest < Test::Unit::TestCase
-  fixtures :relationships
-
-  # Replace this with your real tests.
-  def test_truth
-    assert true
-  end
-end

reply via email to

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