sufia-models 4.0.1 → 4.1.0

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: 225e822263154c92055f19c4a792469b2ce46065
4
- data.tar.gz: 710dd7bb7969847ac3362645003d0fc8b0533fde
3
+ metadata.gz: 77e86bd02adbf9fa79ab2de87508dc843d402376
4
+ data.tar.gz: 0c8fab48b8fce691fd8973a3839b4e0c7c556138
5
5
  SHA512:
6
- metadata.gz: 43c341a486f46e61218acb3db3b75cf15fc6e981da57517357fb2c483faf8c22358940510e0edb4f52427e58167f4f4a4902dd317630873179bc96ca70c2a909
7
- data.tar.gz: a5469d79e6280e930455bfa6b7241e3c467dfc970a704aae4129bab69c0563783ca913ed2022cb5a7ae8e8260ca5e6d9513a7095e9129ae9503574099d035ff6
6
+ metadata.gz: e1bfec2d18baea1222f4913180e4c20dd58bb1ca6db08de6867c8f1cb802a48ceeb71859d16457aa5662e685df5ab7195c7659e3ed7b69442a10c55bb37b3312
7
+ data.tar.gz: f9800b7407df366242d621e8316af5db16533dd1e9c2030480ded54514243069827e662de6239c3acfe8a30e04e45548d4d7546c1db4c9ba8abc12aeca3bb5a5
@@ -1,6 +1,7 @@
1
1
  module Sufia
2
2
  module Ability
3
3
  extend ActiveSupport::Concern
4
+
4
5
  included do
5
6
  self.ability_logic += [:sufia_abilities]
6
7
  end
@@ -10,6 +11,19 @@ module Sufia
10
11
  featured_work_abilities
11
12
  editor_abilities
12
13
  stats_abilities
14
+ proxy_deposit_abilities
15
+ end
16
+
17
+ def proxy_deposit_abilities
18
+ can :transfer, String do |pid|
19
+ get_depositor_from_pid(pid) == current_user.user_key
20
+ end
21
+ can :create, ProxyDepositRequest if user_groups.include? 'registered'
22
+ can :accept, ProxyDepositRequest, receiving_user_id: current_user.id, status: 'pending'
23
+ can :reject, ProxyDepositRequest, receiving_user_id: current_user.id, status: 'pending'
24
+ # a user who sent a proxy deposit request can cancel it if it's pending.
25
+ can :destroy, ProxyDepositRequest, sending_user_id: current_user.id, status: 'pending'
26
+ can :edit, ::User, id: current_user.id
13
27
  end
14
28
 
15
29
  def featured_work_abilities
@@ -30,5 +44,13 @@ module Sufia
30
44
  def stats_abilities
31
45
  alias_action :stats, to: :read
32
46
  end
47
+
48
+ private
49
+
50
+ def get_depositor_from_pid(pid)
51
+ ::GenericFile.load_instance_from_solr(pid).depositor
52
+ rescue
53
+ nil
54
+ end
33
55
  end
34
56
  end
@@ -0,0 +1,22 @@
1
+ module Sufia
2
+ module GenericFile
3
+ module ProxyDeposit
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_attributes :proxy_depositor, :on_behalf_of, datastream: :properties, multiple: false
8
+ after_create :create_transfer_request
9
+ end
10
+
11
+ def create_transfer_request
12
+ Sufia.queue.push(ContentDepositorChangeEventJob.new(pid, on_behalf_of)) if on_behalf_of.present?
13
+ end
14
+
15
+ def request_transfer_to(target)
16
+ raise ArgumentError, "Must provide a target" unless target
17
+ deposit_user = ::User.find_by_user_key(depositor)
18
+ ProxyDepositRequest.create!(pid: pid, receiving_user: target, sending_user: deposit_user)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -19,6 +19,7 @@ module Sufia
19
19
  include Sufia::GenericFile::VirusCheck
20
20
  include Sufia::GenericFile::ReloadOnSave
21
21
  include Sufia::GenericFile::FullTextIndexing
22
+ include Sufia::GenericFile::ProxyDeposit
22
23
  include Hydra::Collections::Collectible
23
24
 
24
25
  included do
@@ -10,6 +10,9 @@ module Sufia
10
10
  # This is where we put the relative path of the file if submitted as a folder
11
11
  t.relative_path
