Browse Source

custom stamping

pull/1/head
Nicolae Claudius 10 years ago
parent
commit
944b7ae77e
  1. 7
      Gemfile
  2. 92
      Gemfile.lock
  3. 11
      app/controllers/users_controller.rb
  4. 19
      app/models/concerns/stampable.rb
  5. 2
      app/models/domain.rb
  6. 2
      app/models/permission.rb
  7. 2
      app/models/record.rb
  8. 5
      app/models/user.rb

7
Gemfile

@ -1,11 +1,11 @@
source 'http://rubygems.org' source 'http://rubygems.org'
# Core # Core
gem 'rails', '4.1.1' gem 'rails', '4.0.5'
gem 'mysql2', '~> 0.3.13' gem 'mysql2', '~> 0.3.13'
# Auth # Auth
gem 'devise', '~> 3.2.2' gem 'devise', '~> 3.1.1'
gem 'omniauth', '~> 1.2.1' gem 'omniauth', '~> 1.2.1'
gem 'omniauth-google-oauth2', '~> 0.2.2' gem 'omniauth-google-oauth2', '~> 0.2.2'
gem 'cancan', '= 1.6.7' gem 'cancan', '= 1.6.7'
@ -14,7 +14,6 @@ gem 'switch_user', '~> 0.9.3'
# ActiveRecord # ActiveRecord
gem 'squeel', '~> 1.1.0' gem 'squeel', '~> 1.1.0'
gem 'sentient_model', '~> 1.0.4' gem 'sentient_model', '~> 1.0.4'
gem 'userstamp', '~> 2.0.2', github: 'kimkong/userstamp'
gem 'nilify_blanks', '~> 1.0.2' gem 'nilify_blanks', '~> 1.0.2'
gem 'active-model-email-validator', '~> 1.0.2' gem 'active-model-email-validator', '~> 1.0.2'
gem 'concerned_with', '~> 0.1.0' gem 'concerned_with', '~> 0.1.0'
@ -38,7 +37,7 @@ gem 'rails_config', '~> 0.4.2'
gem 'rails-settings-cached', '~> 0.4.0' gem 'rails-settings-cached', '~> 0.4.0'
# Other # Other
gem 'acts_as_nested_interval', '~> 0.1.0' gem 'acts_as_nested_interval', '~> 0.1.1'
gem 'seedbank', '~> 0.3.0' gem 'seedbank', '~> 0.3.0'
gem 'unicorn', '~> 4.8.3' gem 'unicorn', '~> 4.8.3'
gem 'dalli', '~> 2.7.0' gem 'dalli', '~> 2.7.0'

92
Gemfile.lock

