-// 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/
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]
--- /dev/null
+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
+++ /dev/null
-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
--- /dev/null
+module LinksHelper
+end
+++ /dev/null
-module MetadataHelper
-end
-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
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
# 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
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
resources :projects
resources :specimens
resources :collections
- resources :metadata
+ resources :links
resources :nodes
resources :pipelines
resources :pipeline_invocations
namespace :orvos do
namespace :v1 do
resources :collections
- resources :metadata
+ resources :links
resources :nodes
resources :pipelines
resources :pipeline_invocations
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
# 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
--- /dev/null
+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
#
# 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
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"
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"
require 'test_helper'
-class MetadataControllerTest < ActionController::TestCase
+class LinksControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
--- /dev/null
+require 'test_helper'
+
+class LinksHelperTest < ActionView::TestCase
+end
+++ /dev/null
-require 'test_helper'
-
-class MetadataHelperTest < ActionView::TestCase
-end
require 'test_helper'
-class MetadatumTest < ActiveSupport::TestCase
+class LinkTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end