12
12
  t.import_url path: 'importUrl', index_as: :symbol
13
+ t.proxy_depositor path: 'proxyDepositor', index_as: :symbol
14
+ # This value is set when a user indicates they are depositing this for someone else
15
+ t.on_behalf_of path: 'onBehalfOf', index_as: :symbol
13
16
  end
14
17
  end
15
18
 
@@ -18,6 +18,15 @@ module Sufia::User
18
18
  # Users should be followable
19
19
  acts_as_followable
20
20
 
21
+ # Setup accessible (or protected) attributes for your model
22
+ has_many :proxy_deposit_requests, foreign_key: 'receiving_user_id'
23
+
24
+ has_many :deposit_rights_given, foreign_key: 'grantor_id', class_name: 'ProxyDepositRights', dependent: :destroy
25
+ has_many :can_receive_deposits_from, through: :deposit_rights_given, source: :grantee
26
+
27
+ has_many :deposit_rights_received, foreign_key: 'grantee_id', class_name: 'ProxyDepositRights', dependent: :destroy
28
+ has_many :can_make_deposits_for, through: :deposit_rights_received, source: :grantor
29
+
21
30
  mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name
22
31
  validates_with AvatarValidator
23
32
  has_many :trophies
@@ -0,0 +1,85 @@
1
+ class ProxyDepositRequest < ActiveRecord::Base
2
+ include Blacklight::SolrHelper
3
+ include ActionView::Helpers::UrlHelper
4
+
5
+ belongs_to :receiving_user, class_name: 'User'
6
+ belongs_to :sending_user, class_name: 'User'
7
+
8
+ validates :sending_user, :pid, presence: true
9
+ validate :transfer_to_should_be_a_valid_username
10
+ validate :sending_user_should_not_be_receiving_user
11
+ validate :should_not_be_already_part_of_a_transfer
12
+
13
+ after_save :send_request_transfer_message
14
+
15
+ attr_reader :transfer_to
16
+
17
+ def transfer_to=(key)
18
+ @transfer_to = key
19
+ self.receiving_user = User.find_by_user_key(key)
20
+ end
21
+
22
+ def transfer_to_should_be_a_valid_username
23
+ errors.add(:transfer_to, "must be an existing user") unless receiving_user
24
+ end
25
+
26
+ def sending_user_should_not_be_receiving_user
27
+ errors.add(:sending_user, 'must specify another user to receive the file') if receiving_user and receiving_user.user_key == sending_user.user_key
28
+ end
29
+
30
+ def should_not_be_already_part_of_a_transfer
31
+ transfers = ProxyDepositRequest.where(pid: pid)
32
+ errors.add(:open_transfer, 'must close open transfer on the file before creating a new one') unless transfers.blank? || ( transfers.count == 1 && transfers[0].id == self.id)
33
+ end
34
+
35
+ def send_request_transfer_message
36
+ if self.updated_at == self.created_at
37
+ message = "#{link_to(sending_user.name, Sufia::Engine.routes.url_helpers.profile_path(sending_user.user_key))} wants to transfer a file to you. Review all <a href='#{Sufia::Engine.routes.url_helpers.transfers_path}'>transfer requests</a>"
38
+ User.batchuser.send_message(receiving_user, message, "Ownership Change Request")
39
+ else
40
+ message = "Your transfer request was #{status}."
41
+ message = message + " Comments: #{receiver_comment}" if !receiver_comment.blank?
42
+ User.batchuser.send_message(sending_user, message, "Ownership Change #{status}")
43
+ end
44
+ end
45
+
46
+ def pending?
47
+ self.status == 'pending'
48
+ end
49
+
50
+ def accepted?
51
+ self.status == 'accepted'
52
+ end
53
+
54
+ # @param [Boolean] reset (false) should the access controls be reset. This means revoking edit access from the depositor
55
+ def transfer!(reset = false)
56
+ Sufia.queue.push(ContentDepositorChangeEventJob.new(pid, receiving_user.user_key, reset))
57
+ self.status = 'accepted'
58
+ self.fulfillment_date = Time.now
59
+ save!
60
+ end
61
+
62
+ def reject!(comment = nil)
63
+ self.receiver_comment = comment if comment
64
+ self.status = 'rejected'
65
+ self.fulfillment_date = Time.now
66
+ save!
67
+ end
68
+
69
+ def cancel!
70
+ self.status = 'canceled'
71
+ self.fulfillment_date = Time.now
72
+ save!
73
+ end
74
+
75
+ def deleted_file?
76
+ !GenericFile.exists?(pid)
77
+ end
78
+
79
+ def title
80
+ return 'file not found' if deleted_file?
81
+ query = ActiveFedora::SolrService.construct_query_for_pids([pid])
82
+ solr_response = ActiveFedora::SolrService.query(query, raw: true)
83
+ SolrDocument.new(solr_response['response']['docs'].first, solr_response).title
84
+ end
85
+ end
@@ -0,0 +1,4 @@
1
+ class ProxyDepositRights < ActiveRecord::Base
2
+ belongs_to :grantor, class_name: "User"
3
+ belongs_to :grantee, class_name: "User"
4
+ end
@@ -1,7 +1,7 @@
1
1
  class Sufia::AvatarUploader < CarrierWave::Uploader::Base
