audit-log 1.0.0 → 1.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: cd049092e7b9e427a66e776f4248c42a74b19fb667a12fec8aa5ecf9abaf08f3
4
- data.tar.gz: 2d7e6e61ddf78747fbf9dbb1b2b427c16fa6c0015405eaf3222e23839afdf691
3
+ metadata.gz: 613411720c743b51ce59f552b9264cddfc19a7b4443ebb886f4bed80f42622ff
4
+ data.tar.gz: f17b916a8898fc3b48b9010f5b9bf39dd4a4e246a245d79b500e8cdd7ca36353
5
5
  SHA512:
6
- metadata.gz: a3c21ee0a6658f309188e1fffb17c906cf0005eb0c67ed337e65f6c0ba901e17ec1238e49e796abb7bb173e70dd61385b28d7af7fcc64d8fefd8cd06c829fa82
7
- data.tar.gz: 3faacb77c43e1af56395c4aa515c67e536a1a96c719baa313051bd6995aa17d949c67454a0234b3bbf35329fa0b7eecc2a29b4d13bbc0105773f2dbfef9da755
6
+ metadata.gz: 2c4ec193452b1ef7ba92e699c3043f8f83fdf5a8e3eacc69ac0ada22816583706894a20d2b0788e573a3a8dff4710b4ee00819b332b1849b744ec271ca8b5a06
7
+ data.tar.gz: 4d0dc7efb373289ffb6cabfd806ad1105259b8e9d0e2a399e694fa2ffc91071dd85004a01684f70925e8b05c7b7afa1b18dbb5980b686c5b80a4e9627eb71d1d
data/README.md CHANGED
@@ -6,6 +6,8 @@ Trail audit logs (Operation logs) into the database for user behaviors, includin
6
6
 
7
7
  > We used audit-log in our production environment more than 1 year, until now (2020.5.21), it's inserted about **20 million** log in our system.
8
8
 
