fcrepo_admin 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.rdoc +6 -0
  3. data/README.rdoc +42 -20
  4. data/app/controllers/fcrepo_admin/associations_controller.rb +7 -0
  5. data/app/controllers/fcrepo_admin/objects_controller.rb +2 -1
  6. data/app/helpers/fcrepo_admin/associations_helper.rb +5 -0
  7. data/app/views/fcrepo_admin/associations/_associations.html.erb +26 -0
  8. data/app/views/fcrepo_admin/associations/index.html.erb +1 -0
  9. data/app/views/fcrepo_admin/associations/show.html.erb +11 -0
  10. data/app/views/fcrepo_admin/catalog/_document.html.erb +6 -0
  11. data/app/views/fcrepo_admin/datastreams/_content.html.erb +4 -3
  12. data/app/views/fcrepo_admin/datastreams/_context_nav.html.erb +9 -0
  13. data/app/views/fcrepo_admin/datastreams/_context_nav_items.html.erb +21 -0
  14. data/app/views/fcrepo_admin/datastreams/{_datastreams.html → _datastreams.html.erb} +16 -3
  15. data/app/views/fcrepo_admin/datastreams/_profile.html.erb +9 -10
  16. data/app/views/fcrepo_admin/datastreams/content.html.erb +1 -0
  17. data/app/views/fcrepo_admin/datastreams/index.html.erb +1 -4
  18. data/app/views/fcrepo_admin/datastreams/show.html.erb +1 -14
  19. data/app/views/fcrepo_admin/objects/_context_nav.html.erb +9 -0
  20. data/app/views/fcrepo_admin/objects/_context_nav_datastreams.html.erb +13 -0
  21. data/app/views/fcrepo_admin/objects/_context_nav_items.html.erb +19 -0
  22. data/app/views/fcrepo_admin/objects/_direct_permissions.html.erb +8 -0
  23. data/app/views/fcrepo_admin/objects/_inherited_permissions.html.erb +23 -0
  24. data/app/views/fcrepo_admin/objects/_permissions_list.html.erb +18 -0
  25. data/app/views/fcrepo_admin/objects/{_permissions_row.html.erb → _permissions_list_item.html.erb} +0 -0
  26. data/app/views/fcrepo_admin/objects/_properties.html.erb +6 -5
  27. data/app/views/fcrepo_admin/objects/permissions.html.erb +5 -0
  28. data/app/views/fcrepo_admin/objects/show.html.erb +3 -46
  29. data/app/views/layouts/fcrepo_admin/datastreams.html.erb +2 -2
  30. data/app/views/layouts/fcrepo_admin/objects.html.erb +1 -1
  31. data/config/locales/fcrepo_admin.en.yml +24 -4
  32. data/config/routes.rb +7 -2
  33. data/lib/fcrepo_admin.rb +4 -1
  34. data/lib/fcrepo_admin/ability.rb +18 -0
  35. data/lib/fcrepo_admin/controller/associations_controller_behavior.rb +49 -0
  36. data/lib/fcrepo_admin/controller/catalog_controller_behavior.rb +9 -0
  37. data/lib/fcrepo_admin/controller/controller_behavior.rb +49 -0
  38. data/lib/fcrepo_admin/controller/datastreams_controller_behavior.rb +21 -28
  39. data/lib/fcrepo_admin/controller/objects_controller_behavior.rb +7 -32
  40. data/lib/fcrepo_admin/helpers/associations_helper_behavior.rb +23 -0
  41. data/lib/fcrepo_admin/helpers/datastreams_helper_behavior.rb +7 -10
  42. data/lib/fcrepo_admin/helpers/fcrepo_admin_helper_behavior.rb +5 -10
  43. data/lib/fcrepo_admin/helpers/objects_helper_behavior.rb +0 -36
  44. data/lib/fcrepo_admin/version.rb +1 -1
  45. data/spec/controllers/associations_controller_spec.rb +34 -0
  46. data/spec/controllers/datastreams_controller_spec.rb +14 -12
  47. data/spec/controllers/objects_controller_spec.rb +6 -6
  48. data/spec/factories/fcrepo_admin_factories.rb +10 -6
  49. data/spec/features/associations/index.html.erb_spec.rb +28 -0
  50. data/spec/features/datastreams/edit.html.erb_spec.rb +1 -1
  51. data/spec/features/datastreams/index.html.erb_spec.rb +12 -0
  52. data/spec/features/datastreams/show.html.erb_spec.rb +1 -1
  53. data/spec/features/datastreams/upload.html.erb_spec.rb +1 -1
  54. data/spec/features/objects/audit_trail.html.erb_spec.rb +1 -1
  55. data/spec/features/objects/permissions.html.erb_spec.rb +19 -0
  56. data/spec/features/objects/show.html.erb_spec.rb +7 -30
  57. data/spec/internal/app/models/ability.rb +1 -1
  58. data/spec/internal/app/models/admin_policy.rb +3 -0
  59. data/spec/internal/app/models/collection.rb +14 -0
  60. data/spec/internal/app/models/item.rb +15 -0
  61. data/spec/internal/app/models/{content_model.rb → part.rb} +2 -1
  62. metadata +65 -73
  63. data/app/views/fcrepo_admin/datastreams/_datastream_nav.html.erb +0 -18
  64. data/app/views/fcrepo_admin/objects/_more_info.html.erb +0 -6
  65. data/app/views/fcrepo_admin/objects/_permissions.html.erb +0 -12
  66. data/app/views/fcrepo_admin/objects/_permissions_header.html.erb +0 -7
  67. data/lib/fcrepo_admin/datastream_ability.rb +0 -22
