enju_inventory 0.1.12 → 0.2.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +3 -3
  3. data/app/controllers/concerns/enju_inventory/controller.rb +9 -0
  4. data/app/controllers/inventories_controller.rb +12 -1
  5. data/app/controllers/inventory_files_controller.rb +11 -1
  6. data/app/models/concerns/enju_inventory/enju_item.rb +26 -0
  7. data/app/policies/inventory_file_policy.rb +21 -0
  8. data/app/policies/inventory_policy.rb +21 -0
  9. data/lib/enju_inventory.rb +0 -19
  10. data/lib/enju_inventory/version.rb +1 -1
  11. data/spec/controllers/inventories_controller_spec.rb +2 -2
  12. data/spec/controllers/inventory_files_controller_spec.rb +4 -4
  13. data/spec/dummy/app/controllers/application_controller.rb +7 -2
  14. data/spec/dummy/app/models/user.rb +1 -2
  15. data/spec/dummy/config/application.rb +5 -24
  16. data/spec/dummy/config/environments/development.rb +25 -14
  17. data/spec/dummy/config/environments/production.rb +50 -31
  18. data/spec/dummy/config/environments/test.rb +23 -18
  19. data/spec/dummy/db/migrate/20140821151023_create_colors.rb +14 -0
  20. data/spec/dummy/db/migrate/20150124152756_add_foreign_key_to_shelves_referencing_libraries.rb +6 -0
  21. data/spec/dummy/db/migrate/20150221063719_add_settings_to_library_group.rb +5 -0
  22. data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +13 -0
  23. data/spec/dummy/db/migrate/20151213070943_add_translation_table_to_library_group.rb +13 -0
  24. data/spec/dummy/db/migrate/20151213072705_add_footer_banner_to_library_group.rb +9 -0
  25. data/spec/dummy/db/schema.rb +105 -70
  26. data/spec/support/devise.rb +2 -2
  27. metadata +69 -29
  28. data/app/models/enju_inventory/ability.rb +0 -20
  29. data/lib/enju_inventory/item.rb +0 -31
  30. data/spec/dummy/config/application.yml +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ed552474749c9a00c855847a9a7aa1e172c6e9e
4
- data.tar.gz: 34e8d592d6ba3ea0b4cc44ec1b3f59bd3cc3d746
3
+ metadata.gz: 14eac3233a4067892209307731879d6ef9cf0374
4
+ data.tar.gz: 611476c9dfc325ca22d441121eec20e96ed0e8a4
5
5
  SHA512:
6
- metadata.gz: 63d869b8be45abdcecf5ba64b6ba85f12b61b808373a678b615deabae71614972e16408e4b63156e902c2fd09d494dca7d8f1451d36025b8c02c741a24144946
7
- data.tar.gz: cf77bcf6a5c0a6e46e574759a63722662b906542c6d52becf9cd67c65b84a4d6f49ad1edcb12197ebf24a5655e01b06ee470abc5ed3edb12e74a4de2519e0a48
6
+ metadata.gz: 78b743ca6bae20540cab2be58a178ab4d725af6e53c48e835cdebdf34728484837b07a632dc5e97962de7554ca88cd76a09cb4d4e1272a4c35af88d91a91f7c2
7
+ data.tar.gz: 83be83a735656b8f1876451fd035fdf4833ce64828230baebc35b4f5c4bc1c7d22845002cb87d8d084cbf8c1ef408b9198e4c918169c5d890c90b451a9980ecc
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = EnjuInventory
2
- {<img src="https://travis-ci.org/next-l/enju_inventory.svg?branch=1.1" alt="Build Status" />}[https://travis-ci.org/next-l/enju_inventory]
3
- {<img src="https://coveralls.io/repos/next-l/enju_inventory/badge.svg?branch=1.1&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_inventory?branch=1.1]
4
- {<img src="https://hakiri.io/github/next-l/enju_inventory/1.1.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_inventory/1.1]
2
+ {<img src="https://travis-ci.org/next-l/enju_inventory.svg?branch=1.2" alt="Build Status" />}[https://travis-ci.org/next-l/enju_inventory]
3
+ {<img src="https://coveralls.io/repos/next-l/enju_inventory/badge.svg?branch=1.2&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_inventory?branch=1.2]
4
+ {<img src="https://hakiri.io/github/next-l/enju_inventory/1.2.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_inventory/1.2]
5
5
 
6
6
  This project rocks and uses MIT-LICENSE.
7
7
 
@@ -0,0 +1,9 @@
1
+ module EnjuInventory
2
+ module Controller
3
+ extend ActiveSupport::Concern
4
+
5
+ def get_inventory_file
6
+ @inventory_file = InventoryFile.find(params[:inventory_file_id]) if params[:inventory_file_id]
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,7 @@
1
1
  class InventoriesController < ApplicationController
2
- load_and_authorize_resource
2
+ before_action :set_inventory, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
4
+
3
5
  # GET /inventories
4
6
  # GET /inventories.json
5
7
  def index
@@ -21,6 +23,15 @@ class InventoriesController < ApplicationController
21
23
  end
22
24
 
23
25
  private
26
+ def set_inventory
27
+ @inventory = Inventory.find(params[:id])
28
+ authorize @inventory
29
+ end
30
+
31
+ def check_policy
32
+ authorize Inventory
33
+ end
34
+
24
35
  def inventory_params
25
36
  params.require(:inventory).permit(
26
37
  :item_id, :inventory_id, :note
@@ -1,5 +1,6 @@
1
1
  class InventoryFilesController < ApplicationController
2
- load_and_authorize_resource
2
+ before_action :set_inventory_file, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
3
4
 
4
5
  # GET /inventory_files
5
6
  # GET /inventory_files.json
@@ -96,6 +97,15 @@ class InventoryFilesController < ApplicationController
96
97
  end
97
98
 
98
99
  private
100
+ def set_inventory_file
101
+ @inventory_file = InventoryFile.find(params[:id])
102
+ authorize @inventory_file
103
+ end
104
+
105
+ def check_policy
106
+ authorize InventoryFile
107
+ end
108
+
99
109
  def inventory_file_params
100
110
  params.require(:inventory_file).permit(:inventory, :note)
101
111
  end
@@ -0,0 +1,26 @@
1
+ module EnjuInventory
2
+ module EnjuItem
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :inventories, :dependent => :destroy
7
+ has_many :inventory_files, :through => :inventories
8
+ searchable do
9
+ integer :inventory_file_ids, :multiple => true
10
+ end
11
+
12
+ def self.inventory_items(inventory_file, mode = 'not_on_shelf')
13
+ item_ids = Item.pluck(:id)
14
+ inventory_item_ids = inventory_file.items.pluck('items.id')
15
+ case mode
16
+ when 'not_on_shelf'
17
+ Item.where(:id => (item_ids - inventory_item_ids))
18
+ when 'not_in_catalog'
19
+ Item.where(:id => (inventory_item_ids - item_ids))
20
+ end
21
+ rescue
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ class InventoryFilePolicy < ApplicationPolicy
2
+ def index?
3
+ user.try(:has_role?, 'Librarian')
4
+ end
5
+
6
+ def show?
7
+ user.try(:has_role?, 'Librarian')
8
+ end
9
+
10
+ def create?
11
+ user.try(:has_role?, 'Librarian')
12
+ end
13
+
14
+ def update?
15
+ user.try(:has_role?, 'Librarian')
16
+ end
17
+
18
+ def destroy?
19
+ user.try(:has_role?, 'Librarian')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class InventoryPolicy < ApplicationPolicy
2
+ def index?
3
+ user.try(:has_role?, 'Librarian')
4
+ end
5
+
6
+ def show?
7
+ user.try(:has_role?, 'Librarian')
8
+ end
9
+
10
+ def create?
11
+ user.try(:has_role?, 'Applicationistrator')
12
+ end
13
+
14
+ def update?
15
+ user.try(:has_role?, 'Applicationistrator')
16
+ end
17
+
18
+ def destroy?
19
+ user.try(:has_role?, 'Applicationistrator')
20
+ end
21
+ end
@@ -1,23 +1,4 @@
1
1
  require "enju_inventory/engine"
2
- require "enju_inventory/item"
3
2
 
4
3
  module EnjuInventory
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
- def enju_inventory
11
- include EnjuInventory::InstanceMethods
12
- end
13
- end
14
-
15
- module InstanceMethods
16
- def get_inventory_file
17
- @inventory_file = InventoryFile.find(params[:inventory_file_id]) if params[:inventory_file_id]
18
- end
19
- end
20
4
  end
21
-
22
- ActiveRecord::Base.send :include, EnjuInventory::InventoryItem
23
- ActionController::Base.send(:include, EnjuInventory)
@@ -1,3 +1,3 @@
1
1
  module EnjuInventory
2
- VERSION = "0.1.12"
2
+ VERSION = "0.2.0.beta.1"
3
3
  end
@@ -29,7 +29,7 @@ describe InventoriesController do
29
29
 
30
30
  it "assigns all empty as @inventories" do
31
31
  get :index
32
- expect(assigns(:inventories)).to be_empty
32
+ expect(assigns(:inventories)).to be_nil
33
33
  expect(response).to be_forbidden
34
34
  end
35
35
  end
@@ -37,7 +37,7 @@ describe InventoriesController do
37
37
  describe "When not logged in" do
38
38
  it "assigns all inventories as @inventories" do
39
39
  get :index
40
- expect(assigns(:inventories)).to be_empty
40
+ expect(assigns(:inventories)).to be_nil
41
41
  expect(response).to redirect_to(new_user_session_url)
42
42
  end
43
43
  end
@@ -28,7 +28,7 @@ describe InventoryFilesController do
28
28
 
29
29
  it "assigns empty as @inventory_files" do
30
30
  get :index
31
- expect(assigns(:inventory_files)).to be_empty
31
+ expect(assigns(:inventory_files)).to be_nil
32
32
  expect(response).to be_forbidden
33
33
  end
34
34
  end
@@ -36,7 +36,7 @@ describe InventoryFilesController do
36
36
  describe "When not logged in" do
37
37
  it "assigns empty as @inventory_files" do
38
38
  get :index
39
- expect(assigns(:inventory_files)).to be_empty
39
+ expect(assigns(:inventory_files)).to be_nil
40
40
  expect(response).to redirect_to(new_user_session_url)
41
41
  end
42
42
  end
@@ -105,7 +105,7 @@ describe InventoryFilesController do
105
105
 
106
106
  it "should not assign the requested inventory_file as @inventory_file" do
107
107
  get :new
108
- expect(assigns(:inventory_file)).to_not be_valid
108
+ expect(assigns(:inventory_file)).to be_nil
109
109
  expect(response).to be_forbidden
110
110
  end
111
111
  end
@@ -113,7 +113,7 @@ describe InventoryFilesController do
113
113
  describe "When not logged in" do
114
114
  it "should not assign the requested inventory_file as @inventory_file" do
115
115
  get :new
116
- expect(assigns(:inventory_file)).to_not be_valid
116
+ expect(assigns(:inventory_file)).to be_nil
117
117
  expect(response).to redirect_to(new_user_session_url)
118
118
  end
119
119
  end
@@ -1,6 +1,11 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
3
 
4
- enju_leaf
5
- enju_library
4
+ include EnjuLeaf::Controller
5
+ include EnjuLibrary::Controller
6
+ include EnjuInventory::Controller
7
+ after_action :verify_authorized
8
+ before_action :set_paper_trail_whodunnit
9
+
10
+ include Pundit
6
11
  end
@@ -1,8 +1,7 @@
1
- # -*- encoding: utf-8 -*-
2
1
  class User < ActiveRecord::Base
3
2
  devise :database_authenticatable, #:registerable,
4
3
  :recoverable, :rememberable, :trackable, #, :validatable
5
4
  :lockable, :lock_strategy => :none, :unlock_strategy => :none
6
5
 
7
- enju_leaf_user_model
6
+ include EnjuLeaf::EnjuUser
8
7
  end
@@ -2,8 +2,9 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- Bundler.require
6
- require "enju_inventory"
5
+ Bundler.require(*Rails.groups)
6
+ require 'enju_inventory'
7
+ require 'enju_leaf'
7
8
 
8
9
  module Dummy
9
10
  class Application < Rails::Application
@@ -11,16 +12,6 @@ module Dummy
11
12
  # Application configuration should go into files in config/initializers
12
13
  # -- all .rb files in that directory are automatically loaded.
13
14
 
14
- # Custom directories with classes and modules you want to be autoloadable.
15
- # config.autoload_paths += %W(#{config.root}/extras)
16
-
17
- # Only load the plugins named here, in the order given (default is alphabetical).
18
- # :all can be used as a placeholder for all plugins not explicitly named.
19
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
-
21
- # Activate observers that should always be running.
22
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
-
24
15
  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
16
  # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
17
  # config.time_zone = 'Central Time (US & Canada)'
@@ -29,18 +20,8 @@ module Dummy
29
20
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
21
  # config.i18n.default_locale = :de
31
22
 
32
- # Configure the default encoding used in templates for Ruby 1.9.
33
- config.encoding = "utf-8"
34
-
35
- # Configure sensitive parameters which will be filtered from the log file.
36
- config.filter_parameters += [:password]
37
-
38
- # Enable the asset pipeline
39
- config.assets.enabled = true
40
-
41
- # Version of your assets, change this if you want to expire all your assets
42
- config.assets.version = '1.0'
23
+ # Do not swallow errors in after_commit/after_rollback callbacks.
24
+ config.active_record.raise_in_transactional_callbacks = true
43
25
  end
44
26
  end
45
27
 
46
- require 'enju_leaf'
@@ -1,30 +1,41 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
5
+ # every request. This slows down response time but is perfect for development
6
6
  # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
11
 
12
- # Show full error reports and disable caching
12
+ # Show full error reports and disable caching.
13
13
  config.consider_all_requests_local = true
14
14
  config.action_controller.perform_caching = false
15
15
 
16
- # Don't care if the mailer can't send
16
+ # Don't care if the mailer can't send.
17
17
  config.action_mailer.raise_delivery_errors = false
18
18
 
19
- # Print deprecation notices to the Rails logger
19
+ # Print deprecation notices to the Rails logger.
20
20
  config.active_support.deprecation = :log
21
21
 
22
- # Only use best-standards-support built into browsers
23
- config.action_dispatch.best_standards_support = :builtin
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
24
 
25
- # Do not compress assets
26
- config.assets.compress = false
27
-
28
- # Expands the lines which load the assets
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
29
28
  config.assets.debug = true
29
+
30
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+ # yet still be able to expire them through the digest params.
32
+ config.assets.digest = true
33
+
34
+ # Adds additional error checking when serving assets at runtime.
35
+ # Checks for improperly declared sprockets dependencies.
36
+ # Raises helpful error messages.
37
+ config.assets.raise_runtime_errors = true
38
+
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
30
41
  end
@@ -1,60 +1,79 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
- # Code is not reloaded between requests
4
+ # Code is not reloaded between requests.
5
5
  config.cache_classes = true
6
6
 
7
- # Full error reports are disabled and caching is turned on
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
8
14
  config.consider_all_requests_local = false
9
15
  config.action_controller.perform_caching = true
10
16
 
11
- # Disable Rails's static asset server (Apache or nginx will already do this)
12
- config.serve_static_assets = false
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like
20
+ # NGINX, varnish or squid.
21
+ # config.action_dispatch.rack_cache = true
22
+
23
+ # Disable serving static files from the `/public` folder by default since
24
+ # Apache or NGINX already handles this.
25
+ config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
13
26
 
14
- # Compress JavaScripts and CSS
15
- config.assets.compress = true
27
+ # Compress JavaScripts and CSS.
28
+ config.assets.js_compressor = :uglifier
29
+ # config.assets.css_compressor = :sass
16
30
 
17
- # Don't fallback to assets pipeline if a precompiled asset is missed
31
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
18
32
  config.assets.compile = false
19
33
 
20
- # Generate digests for assets URLs
34
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
35
+ # yet still be able to expire them through the digest params.
21
36
  config.assets.digest = true
22
37
 
23
- # Defaults to Rails.root.join("public/assets")
24
- # config.assets.manifest = YOUR_PATH
38
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
25
39
 
26
- # Specifies the header that your server uses for sending files
27
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
40
+ # Specifies the header that your server uses for sending files.
41
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
42
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
29
43
 
30
44
  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
45
  # config.force_ssl = true
32
46
 
33
- # See everything in the log (default is :info)
34
- # config.log_level = :debug
47
+ # Use the lowest log level to ensure availability of diagnostic information
48
+ # when problems arise.
49
+ config.log_level = :debug
35
50
 
36
- # Use a different logger for distributed setups
37
- # config.logger = SyslogLogger.new
51
+ # Prepend all log lines with the following tags.
52
+ # config.log_tags = [ :subdomain, :uuid ]
38
53
 
39
- # Use a different cache store in production
40
- # config.cache_store = :mem_cache_store
54
+ # Use a different logger for distributed setups.
55
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
56
 
42
- # Enable serving of images, stylesheets, and JavaScripts from an asset server
43
- # config.action_controller.asset_host = "http://assets.example.com"
57
+ # Use a different cache store in production.
58
+ # config.cache_store = :mem_cache_store
44
59
 
45
- # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
46
- # config.assets.precompile += %w( search.js )
60
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
61
+ # config.action_controller.asset_host = 'http://assets.example.com'
47
62
 
48
- # Disable delivery errors, bad email addresses will be ignored
63
+ # Ignore bad email addresses and do not raise email delivery errors.
64
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
49
65
  # config.action_mailer.raise_delivery_errors = false
50
66
 
51
- # Enable threaded mode
52
- # config.threadsafe!
53
-
54
67
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
55
- # the I18n.default_locale when a translation can not be found)
68
+ # the I18n.default_locale when a translation cannot be found).
56
69
  config.i18n.fallbacks = true
57
70
 
58
- # Send deprecation notices to registered listeners
71
+ # Send deprecation notices to registered listeners.
59
72
  config.active_support.deprecation = :notify
73
+
74
+ # Use default logging formatter so that PID and timestamp are not suppressed.
75
+ config.log_formatter = ::Logger::Formatter.new
76
+
77
+ # Do not dump schema after migrations.
78
+ config.active_record.dump_schema_after_migration = false
60
79
  end