erp_tech_svcs 3.0.8 → 3.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,9 @@ module ErpTechSvcs
8
8
  #log when someone logs in
9
9
  ErpTechSvcs::ErpTechSvcsAuditLog.successful_login(current_user)
10
10
 
11
+ #set logout
12
+ session[:logout_to] = params[:logout_to]
13
+
11
14
  login_to = last_login_at.nil? ? params[:first_login_to] : params[:login_to]
12
15
  login_to = login_to || params[:login_to]
13
16
  request.xhr? ? (render :json => {:success => true, :login_to => login_to}) : (redirect_to login_to)
@@ -19,14 +22,26 @@ module ErpTechSvcs
19
22
  end
20
23
 
21
24
  def destroy
22
- logged_out_user = current_user
25
+ message = "You have successfully logged out."
26
+ logged_out_user_id = current_user.id unless current_user === false
27
+ logout_to = session[:logout_to]
28
+
23
29
  logout
24
30
 
25
31
  #log when someone logs out
26
- ErpTechSvcs::ErpTechSvcsAuditLog.successful_logout(logged_out_user)
32
+ ErpTechSvcs::ErpTechSvcsAuditLog.successful_logout(logged_out_user_id) if logged_out_user_id
33
+
34
+ if logout_to
35
+ redirect_to logout_to, :notice => message
36
+ else
37
+ login_url = params[:login_url].blank? ? ErpTechSvcs::Config.login_url : params[:login_url]
38
+ redirect_to login_url, :notice => message
39
+ end
40
+
41
+ end
27
42
 
28
- login_url = params[:login_url].blank? ? ErpTechSvcs::Config.login_url : params[:login_url]
29
- redirect_to login_url, :notice => "You have successfully logged out."
43
+ def keep_alive
44
+ render :json => {:success => true, :last_activity_at => current_user.last_activity_at}
30
45
  end
31
46
  end#SessionsController
32
47
  end#ErpTechSvcs
@@ -26,7 +26,7 @@ class AuditLog < ActiveRecord::Base
26
26
  def method_missing(m, *args, &block)
27
27
  if self.respond_to?(m)
28
28
  item = get_item_by_item_type_internal_identifier(m.to_s)
29
- (item.nil?) ? super : (return item.value)
29
+ (item.nil?) ? super : (return item.audit_log_item_value)
30
30
  else
31
31
  super
32
32
  end
@@ -39,13 +39,12 @@ class FileAsset < ActiveRecord::Base
39
39
  end
40
40
 
41
41
  after_create :set_sti
42
- after_save :set_data_file_name
43
42
 
44
43
  belongs_to :file_asset_holder, :polymorphic => true
45
44
  instantiates_with_sti
46
45
 
47
46
  has_capabilities
48
-
47
+
49
48
  #paperclip
50
49
  has_attached_file :data,
51
50
  :storage => ErpTechSvcs::Config.file_storage,
@@ -56,6 +55,9 @@ class FileAsset < ActiveRecord::Base
56
55
  :url => ":file_url",
57
56
  :validations => { :extension => lambda { |data, file| validate_extension(data, file) } }
58
57
 
58
+ # must fire after paperclip's after_save :save_attached_files
59
+ after_save :set_data_file_name, :save_dimensions
60
+
59
61
  before_post_process :set_content_type
60
62
 
61
63
  validates_attachment_presence :data
@@ -125,6 +127,40 @@ class FileAsset < ActiveRecord::Base
125
127
  super attributes.merge(:directory => directory, :name => name, :data => data)
126
128
  end
127
129
 
