erp_tech_svcs 3.0.0

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 (109) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.rdoc +2 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/erp_tech_svcs/application.js +9 -0
  5. data/app/assets/stylesheets/erp_tech_svcs/application.css +7 -0
  6. data/app/controllers/erp_tech_svcs/session_controller.rb +19 -0
  7. data/app/controllers/erp_tech_svcs/user_controller.rb +40 -0
  8. data/app/helpers/erp_tech_svcs/application_helper.rb +4 -0
  9. data/app/mailers/user_mailer.rb +16 -0
  10. data/app/models/audit_log.rb +60 -0
  11. data/app/models/audit_log_item.rb +4 -0
  12. data/app/models/audit_log_item_type.rb +6 -0
  13. data/app/models/audit_log_type.rb +24 -0
  14. data/app/models/capability.rb +8 -0
  15. data/app/models/capability_type.rb +3 -0
  16. data/app/models/capable_model.rb +4 -0
  17. data/app/models/encryption_key.rb +9 -0
  18. data/app/models/extensions/contact_purpose.rb +3 -0
  19. data/app/models/extensions/contact_type.rb +3 -0
  20. data/app/models/extensions/note.rb +6 -0
  21. data/app/models/extensions/note_type.rb +3 -0
  22. data/app/models/extensions/party.rb +3 -0
  23. data/app/models/extensions/relationship_type.rb +3 -0
  24. data/app/models/extensions/role_type.rb +3 -0
  25. data/app/models/file_asset.rb +178 -0
  26. data/app/models/role.rb +17 -0
  27. data/app/models/secured_model.rb +13 -0
  28. data/app/models/user.rb +33 -0
  29. data/app/views/layouts/application.html.erb +14 -0
  30. data/app/views/layouts/erp_tech_svcs/application.html.erb +14 -0
  31. data/app/views/user_mailer/activation_needed_email.html.erb +14 -0
  32. data/app/views/user_mailer/reset_password_email.html.erb +14 -0
  33. data/config/initializers/erp_tech_svcs.rb +7 -0
  34. data/config/initializers/file_support.rb +1 -0
  35. data/config/initializers/pdfkit.rb +18 -0
  36. data/config/initializers/sorcery.rb +199 -0
  37. data/config/routes.rb +9 -0
  38. data/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.rb +15 -0
  39. data/db/data_migrations/20111111144706_setup_audit_log_types.rb +21 -0
  40. data/db/migrate/20080805000010_base_tech_services.rb +247 -0
  41. data/db/migrate/20111109161549_add_capabilites.rb +56 -0
  42. data/db/migrate/upgrade/20111109161550_update_roles.rb +33 -0
  43. data/db/migrate/upgrade/20111109161551_update_user.rb +88 -0
  44. data/lib/erp_tech_svcs/application_installer.rb +102 -0
  45. data/lib/erp_tech_svcs/config.rb +27 -0
  46. data/lib/erp_tech_svcs/engine.rb +14 -0
  47. data/lib/erp_tech_svcs/extensions/active_record/acts_as_versioned.rb +494 -0
  48. data/lib/erp_tech_svcs/extensions/active_record/has_capabilities.rb +139 -0
  49. data/lib/erp_tech_svcs/extensions/active_record/has_file_assets.rb +40 -0
  50. data/lib/erp_tech_svcs/extensions/active_record/has_roles.rb +126 -0
  51. data/lib/erp_tech_svcs/extensions.rb +5 -0
  52. data/lib/erp_tech_svcs/file_support/aws_s3_patch.rb +3 -0
  53. data/lib/erp_tech_svcs/file_support/base.rb +30 -0
  54. data/lib/erp_tech_svcs/file_support/file_manipulator.rb +37 -0
  55. data/lib/erp_tech_svcs/file_support/file_system_manager.rb +167 -0
  56. data/lib/erp_tech_svcs/file_support/manager.rb +147 -0
  57. data/lib/erp_tech_svcs/file_support/paperclip_patch.rb +28 -0
  58. data/lib/erp_tech_svcs/file_support/railties/s3_resolver.rb +79 -0
  59. data/lib/erp_tech_svcs/file_support/s3_manager.rb +211 -0
  60. data/lib/erp_tech_svcs/file_support.rb +10 -0
  61. data/lib/erp_tech_svcs/sessions/delete_expired_sessions_job.rb +40 -0
  62. data/lib/erp_tech_svcs/sessions/delete_expired_sessions_service.rb +15 -0
  63. data/lib/erp_tech_svcs/utils/attachment_fu_patch.rb +15 -0
  64. data/lib/erp_tech_svcs/utils/compass_access_negotiator.rb +57 -0
  65. data/lib/erp_tech_svcs/utils/compass_logger.rb +94 -0
  66. data/lib/erp_tech_svcs/utils/compass_pdf.rb +72 -0
  67. data/lib/erp_tech_svcs/utils/default_nested_set_methods.rb +33 -0
  68. data/lib/erp_tech_svcs/utils/pdf_processor.rb +106 -0
  69. data/lib/erp_tech_svcs/version.rb +3 -0
  70. data/lib/erp_tech_svcs.rb +20 -0
  71. data/lib/tasks/erp_tech_svcs_tasks.rake +42 -0
  72. data/spec/dummy/Rakefile +7 -0
  73. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  74. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  75. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  76. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  77. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  78. data/spec/dummy/config/application.rb +43 -0
  79. data/spec/dummy/config/boot.rb +10 -0
  80. data/spec/dummy/config/database.yml +8 -0
  81. data/spec/dummy/config/environment.rb +5 -0
  82. data/spec/dummy/config/environments/spec.rb +27 -0
  83. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  84. data/spec/dummy/config/initializers/inflections.rb +10 -0
  85. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  86. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  87. data/spec/dummy/config/initializers/session_store.rb +8 -0
  88. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  89. data/spec/dummy/config/locales/en.yml +5 -0
  90. data/spec/dummy/config/routes.rb +3 -0
  91. data/spec/dummy/config.ru +4 -0
  92. data/spec/dummy/db/schema.rb +571 -0
  93. data/spec/dummy/db/spec.sqlite3 +0 -0
  94. data/spec/dummy/log/spec.log +2862 -0
  95. data/spec/dummy/public/404.html +26 -0
  96. data/spec/dummy/public/422.html +26 -0
  97. data/spec/dummy/public/500.html +26 -0
  98. data/spec/dummy/public/favicon.ico +0 -0
  99. data/spec/dummy/script/rails +6 -0
  100. data/spec/factories/capability_type.rb +5 -0
  101. data/spec/factories/role.rb +5 -0
  102. data/spec/factories/users.rb +9 -0
  103. data/spec/lib/erp_tech_svcs/extensions/active_record/has_roles_spec.rb +68 -0
  104. data/spec/models/audit_log_spec.rb +48 -0
  105. data/spec/models/audit_log_type_spec.rb +9 -0
  106. data/spec/models/role_spec.rb +17 -0
  107. data/spec/models/user_spec.rb +27 -0
  108. data/spec/spec_helper.rb +61 -0
  109. metadata +273 -0
