Commit 21810adf771dd26a9d14ced33403ad525565b88d
1 parent
422b350a
Exists in
master
and in
11 other branches
rails4: require missing dependencies
Showing
7 changed files
with
84 additions
and
74 deletions
Show diff stats
vendor/ezcrypto/lib/active_crypto.rb
| 1 | require "ezcrypto.rb" | 1 | require "ezcrypto.rb" |
| 2 | module ActiveCrypto # :nodoc: | 2 | module ActiveCrypto # :nodoc: |
| 3 | - | 3 | + |
| 4 | def self.append_features(base) #:nodoc: | 4 | def self.append_features(base) #:nodoc: |
| 5 | super | 5 | super |
| 6 | base.extend(ClassMethods) | 6 | base.extend(ClassMethods) |
| 7 | end | 7 | end |
| 8 | - | 8 | + |
| 9 | =begin rdoc | 9 | =begin rdoc |
| 10 | 10 | ||
| 11 | Usage is very simple. You will generally only need the two class methods listed here in your ActiveRecord class model. | 11 | Usage is very simple. You will generally only need the two class methods listed here in your ActiveRecord class model. |
| @@ -47,19 +47,19 @@ Options are: | @@ -47,19 +47,19 @@ Options are: | ||
| 47 | belongs_to :user | 47 | belongs_to :user |
| 48 | encrypt :title,:body,:key=>:user, :base64 => true | 48 | encrypt :title,:body,:key=>:user, :base64 => true |
| 49 | end | 49 | end |
| 50 | - | 50 | + |
| 51 | =end | 51 | =end |
| 52 | - def encrypt(*attributes) | 52 | + def encrypt(*attributes) |
| 53 | include ActiveCrypto::Encrypted | 53 | include ActiveCrypto::Encrypted |
| 54 | before_save :encrypt_attributes | 54 | before_save :encrypt_attributes |
| 55 | after_save :decrypt_attributes | 55 | after_save :decrypt_attributes |
| 56 | options=attributes.last.is_a?(Hash) ? attributes.pop : {} | 56 | options=attributes.last.is_a?(Hash) ? attributes.pop : {} |
| 57 | keyholder | 57 | keyholder |
| 58 | if options and options[:key] | 58 | if options and options[:key] |
| 59 | - module_eval <<-"end;" | 59 | + module_eval <<-"end;" |
| 60 | def session_key | 60 | def session_key |
| 61 | (send :#{options[:key]} ).send :session_key | 61 | (send :#{options[:key]} ).send :session_key |
| 62 | - end | 62 | + end |
| 63 | @@external_key=true | 63 | @@external_key=true |
| 64 | end; | 64 | end; |
| 65 | end | 65 | end |
| @@ -70,10 +70,10 @@ Options are: | @@ -70,10 +70,10 @@ Options are: | ||
| 70 | #{base64_encode.to_s} | 70 | #{base64_encode.to_s} |
| 71 | end | 71 | end |
| 72 | end; | 72 | end; |
| 73 | - | 73 | + |
| 74 | self.encrypted_attributes=attributes | 74 | self.encrypted_attributes=attributes |
| 75 | - end | ||
| 76 | - | 75 | + end |
| 76 | + | ||
| 77 | =begin rdoc | 77 | =begin rdoc |
| 78 | Creates support in this class for holding a key. Adds the following methods: | 78 | Creates support in this class for holding a key. Adds the following methods: |
| 79 | 79 | ||
| @@ -88,10 +88,10 @@ Use it as follows: | @@ -88,10 +88,10 @@ Use it as follows: | ||
| 88 | keyholder | 88 | keyholder |
| 89 | end | 89 | end |
| 90 | 90 | ||
| 91 | -=end | 91 | +=end |
| 92 | def keyholder() | 92 | def keyholder() |
| 93 | - include ActiveCrypto::AssociationKeyHolder | ||
| 94 | - after_create :save_session_key | 93 | + include ActiveCrypto::AssociationKeyHolder |
| 94 | + after_create :save_session_key | ||
| 95 | end | 95 | end |
| 96 | 96 | ||
| 97 | =begin rdoc | 97 | =begin rdoc |
| @@ -100,8 +100,8 @@ do something out of the ordinary. | @@ -100,8 +100,8 @@ do something out of the ordinary. | ||
| 100 | =end | 100 | =end |
| 101 | def clear_session_keys() #:nodoc: | 101 | def clear_session_keys() #:nodoc: |
| 102 | @@session_keys.clear | 102 | @@session_keys.clear |
| 103 | - end | ||
| 104 | - | 103 | + end |
| 104 | + | ||
| 105 | =begin rdoc | 105 | =begin rdoc |
| 106 | Sets the session_keys array. Only use these if you need to | 106 | Sets the session_keys array. Only use these if you need to |
| 107 | do something out of the ordinary, as it is handled | 107 | do something out of the ordinary, as it is handled |
| @@ -109,17 +109,17 @@ do something out of the ordinary, as it is handled | @@ -109,17 +109,17 @@ do something out of the ordinary, as it is handled | ||
| 109 | def session_keys=(keys) #:nodoc: | 109 | def session_keys=(keys) #:nodoc: |
| 110 | @@session_keys=keys | 110 | @@session_keys=keys |
| 111 | end | 111 | end |
| 112 | - | 112 | + |
| 113 | def session_keys() #:nodoc: | 113 | def session_keys() #:nodoc: |
| 114 | @@session_keys | 114 | @@session_keys |
| 115 | end | 115 | end |
| 116 | - | 116 | + |
| 117 | end | 117 | end |
| 118 | 118 | ||
| 119 | =begin rdoc | 119 | =begin rdoc |
| 120 | This module handles all standard key management features. | 120 | This module handles all standard key management features. |
| 121 | =end | 121 | =end |
| 122 | - module KeyHolder | 122 | + module KeyHolder |
| 123 | 123 | ||
| 124 | =begin rdoc | 124 | =begin rdoc |
| 125 | Creates a key for object based on given password and an optional salt. | 125 | Creates a key for object based on given password and an optional salt. |
| @@ -137,10 +137,10 @@ Decodes the Base64 encoded key and uses it as it's session key | @@ -137,10 +137,10 @@ Decodes the Base64 encoded key and uses it as it's session key | ||
| 137 | =begin rdoc | 137 | =begin rdoc |
| 138 | Sets a session key for the object. This should be a EzCrypto::Key instance. | 138 | Sets a session key for the object. This should be a EzCrypto::Key instance. |
| 139 | =end | 139 | =end |
| 140 | - def set_session_key(key) | 140 | + def set_session_key(key) |
| 141 | @session_key=key | 141 | @session_key=key |
| 142 | self.decrypt_attributes if self.class.include? Encrypted | 142 | self.decrypt_attributes if self.class.include? Encrypted |
| 143 | - end | 143 | + end |
| 144 | 144 | ||
| 145 | =begin rdoc | 145 | =begin rdoc |
| 146 | Returns the session_key | 146 | Returns the session_key |
| @@ -148,28 +148,28 @@ Returns the session_key | @@ -148,28 +148,28 @@ Returns the session_key | ||
| 148 | def session_key | 148 | def session_key |
| 149 | @session_key | 149 | @session_key |
| 150 | end | 150 | end |
| 151 | - | 151 | + |
| 152 | end | 152 | end |
| 153 | 153 | ||
| 154 | - module AssociationKeyHolder | 154 | + module AssociationKeyHolder |
| 155 | include ActiveCrypto::KeyHolder | 155 | include ActiveCrypto::KeyHolder |
| 156 | - | ||
| 157 | - | 156 | + |
| 157 | + | ||
| 158 | def save_session_key | 158 | def save_session_key |
| 159 | ActiveRecord::Base.session_keys[session_key_id]=@session_key if @session_key | 159 | ActiveRecord::Base.session_keys[session_key_id]=@session_key if @session_key |
| 160 | end | 160 | end |
| 161 | =begin rdoc | 161 | =begin rdoc |
| 162 | Sets a session key for the object. This should be a EzCrypto::Key instance. | 162 | Sets a session key for the object. This should be a EzCrypto::Key instance. |
| 163 | =end | 163 | =end |
| 164 | - def set_session_key(key) | 164 | + def set_session_key(key) |
| 165 | if self.new_record? | 165 | if self.new_record? |
| 166 | @session_key=key | 166 | @session_key=key |
| 167 | else | 167 | else |
| 168 | ActiveRecord::Base.session_keys[session_key_id]=key | 168 | ActiveRecord::Base.session_keys[session_key_id]=key |
| 169 | end | 169 | end |
| 170 | decrypt_attributes if self.class.include? Encrypted #if respond_to?(:decrypt_attributes) | 170 | decrypt_attributes if self.class.include? Encrypted #if respond_to?(:decrypt_attributes) |
| 171 | - | ||
| 172 | - end | 171 | + |
| 172 | + end | ||
| 173 | 173 | ||
| 174 | =begin rdoc | 174 | =begin rdoc |
| 175 | Returns the session_key | 175 | Returns the session_key |
| @@ -181,13 +181,13 @@ Returns the session_key | @@ -181,13 +181,13 @@ Returns the session_key | ||
| 181 | ActiveRecord::Base.session_keys[session_key_id] | 181 | ActiveRecord::Base.session_keys[session_key_id] |
| 182 | end | 182 | end |
| 183 | end | 183 | end |
| 184 | - | ||
| 185 | - | 184 | + |
| 185 | + | ||
| 186 | 186 | ||
| 187 | def session_key_id | 187 | def session_key_id |
| 188 | "#{self.class.to_s}:#{id}" | 188 | "#{self.class.to_s}:#{id}" |
| 189 | - end | ||
| 190 | - | 189 | + end |
| 190 | + | ||
| 191 | end | 191 | end |
| 192 | 192 | ||
| 193 | module Encrypted #:nodoc: | 193 | module Encrypted #:nodoc: |
| @@ -195,7 +195,7 @@ Returns the session_key | @@ -195,7 +195,7 @@ Returns the session_key | ||
| 195 | super | 195 | super |
| 196 | base.extend ClassAccessors | 196 | base.extend ClassAccessors |
| 197 | end | 197 | end |
| 198 | - | 198 | + |
| 199 | module ClassAccessors | 199 | module ClassAccessors |
| 200 | def encrypted_attributes | 200 | def encrypted_attributes |
| 201 | @encrypted_attributes||=[] | 201 | @encrypted_attributes||=[] |
| @@ -204,9 +204,9 @@ Returns the session_key | @@ -204,9 +204,9 @@ Returns the session_key | ||
| 204 | def encrypted_attributes=(attrs) | 204 | def encrypted_attributes=(attrs) |
| 205 | @encrypted_attributes=attrs | 205 | @encrypted_attributes=attrs |
| 206 | end | 206 | end |
| 207 | - | 207 | + |
| 208 | end | 208 | end |
| 209 | - | 209 | + |
| 210 | protected | 210 | protected |
| 211 | 211 | ||
| 212 | def encrypt_attributes | 212 | def encrypt_attributes |
| @@ -219,7 +219,7 @@ Returns the session_key | @@ -219,7 +219,7 @@ Returns the session_key | ||
| 219 | end | 219 | end |
| 220 | true | 220 | true |
| 221 | end | 221 | end |
| 222 | - | 222 | + |
| 223 | def decrypt_attributes | 223 | def decrypt_attributes |
| 224 | if is_encrypted? | 224 | if is_encrypted? |
| 225 | self.class.encrypted_attributes.each do |key| | 225 | self.class.encrypted_attributes.each do |key| |
| @@ -230,17 +230,17 @@ Returns the session_key | @@ -230,17 +230,17 @@ Returns the session_key | ||
| 230 | end | 230 | end |
| 231 | true | 231 | true |
| 232 | end | 232 | end |
| 233 | - | 233 | + |
| 234 | def after_find | 234 | def after_find |
| 235 | @is_encrypted=true | 235 | @is_encrypted=true |
| 236 | decrypt_attributes unless session_key.nil? | 236 | decrypt_attributes unless session_key.nil? |
| 237 | end | 237 | end |
| 238 | - | 238 | + |
| 239 | private | 239 | private |
| 240 | def is_encrypted? | 240 | def is_encrypted? |
| 241 | @is_encrypted | 241 | @is_encrypted |
| 242 | end | 242 | end |
| 243 | - | 243 | + |
| 244 | def _decrypt(data) | 244 | def _decrypt(data) |
| 245 | if session_key.nil? | 245 | if session_key.nil? |
| 246 | raise MissingKeyError | 246 | raise MissingKeyError |
| @@ -252,11 +252,11 @@ Returns the session_key | @@ -252,11 +252,11 @@ Returns the session_key | ||
| 252 | end | 252 | end |
| 253 | end | 253 | end |
| 254 | end | 254 | end |
| 255 | - | 255 | + |
| 256 | def _encrypt(data) | 256 | def _encrypt(data) |
| 257 | if session_key.nil? | 257 | if session_key.nil? |
| 258 | raise MissingKeyError | 258 | raise MissingKeyError |
| 259 | - else | 259 | + else |
| 260 | if data | 260 | if data |
| 261 | self.class.ezcrypto_base64? ? session_key.encrypt64(data) : session_key.encrypt(data) | 261 | self.class.ezcrypto_base64? ? session_key.encrypt64(data) : session_key.encrypt(data) |
| 262 | else | 262 | else |
| @@ -264,28 +264,28 @@ Returns the session_key | @@ -264,28 +264,28 @@ Returns the session_key | ||
| 264 | end | 264 | end |
| 265 | end | 265 | end |
| 266 | end | 266 | end |
| 267 | - | 267 | + |
| 268 | end | 268 | end |
| 269 | - | 269 | + |
| 270 | 270 | ||
| 271 | module ActionController # :nodoc: | 271 | module ActionController # :nodoc: |
| 272 | =begin rdoc | 272 | =begin rdoc |
| 273 | This includes some basic support in the ActionController for handling session keys. It creates two filters one before the action and one after. | 273 | This includes some basic support in the ActionController for handling session keys. It creates two filters one before the action and one after. |
| 274 | These do the following: | 274 | These do the following: |
| 275 | - | ||
| 276 | -If the users session already has a 'session_keys' value it loads it into the ActiveRecord::Base.session_keys class field. If not it | 275 | + |
| 276 | +If the users session already has a 'session_keys' value it loads it into the ActiveRecord::Base.session_keys class field. If not it | ||
| 277 | clears any existing session_keys. | 277 | clears any existing session_keys. |
| 278 | 278 | ||
| 279 | Leaving the action it stores any session_keys in the corresponding session variable. | 279 | Leaving the action it stores any session_keys in the corresponding session variable. |
| 280 | 280 | ||
| 281 | These filters are automatically enabled. You do not have to do anything. | 281 | These filters are automatically enabled. You do not have to do anything. |
| 282 | - | 282 | + |
| 283 | To manually clear the session keys call clear_session_keys. This should be done for example as part of a session log off action. | 283 | To manually clear the session keys call clear_session_keys. This should be done for example as part of a session log off action. |
| 284 | -=end | 284 | +=end |
| 285 | def self.append_features(base) #:nodoc: | 285 | def self.append_features(base) #:nodoc: |
| 286 | super | 286 | super |
| 287 | base.send :prepend_before_filter, :load_session_keys | 287 | base.send :prepend_before_filter, :load_session_keys |
| 288 | - base.send :prepend_after_filter, :save_session_keys | 288 | + base.send :prepend_after_filter, :save_session_keys |
| 289 | end | 289 | end |
| 290 | 290 | ||
| 291 | =begin rdoc | 291 | =begin rdoc |
| @@ -294,8 +294,8 @@ Clears the session keys. Call this when a user logs of. | @@ -294,8 +294,8 @@ Clears the session keys. Call this when a user logs of. | ||
| 294 | def clear_session_keys | 294 | def clear_session_keys |
| 295 | ActiveRecord::Base.clear_session_keys | 295 | ActiveRecord::Base.clear_session_keys |
| 296 | end | 296 | end |
| 297 | - | ||
| 298 | - | 297 | + |
| 298 | + | ||
| 299 | private | 299 | private |
| 300 | def load_session_keys | 300 | def load_session_keys |
| 301 | if session['session_keys'] | 301 | if session['session_keys'] |
| @@ -312,14 +312,12 @@ Clears the session keys. Call this when a user logs of. | @@ -312,14 +312,12 @@ Clears the session keys. Call this when a user logs of. | ||
| 312 | session['session_keys']=nil | 312 | session['session_keys']=nil |
| 313 | end | 313 | end |
| 314 | end | 314 | end |
| 315 | - | 315 | + |
| 316 | 316 | ||
| 317 | end | 317 | end |
| 318 | 318 | ||
| 319 | class MissingKeyError < RuntimeError | 319 | class MissingKeyError < RuntimeError |
| 320 | -end | 320 | +end |
| 321 | end | 321 | end |
| 322 | ActiveRecord::Base.send :include, ActiveCrypto | 322 | ActiveRecord::Base.send :include, ActiveCrypto |
| 323 | -require 'actionpack' | ||
| 324 | -require 'action_controller' | ||
| 325 | ActionController::Base.send :include, ActiveCrypto::ActionController | 323 | ActionController::Base.send :include, ActiveCrypto::ActionController |
vendor/plugins/access_control/init.rb
| 1 | +require 'access_control' | ||
| 1 | require 'acts_as_accessor' | 2 | require 'acts_as_accessor' |
| 2 | require 'acts_as_accessible' | 3 | require 'acts_as_accessible' |
| 3 | require 'permission_name_helper' | 4 | require 'permission_name_helper' |
| 5 | +require 'role' | ||
| 6 | +require 'role_assignment' | ||
| 7 | +require 'permission_check' | ||
| 8 | + | ||
| 4 | module ApplicationHelper | 9 | module ApplicationHelper |
| 5 | include PermissionNameHelper | 10 | include PermissionNameHelper |
| 6 | end | 11 | end |
vendor/plugins/action_tracker/lib/action_tracker.rb
| 1 | require File.join(File.dirname(__FILE__), 'action_tracker_model.rb') | 1 | require File.join(File.dirname(__FILE__), 'action_tracker_model.rb') |
| 2 | +require 'user_stamp' | ||
| 2 | 3 | ||
| 3 | module ActionTracker | 4 | module ActionTracker |
| 4 | 5 | ||
| @@ -8,21 +9,21 @@ module ActionTracker | @@ -8,21 +9,21 @@ module ActionTracker | ||
| 8 | base.send :user_stamp, ActionTracker::Record | 9 | base.send :user_stamp, ActionTracker::Record |
| 9 | base.send :extend, ClassMethods | 10 | base.send :extend, ClassMethods |
| 10 | end | 11 | end |
| 11 | - | 12 | + |
| 12 | module ClassMethods | 13 | module ClassMethods |
| 13 | 14 | ||
| 14 | def track_actions_after(verb, options = {}, &block) | 15 | def track_actions_after(verb, options = {}, &block) |
| 15 | track_actions_by_time(verb, :after, options, &block) | 16 | track_actions_by_time(verb, :after, options, &block) |
| 16 | end | 17 | end |
| 17 | - | 18 | + |
| 18 | def track_actions_before(verb, options = {}, &block) | 19 | def track_actions_before(verb, options = {}, &block) |
| 19 | track_actions_by_time(verb, :before, options, &block) | 20 | track_actions_by_time(verb, :before, options, &block) |
| 20 | end | 21 | end |
| 21 | - | 22 | + |
| 22 | def track_actions(verb, options = {}, &block) | 23 | def track_actions(verb, options = {}, &block) |
| 23 | track_actions_by_time(verb, ActionTrackerConfig.default_filter_time, options, &block) | 24 | track_actions_by_time(verb, ActionTrackerConfig.default_filter_time, options, &block) |
| 24 | end | 25 | end |
| 25 | - | 26 | + |
| 26 | def track_actions_by_time(verb, time, options = {}, &block) | 27 | def track_actions_by_time(verb, time, options = {}, &block) |
| 27 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all | 28 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all |
| 28 | send("#{time}_filter", options) do |x| | 29 | send("#{time}_filter", options) do |x| |
| @@ -32,7 +33,7 @@ module ActionTracker | @@ -32,7 +33,7 @@ module ActionTracker | ||
| 32 | send :include, InstanceMethods | 33 | send :include, InstanceMethods |
| 33 | end | 34 | end |
| 34 | end | 35 | end |
| 35 | - | 36 | + |
| 36 | module InstanceMethods | 37 | module InstanceMethods |
| 37 | def save_action_for_verb(verb, keep_params = :all) | 38 | def save_action_for_verb(verb, keep_params = :all) |
| 38 | if keep_params.is_a? Array | 39 | if keep_params.is_a? Array |
| @@ -62,7 +63,7 @@ module ActionTracker | @@ -62,7 +63,7 @@ module ActionTracker | ||
| 62 | def self.included(base) | 63 | def self.included(base) |
| 63 | base.send :extend, ClassMethods | 64 | base.send :extend, ClassMethods |
| 64 | end | 65 | end |
| 65 | - | 66 | + |
| 66 | module ClassMethods | 67 | module ClassMethods |
| 67 | def track_actions(verb, callback, options = {}, &block) | 68 | def track_actions(verb, callback, options = {}, &block) |
| 68 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all | 69 | keep_params = options.delete(:keep_params) || options.delete('keep_params') || :all |
| @@ -78,11 +79,11 @@ module ActionTracker | @@ -78,11 +79,11 @@ module ActionTracker | ||
| 78 | send :include, InstanceMethods | 79 | send :include, InstanceMethods |
| 79 | end | 80 | end |
| 80 | end | 81 | end |
| 81 | - | 82 | + |
| 82 | module InstanceMethods | 83 | module InstanceMethods |
| 83 | def time_spent_doing(verb, conditions = {}) | 84 | def time_spent_doing(verb, conditions = {}) |
| 84 | time = 0 | 85 | time = 0 |
| 85 | - tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t| | 86 | + tracked_actions.all(:conditions => conditions.merge({ :verb => verb.to_s })).each do |t| |
| 86 | time += t.updated_at - t.created_at | 87 | time += t.updated_at - t.created_at |
| 87 | end | 88 | end |
| 88 | time.to_f | 89 | time.to_f |
vendor/plugins/action_tracker/lib/action_tracker_model.rb
| @@ -2,7 +2,7 @@ module ActionTracker | @@ -2,7 +2,7 @@ module ActionTracker | ||
| 2 | class Record < ActiveRecord::Base | 2 | class Record < ActiveRecord::Base |
| 3 | attr_accessible :verb, :params, :user, :target | 3 | attr_accessible :verb, :params, :user, :target |
| 4 | 4 | ||
| 5 | - set_table_name 'action_tracker' | 5 | + self.table_name = 'action_tracker' |
| 6 | 6 | ||
| 7 | belongs_to :user, :polymorphic => true | 7 | belongs_to :user, :polymorphic => true |
| 8 | belongs_to :target, :polymorphic => true | 8 | belongs_to :target, :polymorphic => true |
vendor/plugins/acts_as_tree/init.rb
vendor/plugins/user_stamp/init.rb
vendor/plugins/user_stamp/lib/user_stamp.rb
| @@ -2,19 +2,19 @@ module UserStamp | @@ -2,19 +2,19 @@ module UserStamp | ||
| 2 | mattr_accessor :creator_attribute | 2 | mattr_accessor :creator_attribute |
| 3 | mattr_accessor :updater_attribute | 3 | mattr_accessor :updater_attribute |
| 4 | mattr_accessor :current_user_method | 4 | mattr_accessor :current_user_method |
| 5 | - | 5 | + |
| 6 | def self.creator_assignment_method | 6 | def self.creator_assignment_method |
| 7 | "#{UserStamp.creator_attribute}=" | 7 | "#{UserStamp.creator_attribute}=" |
| 8 | end | 8 | end |
| 9 | - | 9 | + |
| 10 | def self.updater_assignment_method | 10 | def self.updater_assignment_method |
| 11 | "#{UserStamp.updater_attribute}=" | 11 | "#{UserStamp.updater_attribute}=" |
| 12 | end | 12 | end |
| 13 | - | 13 | + |
| 14 | module ClassMethods | 14 | module ClassMethods |
| 15 | def user_stamp(*models) | 15 | def user_stamp(*models) |
| 16 | models.each { |klass| UserStampSweeper.observe(klass) } | 16 | models.each { |klass| UserStampSweeper.observe(klass) } |
| 17 | - | 17 | + |
| 18 | class_eval do | 18 | class_eval do |
| 19 | cache_sweeper :user_stamp_sweeper | 19 | cache_sweeper :user_stamp_sweeper |
| 20 | end | 20 | end |
| @@ -26,25 +26,34 @@ UserStamp.creator_attribute = :creator_id | @@ -26,25 +26,34 @@ UserStamp.creator_attribute = :creator_id | ||
| 26 | UserStamp.updater_attribute = :updater_id | 26 | UserStamp.updater_attribute = :updater_id |
| 27 | UserStamp.current_user_method = :current_user | 27 | UserStamp.current_user_method = :current_user |
| 28 | 28 | ||
| 29 | +# see https://github.com/rails/rails-observers/issues/4 | ||
| 30 | +require 'rails/observers/active_model/active_model' | ||
| 31 | +require "rails/observers/activerecord/active_record" | ||
| 32 | +require 'rails/observers/action_controller/caching' | ||
| 33 | + | ||
| 29 | class UserStampSweeper < ActionController::Caching::Sweeper | 34 | class UserStampSweeper < ActionController::Caching::Sweeper |
| 30 | def before_validation(record) | 35 | def before_validation(record) |
| 31 | return unless current_user | 36 | return unless current_user |
| 32 | - | 37 | + |
| 33 | attribute, method = UserStamp.creator_attribute, UserStamp.creator_assignment_method | 38 | attribute, method = UserStamp.creator_attribute, UserStamp.creator_assignment_method |
| 34 | if record.respond_to?(method) && record.new_record? | 39 | if record.respond_to?(method) && record.new_record? |
| 35 | record.send(method, current_user) unless record.send("#{attribute}_id_changed?") || record.send("#{attribute}_type_changed?") | 40 | record.send(method, current_user) unless record.send("#{attribute}_id_changed?") || record.send("#{attribute}_type_changed?") |
| 36 | end | 41 | end |
| 37 | - | 42 | + |
| 38 | attribute, method = UserStamp.updater_attribute, UserStamp.updater_assignment_method | 43 | attribute, method = UserStamp.updater_attribute, UserStamp.updater_assignment_method |
| 39 | if record.respond_to?(method) | 44 | if record.respond_to?(method) |
| 40 | record.send(method, current_user) if record.send(attribute).blank? | 45 | record.send(method, current_user) if record.send(attribute).blank? |
| 41 | end | 46 | end |
| 42 | end | 47 | end |
| 43 | - | ||
| 44 | - private | 48 | + |
| 49 | + private | ||
| 45 | def current_user | 50 | def current_user |
| 46 | if controller.respond_to?(UserStamp.current_user_method) | 51 | if controller.respond_to?(UserStamp.current_user_method) |
| 47 | controller.send UserStamp.current_user_method | 52 | controller.send UserStamp.current_user_method |
| 48 | end | 53 | end |
| 49 | end | 54 | end |
| 50 | end | 55 | end |
| 56 | + | ||
| 57 | +class ActionController::Base | ||
| 58 | + extend UserStamp::ClassMethods | ||
| 59 | +end |