erp_tech_svcs 3.0.12 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/app/controllers/erp_tech_svcs/session_controller.rb +1 -1
  2. data/app/models/attribute_type.rb +2 -0
  3. data/app/models/attribute_value.rb +2 -0
  4. data/app/models/audit_log.rb +4 -1
  5. data/app/models/audit_log_item.rb +2 -0
  6. data/app/models/audit_log_item_type.rb +2 -0
  7. data/app/models/audit_log_type.rb +2 -0
  8. data/app/models/capability.rb +2 -1
  9. data/app/models/capability_type.rb +2 -0
  10. data/app/models/extensions/category.rb +3 -0
  11. data/app/models/extensions/compass_ae_instance.rb +3 -0
  12. data/app/models/file_asset.rb +3 -1
  13. data/app/models/group.rb +5 -18
  14. data/app/models/scope_type.rb +1 -0
  15. data/app/models/security_role.rb +2 -0
  16. data/app/models/user.rb +29 -42
  17. data/app/views/user_mailer/activation_needed_email.html.erb +1 -1
  18. data/app/views/user_mailer/reset_password_email.html.erb +1 -1
  19. data/config/initializers/erp_tech_svcs.rb +2 -0
  20. data/db/data_migrations/20121130212146_note_capabilities.rb +2 -2
  21. data/db/migrate/20080805000010_base_tech_services.rb +3 -3
  22. data/lib/erp_tech_svcs/config.rb +4 -0
  23. data/lib/erp_tech_svcs/extensions/active_record/acts_as_versioned.rb +105 -106
  24. data/lib/erp_tech_svcs/extensions/active_record/has_capability_accessors.rb +4 -10
  25. data/lib/erp_tech_svcs/extensions/active_record/has_security_roles.rb +2 -0
  26. data/lib/erp_tech_svcs/extensions/active_record/protected_with_capabilities.rb +28 -53
  27. data/lib/erp_tech_svcs/extensions/railties/action_view/base.rb +8 -0
  28. data/lib/erp_tech_svcs/extensions/railties/action_view/helpers/include_helper.rb +28 -0
  29. data/lib/erp_tech_svcs/extensions.rb +3 -0
  30. data/lib/erp_tech_svcs/file_support/railties/s3_resolver.rb +1 -1
  31. data/lib/erp_tech_svcs/sms_wrapper/clickatell.rb +3 -3
  32. data/lib/erp_tech_svcs/utils/compass_access_negotiator.rb +4 -6
  33. data/lib/erp_tech_svcs/version.rb +2 -2
  34. data/lib/erp_tech_svcs.rb +2 -1
  35. data/spec/dummy/config/application.rb +6 -0
  36. data/spec/dummy/config/environments/spec.rb +3 -0
  37. data/spec/dummy/config/s3.yml +23 -0
  38. data/spec/dummy/db/data_migrations/20120109173616_create_download_capability_type.erp_tech_svcs.rb +14 -0
  39. data/spec/dummy/db/migrate/{20130105133955_base_erp_services.erp_base_erp_svcs.rb → 20130107214445_base_erp_services.erp_base_erp_svcs.rb} +0 -0
  40. data/spec/dummy/db/migrate/{20130105133956_base_tech_services.erp_tech_svcs.rb → 20130107214446_base_tech_services.erp_tech_svcs.rb} +0 -0
  41. data/spec/dummy/db/migrate/{20130105133957_create_has_attribute_tables.erp_tech_svcs.rb → 20130107214447_create_has_attribute_tables.erp_tech_svcs.rb} +0 -0
  42. data/spec/dummy/db/migrate/{20130105133958_create_groups.erp_tech_svcs.rb → 20130107214448_create_groups.erp_tech_svcs.rb} +0 -0
  43. data/spec/dummy/db/migrate/{20130105133959_upgrade_security.erp_tech_svcs.rb → 20130107214449_upgrade_security.erp_tech_svcs.rb} +0 -0
  44. data/spec/dummy/db/migrate/{20130105133960_upgrade_security2.erp_tech_svcs.rb → 20130107214450_upgrade_security2.erp_tech_svcs.rb} +0 -0
  45. data/spec/dummy/db/schema.rb +1 -1
  46. data/spec/dummy/db/spec.sqlite3 +0 -0
  47. data/spec/dummy/log/spec.log +15314 -121571
  48. data/spec/dummy/move_test_tmp/file_asset_spec_text.txt +1 -0
  49. data/spec/lib/erp_tech_svcs/extensions/active_record/has_roles_spec.rb +6 -6
  50. data/spec/lib/file_support/s3_manager_spec.rb +1 -0
  51. data/spec/models/audit_log_spec.rb +1 -1
  52. data/spec/models/file_asset_spec.rb +14 -5
  53. data/spec/models/group_spec.rb +41 -0
  54. data/spec/models/security_role_spec.rb +26 -0
  55. data/spec/models/user_spec.rb +12 -2
  56. data/spec/spec_helper.rb +12 -7
  57. metadata +65 -48
  58. data/db/data_migrations/upgrade/20120727152144_set_image_dimensions_on_file_assets.rb +0 -13
  59. data/db/migrate/upgrade/20111109161549_add_capabilites.rb +0 -56
  60. data/db/migrate/upgrade/20111109161550_update_roles.rb +0 -35
  61. data/db/migrate/upgrade/20111109161551_update_user.rb +0 -88
  62. data/db/migrate/upgrade/20120329161641_add_file_asset_indexes.rb +0 -22
  63. data/db/migrate/upgrade/20120517203052_add_queue_to_delayed_jobs.rb +0 -13
  64. data/db/migrate/upgrade/20120725205131_add_image_dimension_columns_to_file_asset.rb +0 -15
  65. data/lib/erp_tech_svcs/application_installer.rb +0 -102
  66. data/lib/erp_tech_svcs/utils/attachment_fu_patch.rb +0 -15
  67. data/lib/erp_tech_svcs/utils/compass_pdf.rb +0 -72
  68. data/lib/erp_tech_svcs/utils/pdf_processor.rb +0 -106
  69. data/spec/dummy/log/adam.log +0 -1
  70. data/spec/factories/role.rb +0 -5
  71. data/spec/models/role_spec.rb +0 -17
  72. data/spec/models/secured_model_spec.rb +0 -22
