audit-log 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0f1ddb5d2e2f1d9b84d0e83a02a83990cce0cc0a1c7fd931d84a607af1f4837
4
- data.tar.gz: 8b072cf51106505f2100aa4dd7760cfef429b131d79b9d3c78e5fe738fcd7769
3
+ metadata.gz: ff47ceeaafa81e2d3304bb1af31fb95c8452259143fda90885098f19cf845629
4
+ data.tar.gz: d02286a6864dae879eebf298ab978843b21ec1917090f676ec9855f1efe00075
5
5
  SHA512:
6
- metadata.gz: 619bdc22b753f80b8b221c4a47531d03f17eaffc19a5f36d3ae3fab4a03562e082eae95335f94dc717de6f5b4cada0a512936c0f62353d57106ff7065081272d
7
- data.tar.gz: f79ea23624ed6ccce2b7e51c8cdfdbbc8cc8229f9f0b508dfa349a6d637215db1c8d79404a6154daf3a3a055422250a990e4757288317aa62734a479eebf8975
6
+ metadata.gz: 0cc4a89d75d0003e9e321dfc92c03e7ae1fb50abf1cb8ecfce22f92ec099ef884917671641496c1040490dac058b1167664e531fff3f2c9ce7f92f0e4e9bbe69
7
+ data.tar.gz: d1e3b71587b23079eb19b7b05c0b5520bcdd2a79f236d18d4e041343abdda15fa5c5a73d2691d21727d31af41d53e505799fe8dd724a932282b485cb250c87f9
data/README.md CHANGED
@@ -97,7 +97,7 @@ Rails.application.routes.draw do
97
97
  end
98
98
  ```
99
99
 
100
- I18n for audit names, you need create a `config/locales/audit_log.zh-CN.yml`:
100
+ I18n for audit names, you need create a `config/locales/audit-log.zh-CN.yml`:
101
101
 
102
102
  ```yml
103
103
  zh-CN:
@@ -7,11 +7,10 @@ module AuditLog
7
7
 
8
8
  def index
9
9
  @logs = Log.order('id desc').includes(:user)
10
-
11
- if params[:q]
12
- @logs = @logs.where('action like ?', "%#{params[:q]}%")
13
- end
14
-
10
+ @logs = @logs.where('action like ?', "%#{params[:q]}%") if params[:q].present?
11
+ @logs = @logs.where("action = ?", params[:action_type]) if params[:action_type].present?
12
+ @logs = @logs.where("created_at >= ?", Time.parse(params[:start_time])) if params[:start_time].present?
13
+ @logs = @logs.where("created_at < ?", Time.parse(params[:end_time])) if params[:end_time].present?
15
14
  @logs = @logs.page(params[:page]).per(15)
16
15
  end
17
16
 
@@ -1,7 +1,14 @@
1
1
  <div class="toolbar">
2
2
  <form class="form-inline" action="<%= audit_log.logs_path %>" method="GET">
3
+ <div class="form-group">
4
+ <%= select_tag(:action_type, options_for_select(AuditLog.action_options, params[:action_type]), include_blank: "All actions", class: "form-control") %>
5
+ </div>
6
+
3
7
  <div class="form-group">
4
8
  <input name="q" type="text" class="form-control" placeholder="Search action" value="<%= params[:q] %>" />
9
+ </div>
10
+
11
+ <div class="form-group">
5
12
  <button type="submit" class="btn btn-primary">Search</button>
6
13
  </div>
7
14
  </form>
@@ -0,0 +1,7 @@
1
+ en:
2
+ audit_log:
3
+ action:
4
+ list_audit_log: List Audit Log
5
+ create_audit_log: Create Audit Log
6
+ update_audit_log: Update Audit Log
7
+ update_password: Update Password
@@ -33,6 +33,9 @@ module AuditLog
33
33
  }
34
34
  end
35
35
 
36
+ # Set nil if record is a new_record, do this for avoid create record.
37
+ record = nil if record&.new_record?
38
+
36
39
  AuditLog::Log.create!(
37
40
  action: action,
38
41
  record: record,
@@ -41,5 +44,10 @@ module AuditLog
41
44
  request: request_info.deep_stringify_keys
42
45
  )
43
46
  end
47
+
48
+ # Get I18n action name options for select
49
+ def action_options(locale: I18n.default_locale)
50
+ I18n.backend.send(:translations)[locale][:audit_log][:action].map { |k, v| [v, k.to_s] }
51
+ end
44
52
  end
45
53
  end
@@ -1,3 +1,3 @@
1
1
  module AuditLog
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -9,6 +9,7 @@ module AuditLog
9
9
 
10
10
  def add_initializer
11
11
  template 'config/initializers/audit-log.rb', 'config/initializers/audit-log.rb'
12
+ template 'config/locales/audit-log.yml', 'config/locales/audit-log.yml'
12
13
  end
13
14
 
14
15
  def add_migrations
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audit-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-31 00:00:00.000000000 Z
11
+ date: 2019-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kaminari
@@ -71,6 +71,7 @@ files:
71
71
  - app/views/audit_log/logs/show.html.erb
72
72
  - app/views/layouts/audit-log/application.html.erb
73
73
  - config/initializers/audit-log.rb
74
+ - config/locales/audit-log.yml
74
75
  - config/routes.rb
75
76
  - db/migrate/20190527035005_create_audit_logs.rb
76
77
  - lib/audit-log.rb