@@ -0,0 +1,23 @@
1
+ module FcrepoAdmin::Helpers
2
+ module AssociationsHelperBehavior
3
+
4
+ def link_to_target(association)
5
+ target = @object.send(association.name)
6
+ if association.collection?
7
+ text = "#{target.size} #{target.size == 1 ? 'object' : 'objects'}"
8
+ if target.size > 0
9
+ link_to text, fcrepo_admin.object_association_path(@object, association.name)
10
+ else
11
+ text
12
+ end
13
+ else # not a collection
14
+ if target
15
+ link_to target.pid, fcrepo_admin.object_path(target)
16
+ else
17
+ "[not assigned]"
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -7,18 +7,15 @@ module FcrepoAdmin::Helpers
7
7
  end
8
8
 
9
9
  def datastream_context_nav_items
10
- items = []
11
- items << [t("fcrepo_admin.datastream.nav.items.summary"), fcrepo_admin.object_datastream_path(@object, @datastream.dsid)]
12
- if can? :edit, @object
13
- items << [t("fcrepo_admin.datastream.nav.items.edit"), fcrepo_admin.edit_object_datastream_path(@object, @datastream.dsid)]
14
- end
15
- items << [t("fcrepo_admin.datastream.nav.items.upload"), fcrepo_admin.upload_object_datastream_path(@object, @datastream.dsid)]
16
- items << [t("fcrepo_admin.datastream.nav.items.download"), fcrepo_admin.download_object_datastream_path(@object, @datastream.dsid)]
17
- items
10
+ render :partial => 'fcrepo_admin/datastreams/context_nav_items', :locals => {:object => @object, :datastream => @datastream}
18
11
  end
19
12
 
20
- def render_datastream_context_nav
21
- render :partial => 'fcrepo_admin/shared/context_nav', :locals => {:header => datastream_context_nav_header, :items => datastream_context_nav_items}
13
+ def can_edit_datastream?
14
+ can? :edit, @object
15
+ end
16
+
17
+ def can_upload_datastream?
18
+ can? :upload, @object
22
19
  end
23
20
 
24
21
  end
@@ -1,21 +1,16 @@
1
1
  module FcrepoAdmin::Helpers
2
2
  module FcrepoAdminHelperBehavior
3
3
 