2
2
  include CarrierWave::MiniMagick
3
3
  include CarrierWave::Compatibility::Paperclip
4
-
4
+
5
5
  version :medium do
6
6
  process resize_to_limit: [300, 300]
7
7
  end
@@ -11,11 +11,10 @@ class Sufia::AvatarUploader < CarrierWave::Uploader::Base
11
11
  end
12
12
 
13
13
  def default_url
14
- "/assets/missing_#{version_name}.png"
14
+ "missing_#{version_name}.png"
15
15
  end
16
16
 
17
17
  def extension_white_list
18
18
  %w(jpg jpeg png gif bmp tif tiff)
19
19
  end
20
-
21
20
  end
@@ -17,6 +17,7 @@ This generator makes the following changes to your application:
17
17
  5. Generates usage stats config
18
18
  6. Installs Blacklight gallery
19
19
  7. Runs full-text generator
20
+ 8. Runs proxies generator
20
21
  """
21
22
 
22
23
  # Implement the required interface for Rails::Generators::Migration.
@@ -55,7 +56,9 @@ This generator makes the following changes to your application:
55
56
  'add_linkedin_to_users.rb',
56
57
  'create_tinymce_assets.rb',
57
58
  'create_content_blocks.rb',
58
- 'create_featured_works.rb'
59
+ 'create_featured_works.rb',
60
+ 'create_proxy_deposit_requests.rb',
61
+ 'create_proxy_deposit_rights.rb'
59
62
  ].each do |file|
60
63
  better_migration_template file
61
64
  end
@@ -102,6 +105,11 @@ This generator makes the following changes to your application:
102
105
  generate "sufia:models:fulltext"
103
106
  end
104
107
 
108
+ # Sets up proxies and transfers
109
+ def full_text_indexing
110
+ generate "sufia:models:proxies"
111
+ end
112
+
105
113
  private
106
114
 
107
115
  def better_migration_template(file)
@@ -0,0 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ class Sufia::Models::ProxiesGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ desc """
11
+ This generator adds proxies and transfers to your application:
12
+ 1. Creates several database migrations if they do not exist in /db/migrate
13
+ """
14
+ # Implement the required interface for Rails::Generators::Migration.
15
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
16
+ def self.next_migration_number(path)
17
+ if @prev_migration_nr
18
+ @prev_migration_nr += 1
19
+ else
20
+ if last_migration = Dir[File.join(path, '*.rb')].sort.last
21
+ @prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
22
+ else
23
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
24
+ end
25
+ end
26
+ @prev_migration_nr.to_s
27
+ end
28
+
29
+ def banner
30
+ say_status("warning", "ADDING PROXY/TRANSFER-RELATED SUFIA MODELS", :yellow)
31
+ end
32
+
33
+ # Setup the database migrations
34
+ def copy_migrations
35
+ # Can't get this any more DRY, because we need this order.
36
+ [
37
+ 'create_proxy_deposit_rights.rb',
38
+ 'create_proxy_deposit_requests.rb'
39
+ ].each do |file|
40
+ better_migration_template file
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def better_migration_template(file)
47
+ begin
48
+ migration_template "migrations/#{file}", "db/migrate/#{file}"
49
+ rescue Rails::Generators::Error => e
50
+ say_status("warning", e.message, :yellow)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,16 @@
1
+ class CreateProxyDepositRequests < ActiveRecord::Migration
2
+ def change
3
+ create_table :proxy_deposit_requests do |t|
4
+ t.string :pid, null: false
5
+ t.references :sending_user, null: false
6
+ t.references :receiving_user, null: false
7
+ t.datetime :fulfillment_date
8
+ t.string :status, null: false, default: 'pending'
9
+ t.text :sender_comment
10
+ t.text :receiver_comment
11
+ t.timestamps
12
+ end
13
+ add_index :proxy_deposit_requests, :receiving_user_id
14
+ add_index :proxy_deposit_requests, :sending_user_id
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ class CreateProxyDepositRights < ActiveRecord::Migration
2
+ def change
3
+ create_table :proxy_deposit_rights do |t|
4
+ t.references :grantor
5
+ t.references :grantee
6
+ t.timestamps
7
+ end
8
+ add_index :proxy_deposit_rights, :grantor_id
9
+ add_index :proxy_deposit_rights, :grantee_id
10
+ end
11
+ end
@@ -1,4 +1,3 @@
1
- require 'sufia/models/resque'
2
1
  module Sufia
3
2
  module Models
4
3
  def self.config(&block)
@@ -10,6 +9,7 @@ module Sufia
10
9
  end
11
10
 
12
11
  class Engine < ::Rails::Engine
12
+ require 'sufia/models/resque'
13
13
 
14
14
  # Set some configuration defaults
15
15
  config.enable_ffmpeg = false
@@ -1,5 +1,5 @@
1
1
  module Sufia
2
2
  module Models
3
- VERSION = "4.0.1"
3
+ VERSION = "4.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sufia-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-28 00:00:00.000000000 Z
11
+ date: 2014-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -296,6 +296,7 @@ files:
296
296
  - app/models/concerns/sufia/generic_file/metadata.rb
297
297
  - app/models/concerns/sufia/generic_file/mime_types.rb
298
298
  - app/models/concerns/sufia/generic_file/permissions.rb
299
+ - app/models/concerns/sufia/generic_file/proxy_deposit.rb
299
300
  - app/models/concerns/sufia/generic_file/reload_on_save.rb
300
301
  - app/models/concerns/sufia/generic_file/trophies.rb
301
302
  - app/models/concerns/sufia/generic_file/versions.rb
@@ -319,6 +320,8 @@ files:
319
320
  - app/models/group.rb
320
321
  - app/models/local_authority.rb
321
322
  - app/models/local_authority_entry.rb
323
+ - app/models/proxy_deposit_request.rb
324
+ - app/models/proxy_deposit_rights.rb
322
325
  - app/models/single_use_link.rb
323
326
  - app/models/subject_local_authority_entry.rb
324
327
  - app/models/sufia/avatar_uploader.rb
@@ -333,6 +336,7 @@ files:
333
336
  - config/locales/sufia.en.yml
334
337
  - lib/generators/sufia/models/fulltext_generator.rb
335
338
  - lib/generators/sufia/models/install_generator.rb
339
+ - lib/generators/sufia/models/proxies_generator.rb
336
340
  - lib/generators/sufia/models/templates/config/analytics.yml
337
341
  - lib/generators/sufia/models/templates/config/clamav.rb
338
342
  - lib/generators/sufia/models/templates/config/mailboxer.rb
@@ -355,6 +359,8 @@ files:
355
359
  - lib/generators/sufia/models/templates/migrations/create_content_blocks.rb
356
360
  - lib/generators/sufia/models/templates/migrations/create_featured_works.rb
357
361
  - lib/generators/sufia/models/templates/migrations/create_local_authorities.rb
362
+ - lib/generators/sufia/models/templates/migrations/create_proxy_deposit_requests.rb
363
+ - lib/generators/sufia/models/templates/migrations/create_proxy_deposit_rights.rb
358
364
  - lib/generators/sufia/models/templates/migrations/create_single_use_links.rb
359
365
  - lib/generators/sufia/models/templates/migrations/create_tinymce_assets.rb
360
366
  - lib/generators/sufia/models/templates/migrations/create_trophies.rb
@@ -399,7 +405,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
399
405
  version: '0'
400
406
  requirements: []
401
407
  rubyforge_project:
402
- rubygems_version: 2.2.2
408
+ rubygems_version: 2.4.2
403
409
  signing_key:
404
410
  specification_version: 4
405
411
  summary: Models and services for sufia