Diff
Modified: branches/packs/app/controllers/packs_controller.rb (3674 => 3675)
--- branches/packs/app/controllers/packs_controller.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/app/controllers/packs_controller.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -417,9 +417,9 @@
case entry
when PackContributableEntry
- resource_uri = entry.resource.uri
+ resource_uri = entry.resource(true).uri
when PackRemoteEntry
- resource_uri = entry.resource.uri
+ resource_uri = entry.resource(true).uri
end
post_process_created_resource(@pack, entry, resource_uri, params)
@@ -524,8 +524,8 @@
return
end
- # Delete the pack contributable entry if it exists.
- pce = @item.pack_contributable_entry.destroy if @item.pack_contributable_entry
+ # Delete the resource context if it exists.
+ pce = @item.context.destroy if @item.context
# Delete the resource
@item.destroy
Modified: branches/packs/app/helpers/packs_helper.rb (3674 => 3675)
--- branches/packs/app/helpers/packs_helper.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/app/helpers/packs_helper.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -149,7 +149,7 @@
label = resource.folder_entry.entry_name
end
- uri = pack_items_path(resource.research_object.pack) + "/" + resource.ore_path
+ uri = pack_items_path(resource.research_object.context) + "/" + resource.ore_path
"<span class='resource-link'>#{image} #{link_to(h(label), uri)}</span>"
end
Modified: branches/packs/app/models/pack.rb (3674 => 3675)
--- branches/packs/app/models/pack.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/app/models/pack.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -32,7 +32,7 @@
belongs_to :license
- belongs_to :research_object, :dependent => :destroy
+ has_one :research_object, :as => 'context', :dependent => :destroy
def find_version(version)
match = versions.find(:first, :conditions => ["version = ?", version])
Modified: branches/packs/app/models/pack_contributable_entry.rb (3674 => 3675)
--- branches/packs/app/models/pack_contributable_entry.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/app/models/pack_contributable_entry.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -22,7 +22,7 @@
after_save :synchronize_research_object
- belongs_to :resource, :dependent => :destroy
+ has_one :resource, :as => :context, :dependent => :destroy
def check_unique
@@ -102,7 +102,7 @@
user_path = "/users/#{user_id}"
- if ro && resource_id.nil?
+ if ro && resource.nil?
case contributable
when Workflow
@@ -117,10 +117,9 @@
:user_uri => user_path,
:path => path, # FIXME - where should these be URL encoded?
:data ="" data,
+ :context => self,
:content_type => contributable.content_type.mime_type)
- update_attribute(:resource_id, resource.id)
-
ro.update_manifest!
end
end
Modified: branches/packs/app/models/pack_remote_entry.rb (3674 => 3675)
--- branches/packs/app/models/pack_remote_entry.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/app/models/pack_remote_entry.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -20,7 +20,7 @@
after_save :synchronize_research_object
- belongs_to :resource, :dependent => :destroy
+ has_one :resource, :as => :context, :dependent => :destroy
def check_unique
if PackRemoteEntry.find(:first, :conditions => ["pack_id = ? AND version = ? AND uri = ?", self.pack_id, self.version, self.uri])
@@ -45,15 +45,14 @@
user_path = "/users/#{user_id}"
- if ro && resource_id.nil?
+ if ro && resource.nil?
resource = ro.create_proxy(
:proxy_for_path => uri,
:proxy_in_path => ".",
+ :context => self,
:user_uri => user_path)
- update_attribute(:resource_id, resource.id)
-
ro.update_manifest!
end
end
Modified: branches/packs/app/models/research_object.rb (3674 => 3675)
--- branches/packs/app/models/research_object.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/app/models/research_object.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -22,7 +22,7 @@
has_many :annotation_resources
- has_one :pack
+ belongs_to :context, :polymorphic => true
validates_presence_of :slug
@@ -289,6 +289,7 @@
throw "proxy_in_path required" unless opts[:proxy_in_path]
create_resource(
+ :context => opts[:context],
:path => opts[:path] || calculate_path(nil, 'application/vnd.wf4ever.proxy'),
:is_proxy => true,
:proxy_for_path => opts[:proxy_for_path],
@@ -359,7 +360,7 @@
end
def create_aggregated_resource(opts = {})
-
+puts "opts = #{opts.inspect}"
throw "user_uri required" unless opts[:user_uri]
throw "data required" unless opts[:data]
throw "content_type required" unless opts[:content_type]
@@ -378,6 +379,7 @@
# Create the resource.
create_resource(
+ :context => opts[:context],
:path => path,
:content_blob => ContentBlob.new(:data ="" opts[:data]),
:creator_uri => opts[:user_uri],
Modified: branches/packs/app/models/resource.rb (3674 => 3675)
--- branches/packs/app/models/resource.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/app/models/resource.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -17,7 +17,7 @@
belongs_to :content_blob, :dependent => :destroy
- has_one :pack_contributable_entry
+ belongs_to :context, :polymorphic => true
def proxy_for
research_object.resources.find(:first,
Modified: branches/packs/db/migrate/20130520145900_create_research_objects.rb (3674 => 3675)
--- branches/packs/db/migrate/20130520145900_create_research_objects.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/db/migrate/20130520145900_create_research_objects.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -7,16 +7,20 @@
def self.up
create_table "research_objects", :force => true do |t|
- t.string "slug"
- t.integer "version"
- t.string "version_type"
- t.integer "user_id"
+ t.string "context_type"
+ t.integer "context_id"
+ t.string "slug"
+ t.integer "version"
+ t.string "version_type"
+ t.integer "user_id"
t.timestamps
end
create_table "resources" do |t|
t.integer "research_object_id"
+ t.string "context_type"
+ t.integer "context_id"
t.integer "content_blob_id"
t.string "sha1", :limit => 40
t.integer "size"
Modified: branches/packs/lib/authorization.rb (3674 => 3675)
--- branches/packs/lib/authorization.rb 2013-09-05 12:27:44 UTC (rev 3674)
+++ branches/packs/lib/authorization.rb 2013-09-05 14:29:09 UTC (rev 3675)
@@ -387,27 +387,27 @@
when "create"
- # Only users that can edit the pack can create RO resources
+ # Only users that can edit the context can create RO resources
return Authorization.check('edit', context, user)
when "view"
- # You can only view a pack resource if you can view the pack
- return false unless Authorization.check('view', object.research_object.pack, user)
+ # You can only view a resource if you can view the context
+ return false unless Authorization.check('view', object.research_object.context, user)
# In addition to the above, you must be able to view the
# contributable if it is local to myExperiment
- if object.pack_contributable_entry
- return Authorization.check('view', object.pack_contributable_entry, user)
+ if object.context
+ return Authorization.check('view', object.context, user)
end
return true
when "destroy"
- # Only users that can edit the pack can delete RO resources
- return Authorization.check('edit', object.research_object.pack, user)
+ # Only users that can edit the context can delete RO resources
+ return Authorization.check('edit', object.research_object.context, user)
end
when "Message"