4
- def object_context_nav_items
5
- items = []
6
- items << [t("fcrepo_admin.object.nav.items.summary"), fcrepo_admin.object_path(@object)]
7
- if object_is_auditable?
8
- items << [t("fcrepo_admin.object.nav.items.audit_trail"), fcrepo_admin.audit_trail_object_path(@object)]
9
- end
10
- items
4
+ def object_has_permissions?
5
+ @object.is_a?(Hydra::ModelMixins::RightsMetadata)
11
6
  end
12
7
 
13
8
  def object_context_nav_header
14
- t("fcrepo_admin.object.nav.header")
9
+ t("fcrepo_admin.object.nav.header")
15
10
  end
16
11
 
17
- def render_object_context_nav
18
- render :partial => 'fcrepo_admin/shared/context_nav', :locals => {:header => object_context_nav_header, :items => object_context_nav_items}
12
+ def object_context_nav_items
13
+ render :partial => 'fcrepo_admin/objects/context_nav_items', :locals => {:object => @object}
19
14
  end
20
15
 
21
16
  end
@@ -9,42 +9,6 @@ module FcrepoAdmin::Helpers
9
9
  def object_type
10
10
  @object.class.to_s
11
11
  end
12
-
13
- def object_has_permissions?
14
- @object.is_a?(Hydra::ModelMixins::RightsMetadata)
15
- end
16
-
17
- def object_model_belongs_to_apo?
18
- !@apo_relationship_name.nil?
19
- end
20
-
21
- def object_admin_policy
22
- @object_admin_policy
23
- end
24
-
25
- def object_has_admin_policy?
26
- !object_admin_policy.nil?
27
- end
28
-
29
- def object_has_inherited_permissions?
30
- object_has_admin_policy?
31
- end
32
-
33
- def object_inherited_permissions
34
- object_admin_policy && object_admin_policy.default_permissions
35
- end
36
-
37
- def admin_policy_enforcement_enabled?
38
- @apo_enforcement_enabled
39
- end
40
-
41
- def admin_policy_object?
42
- # XXX Ideally we would use Hydra::PolicyAwareAccessControlsEnforcement#policy_class,
43
- # but it's only available if it's been included in the application controller, i.e.,
44
- # if APO access control enforcement is enabled. We want to know the name of the
45
- # relationship regardless of whether policy enforcement is enabled.
46
- @object.is_a?(Hydra.config[:permissions].fetch(:policy_class, Hydra::AdminPolicy))
47
- end
48
12
 
49
13
  end
50
14
  end
@@ -1,3 +1,3 @@
1
1
  module FcrepoAdmin
2
- VERSION = "0.3.5"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe FcrepoAdmin::AssociationsController do
4
+ let(:object) { FactoryGirl.create(:item) }
5
+ after { object.delete }
6
+ context "#index" do
7
+ subject { get :index, :object_id => object, :use_route => 'fcrepo_admin' }
8
+ it { should render_template(:index) }
9
+ end
10
+ context "#show" do
11
+ context "association is a collection" do
12
+ let(:part) { FactoryGirl.create(:part) }
13
+ before { object.parts << part }
14
+ after do
15
+ part.delete
16
+ object.reload
17
+ end
18
+ subject { get :show, :object_id => object, :id => "parts", :use_route => 'fcrepo_admin' }
19
+ it { should render_template(:show) }
20
+ end
21
+ context "association is not a collection" do
22
+ subject { get :show, :object_id => object, :id => "collection", :use_route => 'fcrepo_admin' }
23
+ context "has target" do
24
+ let(:collection) { FactoryGirl.create(:collection) }
25
+ before { collection.members << object }
26
+ after { collection.delete }
27
+ its(:response_code) { should eq(302) }
28
+ end
29
+ context "target is nil" do
30
+ its(:response_code) { should eq(404) }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,24 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
- shared_examples "a datastream profile view" do
4
- it { should render_template(:show) }
5
- end
3
+ # shared_examples "a datastream profile view" do
4
+ # it { should render_template(:show) }
5
+ # end
6
6
 
7
7
  describe FcrepoAdmin::DatastreamsController do