@ -17,12 +17,6 @@ GIT
specs: specs:
navigasmic (0.5.6) navigasmic (0.5.6)
GIT
remote: git://github.com/kimkong/userstamp.git
revision: fbb35ccb5004bb04f87e01cbe9b7a5ccdd06b856
specs:
userstamp (2.0.2)
PATH PATH
remote: vendor/cache/active_scaffold remote: vendor/cache/active_scaffold
specs: specs:
@ -32,45 +26,45 @@ PATH
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
actionmailer (4.1.1) actionmailer (4.0.5)
actionpack (= 4.1.1) actionpack (= 4.0.5)
actionview (= 4.1.1)
mail (~> 2.5.4) mail (~> 2.5.4)
actionpack (4.1.1) actionpack (4.0.5)
actionview (= 4.1.1) activesupport (= 4.0.5)
activesupport (= 4.1.1) builder (~> 3.1.0)
erubis (~> 2.7.0)
rack (~> 1.5.2) rack (~> 1.5.2)
rack-test (~> 0.6.2) rack-test (~> 0.6.2)
actionview (4.1.1)
activesupport (= 4.1.1)
builder (~> 3.1)
erubis (~> 2.7.0)
active-model-email-validator (1.0.2) active-model-email-validator (1.0.2)
activemodel activemodel
mail mail
activemodel (4.1.1) activemodel (4.0.5)
activesupport (= 4.1.1) activesupport (= 4.0.5)
builder (~> 3.1) builder (~> 3.1.0)
activerecord (4.1.1) activerecord (4.0.5)
activemodel (= 4.1.1) activemodel (= 4.0.5)
activesupport (= 4.1.1) activerecord-deprecated_finders (~> 1.0.2)
arel (~> 5.0.0) activesupport (= 4.0.5)
activesupport (4.1.1) arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.5)
i18n (~> 0.6, >= 0.6.9) i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7) minitest (~> 4.2)
minitest (~> 5.1) multi_json (~> 1.3)
thread_safe (~> 0.1) thread_safe (~> 0.1)
tzinfo (~> 1.1) tzinfo (~> 0.3.37)
acts_as_nested_interval (0.1.1) acts_as_nested_interval (0.1.1)
rails (>= 3.2.1, < 5) rails (>= 3.2.1, < 5)
addressable (2.3.6) addressable (2.3.6)
arel (5.0.1.20140414130214) arel (4.0.2)
aws-ses (0.5.0) aws-ses (0.5.0)
builder builder
mail (> 2.2.5) mail (> 2.2.5)
mime-types mime-types
xml-simple xml-simple
bcrypt (3.1.7) bcrypt (3.1.7)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
better_errors (1.1.0) better_errors (1.1.0)
coderay (>= 1.0.0) coderay (>= 1.0.0)
erubis (>= 2.6.6) erubis (>= 2.6.6)
@ -78,7 +72,7 @@ GEM
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
bootstrap-sass (3.1.1.1) bootstrap-sass (3.1.1.1)
sass (~> 3.2) sass (~> 3.2)
builder (3.2.2) builder (3.1.4)
bullet (4.9.0) bullet (4.9.0)
activesupport activesupport
uniform_notifier (~> 1.6.0) uniform_notifier (~> 1.6.0)
@ -114,8 +108,8 @@ GEM
debugger-ruby_core_source (1.3.5) debugger-ruby_core_source (1.3.5)
detect_timezone_rails (0.0.5) detect_timezone_rails (0.0.5)
railties (>= 3.1) railties (>= 3.1)
devise (3.2.4) devise (3.1.2)
bcrypt (~> 3.0) bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5) railties (>= 3.2.6, < 5)
thread_safe (~> 0.1) thread_safe (~> 0.1)
@ -164,7 +158,7 @@ GEM
activemodel (>= 3.2, < 5) activemodel (>= 3.2, < 5)
mime-types (1.25.1) mime-types (1.25.1)
mini_portile (0.6.0) mini_portile (0.6.0)
minitest (5.3.4) minitest (4.7.5)
multi_json (1.10.1) multi_json (1.10.1)
multi_xml (0.5.5) multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
@ -209,16 +203,14 @@ GEM
rack (~> 1.3) rack (~> 1.3)
rack-test (0.6.2) rack-test (0.6.2)
rack (>= 1.0) rack (>= 1.0)
rails (4.1.1) rails (4.0.5)
actionmailer (= 4.1.1) actionmailer (= 4.0.5)
actionpack (= 4.1.1) actionpack (= 4.0.5)
actionview (= 4.1.1) activerecord (= 4.0.5)
activemodel (= 4.1.1) activesupport (= 4.0.5)
activerecord (= 4.1.1)
activesupport (= 4.1.1)
bundler (>= 1.3.0, < 2.0) bundler (>= 1.3.0, < 2.0)
railties (= 4.1.1) railties (= 4.0.5)
sprockets-rails (~> 2.0) sprockets-rails (~> 2.0.0)
rails-settings-cached (0.4.1) rails-settings-cached (0.4.1)
rails (>= 4.0.0) rails (>= 4.0.0)
rails_admin (0.6.2) rails_admin (0.6.2)
@ -237,9 +229,9 @@ GEM
sass-rails (~> 4.0) sass-rails (~> 4.0)
rails_config (0.4.2) rails_config (0.4.2)
activesupport (>= 3.0) activesupport (>= 3.0)
railties (4.1.1) railties (4.0.5)
actionpack (= 4.1.1) actionpack (= 4.0.5)
activesupport (= 4.1.1) activesupport (= 4.0.5)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
raindrops (0.13.0) raindrops (0.13.0)
@ -280,7 +272,7 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
rack (~> 1.0) rack (~> 1.0)
tilt (~> 1.1, != 1.3.0) tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.1.3) sprockets-rails (2.0.1)
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (~> 2.8) sprockets (~> 2.8)
@ -303,8 +295,7 @@ GEM
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
turbolinks (2.2.2) turbolinks (2.2.2)
coffee-rails coffee-rails
tzinfo (1.1.0) tzinfo (0.3.39)
thread_safe (~> 0.1)
uglifier (2.4.0) uglifier (2.4.0)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
@ -327,7 +318,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
active-model-email-validator (~> 1.0.2) active-model-email-validator (~> 1.0.2)
active_scaffold (~> 3.4.0.rc)! active_scaffold (~> 3.4.0.rc)!
acts_as_nested_interval (~> 0.1.0) acts_as_nested_interval (~> 0.1.1)
aws-ses (~> 0.5.0) aws-ses (~> 0.5.0)
better_errors (= 1.1.0) better_errors (= 1.1.0)
binding_of_caller (= 0.7.2) binding_of_caller (= 0.7.2)
@ -342,7 +333,7 @@ DEPENDENCIES
database_rewinder (~> 0.2.0) database_rewinder (~> 0.2.0)
debase (~> 0.0.7) debase (~> 0.0.7)
detect_timezone_rails (~> 0.0.3) detect_timezone_rails (~> 0.0.3)
devise (~> 3.2.2) devise (~> 3.1.1)
factory_girl_rails (~> 4.4.1) factory_girl_rails (~> 4.4.1)
faker (~> 1.3.0) faker (~> 1.3.0)
font-awesome-rails (~> 4.1.0.0) font-awesome-rails (~> 4.1.0.0)
@ -359,7 +350,7 @@ DEPENDENCIES
omniauth-google-oauth2 (~> 0.2.2) omniauth-google-oauth2 (~> 0.2.2)
paper_trail (~> 3.0.0) paper_trail (~> 3.0.0)
quiet_assets (~> 1.0.1) quiet_assets (~> 1.0.1)
rails (= 4.1.1) rails (= 4.0.5)
rails-settings-cached (~> 0.4.0) rails-settings-cached (~> 0.4.0)
rails_admin (~> 0.6.1) rails_admin (~> 0.6.1)
rails_config (~> 0.4.2) rails_config (~> 0.4.2)
@ -374,6 +365,5 @@ DEPENDENCIES
turbolinks (~> 2.2.1) turbolinks (~> 2.2.1)
uglifier (~> 2.4.0) uglifier (~> 2.4.0)
unicorn (~> 4.8.3) unicorn (~> 4.8.3)
userstamp (~> 2.0.2)!
validates_hostname (~> 1.0.0)! validates_hostname (~> 1.0.0)!
webshims-rails (~> 1.12.2) webshims-rails (~> 1.12.2)

