rails_audit 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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +165 -0
  3. data/README.md +45 -0
  4. data/Rakefile +37 -0
  5. data/app/controllers/admin/audits_controller.rb +12 -0
  6. data/app/models/audit.rb +14 -0
  7. data/app/models/concerns/auditable.rb +59 -0
  8. data/app/models/history.rb +36 -0
  9. data/app/models/major_record.rb +14 -0
  10. data/app/models/minor_record.rb +15 -0
  11. data/app/views/admin/audits/_index.html.erb +9 -0
  12. data/app/views/admin/audits/_table.html.erb +61 -0
  13. data/app/views/admin/audits/index.html.erb +3 -0
  14. data/app/views/admin/audits/index.js.erb +8 -0
  15. data/config/routes.rb +7 -0
  16. data/db/migrate/20170314035239_create_audits.rb +20 -0
  17. data/lib/rails_audit/controller_helper.rb +39 -0
  18. data/lib/rails_audit/engine.rb +4 -0
  19. data/lib/rails_audit/version.rb +3 -0
  20. data/lib/rails_audit.rb +3 -0
  21. data/lib/tasks/the_history_tasks.rake +4 -0
  22. data/test/dummy/README.md +5 -0
  23. data/test/dummy/Rakefile +6 -0
  24. data/test/dummy/app/assets/config/manifest.js +3 -0
  25. data/test/dummy/app/assets/javascripts/application.js +2 -0
  26. data/test/dummy/app/assets/javascripts/cable.js +13 -0
  27. data/test/dummy/app/assets/stylesheets/application.css +5 -0
  28. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  29. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  30. data/test/dummy/app/controllers/admin/base_controller.rb +7 -0
  31. data/test/dummy/app/controllers/application_controller.rb +3 -0
  32. data/test/dummy/app/controllers/home_controller.rb +11 -0
  33. data/test/dummy/app/controllers/my/base_controller.rb +7 -0
  34. data/test/dummy/app/helpers/application_helper.rb +2 -0
  35. data/test/dummy/app/jobs/application_job.rb +2 -0
  36. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  37. data/test/dummy/app/models/application_record.rb +3 -0
  38. data/test/dummy/app/models/user.rb +3 -0
  39. data/test/dummy/app/views/layouts/_navbar.html.erb +18 -0
  40. data/test/dummy/app/views/layouts/_right_menu.html.erb +23 -0
  41. data/test/dummy/app/views/layouts/application.html.erb +19 -0
  42. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  43. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  44. data/test/dummy/bin/bundle +3 -0
  45. data/test/dummy/bin/rails +4 -0
  46. data/test/dummy/bin/rake +4 -0
  47. data/test/dummy/bin/setup +34 -0
  48. data/test/dummy/bin/update +29 -0
  49. data/test/dummy/config/application.rb +13 -0
  50. data/test/dummy/config/boot.rb +5 -0
  51. data/test/dummy/config/cable.yml +9 -0
  52. data/test/dummy/config/database.yml.mysql +14 -0
  53. data/test/dummy/config/database.yml.sqlite3 +12 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +54 -0
  56. data/test/dummy/config/environments/production.rb +86 -0
  57. data/test/dummy/config/environments/test.rb +42 -0
  58. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  59. data/test/dummy/config/initializers/assets.rb +6 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  62. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/test/dummy/config/initializers/inflections.rb +16 -0
  64. data/test/dummy/config/initializers/mime_types.rb +4 -0
  65. data/test/dummy/config/initializers/new_framework_defaults.rb +18 -0
  66. data/test/dummy/config/initializers/session_store.rb +3 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +23 -0
  69. data/test/dummy/config/puma.rb +47 -0
  70. data/test/dummy/config/routes.rb +7 -0
  71. data/test/dummy/config/secrets.yml +22 -0
  72. data/test/dummy/config/spring.rb +6 -0
  73. data/test/dummy/config.ru +5 -0
  74. data/test/dummy/db/migrate/20180525090830_create_active_storage_tables.active_storage.rb +26 -0
  75. data/test/dummy/log/development.log +2 -0
  76. data/test/dummy/package.json +6 -0
  77. data/test/dummy/public/404.html +67 -0
  78. data/test/dummy/public/422.html +67 -0
  79. data/test/dummy/public/500.html +66 -0
  80. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  81. data/test/dummy/public/apple-touch-icon.png +0 -0
  82. data/test/dummy/public/favicon.ico +0 -0
  83. data/test/dummy/yarn.lock +11 -0
  84. data/test/integration/navigation_test.rb +8 -0
  85. data/test/test_helper.rb +20 -0
  86. data/test/the_audit_test.rb +7 -0
  87. metadata +208 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 66a9b44197ab98e223cd4fe09d5860dd4754b4b33864667a3f24d26637094ab8