8
8
  before do
9
- @object = FactoryGirl.create(:content_model)
9
+ @object = FactoryGirl.create(:item)
10
10
  @dsid = "descMetadata"
11
11
  end
12
12
  after { @object.delete }
13
13
  context "#show" do
14
- context "browser view" do
15
- subject { get :show, :object_id => @object, :id => @dsid, :use_route => 'fcrepo_admin' }
16
- it { should render_template(:show) }
17
- end
18
- context "download" do
19
- subject { get :show, :object_id => @object, :id => @dsid, :download => 'true', :use_route => 'fcrepo_admin' }
20
- it { should be_successful }
21
- end
14
+ subject { get :show, :object_id => @object, :id => @dsid, :use_route => 'fcrepo_admin' }
15
+ it { should render_template(:show) }
16
+ end
17
+ context "#show" do
18
+ subject { get :content, :object_id => @object, :id => @dsid, :use_route => 'fcrepo_admin' }
19
+ it { should render_template(:content) }
20
+ end
21
+ context "#download" do
22
+ subject { get :download, :object_id => @object, :id => @dsid, :use_route => 'fcrepo_admin' }
23
+ it { should be_successful }
22
24
  end
23
25
  context "change methods" do
24
26
  let(:user) { FactoryGirl.create(:user) }
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FcrepoAdmin::ObjectsController do
4
+ let(:object) { FactoryGirl.create(:item) }
5
+ after { object.delete }
4
6
  context "#show" do
5
7
  subject { get :show, :id => object, :use_route => 'fcrepo_admin' }
6
- let(:object) { FactoryGirl.create(:content_model) }
7
- after { object.delete }
8
8
  it { should render_template(:show) }
9
9
  end
10
10
  context "#audit_trail" do
11
- let(:object) { FactoryGirl.create(:content_model) }
12
- after { object.delete }
13
11
  subject { get :audit_trail, :id => object, :use_route => 'fcrepo_admin' }
14
12
  it { should render_template(:audit_trail) }
15
13
  end
16
14
  context "#audit_trail?download=true" do
17
15
  subject { get :audit_trail, :id => object, :download => 'true', :use_route => 'fcrepo_admin' }
18
- let(:object) { FactoryGirl.create(:content_model) }
19
- after { object.delete }
20
16
  its(:response_code) { should eq(200) }
21
17
  end
18
+ context "#permissions" do
19
+ subject { get :permissions, :id => object, :use_route => 'fcrepo_admin' }
20
+ it { should render_template(:permissions) }
21
+ end
22
22
  end
@@ -6,15 +6,19 @@ FactoryGirl.define do
6
6
  default_permissions [{type: 'group', name: 'public', access: 'read'}]
7
7
  end
8
8
 
9
- factory :content_model do
10
- title "Test Object"
9
+ factory :collection do
10
+ title "Test Collection"
11
11
  permissions [{type: 'group', name: 'public', access: 'read'}]
12
+ end
12
13
 
13
- trait :has_apo do
14
- admin_policy { create(:admin_policy) }
15
- end
14
+ factory :item do
15
+ sequence(:title) { |n| "Test Item [#{n}]" }
16
+ permissions [{type: 'group', name: 'public', access: 'read'}]
17
+ end
16
18
 
17
- factory :content_model_has_apo, :traits => [:has_apo]
19
+ factory :part do
20
+ sequence(:title) { |n| "Test Part [#{n}]" }
21
+ permissions [{type: 'group', name: 'public', access: 'read'}]
18
22
  end
19
23
 
