ddr-batch 1.0.2 → 1.1.0.rc1

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: 7070e57201c4afad9a4bf93028b4abe94d2bd820
4
- data.tar.gz: 3553c64cd90f2b04de837008dad6500a0af06e8d
3
+ metadata.gz: 2c090fcbdee8f9e2e6861a5b5a79cb0766ae420c
4
+ data.tar.gz: f441540385d72a68ca2ab832f519481c3a77a58b
5
5
  SHA512:
6
- metadata.gz: 2251199e9fa97080b64b13b5e4dc160589fb6127e46f0c8ec5e2f21615b00fc00bb635615276536261c1fd7e581f12dd5ecea4ca5a8c1181a8aa2a5fff066222
7
- data.tar.gz: 4fa4a48200cbcb0d7cdd6344e901dd315115f2a579189b9de5880a2cc2942b139f9633d9230df8c7da9c904e4c57a7d2f1b6f646ab8beefc2e98a0efda1b8e9a
6
+ metadata.gz: 4b4a3c317a19cd1a03fa30c679c0a847c9c6f918e55a52248ac5eb31f9f3320e7e6b9b055cebc0ac82e28b6cc48eec66a7d031a35eb6bc7dd14e772374ed0c48
7
+ data.tar.gz: 5956b006e1ac730ebbbb1d8a3d9904d6fe6a9d46ea5994e279f5aa7e3f552d90e0a2fd5d79e35972b8b5ea43f084df0a4ee82b4e446c91e7e016bc273bc937fe
@@ -8,6 +8,7 @@ module Ddr::Batch
8
8
  has_many :batch_object_attributes, -> { order "id ASC" }, inverse_of: :batch_object, dependent: :destroy
9
9
  has_many :batch_object_datastreams, inverse_of: :batch_object, dependent: :destroy
10
10
  has_many :batch_object_relationships, inverse_of: :batch_object, dependent: :destroy
11
+ has_many :batch_object_roles, inverse_of: :batch_object, dependent: :destroy
11
12
 
12
13
  VERIFICATION_PASS = "PASS"
13
14
  VERIFICATION_FAIL = "FAIL"
@@ -172,6 +173,11 @@ module Ddr::Batch
172
173
  verifications["#{r.name} relationship is correct"] = verify_relationship(repo_object, r)
173
174
  end
174
175
  end
176
+ unless batch_object_roles.empty?
177
+ batch_object_roles.each do |r|
178
+ verifications["#{r.role_scope} #{r.role_type} #{r.agent} role is correct"] = verify_role(repo_object, r)
179
+ end
180
+ end
175
181
  result = Ddr::Actions::FixityCheck.execute repo_object
176
182
  verifications["Fixity check"] = result.success ? VERIFICATION_PASS : VERIFICATION_FAIL
177
183
  end
@@ -228,6 +234,11 @@ module Ddr::Batch
228
234
  end
229
235
  end
230
236
 
237
+ def verify_role(repo_object, role)
238
+ role_hash = { "role_type"=>[ role.role_type ], "agent"=>[ role.agent ], "scope"=>[ role.role_scope ] }
239
+ repo_object.roles.role_set.map(&:to_h).include?(role_hash) ? VERIFICATION_PASS : VERIFICATION_FAIL
240
+ end
241
+
231
242
  def add_attribute(repo_object, attribute)
232
243
  repo_object.datastreams[attribute.datastream].add_value(attribute.name, attribute.value)
233
244
  return repo_object
@@ -245,6 +256,11 @@ module Ddr::Batch
245
256
  return repo_object
246
257
  end
247
258
 
259
+ def add_role(repo_object, role)
260
+ repo_object.roles.grant(scope: role.role_scope, type: role.role_type, agent: role.agent)
261
+ return repo_object
262
+ end
263
+
248
264
  def populate_datastream(repo_object, datastream)
249
265
  case datastream[:payload_type]
250
266
  when BatchObjectDatastream::PAYLOAD_TYPE_BYTES
