rails_audit 1.0.0 → 1.0.4

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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +20 -165
  3. data/README.md +17 -5
  4. data/app/controllers/auditor/admin/approvals_controller.rb +44 -0
  5. data/app/controllers/auditor/admin/audits_controller.rb +11 -0
  6. data/app/controllers/auditor/admin/base_controller.rb +4 -0
  7. data/app/controllers/auditor/admin/verifications_controller.rb +61 -0
  8. data/app/controllers/auditor/admin/verifiers_controller.rb +69 -0
  9. data/app/controllers/auditor/controller/application.rb +32 -0
  10. data/app/models/auditor/approval.rb +5 -0
  11. data/app/models/auditor/audit.rb +5 -0
  12. data/app/models/auditor/ext/audited.rb +58 -0
  13. data/app/models/auditor/ext/verifiable.rb +10 -0
  14. data/app/models/auditor/ext/verified.rb +25 -0
  15. data/app/models/auditor/model/approval.rb +59 -0
  16. data/app/models/auditor/model/approving.rb +65 -0
  17. data/app/models/auditor/model/audit.rb +25 -0
  18. data/app/models/auditor/model/verification.rb +32 -0
  19. data/app/models/auditor/model/verifier.rb +20 -0
  20. data/app/models/auditor/verification.rb +5 -0
  21. data/app/models/auditor/verifier.rb +5 -0
  22. data/app/models/auditor.rb +11 -0
  23. data/app/views/auditor/_approvals.html.erb +14 -0
  24. data/app/views/auditor/_checks.html.erb +16 -0
  25. data/app/views/auditor/admin/approvals/_filter.html.erb +7 -0
  26. data/app/views/auditor/admin/approvals/_form.html.erb +6 -0
  27. data/app/views/auditor/admin/approvals/_index.html.erb +10 -0
  28. data/app/views/auditor/admin/approvals/_show_table.html.erb +28 -0
  29. data/app/views/auditor/admin/approvals/_table.html.erb +28 -0
  30. data/app/views/auditor/admin/approvals/index.js.erb +3 -0
  31. data/app/views/auditor/admin/audits/_button.html.erb +0 -0
  32. data/app/views/auditor/admin/audits/_index_tbody.html.erb +38 -0
  33. data/app/views/auditor/admin/audits/_index_thead.html.erb +4 -0
  34. data/app/views/auditor/admin/audits/index.html.erb +7 -0
  35. data/app/views/auditor/admin/verifications/_edit_form.html.erb +7 -0
  36. data/app/views/auditor/admin/verifications/_filter_form.html.erb +5 -0
  37. data/app/views/auditor/admin/verifications/_index_tbody.html.erb +4 -0
  38. data/app/views/auditor/admin/verifications/_index_thead.html.erb +5 -0
  39. data/app/views/auditor/admin/verifications/_new_form.html.erb +7 -0
  40. data/app/views/auditor/admin/verifications/_show_table.html.erb +16 -0
  41. data/app/views/auditor/admin/verifiers/_edit_form.html.erb +3 -0
  42. data/app/views/auditor/admin/verifiers/_filter_form.html.erb +9 -0
  43. data/app/views/auditor/admin/verifiers/_form.html.erb +5 -0
  44. data/app/views/auditor/admin/verifiers/_index_tbody.html.erb +3 -0
  45. data/app/views/auditor/admin/verifiers/_index_thead.html.erb +4 -0
  46. data/app/views/auditor/admin/verifiers/_member_field.html.erb +1 -0
  47. data/app/views/auditor/admin/verifiers/_new_form.html.erb +3 -0
  48. data/app/views/auditor/admin/verifiers/_show_table.html.erb +24 -0
  49. data/app/views/auditor/admin/verifiers/members.turbo_stream.erb +3 -0
  50. data/config/locales/en.yml +12 -0
  51. data/config/locales/zh.controller.yml +13 -0
  52. data/config/locales/zh.enum.yml +7 -0
  53. data/config/locales/zh.yml +21 -0
  54. data/config/routes.rb +22 -2
  55. data/lib/rails_audit/config.rb +14 -0
  56. data/lib/rails_audit/engine.rb +15 -6
  57. data/lib/rails_audit.rb +3 -2
  58. data/test/controllers/audit/admin/approvals_controller_test.rb +36 -0
  59. data/test/dummy/Gemfile +54 -0
  60. data/test/dummy/Gemfile.lock +382 -0
  61. data/test/dummy/README.md +8 -1
  62. data/test/dummy/app/assets/images/default_avatar.jpg +0 -0
  63. data/test/dummy/app/assets/images/logo.png +0 -0
  64. data/test/dummy/app/assets/javascripts/admin/application.js +1 -0
  65. data/test/dummy/app/assets/javascripts/application.js +11 -2
  66. data/test/dummy/app/assets/javascripts/phone.js +5 -0
  67. data/test/dummy/app/assets/stylesheets/css.scss +4 -0
  68. data/test/dummy/app/controllers/active_storage/base_controller.rb +19 -0
  69. data/test/dummy/app/controllers/admin_controller.rb +3 -0
  70. data/test/dummy/app/controllers/application_controller.rb +10 -1
  71. data/test/dummy/app/controllers/home_controller.rb +0 -5
  72. data/test/dummy/app/controllers/me_controller.rb +4 -0
  73. data/test/dummy/app/controllers/my_controller.rb +4 -0
  74. data/test/dummy/app/models/auth/user.rb +7 -0
  75. data/test/dummy/app/views/home/index.css +3 -0
  76. data/test/dummy/app/views/home/index.html.erb +0 -0
  77. data/test/dummy/app/views/layouts/_right_menu.html.erb +0 -20
  78. data/test/dummy/bin/bundle +1 -1
  79. data/test/dummy/bin/setup +1 -1
  80. data/test/dummy/bin/vite +19 -0
  81. data/test/dummy/bin/yarn +11 -0
  82. data/test/dummy/config/application.rb +12 -5
  83. data/test/dummy/config/boot.rb +8 -4
  84. data/test/dummy/config/credentials/development.key +1 -0
  85. data/test/dummy/config/credentials/test.key +1 -0
  86. data/test/dummy/config/credentials.yml.enc +1 -0
  87. data/test/dummy/config/database.yml +16 -0
  88. data/test/dummy/config/environment.rb +0 -2
  89. data/test/dummy/config/environments/development.rb +19 -32
  90. data/test/dummy/config/environments/production.rb +1 -13
  91. data/test/dummy/config/environments/test.rb +5 -0
  92. data/test/dummy/config/initializers/mime_types.rb +0 -4
  93. data/test/dummy/config/initializers/new_framework_defaults.rb +0 -4
  94. data/test/dummy/config/locales/en.yml +1 -22
  95. data/test/dummy/config/master.key +1 -0
  96. data/test/dummy/config/puma.rb +28 -41
  97. data/test/dummy/config/routes.rb +9 -2
  98. data/test/dummy/config/storage.yml +11 -0
  99. data/test/dummy/config/vite/base.js +5 -0
  100. data/test/dummy/config/vite/development.js +12 -0
  101. data/test/dummy/config/vite/production.js +6 -0
  102. data/test/dummy/config.ru +2 -0
  103. data/test/dummy/lib/deploy.rb +115 -0
  104. data/test/dummy/package.json +23 -2
  105. data/test/dummy/postcss.config.js +11 -0
  106. data/test/dummy/yarn.lock +2140 -4
  107. data/test/factories/approvals.rb +7 -0
  108. data/test/factories/infos.rb +8 -0
  109. data/test/{the_audit_test.rb → rails_audit_test.rb} +3 -1
  110. data/test/test_helper.rb +9 -16
  111. metadata +151 -97
  112. data/app/controllers/admin/audits_controller.rb +0 -12
  113. data/app/models/rails_audit/audit.rb +0 -14
  114. data/app/models/rails_audit/concerns/auditable.rb +0 -59
  115. data/app/models/rails_audit/history.rb +0 -36
  116. data/app/models/rails_audit/major_record.rb +0 -14
  117. data/app/models/rails_audit/minor_record.rb +0 -15
  118. data/app/views/admin/audits/_index.html.erb +0 -9
  119. data/app/views/admin/audits/_table.html.erb +0 -61
  120. data/app/views/admin/audits/index.html.erb +0 -3
  121. data/app/views/admin/audits/index.js.erb +0 -8
  122. data/db/migrate/20170314035239_create_audits.rb +0 -20
  123. data/lib/rails_audit/controller_helper.rb +0 -39
  124. data/lib/rails_audit/version.rb +0 -3
  125. data/lib/tasks/the_history_tasks.rake +0 -4
  126. data/test/dummy/app/assets/config/manifest.js +0 -3
  127. data/test/dummy/app/assets/javascripts/cable.js +0 -13
  128. data/test/dummy/app/assets/stylesheets/application.css +0 -5
  129. data/test/dummy/app/controllers/admin/base_controller.rb +0 -7
  130. data/test/dummy/app/controllers/my/base_controller.rb +0 -7
  131. data/test/dummy/app/models/application_record.rb +0 -3
  132. data/test/dummy/app/models/user.rb +0 -3
  133. data/test/dummy/app/views/layouts/_navbar.html.erb +0 -18
  134. data/test/dummy/app/views/layouts/application.html.erb +0 -19
  135. data/test/dummy/app/views/layouts/mailer.html.erb +0 -13
  136. data/test/dummy/app/views/layouts/mailer.text.erb +0 -1
  137. data/test/dummy/bin/update +0 -29
  138. data/test/dummy/config/database.yml.mysql +0 -14
  139. data/test/dummy/config/database.yml.sqlite3 +0 -12
  140. data/test/dummy/config/initializers/assets.rb +0 -6
  141. data/test/dummy/config/secrets.yml +0 -22
  142. data/test/dummy/db/migrate/20180525090830_create_active_storage_tables.active_storage.rb +0 -26
  143. data/test/dummy/log/development.log +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b00d680dc06b9a63f46de5eae06eaa3773cbb058ea9a0c89cbdc7e9f09c10d93
