hydra-access-controls 7.0.1 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb6cb1d19ad64f66858147ca9c34f6e8f3a20ca6
4
- data.tar.gz: f2c37ea26c46cdd7676f676d9c5822c84da6300d
3
+ metadata.gz: f8991a10cef55bfeacde859174a79ad06fda0ea6
4
+ data.tar.gz: 7b29e9376d5c436628aaba2d3a30d0b29691b6af
5
5
  SHA512:
6
- metadata.gz: f119dc26165b9b35e4b32e1071c6746e985a45a1742f31d4c5d698ae3a165efa6489b9101826db75823aee112b9fdc98f515f2155c43f48d65d0994f99605d45
7
- data.tar.gz: 6eb53ab0ec02bb635df587d16ee0a7ceed58df5b78ba28be433e9845a467c4bba4d28c0291b94e8af2c72f2df49e72701886eea029994b56f2f8db12cd14a283
6
+ metadata.gz: 59fa9683aaa9f348c6ce9fd6009e721b8049a03b1c802cace301880dacad92af1b6529836d74eaab5022270d312f97fd8865ad0992cb79058f685d7b9bf805cf
7
+ data.tar.gz: 7b86ebf9be757ce7fd69ec7e35f3b77ddac573608f17a5c8667c2430579c5dcc6dd986d98e194e5e4d3dd5f6a8025657828d5a853fda3f45cb21a569e31c3708
@@ -0,0 +1,40 @@
1
+ module Hydra
2
+ module AdminPolicyBehavior
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_metadata "defaultRights", type: Hydra::Datastream::InheritableRightsMetadata
7
+ end
8
+
9
+ ## Updates those permissions that are provided to it. Does not replace any permissions unless they are provided
10
+ # @example
11
+ # obj.default_permissions= [{:name=>"group1", :access=>"discover", :type=>'group'},
12
+ # {:name=>"group2", :access=>"discover", :type=>'group'}]
13
+ def default_permissions=(params)
14
+ perm_hash = {'person' => defaultRights.users, 'group'=> defaultRights.groups}
15
+ params.each do |row|
16
+ if row[:type] == 'user' || row[:type] == 'person'
17
+ perm_hash['person'][row[:name]] = row[:access]
18
+ elsif row[:type] == 'group'
19
+ perm_hash['group'][row[:name]] = row[:access]
20
+ else
21
+ raise ArgumentError, "Permission type must be 'user', 'person' (alias for 'user'), or 'group'"
22
+ end
23
+ end
24
+ defaultRights.update_permissions(perm_hash)
25
+ end
26
+
27
+ ## Returns a list with all the permissions on the object.
28
+ # @example
29
+ # [{:name=>"group1", :access=>"discover", :type=>'group'},
30
+ # {:name=>"group2", :access=>"discover", :type=>'group'},
31
+ # {:name=>"user2", :access=>"read", :type=>'user'},
32
+ # {:name=>"user1", :access=>"edit", :type=>'user'},
33
+ # {:name=>"user3", :access=>"read", :type=>'user'}]
34
+ def default_permissions
35
+ (defaultRights.groups.map {|x| {:type=>'group', :access=>x[1], :name=>x[0] }} +
36
+ defaultRights.users.map {|x| {:type=>'user', :access=>x[1], :name=>x[0]}})
37
+ end
38
+
39
+ end
40
+ end
@@ -14,6 +14,7 @@ module Hydra
14
14
  autoload :Datastream
15
15
  autoload :PolicyAwareAbility
16
16
  autoload :AdminPolicy
17
+ autoload :AdminPolicyBehavior
17
18
  autoload :RoleMapperBehavior
18
19
  autoload :PermissionsQuery
19
20
  autoload :PermissionsCache
@@ -1,17 +1,11 @@
1
1
  class Hydra::AdminPolicy < ActiveFedora::Base
2
2
 
3
- # When you subclass Hydra::AdminPolicy, you probably want to include Hydra::ModelMethods so you can call apply_depositor_metadata
4
- # include Hydra::ModelMethods
5
-
6
- # Uses the Hydra Rights Metadata Schema for tracking access permissions & copyright
7
- has_metadata "defaultRights", type: Hydra::Datastream::InheritableRightsMetadata
8
-
9
- # Uses the Hydra Rights Metadata Schema for tracking access permissions & copyright
10
- has_metadata "rightsMetadata", type: Hydra::Datastream::RightsMetadata
3
+ include Hydra::AdminPolicyBehavior
4
+ include Hydra::AccessControls::Permissions
5
+ extend Deprecation
11
6
 
12
7
  has_metadata 'descMetadata', type: ActiveFedora::QualifiedDublinCoreDatastream do |m|
13
- m.title :type=> :text, :index_as=>[:searchable]
14
-
8
+ m.title :type=> :text, :index_as=>[:searchable]
15
9
  end
16
10
 
17
11
  has_attributes :title, :description, datastream: 'descMetadata', multiple: false
@@ -19,18 +13,18 @@ class Hydra::AdminPolicy < ActiveFedora::Base
19
13
  has_attributes :license_description, datastream: 'rightsMetadata', at: [:license, :description], multiple: false
20
14
  has_attributes :license_url, datastream: 'rightsMetadata', at: [:license, :url], multiple: false
21
15
 
22
- # easy access to edit_groups, etc
23
- include Hydra::AccessControls::Permissions
24
-
25
16
  def self.readable_by_user(user)
