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 CHANGED
@@ -2,4 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'devise'
5
+ gem 'active-fedora', github: 'projecthydra/active_fedora'
6
+ gem 'devise'
@@ -1,3 +1,7 @@
1
+ === 0.3.0
2
+
3
+ * Feature: Added permissions and inherited permissions to object view.
4
+
1
5
  === 0.2.0
2
6
 
3
7
  * Feature: Datastream content editing.
@@ -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
- @object = ActiveFedora::Base.find(params[:id], :cast => true)
8
- authorize! :read, @object
9
- @properties = {}
10
- PROPERTIES.each { |p| @properties[p] = @object.send(p) }
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
- <thead>
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
- <% object.permissions.each do |p| %>
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>
@@ -0,0 +1,5 @@
1
+ <tr>
2
+ <td><%= permission[:type] %></td>
3
+ <td><%= permission[:name] %></td>
4
+ <td><%= permission[:access] %></td>
5
+ </tr>
@@ -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 => @properties} %>
18
+ <%= render :partial => 'properties', :locals => {:properties => object_properties} %>
15
19
  </div>
16
20
  <div class="tab-pane" id="tab-permissions">
17
- <%= render :partial => 'permissions', :locals => {:object => @object} %>
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
- type: 'Type'
19
- name: 'Name'
20
- access: 'Access'
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[:object_id], :cast => true)
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 custom_permissions
11
+ def datastream_permissions
7
12
  can :read, ActiveFedora::Datastream do |ds|
8
13
  test_read(ds.pid)
9
14
  end
@@ -1,3 +1,3 @@
1
1
  module FcrepoAdmin
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
@@ -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
@@ -11,7 +11,7 @@ FactoryGirl.define do
11
11
  permissions [{type: 'group', name: 'public', access: 'read'}]
12
12
 
13
13
  trait :has_apo do
14
- admin_policy
14
+ admin_policy { create(:admin_policy) }
15
15
  end
16
16
 
17
17
  factory :content_model_has_apo, :traits => [:has_apo]
@@ -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
- context "object governed by an admin policy" do
27
- it "should link to the APO"
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
- # Please be sure to impelement current_user and user_session. Blacklight depends on
6
- # these methods in order to perform user specific actions.
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
 
@@ -0,0 +1,2 @@
1
+ class AdminPolicy < Hydra::AdminPolicy
2
+ end
@@ -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.3
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-12 00:00:00.000000000 Z
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: 3240411754357515048
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
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end