130
+ # compass file download url
131
+ def url
132
+ "/download/#{self.name}?#{self.directory}"
133
+ end
134
+
135
+ # returns full path to local image or url to s3 image
136
+ def path
137
+ file_support = ErpTechSvcs::FileSupport::Base.new(:storage => ErpTechSvcs::Config.file_storage)
138
+
139
+ if ErpTechSvcs::Config.file_storage == :s3
140
+ file_path = File.join(self.directory,self.name).sub(%r{^/},'')
141
+ options = {}
142
+ options[:expires] = ErpTechSvcs::Config.s3_url_expires_in_seconds if self.has_capabilities?
143
+ return file_support.bucket.objects[file_path].url_for(:read, options).to_s
144
+ else
145
+ return File.join(Rails.root, self.directory, self.name)
146
+ end
147
+ end
148
+
149
+ def save_dimensions
150
+ if type == 'Image'
151
+ begin
152
+ f = Paperclip::Geometry.from_file(self.path)
153
+ w = f.width.to_i
154
+ h = f.height.to_i
155
+ update_attribute(:width, w) if width != w
156
+ update_attribute(:height, h) if height != h
157
+ rescue Exception=>ex
158
+ Rails.logger.error('Could not save width and height of image. Make sure Image Magick and the identify command are accessible')
159
+ end
160
+ end
161
+ #return true
162
+ end
163
+
128
164
  def basename
129
165
  data_file_name.gsub(/\.#{extname}$/, "")
130
166
  end
@@ -165,7 +201,9 @@ class FileAsset < ActiveRecord::Base
165
201
 
166
202
  result, message = file_support.save_move(old_path, new_parent_path)
167
203
  if result
168
- self.directory = new_parent_path.gsub(Regexp.new(Rails.root.to_s), '') # strip rails root from new_parent_path, we want relative path
204
+ dir = new_parent_path.gsub(Regexp.new(Rails.root.to_s), '') # strip rails root from new_parent_path, we want relative path
205
+ dir = '/' + dir unless dir.match(%r{^/})
206
+ self.directory = dir
169
207
  self.save
170
208
  end
171
209
 
@@ -176,13 +214,13 @@ end
176
214
 
177
215
  class Image < FileAsset
178
216
  self.file_type = :image
179
- self.valid_extensions = %w(.jpg .jpeg .gif .png .ico .PNG .JPEG .JPG)
217
+ self.valid_extensions = %w(.jpg .JPG .jpeg .JPEG .gif .GIF .png .PNG .ico .ICO .bmp .BMP .tif .tiff .TIF .TIFF)
180
218
  end
181
219
 
182
220
  class TextFile < FileAsset
183
221
  self.file_type = :textfile
184
222
  self.content_type = 'text/plain'
185
- self.valid_extensions = %w(.txt .text)
223
+ self.valid_extensions = %w(.txt .TXT .text)
186
224
 
187
225
  def data=(data)
188
226
  data = StringIO.new(data) if data.is_a?(String)
@@ -197,13 +235,13 @@ end
197
235
  class Javascript < TextFile
198
236
  self.file_type = :javascript
199
237
  self.content_type = 'text/javascript'
200
- self.valid_extensions = %w(.js)
238
+ self.valid_extensions = %w(.js .JS)
201
239
  end
202
240
 
203
241
  class Stylesheet < TextFile
204
242
  self.file_type = :stylesheet
205
243
  self.content_type = 'text/css'
206
- self.valid_extensions = %w(.css)
244
+ self.valid_extensions = %w(.css .CSS)
207
245
  end
208
246
 
209
247
  class Template < TextFile
@@ -215,17 +253,17 @@ end
215
253
  class HtmlFile < TextFile
216
254
  self.file_type = :html
217
255
  self.content_type = 'text/html'
218
- self.valid_extensions = %w(.html)
256
+ self.valid_extensions = %w(.html .HTML)
219
257
  end
220
258
 
221
259
  class Pdf < TextFile
222
260
  self.file_type = :pdf
223
261
  self.content_type = 'application/pdf'
224
- self.valid_extensions = %w(.pdf)
262
+ self.valid_extensions = %w(.pdf .PDF)
225
263
  end
226
264
 
227
265
  class Swf < TextFile
228
266
  self.file_type = :swf
229
267
  self.content_type = 'application/x-shockwave-flash'
230
- self.valid_extensions = %w(.swf)
268
+ self.valid_extensions = %w(.swf .SWF)
231
269
  end
data/config/routes.rb CHANGED
@@ -2,6 +2,7 @@ Rails.application.routes.draw do
2
2
  #handle login / logout
3
3
  match "/session/sign_in" => 'erp_tech_svcs/session#create'
4
4
  match "/session/sign_out" => 'erp_tech_svcs/session#destroy'
5
+ match "/session/keep_alive" => 'erp_tech_svcs/session#keep_alive'
5
6
 
6
7
  #handle activation
7
8
  get "/users/activate/:activation_token" => 'erp_tech_svcs/user#activate'
@@ -0,0 +1,13 @@
1
+ class SetImageDimensionsOnFileAssets < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ FileAsset.where(:type => 'Image').all.each do |i|
5
+ i.save_dimensions
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ # do nothing
11
+ end
12
+
13
+ end
@@ -169,6 +169,8 @@ class BaseTechServices < ActiveRecord::Migration
169
169
  t.string :data_content_type
170
170
  t.integer :data_file_size
171
171
  t.datetime :data_updated_at
172
+ t.string :width
173
+ t.string :height
172
174
 
173
175
  t.timestamps
174
176
  end
@@ -0,0 +1,15 @@
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
@@ -2,7 +2,7 @@ module ErpTechSvcs
2
2
  module Config
3
3
  class << self
4
4
 
5
- attr_accessor :max_file_size_in_mb,
5
+ attr_accessor :max_file_size_in_mb,
6
6
  :installation_domain,
7
7
  :login_url,
8
8
  :email_notifications_from,
@@ -25,7 +25,7 @@ module ErpTechSvcs
25
25
  :@s3_protocol => 'https', # Can be either 'http' or 'https'
26
26
  :@file_storage => :filesystem, # Can be either :s3 or :filesystem
27
27
  :@s3_cache_expires_in_minutes => 60,
28
- :@session_expires_in_hours => 12, # this is used by DeleteExpiredSessionsJob to purge inactive sessions from database
28
+ :@session_expires_in_hours => 12, # this is used by DeleteExpiredSessionsJob to purge inactive sessions from database
29
29
  :@compass_logger_path => "#{Rails.root}/log"
30
30
  }