4
- data.tar.gz: 6c8809e533386113ae62445b4f5fe2edad9f9f58ab2e621d669c200852fadaa5
3
+ metadata.gz: cef87b6bd4b0647da33ae95b4e8f1160d9cee3bc979033214293d9a0ccea2d39
4
+ data.tar.gz: bce954e37568dfe314096f18e998906e68905b862af8caeaf9715007569d381b
5
5
  SHA512:
6
- metadata.gz: 22dcddf8435cd9c68cfb2cfcd38162793441631fcbf4e413649fbb553ef7c03b140f244881abb58fff4877780be6d114d52d007c8e2a78715cef8c450609c21f
7
- data.tar.gz: 6db91495ac3d6c5eab814163030629f3e4767cb36126fefdd6610fe649e35135119e4eef9c4751a37c093d4b2b1f375009459c138162ecbff7af42902bc52db4
6
+ metadata.gz: 8159c54eda42df1a6d3974526f98c84839134bfa294510c3114c1d7810ab61bfdc284e64c65482e22487696b132f94e1df9e8044ab4eb2e5506ac20924af0795
7
+ data.tar.gz: 519850e7b7fc226401bc95c05a715e88b5c0d83f62f46aca8927163a1adabd5fcc64b25015b964f9722c49be4a61e15c5279939806c6e3fd8c7cb1b8c733b960
data/LICENSE CHANGED
@@ -1,165 +1,20 @@
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.
1
+ Copyright (c) 2015-Present Mingyuan Qin <mingyuan0715@foxmail.com>
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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # RailsAudit
2
2
 