20
24
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "associations/index.html.erb" do
4
+ let(:object) { FactoryGirl.create(:item) }
5
+ after { object.delete }
6
+ context "association is a collection" do
7
+ let(:part) { FactoryGirl.create(:part) }
8
+ before { object.parts << part }
9
+ after do
10
+ part.delete
11
+ object.reload
12
+ end
13
+ it "should link to the show view of the association" do
14
+ visit fcrepo_admin.object_associations_path(object)
15
+ page.should have_link("1 object", :href => fcrepo_admin.object_association_path(object, "parts"))
16
+ end
17
+ end
18
+ context "association is not a collection" do
19
+ let(:collection) { FactoryGirl.create(:collection) }
20
+ before { collection.members << object }
21
+ after { collection.delete }
22
+ it "should link to the show view of the target object" do
23
+ pending "Bug in Capybara?"
24
+ visit fcrepo_admin.object_associations_path(object)
25
+ page.should have_link(collection.pid, :href => fcrepo_admin.object_path(collection))
26
+ end
27
+ end
28
+ end
@@ -5,7 +5,7 @@ RSpec.configure do |c|
5
5
  end
6
6
 
7
7
  describe "datastreams/edit.html.erb" do
8
- let(:object) { FactoryGirl.create(:content_model) }
8
+ let(:object) { FactoryGirl.create(:item) }
9
9
  let(:user) { FactoryGirl.create(:user) }