31
31
  end
@@ -3,7 +3,8 @@ module ErpTechSvcs
3
3
  class << self
4
4
 
5
5
  #log when a user logs out
6
- def successful_logout(user)
6
+ def successful_logout(user_id)
7
+ user = User.find(user_id)
7
8
  AuditLog.create(
8
9
  :party_id => user.party.id,
9
10
  :event_record => user,
@@ -16,9 +16,12 @@ module ErpTechSvcs
16
16
  after_initialize :initialize_capable_model
17
17
  after_update :save_capable_model
18
18
  after_create :save_capable_model
19
- after_destroy :destroy_capable_model
20
-
21
- has_one :capable_model, :as => :capable_model_record
19
+ after_destroy :destroy_capable_model
20
+
21
+ has_one :capable_model, :as => :capable_model_record
22
+ has_many :capabilities, :through => :capable_model
23
+
24
+ default_scope :include => :capabilities
22
25
  end
23
26
  end
24
27
 
@@ -26,14 +29,11 @@ module ErpTechSvcs
26
29
  end
27
30
 
28
31
  module InstanceMethods
32
+
29
33
  def has_capabilities?
30
34
  !capabilities.empty?
31
35
  end
32
36
 
33
- def capabilities
34
- capable_model.capabilities
35
- end
36
-
37
37
  def available_capability_resources
38
38
  capabilities.collect{|capability| capability.resource}.uniq
39
39
  end
@@ -113,7 +113,8 @@ module ErpTechSvcs
113
113
  end
114
114
 
115
115
  def initialize_capable_model
116
- if self.capable_model.nil?
116
+ # added new_record? because simply querying for a file_asset was causing a plethora of unnecessary queries for capable_model
117
+ if self.new_record? and self.capable_model.nil?
117
118
  capable_model = CapableModel.new
118
119
  self.capable_model = capable_model
119
120
  capable_model.capable_model_record = self
@@ -12,7 +12,7 @@ module ErpTechSvcs
12
12
  extend HasFileAssets::SingletonMethods
13
13
  include HasFileAssets::InstanceMethods
14
14
 
15
- has_many :files, :as => :file_asset_holder, :class_name => 'FileAsset', :dependent => :delete_all
15
+ has_many :files, :as => :file_asset_holder, :class_name => 'FileAsset', :dependent => :delete_all, :include => :capabilities
16
16
  end
17
17
  end
18
18
 
@@ -22,7 +22,7 @@ module ErpTechSvcs
22
22
  after_create :save_secured_model
23
23
  after_destroy :destroy_secured_model
24
24
 
25
- has_one :secured_model, :as => :secured_record
25
+ has_one :secured_model, :as => :secured_record, :include => :roles
26
26
  end
27
27
  end
28
28
 
@@ -55,7 +55,7 @@ module ErpTechSvcs
55
55
  end
56
56
 
57
57
  def add_role(role)
58
- role = Role.find_by_internal_identifier(role) if role.is_a? String
58
+ role = role.is_a?(Role) ? role : Role.find_by_internal_identifier(role.to_s)
59
59
  unless self.has_role?(role)
60
60
  self.secured_model.roles << role
61
61
  self.secured_model.save
@@ -72,7 +72,7 @@ module ErpTechSvcs
72
72
  end
73
73
 
74
74
  def remove_role(role)
75
- role = Role.find_by_internal_identifier(role) if role.is_a? String
75
+ role = role.is_a?(Role) ? role : Role.find_by_internal_identifier(role.to_s)
76
76
  self.secured_model.roles.delete(role) if has_role?(role)
77
77
  end
78
78
 
@@ -93,7 +93,7 @@ module ErpTechSvcs
93
93
  result = false
94
94
  passed_roles.flatten!
95
95
  passed_roles.each do |role|
96
- role_iid = (role.is_a?(String)) ? role : role.internal_identifier
96
+ role_iid = role.is_a?(Role) ? role.internal_identifier : role.to_s
97
97
  self.roles.each do |this_role|
98
98
  result = true if (this_role.internal_identifier == role_iid)
99
99
  break if result
@@ -121,9 +121,10 @@ module ErpTechSvcs
121
121
  end
122
122
  end
123
123
  end
124
- end
125
- end
126
- end
127
- end
124
+
125
+ end #HasRoles
126
+ end #ActiveRecord
127
+ end #Extensions
128
+ end #ErpTechSvcs
128
129
 
129
130
 
@@ -8,12 +8,12 @@ module ErpTechSvcs
8
8
  end
9
9
 
10
10
  def update_file(path, content)
11
- File.open(path, 'w+:ASCII-8BIT') {|f| f.write(content) }
11
+ File.open(path, 'wb+') {|f| f.write(content) }
12
12
  end
13
13
 
14
14
  def create_file(path, name, contents)
15
15
  FileUtils.mkdir_p path unless File.exists? path
16
- File.open(File.join(path,name), 'w+:ASCII-8BIT') {|f| f.write(contents) }
16
+ File.open(File.join(path,name), 'wb+') {|f| f.write(contents) }
17
17
  end
18
18
 
19
19
  def create_folder(path, name)
@@ -22,7 +22,7 @@ module ErpTechSvcs
22
22
 
23
23
  def save_move(path, new_parent_path)
24
24
  old_path = File.join(path)
25
- new_path = File.join(new_parent_path)
25
+ new_path = File.join(Rails.root,new_parent_path)
26
26
  result = false
27
27
  unless File.exists? old_path
28
28
  message = FILE_DOES_NOT_EXIST
@@ -73,7 +73,7 @@ module ErpTechSvcs
73
73
  entries.delete_if{|entry| entry =~ REMOVE_FILES_REGEX}
74
74
  if entries.count > 0 && !options[:force]
75
75
  message = FOLDER_IS_NOT_EMPTY
76
- result = false;
76
+ result = false
77
77
  else
78
78
  FileUtils.rm_rf(path)
79
79
  message = "Folder #{name} was deleted #{name} successfully"
@@ -95,7 +95,7 @@ module ErpTechSvcs
95
95
  unless File.exists? path
96
96
  message = FILE_DOES_NOT_EXIST
97
97
  else
98
- contents = IO.read(path).force_encoding('ASCII-8BIT')
98
+ contents = File.open(path, 'rb') {|file| file.read }
99
99
  end
100
100
  return contents, message
101
101
  end
@@ -95,6 +95,10 @@ module ErpTechSvcs
95
95
  unless file.nil?
96
96
  child_hash[:isSecured] = file.has_capabilities?
97
97
  child_hash[:iconCls] = 'icon-document_lock' if child_hash[:isSecured]
98
+ child_hash[:size] = file.data_file_size
99
+ child_hash[:width] = file.width
100
+ child_hash[:height] = file.height
101
+ child_hash[:url] = file.url
98
102
  end
99
103
 
100
104
  new_parents << child_hash
@@ -100,7 +100,7 @@ module ErpTechSvcs
100
100
  def update_file(path, content)
101
101
  file = FileAsset.where(:name => ::File.basename(path)).where(:directory => ::File.dirname(path)).first
102
102
  acl = (file.has_capabilities? ? :private : :public_read) unless file.nil?
103
- options = (file.nil? ? {} : {:acl => acl})
103
+ options = (file.nil? ? {} : {:acl => acl, :content_type => file.content_type })
104
104
  path = path.sub(%r{^/},'')
105
105
  bucket.objects[path].write(content, options)
106
106
  clear_cache(path)
@@ -1,6 +1,5 @@
1
1
  require 'erp_tech_svcs/file_support/base'
2
2
  require 'erp_tech_svcs/file_support/manager'
3
- require 'erp_tech_svcs/file_support/paperclip_patch'
4
3
  require 'erp_tech_svcs/file_support/file_system_manager'
5
4
  require 'erp_tech_svcs/file_support/s3_manager'
6
5
  require 'erp_tech_svcs/file_support/file_manipulator'
@@ -2,7 +2,7 @@ module ErpTechSvcs
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- TINY = 8
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erp_tech_svcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.8
4
+ version: 3.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erp_base_erp_svcs
16
- requirement: &70128767646120 !ruby/object:Gem::Requirement
16
+ requirement: &70098070406840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70128767646120
24
+ version_requirements: *70098070406840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: erp_dev_svcs
27
- requirement: &70128767645620 !ruby/object:Gem::Requirement
27
+ requirement: &70098070406180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70128767645620
35
+ version_requirements: *70098070406180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aws-sdk
38
- requirement: &70128767645160 !ruby/object:Gem::Requirement
38
+ requirement: &70098070398820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.5.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70128767645160
46
+ version_requirements: *70098070398820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: delayed_job_active_record
49
- requirement: &70128767644700 !ruby/object:Gem::Requirement
49
+ requirement: &70098070397900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.3.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70128767644700
57
+ version_requirements: *70098070397900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: paperclip
60
- requirement: &70128767644240 !ruby/object:Gem::Requirement
60
+ requirement: &70098070396920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - =
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 3.0.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70128767644240
68
+ version_requirements: *70098070396920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pdfkit
71
- requirement: &70128767643780 !ruby/object:Gem::Requirement
71
+ requirement: &70098070395480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - =
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.4.6
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70128767643780
79
+ version_requirements: *70098070395480
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sorcery
82
- requirement: &70128767643320 !ruby/object:Gem::Requirement
82
+ requirement: &70098070394520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - =
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 0.7.12
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70128767643320
90
+ version_requirements: *70098070394520
91
91
  description: This engine is implemented with the premise that services like logging,
92
92
  tracing and encryption would likely already exist in many organizations, so they
93
93
  are factored here so they can easily be re-implemented. There are default implementations
@@ -139,6 +139,7 @@ files:
139
139
  - db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.rb
140
140
  - db/data_migrations/20111111144706_setup_audit_log_types.rb
141
141
  - db/data_migrations/20120109173616_create_download_capability_type.rb
142
+ - db/data_migrations/upgrade/20120727152144_set_image_dimensions_on_file_assets.rb
142
143
  - db/migrate/20080805000010_base_tech_services.rb
143
144
  - db/migrate/20111117183144_create_has_attribute_tables.rb
144
145
  - db/migrate/upgrade/20111109161549_add_capabilites.rb
@@ -146,6 +147,7 @@ files:
146
147
  - db/migrate/upgrade/20111109161551_update_user.rb
147
148
  - db/migrate/upgrade/20120329161641_add_file_asset_indexes.rb
148
149
  - db/migrate/upgrade/20120517203052_add_queue_to_delayed_jobs.rb
150
+ - db/migrate/upgrade/20120725205131_add_image_dimension_columns_to_file_asset.rb
149
151
  - lib/erp_tech_svcs/application_installer.rb
150
152
  - lib/erp_tech_svcs/config.rb
151
153
  - lib/erp_tech_svcs/engine.rb