4
+ data.tar.gz: 9887f80180f32cfd6cc8c7407d8ace12d8135ea1e5fa155e809c0fad0477f2e9
5
+ SHA512:
6
+ metadata.gz: 1ae57713efafa015a7eee6979adda07943432965912bfbf87531cc3c6b11b059a6ea0ece99a9f1557f75d77e0dd677f8168e7bcd2fb682e3aaacf0144ee8a16e
7
+ data.tar.gz: 442bda1479c877b53bae748b477f466e4ad85b09f990f79f67000ded8ed7d994ad30293f1f3d1602bc111b96e2e83d63dd4702aed02fd265e7d67821eef0de78
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # RailsAudit
2
+
3
+ Unlike [audited](https://github.com/collectiveidea/audited) and [paper_trail](https://github.com/airblade/paper_trail) etc. These model audit tools use model callbacks to record every changes.
4
+
5
+ `rails_audit` record ActiveRecord Model changes in Controllers, it will record context with model changes:
6
+
7
+ 1. controller
8
+ 2. action
9
+ 3. request.remote_ip
10
+ 4. current_operator
11
+ 5. any other info you want to record..
12
+
13
+ ### Model style audit VS controller style audit
14
+
15
+ | Model Style Audit | Controller style Audit |
16
+ | --- | --- |
17
+ | Record every changes | Record only when you marked |
18
+ | use model callback, can skip by the data persistence not commit callback | No model callback |
19
+ | use thread variables delivery state from controller to model | Just add variables you can get in controller |
20
+
21
+ ## Usage
22
+
23
+ ### in Model
24
+ 1. include Auditable
25
+
26
+ ```ruby
27
+ class User < ActiveRecord::Base
28
+ include Auditable
29
+
30
+ end
31
+
32
+ ```
33
+
34
+ ### in Controller
35
+
36
+ ```ruby
37
+ class UsersController < ApplicationController
38
+
39
+ # use after action, will auto record changes by use saved_changes api
40
+ after_action only: [:update, :create, :destroy] do
41
+ mark_audites(User, note: 'note something!', extra: { client_headers: request.headers })
42
+ end
43
+
44
+ end
45
+ ```
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsAudit'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,12 @@
1
+ class Admin::AuditsController < Admin::BaseController
2
+
3
+ def index
4
+ @audits = Audit.where(auditable_type: params[:auditable_type], auditable_id: params[:auditable_id]).page(params[:page])
5
+
6
+ respond_to do |format|
7
+ format.html
8
+ format.js
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,14 @@
1
+ class Audit < ApplicationRecord
2
+ serialize :audited_changes, Hash
3
+ serialize :related_changes, Hash
4
+ serialize :unconfirmed_changes, Hash
5
+ serialize :extra, Hash
6
+
7
+ belongs_to :auditable, polymorphic: true
8
+ belongs_to :operator, polymorphic: true
9
+
10
+ def audited_changes_i18n
11
+ audited_changes.transform_keys { |key| auditable.class.human_attribute_name(key) }
12
+ end
13
+
14
+ end
@@ -0,0 +1,59 @@
1
+ module Auditable
2
+ extend ActiveSupport::Concern
3
+ IGNORE = ['updated_at']
4
+
5
+ included do
6
+ has_many :audits, as: :auditable
7
+ end
8
+
9
+ # user: {
10
+ # id: 1,
11
+ # changes: {
12
+ # name: ['a', 'b']
13
+ # }
14
+ # }
15
+
16
+ def save_audits(operator: current_operator, include: [], **extra_options)
17
+ audit = self.audits.build
18
+ audit.audited_changes = self.saved_changes.except(*IGNORE)
19
+ audit.unconfirmed_changes = self.changes
20
+
21
+ if include.present?
22
+ result = {}
23
+
24
+ include.each do |key|
25
+ targets = self.send(key)
26
+ result[key] = []
27
+
28
+ Array(targets).each do |target|
29
+ _saved_changes = target.saved_changes.except(*IGNORE)
30
+ _changes = target.changes
31
+
32
+ if _saved_changes.present? || _changes.present?
33
+ result[key] << {
34
+ id: target.id,
35
+ saved_changes: _saved_changes,
36
+ changes: _changes
37
+ }
38
+ end
39
+ end
40
+ end
41
+
42
+ audit.related_changes = result
43
+ end
44
+
45
+ if self.destroyed?
46
+ audit.action = 'destroy'
47
+ end
48
+
49
+ audit.operator_type = operator.class.name
50
+ audit.operator_id = operator.id
51
+ audit.note = extra_options.delete(:note)
52
+ audit.controller_path = extra_options.delete(:controller_path)
53
+ audit.action_name = extra_options.delete(:action_name)
54
+ audit.remote_ip = extra_options.delete(:remote_ip)
55
+ audit.extra = extra_options
56
+ audit.save
57
+ end
58
+
59
+ end
@@ -0,0 +1,36 @@
1
+ class History < ApplicationRecord
2
+ paginates_per 10
3
+
4
+ belongs_to :wiki
5
+ belongs_to :knowledge
6
+ belongs_to :commit, class_name: 'User', foreign_key: 'commit_id'
7
+ validates :commit_id, presence: true
8
+ validates :active, uniqueness: { scope: :knowledge_id }
9
+
10
+ enum status: [:status_initial, :status_passed]
11
+
12
+ default_scope -> { order(id: :desc) }
13
+ def set_active
14
+ self.class.where.not(id: self.id).where(knowledge_id: self.knowledge_id).update_all(active: false)
15
+ self.update(active: true)
16
+ move_to_wiki
17
+ end
18
+
19
+ end
20
+
21
+ # :item_id, :integer
22
+ # :user_id, :integer
23
+ # :content, :string, limit: 65535
24
+ # :commit_id, :integer
25
+ # :commit_message, :string
26
+ #
27
+ # t.integer "wiki_id", limit: 4
28
+ # t.integer "knowledge_id", limit: 4
29
+ # t.text "body", limit: 65535
30
+ # t.string "commit_message", limit: 4096
31
+ # t.datetime "created_at"
32
+ # t.datetime "updated_at"
33
+ # t.integer "commit_id", limit: 4
34
+ # t.boolean "active", default: false
35
+ # t.integer "status", limit: 4, default: 0
36
+ # t.string "type", limit: 255
@@ -0,0 +1,14 @@
1
+ class MajorRecord < ApplicationRecord
2
+
3
+ belongs_to :knowledge, counter_cache: true
4
+
5
+ def move_to_wiki
6
+ wiki = knowledge.major || knowledge.build_major
7
+ wiki.commit_id = self.commit_id
8
+ wiki.commit_message = self.commit_message
9
+ wiki.body = self.body
10
+ wiki.save
11
+ end
12
+
13
+ end
14
+
@@ -0,0 +1,15 @@
1
+ class MinorRecord < ApplicationRecord
2
+
3
+ belongs_to :knowledge, counter_cache: true
4
+
5
+ def move_to_wiki
6
+ wiki = knowledge.minor || knowledge.build_minor
7
+ wiki.commit_id = self.commit_id
8
+ wiki.commit_message = self.commit_message
9
+ wiki.body = self.body
10
+ wiki.save
11
+ end
12
+
13
+ end
14
+
15
+
@@ -0,0 +1,9 @@
1
+ <div class="ui modal" id="audits_index">
2
+ <i class="close icon"></i>
3
+ <div class="ui header blue">
4
+ 系统日志
5
+ </div>
6
+ <div class="content">
7
+ <%= render 'table' %>
8
+ </div>
9
+ </div>
@@ -0,0 +1,61 @@
1
+ <table class="ui table">
2
+ <thead>
3
+ <tr>
4
+ <th>Operator</th>
5
+ <th>Note</th>
6
+ <th>Changes</th>
7
+ <th>Related Changes</th>
8
+ </tr>
9
+ </thead>
10
+
11
+ <tbody>
12
+ <% @audits.each do |audit| %>
13
+ <tr id="audit_<%= audit.id %>">
14
+ <td>
15
+ <p><%= audit.operator&.name %></p>
16
+ <p><%= audit.action %></p>
17
+ <p><time><%= audit.created_at.to_s(:rfc822) %></time></p>
18
+ <div class="ui labels">
19
+ <span class="ui label">Action: <%= audit.action %></span>
20
+ <span class="ui label">Path: <%= audit.controller_path %>/<%= audit.action_name %></span>
21
+ </div>
22
+ <p>IP: <%= audit.remote_ip %></p>
23
+ </td>
24
+ <td><%= audit.note %></td>
25
+ <td class="ui list">
26
+ <% audit.audited_changes_i18n.each do |key, value| %>
27
+ <div class="item">
28
+ <div class="ui label">
29
+ <%= key %>:
30
+ <div class="detail">
31
+ <span><%= value[0] %></span>
32
+ <i class="arrow circle right icon grey"></i>
33
+ <span><%= value[1] %></span>
34
+ </div>
35
+ </div>
36
+ </div>
37
+ <% end %>
38
+ </td>
39
+ <td>
40
+ <% audit.related_changes.each do |key, value| %>
41
+ <% value.each do |relate| %>
42
+ <div class="ui segment">
43
+ <span class="ui blue label"><%= key %>: <%= relate[:id] %></span>
44
+ <div class="ui divider"></div>
45
+ <% relate[:changes].each do |k, v| %>
46
+ <div class="ui label"><%= k %>: </div>
47
+ <%= v[0] %>
48
+ <i class="arrow circle right icon grey"></i>
49
+ <%= v[1] %>
50
+ <% end %>
51
+ </div>
52
+ <% end %>
53
+ <% end %>
54
+ </td>
55
+ </tr>
56
+ <% end %>
57
+ </tbody>
58
+ </table>
59
+
60
+
61
+
@@ -0,0 +1,3 @@
1
+
2
+
3
+
@@ -0,0 +1,8 @@
1
+ if ($('.ui.modals').length === 0) {
2
+ $('body').append('<%= j(render 'index') %>');
3
+ } else {
4
+ $('.ui.modals').html('<%= j(render 'index') %>');
5
+ }
6
+
7
+
8
+ $('#audits_index').modal('setting', {autofocus: false}).modal('show');
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+
3
+ scope module: 'admin', path: ':auditable_type/:auditable_id' do
4
+ resources :audits, only: ['index']
5
+ end
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ class CreateAudits < ActiveRecord::Migration[5.1]
2
+ def change
3
+
4
+ create_table :audits do |t|
5
+ t.references :auditable, polymorphic: true
6
+ t.references :operator, polymorphic: true
7
+ t.string :action
8
+ t.string :audited_changes, limit: 4096
9
+ t.string :related_changes, limit: 4096
10
+ t.string :unconfirmed_changes, limit: 4096
11
+ t.string :note, limit: 1024
12
+ t.string :remote_ip
13
+ t.string :controller_path
14
+ t.string :action_name
15
+ t.string :extra, limit: 4096
16
+ t.datetime :created_at, index: true, null: false
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ module RailsAudit::ControllerHelper
2
+
3
+ def mark_audits(**options)
4
+ record_classes = options.select { |k, _|
5
+ record_class = k.to_s.safe_constantize
6
+ record_class && record_class.ancestors.include?(ActiveRecord::Base)
7
+ }
8
+
9
+ record_classes.each do |record_symbol, includes|
10
+ record_class = record_symbol.to_s.constantize
11
+ valid_ivars.find do |ivar|
12
+ record = instance_variable_get(ivar)
13
+ if record.is_a? record_class
14
+ record.save_audits current_operator: rails_audit_user,
15
+ include: includes,
16
+ note: options[:note],
17
+ controller_path: controller_path,
18
+ action_name: action_name,
19
+ remote_ip: request.remote_ip,
20
+ extra: options[:extra]
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ def rails_audit_user
27
+ current_user
28
+ end
29
+
30
+ def valid_ivars
31
+ _except = self._protected_ivars.to_a + [:@marked_for_same_origin_verification]
32
+ self.instance_variables - _except
33
+ end
34
+
35
+ end
36
+
37
+ ActiveSupport.on_load :action_controller_base do
38
+ include RailsAudit::ControllerHelper
39
+ end
@@ -0,0 +1,4 @@
1
+ module RailsAudit
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAudit
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'rails_audit/engine'
2
+
3
+ require 'rails_audit/controller_helper'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :the_history do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,5 @@
1
+ # dummy
2
+ 基础rails 项目 for engine test
3
+
4
+ ## Notices
5
+ * Used Sqlite MemoryDB, see https://www.sqlite.org/inmemorydb.html
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,2 @@
1
+ //= require yigexiangfa_ui/dist/javascripts/semantic
2
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
@@ -0,0 +1,5 @@
1
+ /*
2
+ *= require yigexiangfa_ui/dist/stylesheets/semantic
3
+ *= require_tree .
4
+ *= require_self
5
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ class Admin::BaseController < ApplicationController
2
+
3
+ default_form_builder 'AdminBuilder' do |config|
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end