3
+ [![测试](https://github.com/work-design/rails_audit/actions/workflows/test.yml/badge.svg)](https://github.com/work-design/rails_audit/actions/workflows/test.yml)
4
+ [![Docker构建](https://github.com/work-design/rails_audit/actions/workflows/cd.yml/badge.svg)](https://github.com/work-design/rails_audit/actions/workflows/cd.yml)
5
+ [![Gem](https://github.com/work-design/rails_audit/actions/workflows/gempush.yml/badge.svg)](https://github.com/work-design/rails_audit/actions/workflows/gempush.yml)
6
+
3
7
  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
8
 
5
9
  `rails_audit` record ActiveRecord Model changes in Controllers, it will record context with model changes:
@@ -21,11 +25,11 @@ Unlike [audited](https://github.com/collectiveidea/audited) and [paper_trail](ht
21
25
  ## Usage
22
26
 
23
27
  ### in Model
24
- 1. include Auditable
28
+ 1. include Audited
25
29
 
26
30
  ```ruby
27
31
  class User < ActiveRecord::Base
28
- include Auditable
32
+ include RailsAuditExt::Audited
29
33
 
30
34
  end
31
35
 
@@ -35,11 +39,19 @@ end
35
39
 
36
40
  ```ruby
37
41
  class UsersController < ApplicationController
38
-
42
+ include RailsAudit::Application
39
43
  # use after action, will auto record changes by use saved_changes api
40
44
  after_action only: [:update, :create, :destroy] do
41
- mark_audites(User, note: 'note something!', extra: { client_headers: request.headers })
45
+ mark_audits(instance: [:@user, :@role], local: [:current_user], note: 'note something!', extra: { client_headers: request.headers.as_json })
42
46
  end
43
47
 
44
48
  end
45
- ```
49
+ ```
50
+
51
+ ### in View
52
+ ```ruby
53
+ link_to 'Audits', audits_path('User', user.id)
54
+ ```
55
+
56
+ ## 许可证
57
+ 许可证采用 [LGPL License](https://opensource.org/licenses/LGPL-3.0)
@@ -0,0 +1,44 @@
1
+ module Auditor
2
+ class Admin::ApprovalsController < Admin::BaseController
3
+ before_action :set_approval, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ q_params = {}
7
+ q_params.merge! params.permit(:approving_type, :approving_id)
8
+
9
+ @approvals = Approval.default_where(q_params).order(id: :desc).page(params[:page])
10
+ end
11
+
12
+ def show
13
+ end
14
+
15
+ def edit
16
+ end
17
+
18
+ def update
19
+ @approval.assign_attributes(approval_params)
20
+
21
+ unless @approval.save
22
+ render :edit, locals: { model: @approval }, status: :unprocessable_entity
23
+ end
24
+ end
25
+
26
+ def destroy
27
+ @approval.destroy
28
+ end
29
+
30
+ private
31
+ def set_approval
32
+ @approval = Approval.find(params[:id])
33
+ end
34
+
35
+ def approval_params
36
+ params.fetch(:approval, {}).permit(
37
+ :pending_changes,
38
+ :approved,
39
+ :state
40
+ )
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ module Auditor
2
+ class Admin::AuditsController < Admin::BaseController
3
+
4
+ def index
5
+ q_params = {}
6
+ q_params.merge! params.permit(:audited_type, :audited_id)
7
+ @audits = Audit.default_where(q_params).order(id: :desc).page(params[:page])
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Auditor
2
+ class Admin::BaseController < AdminController
3
+ end
4
+ end
@@ -0,0 +1,61 @@
1
+ module Auditor
2
+ class Admin::VerificationsController < Admin::BaseController
3
+ before_action :set_check, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @verifications = Verification.page(params[:page])
7
+ end
8
+
9
+ def new
10
+ @verification = Verification.new(state: params[:state])
11
+ end
12
+
13
+ def create
14
+ @verification = Verification.new(check_params)
15
+
16
+ unless @verification.save
17
+ render :new, locals: { model: @verification }, status: :unprocessable_entity
18
+ end
19
+ end
20
+
21
+ def show
22
+ end
23
+
24
+ def edit
25
+ end
26
+
27
+ def update
28
+ @verification.assign_attributes(check_params)
29
+
30
+ unless @verification.save
31
+ render :edit, locals: { model: @verification }, status: :unprocessable_entity
32
+ end
33
+ end
34
+
35
+ def destroy
36
+ @verification.destroy
37
+ end
38
+
39
+ private
40
+ def set_verified
41
+ @verified = params[:verified_type].safe_constantize&.find_by(id: params[:verified_id])
42
+ end
43
+
44
+ def set_check
45
+ @verification = Verification.find(params[:id])
46
+ end
47
+
48
+ def check_params
49
+ q = params.fetch(:verification, {}).permit(
50
+ :comment,
51
+ :confirmed,
52
+ :state
53
+ )
54
+ q.merge! verified_type: params[:verified_type], verified_id: params[:verified_id]
55
+ q.merge! member_id: current_member&.id
56
+ q.merge! user_id: current_user.id
57
+ q
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,69 @@
1
+ module Auditor
2
+ class Admin::VerifiersController < Admin::BaseController
3
+ before_action :set_verifier, only: [:show, :edit, :update, :destroy]
4
+ before_action :prepare_form, only: [:new, :edit]
5
+
6
+ def index
7
+ @verifiers = Verifier.page(params[:page])
8
+ end
9
+
10
+ def new
11
+ @verifier = Verifier.new
12
+ end
13
+
14
+ def members
15
+ @verifier = Verifier.new params.permit(:verifiable_type, :verifiable_id)
16
+ @verifier.assign_attributes verifier_params.slice(:job_title_id)
17
+
18
+ @members = Member.default_where('member_departments.job_title_id': verifier_params[:job_title_id])
19
+ end
20
+
21
+ def create
22
+ @verifier = Verifier.new(verifier_params)
23
+
24
+ unless @verifier.save
25
+ render :new, locals: { model: @verifier }, status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ def show
30
+ end
31
+
32
+ def edit
33
+ end
34
+
35
+ def update
36
+ @verifier.assign_attributes(verifier_params)
37
+
38
+ unless @verifier.save
39
+ render :edit, locals: { model: @verifier }, status: :unprocessable_entity
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @verifier.destroy
45
+ end
46
+
47
+ private
48
+ def prepare_form
49
+ q_params = {}
50
+ q_params.merge! default_params
51
+
52
+ @job_titles = Org::JobTitle.default_where(q_params)
53
+ end
54
+
55
+ def set_verifier
56
+ @verifier = Verifier.find(params[:id])
57
+ end
58
+
59
+ def verifier_params
60
+ p = params.fetch(:verifier, {}).permit(
61
+ :name,
62
+ :job_title_id,
63
+ :member_id
64
+ )
65
+ p.merge! params.permit(:verifiable_type, :verifiable_id)
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,32 @@
1
+ module Auditor
2
+ module Controller::Application
3
+
4
+ # after_action
5
+ def mark_audits(instance: [], local: [], **options)
6
+ instance_records = Array(instance).map!(&:to_sym) & valid_ivars
7
+ instance_records.each do |ivar|
8
+ record = instance_variable_get(ivar)
9
+ next unless record.is_a?(ActiveRecord::Base)
10
+ save_audits(record, **options)
11
+ end
12
+
13
+ local_records = Array(local).map!(&:to_sym) & local_variables
14
+ local_records.each do |ivar|
15
+ record = eval(ivar)
16
+ next unless record.is_a?(ActiveRecord::Base)
17
+ save_audits(record, **options)
18
+ end
19
+ end
20
+
21
+ def save_audits(record, **options)
22
+ record.save_audits(
23
+ operator: rails_audit_user,
24
+ controller_path: controller_path,
25
+ action_name: action_name,
26
+ remote_ip: request.remote_ip,
27
+ **options.slice(:only, :except, :include, :note, :extra)
28
+ )
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module Auditor
2
+ class Approval < ApplicationRecord
3
+ include Model::Approval
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Auditor
2
+ class Audit < ApplicationRecord
3
+ include Model::Audit
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ module Auditor
2
+ module Ext::Audited
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :audits, class_name: 'Auditor::Audit', as: :audited
7
+ end
8
+
9
+ # user: {
10
+ # id: 1,
11
+ # changes: {
12
+ # name: ['a', 'b']
13
+ # }
14
+ # }
15
+ # params same as as_json
16
+ def save_audits(operator:, only: [], except: [], include: [], **extra_options)
17
+ audit = self.audits.build
18
+ if only.present?
19
+ audit.audited_changes = self.saved_changes.slice(*only)
20
+ else
21
+ except = RailsAudit.config.default_except + except
22
+ audit.audited_changes = self.saved_changes.except(*except)
23
+ end
24
+
25
+ result = {}
26
+ include.each do |key|
27
+ targets = self.public_send(key)
28
+ attr_key = "#{key}_attributes"
29
+ result[attr_key] = []
30
+
31
+ Array(targets).each do |target|
32
+ _saved_changes = target.saved_changes.except(*RailsAudit.config.default_except)
33
+
34
+ if _saved_changes.present?
35
+ result[attr_key] << { id: target.id }.merge!(_saved_changes)
36
+ end
37
+ end
38
+ end
39
+ audit.related_changes = result
40
+
41
+ return if audit.audited_changes.blank? && audit.related_changes.blank?
42
+
43
+ if self.destroyed?
44
+ audit.action = 'destroy'
45
+ end
46
+
47
+ audit.operator_type = operator.class.name
48
+ audit.operator_id = operator.id
49
+ audit.note = extra_options.delete(:note)
50
+ audit.controller_path = extra_options.delete(:controller_path)
51
+ audit.action_name = extra_options.delete(:action_name)
52
+ audit.remote_ip = extra_options.delete(:remote_ip)
53
+ audit.extra = extra_options
54
+ audit.save
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,10 @@
1
+ module Auditor
2
+ module Ext::Verifiable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :verifiers, -> { order(position: :asc) }, class_name: 'Auditor::Verifier', as: :verifiable, dependent: :delete_all
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ module Auditor
2
+ module Ext::Verified
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Com::Ext::StateMachine
7
+ has_many :verifications, -> { order(position: :asc) }, class_name: 'Auditor::Verification', as: :verified, dependent: :delete_all, inverse_of: :verified
8
+ end
9
+
10
+ def all_verifications
11
+ verifiers.map do |verifier|
12
+ verifications.find(&->(i){ i.verifier_id == verifier.id }) || verifications.build(verifier: verifier)
13
+ end
14
+ end
15
+
16
+ def next_verifiers
17
+ taxon.verifiers.where.not(id: verifications.pluck(:verifier_id))
18
+ end
19
+
20
+ def next_verifier
21
+ next_verifiers[0]
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,59 @@
1
+ module Auditor
2
+ module Model::Approval
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ attribute :approved, :boolean, default: false
7
+ attribute :pending_changes, :json, default: {}
8
+ attribute :related_changes, :json, default: {}
9
+ attribute :comment, :string
10
+ attribute :approved_at, :datetime
11
+ attribute :unapproved_approvals_count, :integer, default: 0
12
+
13
+ belongs_to :approving, polymorphic: true
14
+ belongs_to :operator, polymorphic: true, optional: true
15
+
16
+ enum state: {
17
+ init: 'init'
18
+ }, _default: 'init'
19
+
20
+ before_update :apply_changes, if: -> { approved_changed? }
21
+
22
+ def pending_changes_i18n
23
+ pending_changes.transform_keys { |key| approving.class.human_attribute_name(key) }
24
+ end
25
+
26
+ def apply_changes
27
+ if approved
28
+ self.approved_at = Time.current
29
+ approving.assign_attributes apply_attributes
30
+ else
31
+ self.approved_at = Time.current
32
+ approving.assign_attributes revert_attributes
33
+ end
34
+
35
+ approving.save
36
+ end
37
+
38
+ def apply_attributes
39
+ r1 = pending_changes.transform_values { |i| i[-1] }
40
+ r2 = related_changes.transform_values do |i|
41
+ i.map { |si| si.transform_values(&->(c){ Array(c)[-1] }) }
42
+ end
43
+
44
+ r1.merge! r2
45
+ end
46
+
47
+ def revert_attributes
48
+ r1 = pending_changes.transform_values { |i| i[0] }
49
+ r2 = related_changes.transform_values do |i|
50
+ i.map { |si| si.transform_values(&->(c){ Array(c)[0] }) }
51
+ end
52
+
53
+ r1.merge! r2
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+ end