17
+ Deprecation.warn(Hydra::AdminPolicy, "The class method Hydra::AdminPolicy.readable_by_user(user) is deprecated and will be removed from hydra-head 8.0.", caller)
26
18
  where_user_has_permissions(user, [:read, :edit])
27
19
  end
28
20
 
29
21
  def self.editable_by_user(user)
22
+ Deprecation.warn(Hydra::AdminPolicy, "The class method Hydra::AdminPolicy.editable_by_user(user) is deprecated and will be removed from hydra-head 8.0.", caller)
30
23
  where_user_has_permissions(user, [:edit])
31
24
  end
32
25
 
33
26
  def self.where_user_has_permissions(user, permissions=[:edit])
27
+ Deprecation.warn(Hydra::AdminPolicy, "The class method Hydra::AdminPolicy.where_user_has_permissions(user) is deprecated and will be removed from hydra-head 8.0.", caller)
34
28
  or_query = []
35
29
  RoleMapper.roles(user).each do |group|
36
30
  permissions.each do |permission|
@@ -43,37 +37,4 @@ class Hydra::AdminPolicy < ActiveFedora::Base
43
37
  find_with_conditions(or_query.join(" OR "))
44
38
  end
45
39
 
46
- ## Updates those permissions that are provided to it. Does not replace any permissions unless they are provided
47
- # @example
48
- # obj.default_permissions= [{:name=>"group1", :access=>"discover", :type=>'group'},
49
- # {:name=>"group2", :access=>"discover", :type=>'group'}]
50
- def default_permissions=(params)
51
- perm_hash = {'person' => defaultRights.users, 'group'=> defaultRights.groups}
52
-
53
- params.each do |row|
54
- if row[:type] == 'user' || row[:type] == 'person'
55
- perm_hash['person'][row[:name]] = row[:access]
56
- elsif row[:type] == 'group'
57
- perm_hash['group'][row[:name]] = row[:access]
58
- else
59
- raise ArgumentError, "Permission type must be 'user', 'person' (alias for 'user'), or 'group'"
60
- end
61
- end
62
-
63
- defaultRights.update_permissions(perm_hash)
64
- end
65
-
66
- ## Returns a list with all the permissions on the object.
67
- # @example
68
- # [{:name=>"group1", :access=>"discover", :type=>'group'},
69
- # {:name=>"group2", :access=>"discover", :type=>'group'},
70
- # {:name=>"user2", :access=>"read", :type=>'user'},
71
- # {:name=>"user1", :access=>"edit", :type=>'user'},
72
- # {:name=>"user3", :access=>"read", :type=>'user'}]
73
- def default_permissions
74
- (defaultRights.groups.map {|x| {:type=>'group', :access=>x[1], :name=>x[0] }} +
75
- defaultRights.users.map {|x| {:type=>'user', :access=>x[1], :name=>x[0]}})
76
-
77
- end
78
-
79
40
  end
@@ -176,7 +176,7 @@ module Hydra
176
176
  def embargo_release_date=(release_date)
177
177
  release_date = release_date.to_s if release_date.is_a? Date
178
178
  begin
179
- Date.parse(release_date)
179
+ release_date.nil? || Date.parse(release_date)
180
180
  rescue
181
181
  return "INVALID DATE"
182
182
  end
@@ -1,9 +1,6 @@
1
1
  module Hydra
2
2
  module PermissionsQuery
3
3
  extend ActiveSupport::Concern
4
- included do
5
- include Blacklight::SolrHelper # for force_to_utf8
6
- end
7
4
 
8
5
  def permissions_doc(pid)
9
6
  doc = cache.get(pid)
@@ -26,7 +23,7 @@ module Hydra
26
23
  raise Blacklight::Exceptions::InvalidSolrID.new("The application is trying to retrieve permissions without specifying an asset id") if id.nil?
27
24
  solr_opts = permissions_solr_doc_params(id).merge(extra_controller_params)
28
25
  response = ActiveFedora::SolrService.instance.conn.get('select', :params=> solr_opts)
29
- solr_response = Blacklight::SolrResponse.new(force_to_utf8(response), solr_opts)
26
+ solr_response = Blacklight::SolrResponse.new(response, solr_opts)
30
27
 
31
28
  raise Blacklight::Exceptions::InvalidSolrID.new("The solr permissions search handler didn't return anything for id \"#{id}\"") if solr_response.docs.empty?
32
29
  Hydra::PermissionsSolrDocument.new(solr_response.docs.first, solr_response)
@@ -176,6 +176,11 @@ describe Hydra::Datastream::RightsMetadata do
176
176
  it "should only accept valid date values" do
177
177
 
178
178
  end
179
+ it "should accept a nil value after having a date value" do
180
+ @sample.embargo_release_date=("2010-12-01")
181
+ @sample.embargo_release_date=(nil)
182
+ @sample.embargo_release_date.should == nil
183
+ end
179
184
  end
180
185
  describe "embargo_release_date" do
181
186
  it "should return solr formatted date" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-access-controls
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.1
4
+ version: 7.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-04-01 00:00:00.000000000 Z
13
+ date: 2014-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -140,6 +140,7 @@ files:
140
140
  - app/models/concerns/hydra/access_controls/permissions.rb
141
141
  - app/models/concerns/hydra/access_controls/visibility.rb
142
142
  - app/models/concerns/hydra/access_controls/with_access_right.rb
143
+ - app/models/concerns/hydra/admin_policy_behavior.rb
143
144
  - app/models/role_mapper.rb
144
145
  - config/fedora.yml
145
146
  - config/solr.yml