action_trace 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac6e3bcd7ddba0d325500935c892b7832116e9f53035b352e757e258fb5b28d4
4
- data.tar.gz: ddc86843cab5355f2c08b8134048b9d2e6bb00771112570ae037b44a59ca4e4e
3
+ metadata.gz: 8203cf9f2490c006cca8d9ce25fd692cfe5d06c576c44837733da34ec83f22e6
4
+ data.tar.gz: 77310c6e8c0f072dc2714f251d0db19d968fa3edf5c8d5ace62ffd9a4393218a
5
5
  SHA512:
6
- metadata.gz: 8f4a13e9befd1d7a05e99acd17cbb3521004cdc4e2ede8e2d0fc9f49f2c176f45a7d20a7a280fc017895927c6e69513b744a479350a109359537927b6067cfc2
7
- data.tar.gz: ab8913e299894c6c8868384e96a1056d859ae0368e85eb214c57e745808eddad16889f1cf7290b24f0a1afc4ae578c666994461f5ccf5008fa98cd253be1ce73
6
+ metadata.gz: 0ec68b1545e8e87b327b2288b451ec69b8a864829341b7c6f163e17be14b0e868753c888c6dc81de3f31574eb2f6acecae17c1e806346dc07638b7f952cbcf52
7
+ data.tar.gz: 7152f64871c07d49360cd285f456376f6d5aeac054f7b35583249ed0f98c4ee9efc1e0fb1e89e3184a6d91fcfd81b43c486b65f2cba9f7965ab71fbf43ebe59c
@@ -19,7 +19,7 @@ module ActionTrace
19
19
  id: "act_#{activity.id}",
20
20
  source: source_type(activity),
21
21
  occurred_at: activity.created_at,
22
- user: activity.owner&.complete_name,
22
+ user: activity.owner,
23
23
  trackable_type: activity.trackable_type,
24
24
  details: activity.parameters || {},
25
25
  paper_trail_version: PaperTrail::Version.find_by(id: activity.version_id),
@@ -42,7 +42,7 @@ module ActionTrace
42
42
  id: "ahoy_#{event.id}",
43
43
  source: event.name == 'session_end' ? 'session_end' : 'page_visit',
44
44
  occurred_at: event.time,
45
- user: event.user&.complete_name,
45
+ user: event.user,
46
46
  url: props['path'],
47
47
  details: props
48
48
  }
@@ -19,7 +19,7 @@ module ActionTrace
19
19
  id: "visit_#{visit.id}",
20
20
  source: 'session_start',
21
21
  occurred_at: visit.started_at,
22
- user: visit.user&.complete_name,
22
+ user: visit.user,
23
23
  subject: "#{visit.browser} on #{visit.os} (#{visit.ip})",
24
24
  details: visit.attributes.slice('ip', 'browser', 'os', 'device_type', 'country', 'landing_page', 'user_agent')
25
25
  }
@@ -21,8 +21,10 @@ module ActivityLogFetchable
21
21
  if context.company_id.present?
22
22
  scope = if model_class.respond_to?(:filter_by_company)
23
23
  model_class.filter_by_company(scope, context.company_id)
24
- else
24
+ elsif model_class.method_defined?(:company_id)
25
25
  scope.where(company_id: context.company_id)
26
+ else
27
+ scope
26
28
  end
27
29
  end
28
30
 
@@ -6,7 +6,7 @@ module ActionTrace
6
6
  include ActionTrace::ActivityLogPresenter
7
7
 
8
8
  attr_reader :id, :source, :occurred_at, :user, :raw_subject, :details, :url, :paper_trail_version, :trackable,
9
- :trackable_type
9
+ :trackable_type, :company
10
10
 
11
11
  SOURCES = {
12
12
  data_create: 'data_create',
@@ -28,6 +28,7 @@ module ActionTrace
28
28
  @paper_trail_version = attributes[:paper_trail_version]
29
29
  @trackable = attributes[:trackable]
30
30
  @trackable_type = attributes[:trackable_type]
31
+ @company = attributes[:user]&.company if attributes[:user].respond_to?(:company)
31
32
  end
32
33
 
33
34
  def data_create?
@@ -24,13 +24,6 @@ module ActionTrace
24
24
  user_ids = user_class.where(company_id: company_id).select(:id)
25
25
  scope.where(owner_type: user_class.name, owner_id: user_ids)
26
26
  end
27
-
28
- [Ahoy::Visit, Ahoy::Event].each do |klass|
29
- klass.define_singleton_method(:filter_by_company) do |scope, company_id|
30
- user_ids = user_class.where(company_id: company_id).select(:id)
31
- scope.where(user_id: user_ids)
32
- end
33
- end
34
27
  end
35
28
  end
36
- end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionTrace
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -30,6 +30,7 @@ module ActionTrace
30
30
 
31
31
  def run_ahoy_install
32
32
  generate 'ahoy:install' unless options[:skip_ahoy]
33
+ inject_ahoy_filter_by_company
33
34
  end
34
35
 
35
36
  def run_paper_trail_install
@@ -51,6 +52,23 @@ module ActionTrace
51
52
  template 'initializers/action_trace.rb.tt', 'config/initializers/action_trace.rb'
52
53
  end
53
54
 
55
+ private
56
+
57
+ def inject_ahoy_filter_by_company
58
+ filter_method = <<~RUBY
59
+
60
+ def self.filter_by_company(scope, company_id)
61
+ scope.joins(:user).where(users: { company_id: company_id })
62
+ end
63
+ RUBY
64
+
65
+ %w[visit event].each do |model|
66
+ inject_into_file "app/models/ahoy/#{model}.rb", filter_method, before: " end\nend\n"
67
+ end
68
+ end
69
+
70
+ public
71
+
54
72
  def show_post_install_message
55
73
  readme 'POST_INSTALL' if behavior == :invoke
56
74
  end
@@ -15,7 +15,10 @@ module ActionTrace
15
15
  end
16
16
 
17
17
  def copy_views
18
- directory 'views/action_trace', 'app/views/action_trace'
18
+ directory(
19
+ File.expand_path('../../../../app/views/action_trace', __dir__),
20
+ 'app/views/action_trace'
21
+ )
19
22
  end
20
23
 
21
24
  def copy_controller
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gimbaro
@@ -267,8 +267,6 @@ files:
267
267
  - lib/generators/action_trace/install/install_generator.rb
268
268
  - lib/generators/action_trace/install/templates/initializers/action_trace.rb.tt
269
269
  - lib/generators/action_trace/install/templates/migrations/add_version_id_to_activities.rb.tt
270
- - lib/generators/action_trace/views/templates/views/action_trace/activity_logs/_index.html.erb
271
- - lib/generators/action_trace/views/templates/views/action_trace/activity_logs/index.html.erb
272
270
  - lib/generators/action_trace/views/views_generator.rb
273
271
  - lib/tasks/action_trace_tasks.rake
274
272
  homepage: https://github.com/Engim-eu/action_trace
@@ -1,7 +0,0 @@
1
- <div id="activity-logs">
2
- <% @activity_logs.each do |log| %>
3
- <div class="activity-log">
4
- <%= log %>
5
- </div>
6
- <% end %>
7
- </div>