fcrepo_admin 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/HISTORY.rdoc +4 -0
- data/README.rdoc +6 -0
- data/app/controllers/fcrepo_admin/objects_controller.rb +41 -4
- data/app/views/fcrepo_admin/objects/_permissions.html.erb +8 -14
- data/app/views/fcrepo_admin/objects/_permissions_header.html.erb +7 -0
- data/app/views/fcrepo_admin/objects/_permissions_row.html.erb +5 -0
- data/app/views/fcrepo_admin/objects/show.html.erb +30 -2
- data/config/locales/fcrepo_admin.en.yml +10 -3
- data/lib/fcrepo_admin/controller_behavior.rb +5 -6
- data/lib/fcrepo_admin/datastream_ability.rb +6 -1
- data/lib/fcrepo_admin/version.rb +1 -1
- data/spec/controllers/objects_controller_spec.rb +10 -0
- data/spec/factories/fcrepo_admin_factories.rb +1 -1
- data/spec/features/objects/show.html.erb_spec.rb +8 -2
- data/spec/internal/app/controllers/application_controller.rb +6 -3
- data/spec/internal/app/models/admin_policy.rb +2 -0
- data/spec/internal/config/initializers/hydra_config.rb +1 -0
- metadata +9 -4
- data/app/helpers/application_helper.rb +0 -2
data/Gemfile
CHANGED
data/HISTORY.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -37,6 +37,12 @@ See https://github.com/projecthydra/hydra-head/wiki/Installation-Prerequisites.
|
|
37
37
|
You may replace <code>'/admin'</code> with any mount point (except perhaps <code>'/catalog'</code>),
|
38
38
|
including <code>'/'</code>. All routes include <code>objects</code> as a subpath.
|
39
39
|
|
40
|
+
* Add abilities to your Ability class
|
41
|
+
|
42
|
+
In app/models/ability.rb add this line after the Hydra abilities:
|
43
|
+
|
44
|
+
include FcrepoAdmin::DatastreamAbility
|
45
|
+
|
40
46
|
* Extend the SolrDocument model
|
41
47
|
|
42
48
|
In app/models/solr_document.rb add this line:
|
@@ -1,13 +1,50 @@
|
|
1
1
|
module FcrepoAdmin
|
2
2
|
class ObjectsController < ApplicationController
|
3
|
+
|
4
|
+
include FcrepoAdmin::ControllerBehavior
|
3
5
|
|
4
6
|
PROPERTIES = [:owner_id, :state, :create_date, :modified_date, :label]
|
5
7
|
|
8
|
+
helper_method :apo_enforcement_enabled?
|
9
|
+
helper_method :object_properties
|
10
|
+
|
11
|
+
before_filter { |c| c.load_and_authz_object :id }
|
12
|
+
before_filter :load_apo_info # depends on load_and_authz_object
|
13
|
+
|
6
14
|
def show
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def apo_enforcement_enabled?
|
20
|
+
# Including Hydra::PolicyAwareAccessControlsEnforcement in ApplicationController
|
21
|
+
# appears to be the only way that APO access control enforcement can be enabled.
|
22
|
+
self.class.ancestors.include?(Hydra::PolicyAwareAccessControlsEnforcement)
|
23
|
+
end
|
24
|
+
|
25
|
+
def object_properties
|
26
|
+
properties = {}
|
27
|
+
PROPERTIES.each { |p| properties[p] = @object.send(p) }
|
28
|
+
properties
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_apo_info
|
32
|
+
@apo_relationship_name = nil
|
33
|
+
@apo = nil
|
34
|
+
# XXX Ideally we would use Hydra::PolicyAwareAccessControlsEnforcement#policy_class,
|
35
|
+
# but it's only available if it's been included in the application controller, i.e.,
|
36
|
+
# if APO access control enforcement is enabled. We want to know the name of the
|
37
|
+
# relationship regardless of whether policy enforcement is enabled.
|
38
|
+
apo_class = Hydra.config[:permissions].fetch(:policy_class, Hydra::AdminPolicy)
|
39
|
+
@object.reflections.each_value do |reflection|
|
40
|
+
if reflection.options[:property] == :is_governed_by \
|
41
|
+
&& reflection.macro == :belongs_to #&& reflection.class_name == apo_class.to_s
|
42
|
+
@apo_relationship_name = reflection.name
|
43
|
+
@apo = @object.send(@apo_relationship_name)
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
11
48
|
end
|
12
49
|
|
13
50
|
end
|
@@ -1,18 +1,12 @@
|
|
1
|
+
<% if permissions.empty? %>
|
2
|
+
<p>
|
3
|
+
<%= t("fcrepo_admin.object.permissions.no_permissions") %>
|
4
|
+
</p>
|
5
|
+
<% else %>
|
1
6
|
<table class="table table-bordered table-condensed">
|
2
|
-
|
3
|
-
<tr>
|
4
|
-
<th scope="col"><%= t("fcrepo_admin.object.permissions.type") %></th>
|
5
|
-
<th scope="col"><%= t("fcrepo_admin.object.permissions.name") %></th>
|
6
|
-
<th scope="col"><%= t("fcrepo_admin.object.permissions.access") %></th>
|
7
|
-
</tr>
|
8
|
-
</thead>
|
7
|
+
<%= render :partial => "permissions_header" %>
|
9
8
|
<tbody>
|
10
|
-
|
11
|
-
<tr>
|
12
|
-
<td><%= p[:type] %></td>
|
13
|
-
<td><%= p[:name] %></td>
|
14
|
-
<td><%= p[:access] %></td>
|
15
|
-
</tr>
|
16
|
-
<% end %>
|
9
|
+
<%= render :partial => "permissions_row", :collection => permissions, :as => :permission %>
|
17
10
|
</tbody>
|
18
11
|
</table>
|
12
|
+
<% end %>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<thead>
|
2
|
+
<tr>
|
3
|
+
<th scope="col"><%= t("fcrepo_admin.object.permissions.header.type") %></th>
|
4
|
+
<th scope="col"><%= t("fcrepo_admin.object.permissions.header.name") %></th>
|
5
|
+
<th scope="col"><%= t("fcrepo_admin.object.permissions.header.access") %></th>
|
6
|
+
</tr>
|
7
|
+
</thead>
|
@@ -1,5 +1,9 @@
|
|
1
1
|
<h1><%= @object.pid %></h1>
|
2
2
|
|
3
|
+
<p>
|
4
|
+
Object Type: <%= @object.class.to_s %>
|
5
|
+
</p>
|
6
|
+
|
3
7
|
<div class="tabbable">
|
4
8
|
<ul class="nav nav-tabs">
|
5
9
|
<li class="active"><a href="#tab-datastreams" data-toggle="tab"><%= t("fcrepo_admin.object.tabs.datastreams") %></a></li>
|
@@ -11,10 +15,34 @@
|
|
11
15
|
<%= render :partial => 'fcrepo_admin/datastreams/datastreams', :locals => {:datastreams => @object.datastreams} %>
|
12
16
|
</div>
|
13
17
|
<div class="tab-pane" id="tab-properties">
|
14
|
-
<%= render :partial => 'properties', :locals => {:properties =>
|
18
|
+
<%= render :partial => 'properties', :locals => {:properties => object_properties} %>
|
15
19
|
</div>
|
16
20
|
<div class="tab-pane" id="tab-permissions">
|
17
|
-
|
21
|
+
<h4>Direct Permissions</h4>
|
22
|
+
<%= render :partial => 'permissions', :locals => {:permissions => @object.permissions} %>
|
23
|
+
<h4>Inherited Permissions</h4>
|
24
|
+
<% unless apo_enforcement_enabled? %>
|
25
|
+
<p class="alert">
|
26
|
+
<%= t("fcrepo_admin.object.apo.enforcement_disabled") %>
|
27
|
+
</p>
|
28
|
+
<% end %>
|
29
|
+
<% if @apo_relationship_name %>
|
30
|
+
<p>
|
31
|
+
<%= t("fcrepo_admin.object.apo.governed_by") %>:
|
32
|
+
<% if @apo %>
|
33
|
+
<%= link_to @apo.pid, fcrepo_admin.object_path(@apo.pid) %>
|
34
|
+
<% else %>
|
35
|
+
<span class="label"><%= t("fcrepo_admin.object.apo.not_assigned") %></span>
|
36
|
+
<% end %>
|
37
|
+
</p>
|
38
|
+
<% if @apo %>
|
39
|
+
<%= render :partial => 'permissions', :locals => {:permissions => @apo.default_permissions} %>
|
40
|
+
<% end %>
|
41
|
+
<% else %>
|
42
|
+
<p class="alert alert-info">
|
43
|
+
<%= t("fcrepo_admin.object.apo.relationship_undefined") %>
|
44
|
+
</p>
|
45
|
+
<% end %>
|
18
46
|
</div>
|
19
47
|
</div>
|
20
48
|
</div>
|
@@ -15,9 +15,16 @@ en:
|
|
15
15
|
modified_date: 'Modified Date'
|
16
16
|
label: 'Label'
|
17
17
|
permissions:
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
no_permissions: 'No permissions.'
|
19
|
+
header:
|
20
|
+
type: 'Type'
|
21
|
+
name: 'Name'
|
22
|
+
access: 'Access'
|
23
|
+
apo:
|
24
|
+
governed_by: 'Governed By'
|
25
|
+
not_assigned: 'Not Assigned'
|
26
|
+
enforcement_disabled: 'Admin policy access control enforcement is disabled.'
|
27
|
+
relationship_undefined: 'This object type does not define an admin policy relationship.'
|
21
28
|
audit_trail:
|
22
29
|
title: 'Audit Trail'
|
23
30
|
download: 'Download'
|
@@ -1,17 +1,16 @@
|
|
1
1
|
module FcrepoAdmin
|
2
2
|
module ControllerBehavior
|
3
3
|
|
4
|
-
def load_and_authz_object
|
5
|
-
load_object
|
4
|
+
def load_and_authz_object(param = :object_id)
|
5
|
+
load_object param
|
6
6
|
authorize_object
|
7
7
|
end
|
8
8
|
|
9
|
-
def load_object
|
10
|
-
@object = ActiveFedora::Base.find(params[
|
9
|
+
def load_object(param = :object_id)
|
10
|
+
@object = ActiveFedora::Base.find(params[param], :cast => true)
|
11
11
|
end
|
12
12
|
|
13
13
|
def authorize_object
|
14
|
-
#authorize_resource :instance_name => 'object'
|
15
14
|
authorize! params[:action].to_sym, @object
|
16
15
|
end
|
17
16
|
|
@@ -21,7 +20,7 @@ module FcrepoAdmin
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def load_datastream
|
24
|
-
load_object
|
23
|
+
load_object unless @object
|
25
24
|
@datastream = @object.datastreams[params[:id]]
|
26
25
|
end
|
27
26
|
|
@@ -2,8 +2,13 @@ require 'cancan'
|
|
2
2
|
|
3
3
|
module FcrepoAdmin
|
4
4
|
module DatastreamAbility
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
self.ability_logic += [:datastream_permissions]
|
9
|
+
end
|
5
10
|
|
6
|
-
def
|
11
|
+
def datastream_permissions
|
7
12
|
can :read, ActiveFedora::Datastream do |ds|
|
8
13
|
test_read(ds.pid)
|
9
14
|
end
|
data/lib/fcrepo_admin/version.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FcrepoAdmin::ObjectsController do
|
4
|
+
context "#show" do
|
5
|
+
subject { get :show, :id => object, :use_route => 'fcrepo_admin' }
|
6
|
+
let(:object) { FactoryGirl.create(:content_model) }
|
7
|
+
after { object.delete }
|
8
|
+
it { should render_template(:show) }
|
9
|
+
end
|
10
|
+
end
|
@@ -23,8 +23,14 @@ describe "objects/show.html.erb" do
|
|
23
23
|
page.should have_link(I18n.t("fcrepo_admin.audit_trail.title"), :href => fcrepo_admin.object_audit_trail_index_path(object))
|
24
24
|
end
|
25
25
|
it "should display the object's permissions"
|
26
|
-
|
27
|
-
|
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.pid))
|
28
33
|
end
|
34
|
+
it "should display the inherited permissions"
|
29
35
|
end
|
30
36
|
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
class ApplicationController < ActionController::Base
|
2
2
|
|
3
|
-
# Adds a few additional behaviors into the application controller
|
4
3
|
include Blacklight::Controller
|
5
|
-
|
6
|
-
|
4
|
+
include Hydra::Controller::ControllerBehavior
|
5
|
+
include Hydra::PolicyAwareAccessControlsEnforcement
|
6
|
+
|
7
|
+
rescue_from CanCan::AccessDenied do |exception|
|
8
|
+
render :file => "#{Rails.root}/public/403", :formats => [:html], :status => 403, :layout => false
|
9
|
+
end
|
7
10
|
|
8
11
|
layout 'blacklight'
|
9
12
|
|
@@ -30,5 +30,6 @@ if Hydra.respond_to?(:configure)
|
|
30
30
|
:owner => ActiveFedora::SolrService.solr_name("inheritable_depositor", indexer),
|
31
31
|
:embargo_release_date => ActiveFedora::SolrService.solr_name("inheritable_embargo_release_date", Solrizer::Descriptor.new(:date, :stored, :indexed))
|
32
32
|
}
|
33
|
+
config[:permissions][:policy_class] = AdminPolicy
|
33
34
|
end
|
34
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fcrepo_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-04-
|
15
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: hydra-head
|
@@ -259,7 +259,6 @@ files:
|
|
259
259
|
- app/controllers/fcrepo_admin/audit_trail_controller.rb
|
260
260
|
- app/controllers/fcrepo_admin/datastreams_controller.rb
|
261
261
|
- app/controllers/fcrepo_admin/objects_controller.rb
|
262
|
-
- app/helpers/application_helper.rb
|
263
262
|
- app/mailers/.gitkeep
|
264
263
|
- app/models/.gitkeep
|
265
264
|
- app/views/fcrepo_admin/audit_trail/index.html.erb
|
@@ -273,6 +272,8 @@ files:
|
|
273
272
|
- app/views/fcrepo_admin/datastreams/show.html.erb
|
274
273
|
- app/views/fcrepo_admin/objects/_more_info.html.erb
|
275
274
|
- app/views/fcrepo_admin/objects/_permissions.html.erb
|
275
|
+
- app/views/fcrepo_admin/objects/_permissions_header.html.erb
|
276
|
+
- app/views/fcrepo_admin/objects/_permissions_row.html.erb
|
276
277
|
- app/views/fcrepo_admin/objects/_properties.html.erb
|
277
278
|
- app/views/fcrepo_admin/objects/show.html.erb
|
278
279
|
- config/locales/fcrepo_admin.en.yml
|
@@ -291,6 +292,7 @@ files:
|
|
291
292
|
- lib/tasks/fcrepo_admin.rake
|
292
293
|
- spec/controllers/audit_trail_controller_spec.rb
|
293
294
|
- spec/controllers/datastreams_controller_spec.rb
|
295
|
+
- spec/controllers/objects_controller_spec.rb
|
294
296
|
- spec/factories/fcrepo_admin_factories.rb
|
295
297
|
- spec/factories/user_factories.rb
|
296
298
|
- spec/features/audit_trail/index.html.erb_spec.rb
|
@@ -310,6 +312,7 @@ files:
|
|
310
312
|
- spec/internal/app/mailers/.gitkeep
|
311
313
|
- spec/internal/app/models/.gitkeep
|
312
314
|
- spec/internal/app/models/ability.rb
|
315
|
+
- spec/internal/app/models/admin_policy.rb
|
313
316
|
- spec/internal/app/models/content_model.rb
|
314
317
|
- spec/internal/app/models/solr_document.rb
|
315
318
|
- spec/internal/app/models/user.rb
|
@@ -369,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
369
372
|
version: '0'
|
370
373
|
segments:
|
371
374
|
- 0
|
372
|
-
hash:
|
375
|
+
hash: -547145690877426491
|
373
376
|
requirements: []
|
374
377
|
rubyforge_project:
|
375
378
|
rubygems_version: 1.8.25
|
@@ -379,6 +382,7 @@ summary: Hydra-based Fedora Commons repository admin tool.
|
|
379
382
|
test_files:
|
380
383
|
- spec/controllers/audit_trail_controller_spec.rb
|
381
384
|
- spec/controllers/datastreams_controller_spec.rb
|
385
|
+
- spec/controllers/objects_controller_spec.rb
|
382
386
|
- spec/factories/fcrepo_admin_factories.rb
|
383
387
|
- spec/factories/user_factories.rb
|
384
388
|
- spec/features/audit_trail/index.html.erb_spec.rb
|
@@ -398,6 +402,7 @@ test_files:
|
|
398
402
|
- spec/internal/app/mailers/.gitkeep
|
399
403
|
- spec/internal/app/models/.gitkeep
|
400
404
|
- spec/internal/app/models/ability.rb
|
405
|
+
- spec/internal/app/models/admin_policy.rb
|
401
406
|
- spec/internal/app/models/content_model.rb
|
402
407
|
- spec/internal/app/models/solr_document.rb
|
403
408
|
- spec/internal/app/models/user.rb
|