devise_auditable 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ef3714b008a0ac6dc42ac934e9a6271f766fe64
4
+ data.tar.gz: f4f23dbdbf6a3c72ad16ac487b744682c5d47539
5
+ SHA512:
6
+ metadata.gz: 4697cd6c35a2ff415a4929731b11c8bfee503c823e1c1fe43025bb7ca87b65112c5d58162ac790f778c840eefd2430ee50e1a425786d16d2886acc038ba43bcc
7
+ data.tar.gz: aeb7a75c87bdc543816e6f65b05adbbb58dbfd04a782c58dc7764cbd2666a9373fc5df0af7dbf7f04581a1e212c7a50a0dfd82fdd281b4c8d4df59243ef3eeea
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2010 Entropi Software 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.md ADDED
@@ -0,0 +1,21 @@
1
+ devise_auditable
2
+ =================
3
+
4
+ devise_auditable is a plugin for Devise that adds a audit log support to Devise.
5
+
6
+ Installation
7
+ =================
8
+
9
+ Add devise_auditable to your Gemfile
10
+
11
+ gem 'devise_auditable'
12
+
13
+ Run the installer
14
+
15
+ rails g devise_auditable User
16
+
17
+ Add the auditable key to your devise user model
18
+
19
+ class User < ActiveRecord::Base
20
+ devise :database_authenticatable, ..... , :auditable
21
+ end
@@ -0,0 +1,11 @@
1
+ unless defined?(Devise)
2
+ require 'devise'
3
+ end
4
+ require 'devise_auditable'
5
+
6
+ Devise.add_module :auditable, :model => 'devise_auditable/model'
7
+
8
+ module DeviseAuditable
9
+ end
10
+
11
+ require 'devise_auditable/engine'
@@ -0,0 +1,7 @@
1
+ require 'devise_auditable'
2
+
3
+ module DeviseAuditable
4
+ class Engine < ::Rails::Engine
5
+
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ Warden::Manager.after_authentication do |record, warden, opts|
2
+ if record.respond_to?(:audit_login!)
3
+ record.audit_login!(warden.request)
4
+ end
5
+ end
6
+
7
+ Warden::Manager.before_logout do |record, warden, opts|
8
+ if record.respond_to?(:audit_logout!)
9
+ record.audit_logout!(warden.request)
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require 'devise_auditable/hooks/auditable'
2
+
3
+ module Devise
4
+ module Models
5
+ module Auditable
6
+ def audit_login!(request)
7
+ audit!("login", request)
8
+ end
9
+
10
+ def audit_logout!(request)
11
+ audit!("logout", request)
12
+ end
13
+
14
+ def audit!(action, request)
15
+ Rails.logger.info "The Current Action is: #{action}"
16
+ Rails.logger.info "The Current Time is: #{Time.now}"
17
+ Rails.logger.info "The Current IP is: #{request.remote_ip}"
18
+ Rails.logger.info "The User Agent is: #{request.headers['User-Agent']}"
19
+
20
+ "#{self.class}Audit".constantize.create(
21
+ action: action,
22
+ action_occured_at: Time.now,
23
+ client_ip: request.remote_ip,
24
+ user_agent: request.headers['User-Agent'],
25
+ "#{self.class}".foreign_key.to_sym => self.id
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module DeviseAuditable
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,62 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class DeviseAuditableGenerator < Rails::Generators::NamedBase
4
+ include Rails::Generators::Migration
5
+
6
+ desc "Generates a model with the given NAME (if one does not exist) with devise " <<
7
+ "configuration plus a migration file and devise routes."
8
+
9
+ def self.source_root
10
+ @_devise_source_root ||= File.expand_path("../templates", __FILE__)
11
+ end
12
+
13
+ def self.orm_has_migration?
14
+ Rails::Generators.options[:rails][:orm] == :active_record
15
+ end
16
+
17
+ def self.next_migration_number(dirname)
18
+ if ActiveRecord::Base.timestamped_migrations
19
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
20
+ else
21
+ "%.3d" % (current_migration_number(dirname) + 1)
22
+ end
23
+ end
24
+
25
+ class_option :orm
26
+ class_option :migration, :type => :boolean, :default => orm_has_migration?
27
+
28
+ def invoke_orm_model
29
+ create_file "app/models/#{name.downcase}_audit.rb", "class #{name}Audit < ActiveRecord::Base\n" <<
30
+ "attr_accessible :action, :action_occured_at, :client_ip, :user_agent, :#{name.downcase}_id\n" <<
31
+ "end"
32
+
33
+ if model_exists?
34
+ say "* Model already exists."
35
+ elsif options[:orm].present?
36
+ invoke "model", ["#{name}Audits"], :migration => false, :orm => options[:orm]
37
+
38
+ unless model_exists?
39
+ abort "Tried to invoke the model generator for '#{options[:orm]}' but could not find it.\n" <<
40
+ "Please create your model by hand before calling `rails g devise_auditable #{name}`."
41
+ end
42
+ else
43
+ abort "Cannot create a devise model because config.generators.orm is blank.\n" <<
44
+ "Please create your model by hand or configure your generators orm before calling `rails g devise_auditable #{name}`."
45
+ end
46
+ end
47
+
48
+ def create_migration_file
49
+ migration_template 'migration.rb', "db/migrate/devise_create_#{name.downcase}_audits.rb"
50
+ end
51
+
52
+ protected
53
+
54
+ def model_exists?
55
+ File.exists?(File.join(destination_root, model_path))
56
+ end
57
+
58
+ def model_path
59
+ print file_path
60
+ @model_path ||= File.join("app", "models", "#{file_path}.rb")
61
+ end
62
+ end
@@ -0,0 +1,17 @@
1
+ class DeviseCreate<%= table_name.camelize.singularize %>Audits < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name.singularize %>_audits do |t|
4
+ t.integer :<%= table_name.classify.foreign_key %>
5
+ t.string "action"
6
+ t.datetime "action_occured_at"
7
+ t.string "client_ip"
8
+ t.string "user_agent"
9
+ end
10
+
11
+ add_index :<%= table_name.singularize %>_audits, :<%= table_name.classify.foreign_key %>
12
+ end
13
+
14
+ def self.down
15
+ drop_table :<%= table_name.singularize %>_audits
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_auditable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas W. Watson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devise
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: warden
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Auditing Plugin for Devise
70
+ email:
71
+ - nick@entropi.co
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/devise_auditable/engine.rb
77
+ - lib/devise_auditable/hooks/auditable.rb
78
+ - lib/devise_auditable/model.rb
79
+ - lib/devise_auditable/version.rb
80
+ - lib/devise_auditable.rb
81
+ - lib/generators/devise_auditable/devise_auditable_generator.rb
82
+ - lib/generators/devise_auditable/templates/migration.rb
83
+ - MIT-LICENSE
84
+ - README.md
85
+ homepage: http://github.com/entropillc/devise_auditable
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.0.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Auditing Plugin for Devise
109
+ test_files: []