10
10
  before {
11
11
  object.permissions = [{type: 'user', name: user.email, access: 'edit'}]
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "datastreams/index.html.erb" do
4
+ before { visit fcrepo_admin.object_datastreams_path(object) }
5
+ after { object.delete }
6
+ let(:object) { FactoryGirl.create(:item) }
7
+ it "should link to all persisted datastreams" do
8
+ object.datastreams.reject { |dsid, ds| ds.profile.empty? }.each_key do |dsid|
9
+ page.should have_link(dsid, :href => fcrepo_admin.object_datastream_path(object, dsid))
10
+ end
11
+ end
12
+ end
@@ -5,7 +5,7 @@ RSpec.configure do |c|
5
5
  end
6
6
 
7
7
  describe "datastreams/show.html.erb" do
8
- let!(:object) { FactoryGirl.create(:content_model) }
8
+ let!(:object) { FactoryGirl.create(:item) }
9
9
  let(:dsid) { "descMetadata" }
10
10
  before { visit fcrepo_admin.object_datastream_path(object, dsid) }
11
11
  after { object.delete }
@@ -5,7 +5,7 @@ RSpec.configure do |c|
5
5
  end
6
6
 
7
7
  describe "datastreams/upload.html.erb" do
8
- let(:object) { FactoryGirl.create(:content_model) }
8
+ let(:object) { FactoryGirl.create(:item) }
9
9
  let(:user) { FactoryGirl.create(:user) }
10
10
  before {
11
11
  object.permissions = [{type: 'user', name: user.email, access: 'edit'}]
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "audit_trail.html.erb" do
4
- let(:object) { FactoryGirl.create(:content_model) }
4
+ let(:object) { FactoryGirl.create(:item) }
5
5
  after { object.delete }
6
6
  it "should display the audit trail" do
7
7
  visit fcrepo_admin.audit_trail_object_path(object)
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "objects/permissions.html.erb" do
4
+ after { object.delete }
5
+ context "object governed by an admin policy" do
6
+ let(:object) { FactoryGirl.create(:item) }
7
+ let(:apo) { FactoryGirl.create(:admin_policy) }
8
+ before do
9
+ object.admin_policy = apo
10
+ object.save
11
+ end
12
+ after { apo.delete }
13
+ it "should link to the APO" do
14
+ visit fcrepo_admin.permissions_object_path(object)
15
+ page.should have_link(object.admin_policy.pid, :href => fcrepo_admin.object_path(object.admin_policy))
16
+ end
17
+ it "should display the inherited permissions"
18
+ end
19
+ end
@@ -1,36 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "objects/show.html.erb" do
4
+ before { visit fcrepo_admin.object_path(object) }
4
5
  after { object.delete }
5
- context "basic object" do
6
- let(:object) { FactoryGirl.create(:content_model) }
7
- it "should display the object's properties" do
8
- visit fcrepo_admin.object_path(object)
9
- page.should have_content(I18n.t("fcrepo_admin.object.properties.keys.state"))
10
- page.should have_content(I18n.t("fcrepo_admin.object.properties.keys.create_date"))
11
- page.should have_content(I18n.t("fcrepo_admin.object.properties.keys.modified_date"))
12
- page.should have_content(I18n.t("fcrepo_admin.object.properties.keys.owner_id"))
13
- page.should have_content(I18n.t("fcrepo_admin.object.properties.keys.label"))
14
- end
15
- it "should link to all datastreams" do
16
- visit fcrepo_admin.object_path(object)
17
- object.datastreams.reject { |dsid, ds| ds.profile.empty? }.each_key do |dsid|
18
- page.should have_link(dsid, :href => fcrepo_admin.object_datastream_path(object, dsid))
19
- end
20
- end
21
- it "should link to its audit trail" do
22
- visit fcrepo_admin.object_path(object)
23
- page.should have_link(I18n.t("fcrepo_admin.object.audit_trail.title"), :href => fcrepo_admin.audit_trail_object_path(object))
24
- end
25
- it "should display the object's permissions"
26
- end
27
- context "object governed by an admin policy" do
28
- let(:object) { FactoryGirl.create(:content_model_has_apo) }
29
- after { object.admin_policy.delete }
30
- it "should link to the APO" do
31
- visit fcrepo_admin.object_path(object)
32
- page.should have_link(object.admin_policy.pid, :href => fcrepo_admin.object_path(object.admin_policy))
33
- end
34
- it "should display the inherited permissions"
6
+ let(:object) { FactoryGirl.create(:item) }
7
+ it "should link to other views" do
8
+ page.should have_link(I18n.t("fcrepo_admin.object.nav.items.audit_trail"), :href => fcrepo_admin.audit_trail_object_path(object))
9
+ page.should have_link(I18n.t("fcrepo_admin.object.nav.items.permissions"), :href => fcrepo_admin.permissions_object_path(object))
10
+ page.should have_link(I18n.t("fcrepo_admin.object.nav.items.associations"), :href => fcrepo_admin.object_associations_path(object))
11
+ page.should have_link(I18n.t("fcrepo_admin.object.nav.items.datastreams"), :href => fcrepo_admin.object_datastreams_path(object))
35
12
  end
36
13
  end
@@ -1,5 +1,5 @@
1
1
  class Ability
2
2
  include Hydra::Ability
3
3
  include Hydra::PolicyAwareAbility
4
- include FcrepoAdmin::DatastreamAbility
4
+ include FcrepoAdmin::Ability
5
5
  end
@@ -1,2 +1,5 @@
1
1
  class AdminPolicy < Hydra::AdminPolicy
2
+
3
+ has_many :governs, :property => :is_governed_by, :inbound => true, :class_name => 'ActiveFedora::Base'
4
+
2
5
  end
@@ -0,0 +1,14 @@
1
+ class Collection < ActiveFedora::Base
2
+
3
+ has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream
4
+ has_metadata :name => "rightsMetadata", :type => Hydra::Datastream::RightsMetadata
5
+
6
+ delegate :title, :to => "descMetadata", :unique => true
7
+
8
+ belongs_to :admin_policy, :property => :is_governed_by
9
+ has_many :members, :property => :is_member_of_collection, :inbound => true, :class_name => 'Item'
10
+
11
+ include Hydra::ModelMixins::RightsMetadata
12
+ include ActiveFedora::Auditable
13
+
14
+ end
@@ -0,0 +1,15 @@
1
+ class Item < ActiveFedora::Base
2
+
3
+ has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream
4
+ has_metadata :name => "rightsMetadata", :type => Hydra::Datastream::RightsMetadata
5
+
6
+ delegate :title, :to => "descMetadata", :unique => true
7
+
8
+ belongs_to :admin_policy, :property => :is_governed_by
9
+ belongs_to :collection, :property => :is_member_of_collection, :class_name => 'Collection'
10
+ has_many :parts, :property => :is_part_of, :inbound => true, :class_name => 'Part'
11
+
12
+ include Hydra::ModelMixins::RightsMetadata
13
+ include ActiveFedora::Auditable
14
+
15
+ end