@@ -1,88 +0,0 @@
1
- class UpdateUser < ActiveRecord::Migration
2
- def up
3
- unless columns(:users).collect {|c| c.name}.include?('activation_state')
4
-
5
- #have to move over current users
6
- current_users = []
7
- User.all.each do |user|
8
- current_users << {
9
- :enabled => user.enabled,
10
- :email => user.email
11
- }
12
- end
13
-
14
- #change_columns
15
- change_column :users, :salt, :string
16
- change_column :users, :crypted_password, :string
17
-
18
- #remove old columns
19
- remove_column :users, :name
20
- remove_column :users, :activated_at
21
- remove_column :users, :enabled
22
- remove_column :users, :identity_url
23
- remove_column :users, :invitation_id
24
- remove_column :users, :invitation_limit
25
- remove_column :users, :club_number
26
- remove_column :users, :owner_number
27
- remove_column :users, :dob
28
- remove_column :users, :ssn_last_four
29
- remove_column :users, :salutation
30
- remove_column :users, :first_name
31
- remove_column :users, :last_name
32
- remove_column :users, :street_address
33
- remove_column :users, :city
34
- remove_column :users, :state_province
35
- remove_column :users, :postal_code
36
- remove_column :users, :country
37
- remove_column :users, :phone
38
- remove_column :users, :security_question_1
39
- remove_column :users, :security_answer_1
40
- remove_column :users, :security_question_2
41
- remove_column :users, :security_answer_2
42
-
43
- #rename columns
44
- rename_column :users, :remember_token, :remember_me_token
45
- rename_column :users, :remember_token_expires_at, :remember_me_token_expires_at
46
- rename_column :users, :activation_code, :activation_token
47
- rename_column :users, :activation_code_expires_at, :activation_token_expires_at
48
- rename_column :users, :password_reset_code, :password_reset_token
49
- rename_column :users, :lock_count, :failed_logins_count
50
- rename_column :users, :login, :username
51
-
52
- if columns(:users).collect {|c| c.name}.include?('user_type')
53
- rename_column :users, :user_type, :type
54
- end
55
-
56
- #activity logging
57
- add_column :users, :last_login_at, :datetime, :default => nil
58
- add_column :users, :last_logout_at, :datetime, :default => nil
59
- add_column :users, :last_activity_at, :datetime, :default => nil
60
- add_index :users, [:last_logout_at, :last_activity_at], :name => 'activity_idx'
61
-
62
- #brute force protection
63
- add_column :users, :lock_expires_at, :datetime, :default => nil
64
-
65
- #reset password
66
- add_column :users, :reset_password_token, :datetime, :default => nil
67
- add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
68
- add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
69
-
70
- #user activation
71
- add_column :users, :activation_state, :string, :default => nil
72
-
73
- current_users.each do |user_hash|
74
- if user_hash[:enabled]
75
- User.reset_column_information
76
- user = User.find_by_email(user_hash[:email])
77
- user.activate!
78
- user.password_confirmation = 'password'
79
- user.change_password!('password')
80
- end
81
- end
82
-
83
- end
84
- end
85
-
86
- def down
87
- end
88
- end
@@ -1,22 +0,0 @@
1
- class AddFileAssetIndexes < ActiveRecord::Migration
2
- def self.up
3
- unless indexes(:file_assets).collect {|i| i.name}.include?('index_file_assets_on_type')
4
- add_index :file_assets, :type
5
- end
6
-
7
- unless indexes(:file_assets).collect {|i| i.name}.include?('file_asset_holder_idx')
8
- add_index :file_assets, [:file_asset_holder_id, :file_asset_holder_type], :name => 'file_asset_holder_idx'
9
- end
10
-
11
- unless indexes(:file_assets).collect {|i| i.name}.include?('index_file_assets_on_name')
12
- add_index :file_assets, :name
13
- end
14
-
15
- unless indexes(:file_assets).collect {|i| i.name}.include?('index_file_assets_on_directory')
16
- add_index :file_assets, :directory
17
- end
18
- end
19
-
20
- def self.down
21
- end
22
- end
@@ -1,13 +0,0 @@
1
- class AddQueueToDelayedJobs < ActiveRecord::Migration
2
- def self.up
3
- unless column_exists?(:delayed_jobs, :queue)
4
- add_column :delayed_jobs, :queue, :string
5
- end
6
- end
7
-
8
- def self.down
9
- if column_exists?(:delayed_jobs, :queue)
10
- remove_column :delayed_jobs, :queue
11
- end
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- class AddImageDimensionColumnsToFileAsset < ActiveRecord::Migration
2
- def self.up
3
- unless columns(:file_assets).collect {|c| c.name}.include?('width')
4
- add_column :file_assets, :width, :string
5
- add_column :file_assets, :height, :string
6
- end
7
- end
8
-
9
- def self.down
10
- if columns(:file_assets).collect {|c| c.name}.include?('width')
11
- remove_column :file_assets, :width
12
- remove_column :file_assets, :height
13
- end
14
- end
15
- end
@@ -1,102 +0,0 @@
1
- require 'rubygems'
2
-
3
- module Bundler
4
- class RubygemsIntegration
5
- def replace_entrypoints(specs)
6
- ErpTechSvcs::ApplicationInstaller.compass_gem_specs.each do |spec|
7
- specs << spec
8
- end rescue nil
9
- reverse_rubygems_kernel_mixin
10
-
11
- replace_gem(specs)
12
-
13
- stub_rubygems(specs)
14
-
15
- replace_bin_path(specs)
16
- replace_refresh
17
-
18
- Gem.clear_paths
19
- end
20
- end
21
- end
22
-
23
- module Bundler
24
- def self.setup(reload=false, *groups)
25
- # Just return if all groups are already loaded
26
- return @setup if (defined?(@setup) && !reload)
27
-
28
- if groups.empty?
29
- # Load all groups, but only once
30
- @setup = load(reload).setup
31
- else
32
- @completed_groups ||= []
33
- # Figure out which groups haven't been loaded yet
34
- unloaded = groups - @completed_groups
35
- # Record groups that are now loaded
36
- @completed_groups = groups
37
- unloaded.any? ? load(reload).setup(*groups) : load
38
- end
39
- end
40
-
41
- def self.load(reload=false)
42
- reload ? (@load = Runtime.new(root, definition(true))) : (@load ||= Runtime.new(root, definition))
43
- end
44
- end
45
-
46
- module ErpTechSvcs
47
- class ApplicationInstaller
48
- class << self
49
-
50
- cattr_accessor :compass_gem_specs
51
-
52
- def setup_compass_applications
53
- # Bundler.rubygems.gem_path.push File.join(Rails.root, "vendor/compass_applications")
54
- end
55
-
56
- def install_application(application_name)
57
- unless application_installed?(application_name)
58
- ErpTechSvcs::ApplicationInstaller.compass_gem_specs = ErpTechSvcs::ApplicationInstaller.compass_gem_specs.nil? ? [] : ErpTechSvcs::ApplicationInstaller.compass_gem_specs
59
-
60
- #install_gem(application_name)
61
- #ErpTechSvcs::FileManipulator.append_file('Gemfile',"gem '#{application_name}'")
62
- #spec = Bundler.rubygems.spec_from_gem(File.join(Rails.root,'vendor','compass_applications','tenancy','tenancy-0.0.1.gem'))
63
- #ErpTechSvcs::ApplicationInstaller.compass_gem_specs << spec
64
- Bundler.setup true
65
- #Bundler.require :default
66
- #require "tenancy"
67
- end
68
- end
69
-
70
- def include_application(application)
71
- path = File.join(Rails.root, "vendor/compass_applications", application[:description], 'lib', "#{application[:name]}.rb")
72
- puts path
73
- require path
74
- end
75
-
76
- def application_installed?(application_name)
77
- installed_engines = Rails::Application::Railties.engines.collect{|e| e.railtie_name.camelize}
78
- installed_engines.include?(application_name.camelize)
79
- end
80
-
81
- def install_gem(application_name)
82
- out, _ = sh_with_code("gem install '#{application_name}'")
83
- puts out
84
- raise "Couldn't install gem, run `gem install #{application_name}' for more detailed output" unless out[/Successfully installed/]
85
- end
86
-
87
- def sh_with_code(cmd, &block)
88
- cmd << " 2>&1"
89
- outbuf = ''
90
- puts (Rails.root)
91
- Dir.chdir(Rails.root) {
92
- outbuf = `#{cmd}`
93
- if $? == 0
94
- block.call(outbuf) if block
95
- end
96
- }
97
- [outbuf, $?]
98
- end
99
-
100
- end
101
- end
102
- end
@@ -1,15 +0,0 @@
1
- #This patch is to make the attachment_fu plugin work on Windows
2
- #It is not necessary for 'nix operating systems, though it is not known
3
- #to cause problems
4
- require 'tempfile'
5
- class Tempfile
6
- def size
7
- if @tmpfile
8
- @tmpfile.fsync # added this line
9
- @tmpfile.flush
10
- @tmpfile.stat.size
11
- else
12
- 0
13
- end
14
- end
15
- end
@@ -1,72 +0,0 @@
1
- module CompassPDF
2
-
3
- class PDFXLate
4
-
5
- # pdf xlator utility
6
- attr_accessor :pdf_util
7
-
8
- # options to the pdf xlator
9
- attr_accessor :util_options
10
-
11
- # temp file that contains the html to be xlated
12
- attr_accessor :html_filename
13
-
14
- # output option
15
- attr_accessor :pdf_out_option
16
-
17
- # pdf file generated
18
- attr_accessor :pdf_filename
19
-
20
- # shell command/s to invoke the xlation process and return the results
21
- attr_accessor :command
22
-
23
- def initialize(options={})
24
- # lets default to using prince, we're big spenders
25
- #options = {:pdf_util => "#{PDF_COMMAND}",:util_options => '--input=html --media=screen --baseurl=http://localhost:3000', :pdf_out_option => '-o '}.merge(options)
26
-
27
- # lets use wkhtmltopdf, we're cheap
28
- #options = {:pdf_util => "#{PDF_COMMAND}",:util_options => '', :pdf_out_option => ""}.merge(options)
29
- options.each{ |k,v| self.send("#{k}=".to_sym, v) }
30
- end
31
-
32
- def command
33
- # TODO: send this to a background process to do the xlate
34
- # TODO: add timeout
35
- # Could bog down the rails process
36
- # cmd = "#{@pdf_util} #{@util_options} #{self.html_filename} -o #{self.pdf_out} &>/dev/null;"
37
- cmd = "#{@pdf_util} #{@util_options} #{self.html_filename} #{self.pdf_out_option} #{pdf_filename}"
38
- # cmd << "cat #{self.pdf_filename}"
39
- end
40
-
41
- def html_filename=(file_name)
42
- @fname = file_name
43
- end
44
-
45
- def html_filename
46
- @fname ||= "tmp/html_output_#{Digest::MD5.hexdigest(Time.now.to_i.to_s)}.html"
47
- end
48
-
49
- def pdf_filename
50
- html_filename.sub(/\.html/, '.pdf')
51
- end
52
-
53
- def write_html_response(body)
54
- File.open("#{html_filename}", "w") { |f| f.puts(body) }
55
- end
56
-
57
- def get_pdf_generated
58
- pdf_contents = nil
59
- File.open("#{pdf_filename}",'rb') do |f|
60
- pdf_contents = f.read
61
- end
62
- pdf_contents
63
- end
64
-
65
- def invoke
66
- puts "invoking command #{self.command}"
67
- `#{self.command}`
68
- #TODO: cleanup temp files, etc.
69
- end
70
- end
71
-
72
- end
@@ -1,106 +0,0 @@
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
@@ -1 +0,0 @@
1
- Connecting to database specified by database.yml
@@ -1,5 +0,0 @@
1
- FactoryGirl.define do
2
- factory :role do |r|
3
-
4
- end
5
- end
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Role do
4
-
5
- before(:all) do
6
- @role = SecurityRole.create(:internal_identifier => 'employee')
7
- end
8
-
9
- it "can transform into xml" do
10
- @role.to_xml
11
- end
12
-
13
- after(:all) do
14
- SecurityRole.destroy_all
15
- end
16
-
17
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SecuredModel do
4
-
5
- it "can find models by Class and role" do
6
- admin_role = SecurityRole.create(:description => 'Admin', :internal_identifier => 'admin')
7
- admin_user = User.create(:username => "admin",:email => "admin@portablemind.com")
8
- admin_user.add_role('admin')
9
-
10
- admin_user.has_role?('admin').should eq true
11
-
12
- model = SecuredModel.find_models_by_klass_and_role(User, 'admin').first
13
- model.username.should eq 'admin'
14
-
15
- model = SecuredModel.find_models_by_klass_and_role('User', admin_role).first
16
- model.username.should eq 'admin'
17
-
18
- admin_user.destroy
19
- admin_role.destroy
20
- end
21
-
22
- end