9
+ [中文介绍与使用说明](https://ruby-china.org/topics/39890)
10
+
9
11
  ## Demo UI
10
12
 
11
13
  Audit log list:
data/Rakefile CHANGED
@@ -1,34 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  begin
4
- require 'bundler/setup'
4
+ require "bundler/setup"
5
5
  rescue LoadError
6
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
7
  end
8
8
 
9
- require 'rdoc/task'
9
+ require "rdoc/task"
10
10
 
11
11
  RDoc::Task.new(:rdoc) do |rdoc|
12
- rdoc.rdoc_dir = 'rdoc'
13
- rdoc.title = 'AuditLog'
14
- rdoc.options << '--line-numbers'
15
- rdoc.rdoc_files.include('README.md')
16
- rdoc.rdoc_files.include('lib/**/*.rb')
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "AuditLog"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("lib/**/*.rb")
17
17
  end
18
18
 
19
- APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
20
- load 'rails/tasks/engine.rake'
19
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
20
+ load "rails/tasks/engine.rake"
21
21
 
22
- load 'rails/tasks/statistics.rake'
22
+ load "rails/tasks/statistics.rake"
23
23
 
24
- require 'bundler/gem_tasks'
24
+ require "bundler/gem_tasks"
25
25
 
26
- require 'rake/testtask'
26
+ require "rake/testtask"
27
27
 
28
28
  Rake::TestTask.new(:test) do |t|
29
- t.libs << 'lib'
30
- t.libs << 'test'
31
- t.pattern = 'test/**/*_test.rb'
29
+ t.libs << "lib"
30
+ t.libs << "test"
31
+ t.pattern = "test/**/*_test.rb"
32
32
  t.verbose = false
33
33
  end
34
34
 
@@ -2,12 +2,12 @@
2
2
 
3
3
  module AuditLog
4
4
  class LogsController < ActionController::Base
5
- layout 'audit-log/application'
5
+ layout "audit-log/application"
6
6
  before_action :set_log, only: %i[show destroy]
7
7
 
8
8
  def index
9
- @logs = Log.order('id desc').includes(:user)
10
- @logs = @logs.where('action like ?', "%#{params[:q]}%") if params[:q].present?
9
+ @logs = Log.order("id desc").includes(:user)
10
+ @logs = @logs.where("action like ?", "%#{params[:q]}%") if params[:q].present?
11
11
  @logs = @logs.where("action = ?", params[:action_type]) if params[:action_type].present?
12
12
  @logs = @logs.where("created_at >= ?", Time.parse(params[:start_time])) if params[:start_time].present?
13
13
  @logs = @logs.where("created_at < ?", Time.parse(params[:end_time])) if params[:end_time].present?
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  AuditLog::Engine.routes.draw do
4
- resources :logs, path: ''
4
+ resources :logs, path: ""
5
5
  end
@@ -1,17 +1,19 @@
1
- class CreateAuditLogs < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
+
3
+ class CreateAuditLogs < ActiveRecord::Migration[5.2]
2
4
  def change
3
- create_table 'audit_logs', force: :cascade do |t|
4
- t.string 'action', null: false
5
- t.integer 'user_id'
6
- t.integer 'record_id'
7
- t.string 'record_type'
8
- t.text 'payload'
9
- t.text 'request'
10
- t.datetime 'created_at'
11
- t.datetime 'updated_at'
5
+ create_table "audit_logs", force: :cascade do |t|
6
+ t.string "action", null: false
7
+ t.bigint "user_id"
8
+ t.bigint "record_id"
9
+ t.string "record_type"
10
+ t.text "payload"
11
+ t.text "request"
12
+ t.datetime "created_at"
13
+ t.datetime "updated_at"
12
14
  t.index %w[record_type record_id], using: :btree
13
15
  t.index %w[user_id action], using: :btree
14
- t.index ['action'], using: :btree
16
+ t.index ["action"], using: :btree
15
17
  end
16
18
  end
17
19
  end
@@ -10,5 +10,8 @@ module AuditLog
10
10
 
11
11
  # user name method, default: "name"
12
12
  attr_accessor :user_name_method
13
+
14
+ # set a speicla table_name for AuditLog Model, default: 'audit_logs'
15
+ attr_accessor :table_name
13
16
  end
14
17
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AuditLog
2
4
  module ControllerHelper
3
5
  # Create an audit log
4
6
  #
5
7
  # audit!(:edit_account, @account, payload: account_params)
6
8
  def audit!(action, record = nil, payload: nil, user: nil)
7
- user ||= self.send(AuditLog.config.current_user_method.to_sym)
9
+ user ||= send(AuditLog.config.current_user_method.to_sym)
8
10
  AuditLog.audit!(action, record, payload: payload, request: request, user: user)
9
11
  end
10
12
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './controller_helper'
3
+ require_relative "./controller_helper"
4
4
 
5
5
  module AuditLog
6
6
  class Engine < Rails::Engine
@@ -12,7 +12,7 @@ module AuditLog
12
12
 
13
13
  AuditLog::LogSubscriber.attach_to :audit_log
14
14
 
15
- initializer 'audit-log.assets.precompile', group: :all do |app|
15
+ initializer "audit-log.assets.precompile", group: :all do |app|
16
16
  app.config.assets.precompile += %w[audit-log/application.css]
17
17
  end
18
18
  end
@@ -4,7 +4,7 @@ module AuditLog
4
4
  class LogSubscriber < ActiveSupport::LogSubscriber
5
5
  # ActiveSupport::Notifications.instrument('audit.audit_log', action: action)
6
6
  def audit(event)
7
- prefix = color('AuditLog', CYAN)
7
+ prefix = color("AuditLog", CYAN)
8
8
  action = color(event.payload[:action], BLUE)
9
9
  debug " #{prefix} #{action} (#{event.duration.round(1)}ms)"
10
10
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AuditLog
2
4
  module Model
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  included do
6
- self.table_name = 'audit_logs'
8
+ self.table_name = AuditLog.config.table_name
7
9
 
8
10
  serialize :payload, JSON
9
11
  serialize :request, JSON
@@ -22,13 +24,13 @@ module AuditLog
22
24
  end
23
25
 
24
26
  def user_name
25
- return 'none' if self.user.blank?
27
+ return "none" if user.blank?
26
28
 
27
- self.user.send(AuditLog.config.user_name_method)
29
+ user.send(AuditLog.config.user_name_method)
28
30
  end
29
31
 
30
32
  def action_name
31
- I18n.t("audit_log.action.#{self.action}", default: self.action)
33
+ I18n.t("audit_log.action.#{action}", default: action)
32
34
  end
33
35
  end
34
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AuditLog
4
- VERSION = '1.0.0'
4
+ VERSION = "1.2.0"
5
5
  end
data/lib/audit-log.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './audit-log/version'
4
- require_relative './audit-log/configuration'
5
- require_relative './audit-log/model'
6
- require_relative './audit-log/log_subscriber'
7
- require_relative './audit-log/engine'
8
- require 'kaminari'
3
+ require_relative "./audit-log/version"
4
+ require_relative "./audit-log/configuration"
5
+ require_relative "./audit-log/model"
6
+ require_relative "./audit-log/log_subscriber"
7
+ require_relative "./audit-log/engine"
8
+ require "kaminari"
9
9
 
10
10
  module AuditLog
11
11
  class << self
@@ -13,9 +13,10 @@ module AuditLog
13
13
  return @config if defined?(@config)
14
14
 
15
15
  @config = Configuration.new
16
- @config.user_class = 'User'
17
- @config.current_user_method = 'current_user'
18
- @config.user_name_method = 'name'
16
+ @config.user_class = "User"
17
+ @config.current_user_method = "current_user"
18
+ @config.user_name_method = "name"
19
+ @config.table_name = "audit_logs"
19
20
  @config
20
21
  end
21
22
 
@@ -27,7 +28,7 @@ module AuditLog
27
28
  #
28
29
  # AuditLog.audit!(:edit_account, @account, payload: account_params, user: current_user)
29
30
  def audit!(action, record = nil, payload: nil, user: nil, request: nil)
30
- ActiveSupport::Notifications.instrument('audit.audit_log', action: action) do
31
+ ActiveSupport::Notifications.instrument("audit.audit_log", action: action) do
31
32
  request_info = {}
32
33
  if request
33
34
  request_info = {
@@ -55,7 +56,7 @@ module AuditLog
55
56
 
56
57
  # Get I18n action name options for select
57
58
  def action_options
58
- I18n.t('audit_log.action').map { |k, v| [v, k.to_s] }
59
+ I18n.t("audit_log.action").map { |k, v| [v, k.to_s] }
59
60
  end
60
61
  end
61
62
  end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
3
+ require "rails/generators"
4
4
  module AuditLog
5
5
  module Generators
6
6
  class InstallGenerator < Rails::Generators::Base
7
7
  desc "Create AuditLog's base files"
8
- source_root File.expand_path('../../..', __dir__)
8
+ source_root File.expand_path("../../..", __dir__)
9
9
 
10
10
  def add_initializer
11
- template 'config/initializers/audit-log.rb', 'config/initializers/audit-log.rb'
12
- template 'config/locales/audit-log.yml', 'config/locales/audit-log.yml'
11
+ template "config/initializers/audit-log.rb", "config/initializers/audit-log.rb"
12
+ template "config/locales/audit-log.yml", "config/locales/audit-log.yml"
13
13
  end
14
14
 
15
15
  def add_migrations
16
- exec('rake audit_log:install:migrations')
16
+ exec("rake audit_log:install:migrations")
17
17
  end
18
18
  end
19
19
  end
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: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kaminari
@@ -30,28 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
33
+ version: '5.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '4.0'
41
- - !ruby/object:Gem::Dependency
42
- name: mysql2
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '5.2'
55
41
  description: Trail audit logs (Operation logs) into the database for user behaviors,
56
42
  including a web UI to query logs.
57
43
  email:
@@ -85,7 +71,7 @@ homepage: https://github.com/rails-engine/audit-log
85
71
  licenses:
86
72
  - MIT
87
73
  metadata: {}
88
- post_install_message:
74
+ post_install_message:
89
75
  rdoc_options: []
90
76
  require_paths:
91
77
  - lib
@@ -100,8 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
86
  - !ruby/object:Gem::Version
101
87
  version: '0'
102
88
  requirements: []
103
- rubygems_version: 3.0.3
104
- signing_key:
89
+ rubygems_version: 3.3.12
90
+ signing_key:
105
91
  specification_version: 4
106
92
  summary: Trail audit logs (Operation logs) into the database for user behaviors, including
107
93
  a web UI to query logs