@@ -0,0 +1,26 @@
1
+ module Ddr::Batch
2
+
3
+ class BatchObjectRole < ActiveRecord::Base
4
+ belongs_to :batch_object, :inverse_of => :batch_object_roles
5
+
6
+ OPERATION_ADD = "ADD".freeze # Add the principal and role to the object in the indicated scope
7
+ OPERATIONS = [ OPERATION_ADD ].freeze
8
+
9
+ validates :operation, inclusion: { in: OPERATIONS }
10
+ validate :valid_role, if: :operation_requires_valid_role?
11
+ validate :policy_role_scope_only_for_collections, if: "role_scope == Ddr::Auth::Roles::POLICY_SCOPE"
12
+
13
+ def operation_requires_valid_role?
14
+ [ OPERATION_ADD ].include? operation
15
+ end
16
+
17
+ def valid_role
18
+ Ddr::Auth::Roles::Role.build(type: role_type, agent: agent, scope: role_scope).valid?
19
+ end
20
+
21
+ def policy_role_scope_only_for_collections
22
+ errors.add(:role_scope, "policy role scope is valid only for Collections") unless batch_object.model == "Collection"
23
+ end
24
+ end
25
+
26
+ end
@@ -88,6 +88,7 @@ module Ddr::Batch
88
88
  batch_object_attributes.each { |a| repo_object = add_attribute(repo_object, a) }
89
89
  batch_object_datastreams.each { |d| repo_object = populate_datastream(repo_object, d) }
90
90
  batch_object_relationships.each { |r| repo_object = add_relationship(repo_object, r) }
91
+ batch_object_roles.each { |r| repo_object = add_role(repo_object, r) }
91
92
  repo_object.save
92
93
  rescue Exception => e1
93
94
  logger.fatal("Error in creating repository object #{repo_object.pid} for #{identifier} : #{e1}")
@@ -0,0 +1,15 @@
1
+ class CreateBatchObjectRoles < ActiveRecord::Migration
2
+ def change
3
+ unless table_exists?(:batch_object_roles)
4
+ create_table :batch_object_roles do |t|
5
+ t.integer "batch_object_id"
6
+ t.string "operation"
7
+ t.string "agent"
8
+ t.string "role_type"
9
+ t.string "role_scope"
10
+ t.datetime "created_at"
11
+ t.datetime "updated_at"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Batch
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0.rc1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Coble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-04 00:00:00.000000000 Z
12
+ date: 2016-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -183,6 +183,7 @@ files:
183
183
  - app/models/ddr/batch/batch_object_attribute.rb
184
184
  - app/models/ddr/batch/batch_object_datastream.rb
185
185
  - app/models/ddr/batch/batch_object_relationship.rb
186
+ - app/models/ddr/batch/batch_object_role.rb
186
187
  - app/models/ddr/batch/ingest_batch_object.rb
187
188
  - app/models/ddr/batch/update_batch_object.rb
188
189
  - app/scripts/ddr/batch/batch_processor.rb
@@ -195,6 +196,7 @@ files:
195
196
  - db/migrate/20150828202118_create_batch_object_attributes.rb
196
197
  - db/migrate/20150828202200_create_batch_object_datastreams.rb
197
198
  - db/migrate/20150828202240_create_batch_object_relationships.rb
199
+ - db/migrate/20160816164010_create_batch_object_roles.rb
198
200
  - lib/ddr-batch.rb
199
201
  - lib/ddr/batch.rb
200
202
  - lib/ddr/batch/batch_user.rb
@@ -216,12 +218,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
216
218
  version: '0'
217
219
  required_rubygems_version: !ruby/object:Gem::Requirement
218
220
  requirements:
219
- - - ">="
221
+ - - ">"
220
222
  - !ruby/object:Gem::Version
221
- version: '0'
223
+ version: 1.3.1
222
224
  requirements: []
223
225
  rubyforge_project:
224
- rubygems_version: 2.2.2
226
+ rubygems_version: 2.4.3
225
227
  signing_key:
226
228
  specification_version: 4
227
229
  summary: Batch processing for Duke Digital Repository