11
app/controllers/users_controller.rb

@ -1,7 +1,7 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :set_stampers before_filter :set_user_current
include Userstamp after_filter :unset_user_current
layout :scoped_layout layout :scoped_layout
rescue_from CanCan::AccessDenied, ActiveScaffold::ActionNotAllowed do |exception| rescue_from CanCan::AccessDenied, ActiveScaffold::ActionNotAllowed do |exception|
@ -11,9 +11,12 @@ class UsersController < ApplicationController
protected protected
def set_stampers def set_user_current
User.current = current_user User.current = current_user
User.stamper = current_user end
def unset_user_current
User.current = nil
end end
def ensure_nested_under_domain def ensure_nested_under_domain

19
app/models/concerns/stampable.rb

@ -0,0 +1,19 @@
module Stampable
extend ActiveSupport::Concern
included do
belongs_to :creator, :class_name => 'User'
belongs_to :updator, :class_name => 'User'
before_create :set_creator_attribute
before_save :set_updator_attribute
end
def set_creator_attribute
self.creator = User.current
end
def set_updator_attribute
self.updator = User.current
end
end

2
app/models/domain.rb

@ -1,7 +1,7 @@
class Domain < ActiveRecord::Base class Domain < ActiveRecord::Base
self.inheritance_column = :sti_disabled self.inheritance_column = :sti_disabled
nilify_blanks nilify_blanks
stampable include Stampable
has_paper_trail has_paper_trail
# optional IP for create form, results in a type A record # optional IP for create form, results in a type A record

2
app/models/permission.rb

@ -1,5 +1,5 @@
class Permission < ActiveRecord::Base class Permission < ActiveRecord::Base
stampable include Stampable
has_paper_trail has_paper_trail
belongs_to :domain, :inverse_of => :permissions belongs_to :domain, :inverse_of => :permissions

2
app/models/record.rb

@ -1,5 +1,5 @@
class Record < ActiveRecord::Base class Record < ActiveRecord::Base
stampable include Stampable
belongs_to :domain, :inverse_of => :records belongs_to :domain, :inverse_of => :records
belongs_to :user, :inverse_of => :records belongs_to :user, :inverse_of => :records

5
app/models/user.rb

@ -1,7 +1,6 @@
class User < ActiveRecord::Base class User < ActiveRecord::Base
include SentientModel include SentientModel
model_stamper include Stampable
stampable
has_paper_trail has_paper_trail
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
@ -80,10 +79,8 @@ class User < ActiveRecord::Base
def self.do_as(user) def self.do_as(user)
self.current = user self.current = user
self.stamper = user
yield yield
self.current = nil self.current = nil
self.reset_stamper
end end
protected protected

Loading…
Cancel
Save