user_stamp 0.0.2
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +65 -0
- data/Rakefile +40 -0
- data/config/routes.rb +28 -0
- data/lib/generators/user_stamp/USAGE +9 -0
- data/lib/generators/user_stamp/templates/user_stamp.template +26 -0
- data/lib/generators/user_stamp/user_stamp_generator.rb +34 -0
- data/lib/tasks/user_stamp_tasks.rake +4 -0
- data/lib/user_stamp.rb +36 -0
- data/lib/user_stamp/app_controller.rb +40 -0
- data/lib/user_stamp/config.rb +60 -0
- data/lib/user_stamp/engine.rb +37 -0
- data/lib/user_stamp/user.rb +41 -0
- data/lib/user_stamp/user_stamp.rb +62 -0
- data/lib/user_stamp/version.rb +29 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/materials.js +2 -0
- data/test/dummy/app/assets/javascripts/products.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/materials.css +4 -0
- data/test/dummy/app/assets/stylesheets/products.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +33 -0
- data/test/dummy/app/controllers/materials_controller.rb +83 -0
- data/test/dummy/app/controllers/products_controller.rb +83 -0
- data/test/dummy/app/helpers/application_helper.rb +28 -0
- data/test/dummy/app/helpers/materials_helper.rb +28 -0
- data/test/dummy/app/helpers/products_helper.rb +28 -0
- data/test/dummy/app/models/material.rb +43 -0
- data/test/dummy/app/models/product.rb +40 -0
- data/test/dummy/app/models/user.rb +36 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/materials/_form.html.erb +33 -0
- data/test/dummy/app/views/materials/edit.html.erb +6 -0
- data/test/dummy/app/views/materials/index.html.erb +29 -0
- data/test/dummy/app/views/materials/new.html.erb +6 -0
- data/test/dummy/app/views/materials/show.html.erb +28 -0
- data/test/dummy/app/views/products/_form.html.erb +33 -0
- data/test/dummy/app/views/products/edit.html.erb +6 -0
- data/test/dummy/app/views/products/index.html.erb +29 -0
- data/test/dummy/app/views/products/new.html.erb +5 -0
- data/test/dummy/app/views/products/show.html.erb +25 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/devise.rb +259 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/user_stamp.rb +26 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/devise.en.yml +60 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +7 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20150418012302_devise_create_users.rb +43 -0
- data/test/dummy/db/migrate/20150418013334_create_products.rb +13 -0
- data/test/dummy/db/migrate/20150420023321_create_materials.rb +13 -0
- data/test/dummy/db/schema.rb +55 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +168 -0
- data/test/dummy/log/test.log +5481 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/functional/materials_controller_test.rb +98 -0
- data/test/dummy/test/functional/products_controller_test.rb +99 -0
- data/test/dummy/test/unit/helpers/materials_helper_test.rb +30 -0
- data/test/dummy/test/unit/helpers/products_helper_test.rb +30 -0
- data/test/dummy/test/unit/material_test.rb +33 -0
- data/test/dummy/test/unit/product_test.rb +33 -0
- data/test/dummy/test/unit/user_test.rb +33 -0
- data/test/fixtures/materials.yml +51 -0
- data/test/fixtures/products.yml +51 -0
- data/test/fixtures/users.yml +40 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +45 -0
- data/test/user_stamp_test.rb +33 -0
- metadata +248 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 778222999ec6c78d8a08b51f23524cab1bd169cb
|
4
|
+
data.tar.gz: 53a6b9114afb779991d02bb17a214d2c5f427fe6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe1892f8678cc327238def83455311654ae78a022d77e8724c2029c0f4c2ae879be209cfca6ea5e7ba7ae08977f267c57b6c00af6ccf190ea22ca370fe5f3f82
|
7
|
+
data.tar.gz: a9ad277a20c3cf4da3f77bbdc7112d125245cd56473a79ce1d9699d5089510679ee7d45d5ee75258fdec1c9cec043adc3289e5087046d449b7c29d456f407013
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 PD Technology Solutions, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
= UserStamp
|
2
|
+
Provides the functionality to automatically update records in the database with the logged in users identity. Alleviates the need to update the identify of the user for every save, update or destroy.
|
3
|
+
|
4
|
+
This gem has been build using ruby v2.1.2 and rails 3.2.x
|
5
|
+
|
6
|
+
|
7
|
+
== Requirements
|
8
|
+
Users must be logged into the system so there is a current_user object. Authentication engines such as Devise provides this object.
|
9
|
+
By default the identify field is called login_name. The login_name field is a string in the User model/table.
|
10
|
+
|
11
|
+
|
12
|
+
== Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'user_stamp'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install user_stamp
|
25
|
+
|
26
|
+
|
27
|
+
== Setup
|
28
|
+
1. After including the gem in you project, run:
|
29
|
+
rails generate user_stamp install
|
30
|
+
This copies the config file to /config/initilizers/user_stamp.rb
|
31
|
+
|
32
|
+
2. In the ApplicationController file add the line:
|
33
|
+
before_filter :set_user_stamp
|
34
|
+
|
35
|
+
3. In each /app/model/{file}, include UserStamp
|
36
|
+
|
37
|
+
4. Add the user identity fields to each table. If you do not need to store one of the fields, simply do not add it to the model.
|
38
|
+
The identity fields must be named: created_user, updated_user and destroy_user.
|
39
|
+
If you are storing the login_name or email, make these fields of type string.
|
40
|
+
If you are storing the id value, then make these field of type integer in the database.
|
41
|
+
|
42
|
+
That's it. Enjoy.
|
43
|
+
|
44
|
+
|
45
|
+
== Deficencies
|
46
|
+
In future versions the three identity fields should be made configurable.
|
47
|
+
The tree identify field (created_user, updated_user and destory_user) needs to be manually added to each table. A rails generate script might be included in future versions to automatically create the migration to add the fields.
|
48
|
+
Also a short cut marco needs to be added to ease the adding of the identify fields.
|
49
|
+
|
50
|
+
== License
|
51
|
+
|
52
|
+
This library is free software and utilizes the MIT License. Please refer to the MIT-LICENSE file for details.
|
53
|
+
|
54
|
+
|
55
|
+
== Acknowledgments
|
56
|
+
|
57
|
+
PD Technology Solutions provides this gem AS-IS with no warrenty.
|
58
|
+
All copyrights, 2015, reserved. You may fork this code for your own purposes, however credit to PD Technology Solutions must be included.
|
59
|
+
|
60
|
+
|
61
|
+
== Change Log
|
62
|
+
|
63
|
+
4/19/15 v0.0.2 - First working version completed.
|
64
|
+
|
65
|
+
4/17/15 V0.0.1 - Initial Commit
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'UserStamp'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
data/config/routes.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# This file is part of the UserStamp library that provides tools to
|
2
|
+
# track who created, updated, or destroyed a record in the database.
|
3
|
+
#
|
4
|
+
# https://github.com/mjpete3/user_stamp
|
5
|
+
#
|
6
|
+
# Copyright (C) 2015 PD Technology Solutions, LLC
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
Rails.application.routes.draw do
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Initilization file for UserStamp gem
|
4
|
+
#
|
5
|
+
UserStamp.configure do |config|
|
6
|
+
|
7
|
+
# ===== Config.current_user =====
|
8
|
+
# Set the name of the user object created when checking authentication
|
9
|
+
# By default uses the current_user object that devise creates
|
10
|
+
# need to make sure that the user_field is defined within the user object
|
11
|
+
|
12
|
+
# Default
|
13
|
+
# config.current_user = :current_user
|
14
|
+
|
15
|
+
|
16
|
+
# ===== Config.user_field ======
|
17
|
+
# The field within the user object / user database that is stored for each record in the database
|
18
|
+
# To change the behavior to store the user.id field use the following config:
|
19
|
+
# config.user_field = :id
|
20
|
+
# To store the user's email use the following config:
|
21
|
+
# config.user_field = :email
|
22
|
+
|
23
|
+
# Default
|
24
|
+
# config.user_field = :login_name
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# This file is part of the UserStamp library that provides tools to
|
2
|
+
# track who created, updated, or destroyed a record in the database.
|
3
|
+
#
|
4
|
+
# https://github.com/mjpete3/user_stamp
|
5
|
+
#
|
6
|
+
# Copyright (C) 2015 PD Technology Solutions, LLC
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
class UserStampGenerator < Rails::Generators::NamedBase
|
28
|
+
source_root File.expand_path('../templates', __FILE__)
|
29
|
+
|
30
|
+
# copies the user_stamp template to the initializer directory
|
31
|
+
def copy_initializer_file
|
32
|
+
copy_file "user_stamp.template", "config/initializers/user_stamp.rb"
|
33
|
+
end
|
34
|
+
end
|
data/lib/user_stamp.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# This file is part of the UserStamp library that provides tools to
|
2
|
+
# track who created, updated, or destroyed a record in the database.
|
3
|
+
#
|
4
|
+
# https://github.com/mjpete3/user_stamp
|
5
|
+
#
|
6
|
+
# Copyright (C) 2015 PD Technology Solutions, LLC
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
require 'devise'
|
28
|
+
|
29
|
+
require "user_stamp/engine"
|
30
|
+
require "user_stamp/config"
|
31
|
+
require "user_stamp/user_stamp"
|
32
|
+
require "user_stamp/app_controller"
|
33
|
+
require "user_stamp/user"
|
34
|
+
|
35
|
+
module UserStamp
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# This file is part of the UserStamp library that provides tools to
|
2
|
+
# track who created, updated, or destroyed a record in the database.
|
3
|
+
#
|
4
|
+
# https://github.com/mjpete3/user_stamp
|
5
|
+
#
|
6
|
+
# Copyright (C) 2015 PD Technology Solutions, LLC
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
|
28
|
+
module UserStamp
|
29
|
+
module AppController
|
30
|
+
|
31
|
+
#
|
32
|
+
# Called by the main application using a :before_filter
|
33
|
+
#
|
34
|
+
def set_user_stamp
|
35
|
+
# use the current_user configuration as an object within the main app
|
36
|
+
User.current = self.send(UserStamp.configuration.current_user)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# This file is part of the UserStamp library that provides tools to
|
2
|
+
# track who created, updated, or destroyed a record in the database.
|
3
|
+
#
|
4
|
+
# https://github.com/mjpete3/user_stamp
|
5
|
+
#
|
6
|
+
# Copyright (C) 2015 PD Technology Solutions, LLC
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
require 'active_support/configurable'
|
28
|
+
|
29
|
+
module UserStamp
|
30
|
+
#
|
31
|
+
# Configures global settings for UserStamp
|
32
|
+
# UserStamp.configure do |config|
|
33
|
+
# config.user_field = [:login_name]
|
34
|
+
# end
|
35
|
+
|
36
|
+
|
37
|
+
def self.configuration
|
38
|
+
@config ||= Configuration.new
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Global settings for UserStamp
|
43
|
+
def self.configure
|
44
|
+
yield configuration
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
class Configuration
|
49
|
+
include ActiveSupport::Configurable
|
50
|
+
config_accessor :current_user
|
51
|
+
config_accessor :user_field
|
52
|
+
|
53
|
+
# set the defaults
|
54
|
+
def initialize
|
55
|
+
self.current_user = :current_user
|
56
|
+
self.user_field = :login_name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This file is part of the UserStamp library that provides tools to
|
2
|
+
# track who created, updated, or destroyed a record in the database.
|
3
|
+
#
|
4
|
+
# https://github.com/mjpete3/user_stamp
|
5
|
+
#
|
6
|
+
# Copyright (C) 2015 PD Technology Solutions, LLC
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
module UserStamp
|
28
|
+
class Engine < ::Rails::Engine
|
29
|
+
|
30
|
+
# initialize the ActionController so the methods in AppController are
|
31
|
+
# available in the main application_controller
|
32
|
+
initializer "userstamp.load_helpers" do |app|
|
33
|
+
ActionController::Base.send :include, UserStamp::AppController
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# This file is part of the UserStamp library that provides tools to
|
2
|
+
# track who created, updated, or destroyed a record in the database.
|
3
|
+
#
|
4
|
+
# https://github.com/mjpete3/user_stamp
|
5
|
+
#
|
6
|
+
# Copyright (C) 2015 PD Technology Solutions, LLC
|
7
|
+
#
|
8
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
# a copy of this software and associated documentation files (the
|
10
|
+
# "Software"), to deal in the Software without restriction, including
|
11
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
# the following conditions:
|
15
|
+
#
|
16
|
+
# The above copyright notice and this permission notice shall be
|
17
|
+
# included in all copies or substantial portions of the Software.
|
18
|
+
#
|
19
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
|
27
|
+
module UserStamp
|
28
|
+
|
29
|
+
class User < ActiveRecord::Base
|
30
|
+
# attr_accessible :title, :body
|
31
|
+
|
32
|
+
def self.current=(user)
|
33
|
+
Thread.current[:current_user] = user
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.current
|
37
|
+
Thread.current[:current_user]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|