rename Metadatum to Link, head to head_uuid, tail to tail_uuid
authorTom Clegg <tom@clinicalfuture.com>
Mon, 28 Jan 2013 20:48:35 +0000 (12:48 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Mon, 28 Jan 2013 21:19:28 +0000 (13:19 -0800)
17 files changed:
app/assets/javascripts/links.js.coffee [moved from app/assets/javascripts/metadata.js.coffee with 100% similarity]
app/assets/stylesheets/links.css.scss [moved from app/assets/stylesheets/metadata.css.scss with 63% similarity]
app/controllers/application_controller.rb
app/controllers/orvos/v1/links_controller.rb [new file with mode: 0644]
app/controllers/orvos/v1/metadata_controller.rb [deleted file]
app/helpers/links_helper.rb [new file with mode: 0644]
app/helpers/metadata_helper.rb [deleted file]
app/models/link.rb [moved from app/models/metadatum.rb with 73% similarity]
app/models/orvos_model.rb
config/routes.rb
db/migrate/20130128202518_rename_metadata_to_links.rb [new file with mode: 0644]
db/schema.rb
test/fixtures/links.yml [moved from test/fixtures/metadata.yml with 100% similarity]
test/functional/links_controller_test.rb [moved from test/functional/metadata_controller_test.rb with 57% similarity]
test/unit/helpers/links_helper_test.rb [new file with mode: 0644]
test/unit/helpers/metadata_helper_test.rb [deleted file]
test/unit/link_test.rb [moved from test/unit/metadatum_test.rb with 62% similarity]

similarity index 63%
rename from app/assets/stylesheets/metadata.css.scss
rename to app/assets/stylesheets/links.css.scss
index 72bd8b84d36407b588ff6f3c1b5e750ee2dc1d4e..81ec94bf1d3b5f150288cc245defb49edc785bd4 100644 (file)
@@ -1,3 +1,3 @@
-// Place all the styles related to the metadata controller here.
+// Place all the styles related to the links controller here.
 // They will automatically be included in application.css.
 // You can use Sass (SCSS) here: http://sass-lang.com/
index ba5d26babb64d0ed043e9a3411c9e8d7c3c9ac3b..076e3f868e8ee2bef1b13359cf398bcc037968e3 100644 (file)
@@ -50,8 +50,8 @@ class ApplicationController < ActionController::Base
 
   def index
     @objects ||= model_class.
-      joins("LEFT JOIN metadata permissions ON permissions.head=#{table_name}.owner AND permissions.tail=#{model_class.sanitize current_user.uuid} AND permissions.metadata_class='permission'").
-      where("?=? OR #{table_name}.owner=? OR #{table_name}.uuid=? OR permissions.head IS NOT NULL",
+      joins("LEFT JOIN links permissions ON permissions.head_uuid=#{table_name}.owner AND permissions.tail_uuid=#{model_class.sanitize current_user.uuid} AND permissions.link_class='permission'").
+      where("?=? OR #{table_name}.owner=? OR #{table_name}.uuid=? OR permissions.head_uuid IS NOT NULL",
             true, current_user.is_admin,
             current_user.uuid, current_user.uuid)
     if params[:where]
diff --git a/app/controllers/orvos/v1/links_controller.rb b/app/controllers/orvos/v1/links_controller.rb
new file mode 100644 (file)
index 0000000..e517709
--- /dev/null
@@ -0,0 +1,10 @@
+class Orvos::V1::LinksController < ApplicationController
+  def index
+    if params[:tail_uuid]
+      params[:where] = JSON.parse(params[:where]) if params[:where].is_a?(String)
+      params[:where] ||= {}
+      params[:where][:tail_uuid] = params[:tail_uuid]
+    end
+    super
+  end
+end
diff --git a/app/controllers/orvos/v1/metadata_controller.rb b/app/controllers/orvos/v1/metadata_controller.rb
deleted file mode 100644 (file)
index b5ca600..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-class Orvos::V1::MetadataController < ApplicationController
-  def index
-    if params[:tail_kind] and params[:tail]
-      params[:where] = JSON.parse(params[:where]) if params[:where].is_a?(String)
-      params[:where] ||= {}
-      params[:where][:tail_kind] = params[:tail_kind]
-      params[:where][:tail] = params[:tail]
-    end
-    super
-  end
-end
diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb
new file mode 100644 (file)
index 0000000..f6bc988
--- /dev/null
@@ -0,0 +1,2 @@
+module LinksHelper
+end
diff --git a/app/helpers/metadata_helper.rb b/app/helpers/metadata_helper.rb
deleted file mode 100644 (file)
index 300d90e..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-module MetadataHelper
-end
similarity index 73%
rename from app/models/metadatum.rb
rename to app/models/link.rb
index 3ce96f656906774590c88fa1a8306ea67e6c8e66..9600d177e0f5f2e58962d0feb7242a1d96649ae5 100644 (file)
@@ -1,19 +1,19 @@
-class Metadatum < OrvosModel
+class Link < OrvosModel
   include AssignUuid
   include KindAndEtag
   include CommonApiTemplate
-  serialize :info, Hash
+  serialize :properties, Hash
   before_create :permission_to_attach_to_objects
   before_update :permission_to_attach_to_objects
 
   api_accessible :superuser, :extend => :common do |t|
     t.add :tail_kind
-    t.add :tail
-    t.add :metadata_class
+    t.add :tail_uuid
+    t.add :link_class
     t.add :name
     t.add :head_kind
-    t.add :head
-    t.add :info
+    t.add :head_uuid
+    t.add :properties
   end
 
   def info
@@ -24,11 +24,11 @@ class Metadatum < OrvosModel
   protected
 
   def permission_to_attach_to_objects
-    # Anonymous users cannot write metadata
+    # Anonymous users cannot write links
     return false if !current_user
 
-    # All users can write metadata that doesn't affect permissions
-    return true if self.metadata_class != 'permission'
+    # All users can write links that don't affect permissions
+    return true if self.link_class != 'permission'
 
     # Administrators can grant permissions
     return true if current_user.is_admin
@@ -45,8 +45,8 @@ class Metadatum < OrvosModel
     # Users with "can_grant" permission on an object can grant
     # permissions on that object
     has_grant_permission = self.class.
-      where('metadata_class=? AND name=? AND tail=? AND head=?',
-            'permission', 'can_grant', current_user.uuid, self.head).
+      where('link_class=? AND name=? AND tail_uuid=? AND head_uuid=?',
+            'permission', 'can_grant', current_user.uuid, self.head_uuid).
       count > 0
     return true if has_grant_permission
 
index bdd27a67c31584a2c736b5eb0522bb63ef585ebc..6601216980fdc7032131fc5fd43a8f084cfb5d8a 100644 (file)
@@ -34,19 +34,19 @@ class OrvosModel < ActiveRecord::Base
     return false unless current_user
     if self.owner_changed? and
         self.owner_was != current_user.uuid and
-        0 == Metadatum.where(metadata_class: 'permission',
-                             name: 'can_pillage',
-                             tail: self.owner,
-                             head: current_user.uuid).count
+        0 == Link.where(link_class: 'permission',
+                        name: 'can_pillage',
+                        tail_uuid: self.owner,
+                        head_uuid: current_user.uuid).count
       return false
     end
     self.owner == current_user.uuid or
       current_user.is_admin or
       current_user.uuid == self.uuid or
-      Metadatum.where(metadata_class: 'permission',
-                      name: 'can_write',
-                      tail: self.owner,
-                      head: current_user.uuid).count > 0
+      Link.where(link_class: 'permission',
+                 name: 'can_write',
+                 tail_uuid: self.owner,
+                 head_uuid: current_user.uuid).count > 0
   end
 
   def update_modified_by_fields
index b592c58a071f3a37a96143dde2f11fd0ab115c26..648297685e9d8d51bf5ee86f33b95822843ce258 100644 (file)
@@ -5,7 +5,7 @@ Server::Application.routes.draw do
   resources :projects
   resources :specimens
   resources :collections
-  resources :metadata
+  resources :links
   resources :nodes
   resources :pipelines
   resources :pipeline_invocations
@@ -70,7 +70,7 @@ Server::Application.routes.draw do
   namespace :orvos do
     namespace :v1 do
       resources :collections
-      resources :metadata
+      resources :links
       resources :nodes
       resources :pipelines
       resources :pipeline_invocations
@@ -81,7 +81,7 @@ Server::Application.routes.draw do
       resources :users
       match '/schema' => 'schema#show'
       match '/nodes/:uuid/ping' => 'nodes#ping', :as => :ping_node
-      match '/metadata/:tail_kind/:tail' => 'metadata#index'
+      match '/links/:tail_uuid' => 'links#index'
     end
   end
 
@@ -95,7 +95,7 @@ Server::Application.routes.draw do
 
   # Send unroutable requests to an arbitrary controller
   # (ends up at ApplicationController#render_not_found)
-  match '*a', :to => 'orvos/v1/metadata#render_not_found'
+  match '*a', :to => 'orvos/v1/links#render_not_found'
 
   root :to => 'static#home'
 end
diff --git a/db/migrate/20130128202518_rename_metadata_to_links.rb b/db/migrate/20130128202518_rename_metadata_to_links.rb
new file mode 100644 (file)
index 0000000..067c69c
--- /dev/null
@@ -0,0 +1,27 @@
+class RenameMetadataToLinks < ActiveRecord::Migration
+  def up
+    rename_table :metadata, :links
+    rename_column :links, :tail, :tail_uuid
+    rename_column :links, :head, :head_uuid
+    rename_column :links, :info, :properties
+    rename_column :links, :metadata_class, :link_class
+    rename_index :links, :index_metadata_on_head_kind, :index_links_on_head_kind
+    rename_index :links, :index_metadata_on_head, :index_links_on_head_uuid
+    rename_index :links, :index_metadata_on_tail_kind, :index_links_on_tail_kind
+    rename_index :links, :index_metadata_on_tail, :index_links_on_tail_uuid
+    rename_index :links, :index_metadata_on_uuid, :index_links_on_uuid
+  end
+
+  def down
+    rename_index :links, :index_links_on_uuid, :index_metadata_on_uuid
+    rename_index :links, :index_links_on_head_kind, :index_metadata_on_head_kind
+    rename_index :links, :index_links_on_head_uuid, :index_metadata_on_head
+    rename_index :links, :index_links_on_tail_kind, :index_metadata_on_tail_kind
+    rename_index :links, :index_links_on_tail_uuid, :index_metadata_on_tail
+    rename_column :links, :link_class, :metadata_class
+    rename_column :links, :properties, :info
+    rename_column :links, :head_uuid, :head
+    rename_column :links, :tail_uuid, :tail
+    rename_table :links, :metadata
+  end
+end
index 833a94b8c5f3acdb82fe09c3b5e338c872525c81..8507e0cdf29c3001ea2c5055ae5a335f278c8fb6 100644 (file)
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130125220425) do
+ActiveRecord::Schema.define(:version => 20130128202518) do
 
   create_table "api_client_authorizations", :force => true do |t|
     t.string   "api_token",               :null => false
@@ -63,6 +63,31 @@ ActiveRecord::Schema.define(:version => 20130125220425) do
 
   add_index "collections", ["uuid"], :name => "index_collections_on_uuid", :unique => true
 
+  create_table "links", :force => true do |t|
+    t.string   "uuid"
+    t.string   "owner"
+    t.datetime "created_at"
+    t.string   "modified_by_client"
+    t.string   "modified_by_user"
+    t.datetime "modified_at"
+    t.string   "tail_uuid"
+    t.string   "tail_kind"
+    t.integer  "native_target_id"
+    t.string   "native_target_type"
+    t.string   "link_class"
+    t.string   "name"
+    t.string   "head_uuid"
+    t.text     "properties"
+    t.datetime "updated_at"
+    t.string   "head_kind"
+  end
+
+  add_index "links", ["head_kind"], :name => "index_links_on_head_kind"
+  add_index "links", ["head_uuid"], :name => "index_links_on_head_uuid"
+  add_index "links", ["tail_kind"], :name => "index_links_on_tail_kind"
+  add_index "links", ["tail_uuid"], :name => "index_links_on_tail_uuid"
+  add_index "links", ["uuid"], :name => "index_links_on_uuid", :unique => true
+
   create_table "logs", :force => true do |t|
     t.string   "uuid"
     t.string   "owner"
@@ -86,31 +111,6 @@ ActiveRecord::Schema.define(:version => 20130125220425) do
   add_index "logs", ["summary"], :name => "index_logs_on_summary"
   add_index "logs", ["uuid"], :name => "index_logs_on_uuid", :unique => true
 
-  create_table "metadata", :force => true do |t|
-    t.string   "uuid"
-    t.string   "owner"
-    t.datetime "created_at"
-    t.string   "modified_by_client"
-    t.string   "modified_by_user"
-    t.datetime "modified_at"
-    t.string   "tail"
-    t.string   "tail_kind"
-    t.integer  "native_target_id"
-    t.string   "native_target_type"
-    t.string   "metadata_class"
-    t.string   "name"
-    t.string   "head"
-    t.text     "info"
-    t.datetime "updated_at"
-    t.string   "head_kind"
-  end
-
-  add_index "metadata", ["head"], :name => "index_metadata_on_head"
-  add_index "metadata", ["head_kind"], :name => "index_metadata_on_head_kind"
-  add_index "metadata", ["tail"], :name => "index_metadata_on_tail"
-  add_index "metadata", ["tail_kind"], :name => "index_metadata_on_tail_kind"
-  add_index "metadata", ["uuid"], :name => "index_metadata_on_uuid", :unique => true
-
   create_table "nodes", :force => true do |t|
     t.string   "uuid"
     t.string   "owner"
similarity index 57%
rename from test/functional/metadata_controller_test.rb
rename to test/functional/links_controller_test.rb
index ec39c5609268477dfeb2e710fe559c41e057675d..a8e87e117077a95efbe4d1b53b9153a7088c5323 100644 (file)
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class MetadataControllerTest < ActionController::TestCase
+class LinksControllerTest < ActionController::TestCase
   # test "the truth" do
   #   assert true
   # end
diff --git a/test/unit/helpers/links_helper_test.rb b/test/unit/helpers/links_helper_test.rb
new file mode 100644 (file)
index 0000000..3ff1dea
--- /dev/null
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class LinksHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/helpers/metadata_helper_test.rb b/test/unit/helpers/metadata_helper_test.rb
deleted file mode 100644 (file)
index d50e16c..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'test_helper'
-
-class MetadataHelperTest < ActionView::TestCase
-end
similarity index 62%
rename from test/unit/metadatum_test.rb
rename to test/unit/link_test.rb
index 1fd95dbec6d44f86691843c5ee686c0150588d93..944bfced3d30423ff2b83e0d6cf7c134ce1f8e88 100644 (file)
@@ -1,6 +1,6 @@
 require 'test_helper'
 
-class MetadatumTest < ActiveSupport::TestCase
+class LinkTest < ActiveSupport::TestCase
   # test "the truth" do
   #   assert true
   # end