@@ -0,0 +1,106 @@
1
+ require 'erp_tech_svcs/utils/compass_pdf'
2
+
3
+ # Middleware that will convert html to pdf.
4
+ # This will intercept a HTTP Request and look for the .pdf on the end of the URI
5
+ # if found then we'll convert any request for html to pdf.
6
+
7
+ # NOTE: The executable, wkhtmltopdf, that does the conversion must be installed
8
+ # and available.
9
+ # wkhtmltopdf is available at http://code.google.com/p/wkhtmltopdf/
10
+
11
+ # NOTE: To enable this add, or uncomment, this in the environment.rb
12
+ # config.middleware.use "PDFProcessor"
13
+
14
+ # TODO:
15
+ # Better Loggging with the Rails logger
16
+ # Restrict based on URL, may want to use Rack::Builder
17
+ # Extract pdf processor to technical service.
18
+ # May want to look into async procssing
19
+ class PDFProcessor
20
+
21
+ def initialize(app, enable_logging = false)
22
+ @app = app
23
+ @log_enabled = enable_logging
24
+ end
25
+
26
+ def call(env)
27
+ @req = Rack::Request.new(env)
28
+
29
+ pre_process(env)
30
+
31
+ # call the next middleware/app. Currently only rails
32
+ @status, @headers, @response = @app.call(env)
33
+
34
+ log "HTTP Response @status = #{@status.inspect}"
35
+ log "HTTP Response @headers = #{@headers.inspect}"
36
+
37
+ post_process(env)
38
+ log "returning from #{self.class.name}"
39
+ [@status, @headers, @response]
40
+
41
+ end
42
+
43
+ def pre_process(env)
44
+ # break the URI, ex: /hicv/home.pdf
45
+ # path = /hicv/home
46
+ # format = pdf
47
+ @path, @format = @req.path_info.split('.')
48
+ @req.path_info = @path
49
+
50
+ log "format = #{@format}"
51
+ log "@request.path_info = #{@req.path_info}"
52
+
53
+ # rewrite the URI, so rails doesn't see the pdf format/extension
54
+ # Otherwise, it'll attempt to handle pdf MIME content in the respond_to block
55
+ if !!@format && @format == 'pdf'
56
+ env["REQUEST_PATH"] = @path
57
+ env["REQUEST_URI"] = @path
58
+ end
59
+ log " REQUEST_PATH = #{env["REQUEST_PATH"]}"
60
+ log " REQUEST_URI = #{env["REQUEST_URI"]}"
61
+
62
+ end
63
+
64
+ def post_process(env)
65
+ # process the html into pdf iff:
66
+ # - Good HTTP status
67
+ # TODO: should check other HTTP status, redirect,...
68
+ # AND
69
+ # - Response Content-Type is html
70
+ # AND
71
+ # - Incoming URI has an '.pdf' extension OR format=pdf param
72
+
73
+ # TODO: Checked of for Accept application/pdf in HTTP Request
74
+ if @status == 200 && @headers["Content-Type"].include?("text/html") && @format == 'pdf'
75
+ orig_body = @response.body
76
+
77
+ # add full path to images, needed for pdf generation
78
+ img_tag = "img src=\"file://"+ "#{RAILS_ROOT}" + "/public/"
79
+ log "img_tag = #{img_tag}"
80
+ body = orig_body.gsub(/img src=\"/,img_tag)
81
+
82
+ # invoke prince with the right options
83
+ pdf_xlate = CompassPDF::PDF_XLATOR
84
+ # save the response generated by rails
85
+ pdf_xlate.write_html_response(body)
86
+
87
+ # generate the pdf
88
+ log "pdf_command = #{pdf_xlate.command.inspect}"
89
+ pdf_xlate.invoke
90
+
91
+ pdf_out = pdf_xlate.get_pdf_generated
92
+ #log "pdf_out = #{pdf_out.inspect}"
93
+
94
+ # return the pdf
95
+ @response.body = pdf_out
96
+ @headers = { "Content-Type" => "application/pdf"}
97
+
98
+ end
99
+ end
100
+ private
101
+
102
+ def log(message)
103
+ puts "PDFProcessor:: #{message}" if @log_enabled
104
+ end
105
+
106
+ end
@@ -0,0 +1,3 @@
1
+ module ErpTechSvcs
2
+ VERSION = "3.0.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ #compass libraries
2
+ require 'erp_base_erp_svcs'
3
+
4
+ require 'paperclip'
5
+ require 'delayed_job'
6
+ require 'sorcery'
7
+ require 'pdfkit'
8
+ require "erp_tech_svcs/utils/compass_logger"
9
+ require "erp_tech_svcs/utils/default_nested_set_methods"
10
+ require "erp_tech_svcs/utils/compass_access_negotiator"
11
+ require "erp_tech_svcs/extensions"
12
+ require 'erp_tech_svcs/file_support'
13
+ require "erp_tech_svcs/config"
14
+ #require "erp_tech_svcs/application_installer"
15
+ require "erp_tech_svcs/engine"
16
+ require 'erp_tech_svcs/sessions/delete_expired_sessions_job'
17
+ require 'erp_tech_svcs/sessions/delete_expired_sessions_service'
18
+
19
+ module ErpTechSvcs
20
+ end
@@ -0,0 +1,42 @@
1
+ namespace :erp_tech_svcs do
2
+
3
+ namespace :file_support do
4
+
5
+ desc "Sync storage between database and storage location ie (s3 or file system), taskes storage option"
6
+ task :sync_storage, [:storage] => :environment do |t,args|
7
+ file_support = ErpTechSvcs::FileSupport::Base.new(:storage => args.storage.to_sym)
8
+
9
+ #sync shared
10
+ puts "Syncing Shared Assets..."
11
+ file_support.sync(File.join(file_support.root, '/images'), CompassAeInstance.first)
12
+ file_support.sync(File.join(file_support.root, '/files'), CompassAeInstance.first)
13
+ puts "Complete"
14
+
15
+ #sync websites
16
+ puts "Syncing Websites..."
17
+ Website.all.each do |website|
18
+ file_support.sync(File.join(file_support.root, "/sites/site-#{website.id}/images"), website)
19
+ file_support.sync(File.join(file_support.root, "/sites/site-#{website.id}/files"), website)
20
+ end
21
+ puts "Complete"
22
+
23
+ #sync themes
24
+ puts "Syncing Themes..."
25
+ Theme.all.each do |theme|
26
+ file_support.sync(File.join(file_support.root, "/"+theme.url), theme)
27
+ end
28
+ puts "Complete"
29
+ end
30
+
31
+ end
32
+
33
+ namespace :application do
34
+
35
+ task :install do
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require
6
+ require "erp_base_erp_svcs"
7
+ require "erp_tech_svcs"
8
+
9
+ module Dummy
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Custom directories with classes and modules you want to be autoloadable.
16
+ # config.autoload_paths += %W(#{config.root}/extras)
17
+
18
+ # Only load the plugins named here, in the order given (default is alphabetical).
19
+ # :all can be used as a placeholder for all plugins not explicitly named.
20
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
+
22
+ # Activate observers that should always be running.
23
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
+
25
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
+ # config.time_zone = 'Central Time (US & Canada)'
28
+
29
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
+ # config.i18n.default_locale = :de
32
+
33
+ # Configure the default encoding used in templates for Ruby 1.9.
34
+ config.encoding = "utf-8"
35
+
36
+ # Configure sensitive parameters which will be filtered from the log file.
37
+ config.filter_parameters += [:password]
38
+
39
+ # Enable the asset pipeline
40
+ config.assets.enabled = true
41
+ end
42
+ end
43
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,8 @@
1
+ # Warning: The database defined as "test" will be erased and
2
+ # re-generated from your development database when you run "rake".
3
+ # Do not set this db to the same as development or production.
4
+ spec:
5
+ adapter: sqlite3
6
+ database: db/spec.sqlite3
7
+ pool: 5
8
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,27 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
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
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Do not compress assets
26
+ config.assets.compress = false
27
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'ae0d58840f73a49e40850c9d815a6a135e169865cdb8721cec7f335a738af09f3483de0f99d7c131f8fdecf2d8b508f8fd5e2e33c8d0565dcc9030eadb227695'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,12 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActionController::Base.wrap_parameters :format => [:json]
8
+
9
+ # Disable root element in JSON by default.
10
+ if defined?(ActiveRecord)
11
+ ActiveRecord::Base.include_root_in_json = false
12
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ mount ErpTechSvcs::Engine => "/erp_tech_svcs"
3
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application