lesli_audit 1.1.1 → 1.1.3

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +6 -1
  3. data/app/assets/stylesheets/lesli_audit/application.css +549 -35
  4. data/app/controllers/lesli_audit/accounts_controller.rb +7 -3
  5. data/app/controllers/lesli_audit/analytics_controller.rb +16 -0
  6. data/app/controllers/lesli_audit/logs_controller.rb +12 -7
  7. data/app/controllers/lesli_audit/traffic_controller.rb +25 -0
  8. data/app/controllers/lesli_audit/users_controller.rb +7 -4
  9. data/app/interfaces/lesli_audit/logger_interface.rb +56 -58
  10. data/app/jobs/lesli_audit/cloudflare_traffic_sync_job.rb +78 -0
  11. data/app/jobs/lesli_audit/retention_cleanup_job.rb +9 -0
  12. data/app/models/concerns/lesli_audit/append_only.rb +12 -0
  13. data/app/models/lesli_audit/account.rb +38 -10
  14. data/app/models/lesli_audit/account_device.rb +3 -1
  15. data/app/models/lesli_audit/account_log.rb +12 -7
  16. data/app/models/lesli_audit/account_request.rb +3 -1
  17. data/app/models/lesli_audit/cloudflare_traffic_sync.rb +99 -0
  18. data/app/models/lesli_audit/traffic_breakdown.rb +38 -0
  19. data/app/models/lesli_audit/traffic_rollup.rb +33 -0
  20. data/app/models/lesli_audit/user_journal.rb +14 -3
  21. data/app/models/lesli_audit/user_log.rb +12 -3
  22. data/app/models/lesli_audit/user_request.rb +7 -3
  23. data/app/services/lesli_audit/activity_audit.rb +134 -0
  24. data/app/services/lesli_audit/analytics_service.rb +237 -0
  25. data/app/services/lesli_audit/cloudflare/configuration.rb +92 -0
  26. data/app/services/lesli_audit/cloudflare/graphql_client.rb +309 -0
  27. data/app/services/lesli_audit/cloudflare/snapshot_converter.rb +101 -0
  28. data/app/services/lesli_audit/cloudflare/sync_service.rb +79 -0
  29. data/app/services/lesli_audit/cloudflare_traffic_snapshot.rb +182 -0
  30. data/app/services/lesli_audit/log_service.rb +99 -5
  31. data/app/services/lesli_audit/request_service.rb +74 -44
  32. data/app/services/lesli_audit/retention_cleanup.rb +146 -0
  33. data/app/services/lesli_audit/traffic_service.rb +216 -0
  34. data/app/services/lesli_audit/traffic_snapshot_importer.rb +120 -0
  35. data/app/services/lesli_audit/user_agent_parser.rb +51 -0
  36. data/app/services/lesli_audit/user_service.rb +119 -150
  37. data/app/views/lesli_audit/{visitors → analytics}/index.html.erb +40 -30
  38. data/app/views/lesli_audit/logs/index.html.erb +88 -19
  39. data/app/views/lesli_audit/logs/show.html.erb +41 -7
  40. data/app/views/lesli_audit/partials/_navigation.html.erb +5 -4
  41. data/app/views/lesli_audit/requests/index.html.erb +80 -19
  42. data/app/views/lesli_audit/traffic/_breakdown.html.erb +46 -0
  43. data/app/views/lesli_audit/traffic/index.html.erb +177 -0
  44. data/app/views/lesli_audit/users/index.html.erb +97 -43
  45. data/config/locales/translations.en.yml +137 -1
  46. data/config/locales/translations.es.yml +137 -1
  47. data/config/locales/translations.fr.yml +132 -1
  48. data/config/locales/translations.it.yml +132 -1
  49. data/config/locales/translations.pt.yml +132 -1
  50. data/config/routes.rb +6 -22
  51. data/db/migrate/v1.0/0501000110_create_lesli_audit_accounts.rb +14 -1
  52. data/db/migrate/v1.0/0501110110_create_lesli_audit_account_logs.rb +11 -6
  53. data/db/migrate/v1.0/0501110210_create_lesli_audit_account_devices.rb +10 -7
  54. data/db/migrate/v1.0/0501110310_create_lesli_audit_account_requests.rb +10 -7
  55. data/db/migrate/v1.0/0501120110_create_lesli_audit_user_logs.rb +12 -7
  56. data/db/migrate/v1.0/0501120210_create_lesli_audit_user_journals.rb +16 -8
  57. data/db/migrate/v1.0/0501120310_create_lesli_audit_user_requests.rb +13 -10
  58. data/db/migrate/v1.0/0501130110_create_lesli_audit_traffic_rollups.rb +55 -0
  59. data/db/migrate/v1.0/0501130210_create_lesli_audit_traffic_breakdowns.rb +41 -0
  60. data/db/migrate/v1.0/0501130310_create_lesli_audit_cloudflare_traffic_syncs.rb +42 -0
  61. data/db/seed/devices.rb +3 -2
  62. data/db/seed/requests.rb +3 -3
  63. data/db/seed/traffic.rb +128 -0
  64. data/db/seed/users.rb +68 -27
  65. data/db/seeds.rb +3 -2
  66. data/lib/lesli_audit/engine.rb +1 -12
  67. data/lib/lesli_audit/version.rb +2 -2
  68. data/lib/tasks/lesli_audit_cloudflare_traffic.rake +16 -0
  69. data/lib/tasks/lesli_audit_tasks.rake +12 -4
  70. data/readme.md +28 -5
  71. metadata +36 -9
  72. data/app/assets/stylesheets/lesli_audit/application.tailwind.css +0 -2
  73. data/app/controllers/lesli_audit/visitors_controller.rb +0 -14
  74. data/app/models/concerns/lesli_audit/user_associations.rb +0 -11
  75. data/app/services/lesli_audit/visitor_service.rb +0 -239
@@ -0,0 +1,120 @@
1
+ module LesliAudit
2
+ # Persists one complete set of totals for a Cloudflare path and day.
3
+ # A newer snapshot replaces the totals; retries and older snapshots are
4
+ # no-ops. Breakdowns are replaced only when the DTO explicitly provides
5
+ # them, allowing omitted data and an intentionally empty set to differ.
6
+ class TrafficSnapshotImporter
7
+ UNIQUE_INDEX = "index_lesli_audit_traffic_rollups_on_provider_path_and_date"
8
+ BREAKDOWN_INDEX = "index_lesli_audit_traffic_breakdowns_on_dimension"
9
+
10
+ class ResourceConflict < StandardError; end
11
+
12
+ def self.call(account:, snapshot:)
13
+ new(account:, snapshot:).call
14
+ end
15
+
16
+ def initialize(account:, snapshot:)
17
+ @account = account
18
+ @snapshot = snapshot
19
+ end
20
+
21
+ def call
22
+ validate_input!
23
+
24
+ # The account row is the stable lock shared by new and existing
25
+ # paths, so concurrent imports cannot race before a rollup exists.
26
+ account.with_lock do
27
+ rollup = locked_rollup
28
+ ensure_resource_matches!(rollup) if rollup
29
+ return rollup if rollup && rollup.snapshot_at >= snapshot.snapshot_at
30
+
31
+ upsert_rollup
32
+ rollup = locked_rollup
33
+ replace_breakdowns(rollup) if snapshot.breakdowns_provided?
34
+ rollup.reload
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ attr_reader :account, :snapshot
41
+
42
+ def validate_input!
43
+ unless account.is_a?(LesliAudit::Account) && account.persisted?
44
+ raise ArgumentError, "account must be a persisted LesliAudit::Account"
45
+ end
46
+ return if snapshot.is_a?(LesliAudit::CloudflareTrafficSnapshot)
47
+
48
+ raise ArgumentError, "snapshot must be a CloudflareTrafficSnapshot"
49
+ end
50
+
51
+ def identity
52
+ {
53
+ provider: snapshot.provider,
54
+ hostname: snapshot.hostname,
55
+ path: snapshot.path,
56
+ date: snapshot.date
57
+ }
58
+ end
59
+
60
+ def locked_rollup
61
+ account.traffic_rollups.lock.find_by(identity)
62
+ end
63
+
64
+ def upsert_rollup
65
+ now = Time.current
66
+ TrafficRollup.upsert_all(
67
+ [ {
68
+ account_id: account.id,
69
+ **identity,
70
+ resource_type: snapshot.resource_type,
71
+ resource_id: snapshot.resource_id,
72
+ page_views: snapshot.page_views,
73
+ visits: snapshot.visits,
74
+ snapshot_at: snapshot.snapshot_at,
75
+ created_at: now,
76
+ updated_at: now
77
+ } ],
78
+ unique_by: UNIQUE_INDEX,
79
+ update_only: %i[page_views visits snapshot_at updated_at]
80
+ )
81
+ end
82
+
83
+ def ensure_resource_matches!(rollup)
84
+ return if rollup.resource_type == snapshot.resource_type && rollup.resource_id == snapshot.resource_id
85
+
86
+ raise ResourceConflict,
87
+ "hostname and path are already attributed to another resource for this date"
88
+ end
89
+
90
+ def replace_breakdowns(rollup)
91
+ relation = rollup.traffic_breakdowns
92
+ relation.delete_all if snapshot.breakdowns.empty?
93
+ return if snapshot.breakdowns.empty?
94
+
95
+ now = Time.current
96
+ rows = snapshot.breakdowns.map do |breakdown|
97
+ {
98
+ account_id: account.id,
99
+ traffic_rollup_id: rollup.id,
100
+ **breakdown,
101
+ created_at: now,
102
+ updated_at: now
103
+ }
104
+ end
105
+ TrafficBreakdown.upsert_all(
106
+ rows,
107
+ unique_by: BREAKDOWN_INDEX,
108
+ update_only: %i[page_views visits updated_at]
109
+ )
110
+
111
+ kept_ids = snapshot.breakdowns.map do |breakdown|
112
+ relation.find_by!(
113
+ dimension: breakdown[:dimension],
114
+ value: breakdown[:value]
115
+ ).id
116
+ end
117
+ relation.where.not(id: kept_ids).delete_all
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,51 @@
1
+ =begin
2
+
3
+ Lesli
4
+
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see http://www.gnu.org/licenses/.
19
+
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
+
22
+ Made with ♥ by LesliTech
23
+ Building a better future, one line of code at a time.
24
+
25
+ @contact hello@lesli.tech
26
+ @website https://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ require "device_detector"
34
+
35
+ module LesliAudit
36
+ # Provides one normalized user-agent contract for the engines that need to
37
+ # persist browser and operating-system metadata.
38
+ class UserAgentParser
39
+ def self.parse(user_agent)
40
+ detector = DeviceDetector.new(user_agent.to_s)
41
+
42
+ {
43
+ platform: detector.os_name,
44
+ os: detector.os_full_version,
45
+ browser: detector.name,
46
+ version: detector.full_version,
47
+ device: detector.device_type
48
+ }
49
+ end
50
+ end
51
+ end
@@ -27,189 +27,158 @@ Building a better future, one line of code at a time.
27
27
  @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
28
 
29
29
  // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
- // ·
30
+ // ·
31
31
  =end
32
32
 
33
33
  module LesliAudit
34
34
  class UserService < Lesli::ApplicationLesliService
35
+ REGISTRATION_MONTHS = 12
36
+ ACTIVITY_DAYS = 30
37
+ ACTIVITY_LIMIT = 20
35
38
 
36
- def users
37
- users = current_user.account.users
38
-
39
- now = Time.current
40
- last_30_days = 30.days.ago
41
-
42
- stats = users.pick(
43
- # total users
44
- Arel.sql("COUNT(*)"),
45
-
46
- # total deactivated users
47
- Arel.sql("SUM(CASE WHEN active = 0 AND deleted_at IS NULL THEN 1 ELSE 0 END)"),
48
-
49
- # total locked users
50
- Arel.sql(
51
- "SUM(CASE WHEN (
52
- locked_at IS NOT NULL
53
- OR locked_until > #{ActiveRecord::Base.connection.quote(Time.current)}
54
- ) AND deleted_at IS NULL THEN 1 ELSE 0 END)"
55
- ),
56
-
57
- # total not confirmed users
58
- Arel.sql("SUM(CASE WHEN confirmed_at IS NULL AND deleted_at IS NULL THEN 1 ELSE 0 END)"),
59
-
60
- # total deleted users
61
- Arel.sql("SUM(CASE WHEN deleted_at IS NOT NULL THEN 1 ELSE 0 END)"),
62
-
63
- # users that never signed in
64
- Arel.sql("SUM(CASE WHEN last_sign_in_at IS NULL AND deleted_at IS NULL THEN 1 ELSE 0 END)"),
65
-
66
- # total active users for the last 30 days
67
- Arel.sql("SUM(CASE WHEN last_sign_in_at >= #{ActiveRecord::Base.connection.quote(last_30_days)} AND deleted_at IS NULL THEN 1 ELSE 0 END)"),
68
-
69
- # users with failed logins
70
- Arel.sql("SUM(CASE WHEN failed_attempts > 0 AND deleted_at IS NULL THEN 1 ELSE 0 END)"),
71
- )
39
+ def dashboard
40
+ {
41
+ summary: summary,
42
+ attention: attention,
43
+ registrations: registrations,
44
+ working_hours: working_hours
45
+ }
46
+ end
72
47
 
73
- summary = {
74
- total_users: stats[0].to_i,
75
- total_users_deactivated: stats[1].to_i,
76
- total_users_locked: stats[2].to_i,
77
- total_users_unconfirmed: stats[3].to_i,
78
- total_users_deleted: stats[4].to_i,
48
+ private
79
49
 
80
- total_users_never_signed_in: stats[5].to_i,
81
- total_users_active_last_30_days: stats[6].to_i,
82
- total_users_with_failed_attempts: stats[7].to_i
50
+ def summary
51
+ {
52
+ registered: all_users.count,
53
+ enabled: current_users.where(active: true).count,
54
+ active_last_30_days: current_users.where(last_sign_in_at: ACTIVITY_DAYS.days.ago..).count,
55
+ deactivated: current_users.where(active: false).count,
56
+ deleted: all_users.where.not(deleted_at: nil).count
83
57
  }
58
+ end
84
59
 
60
+ def attention
85
61
  {
86
- overview: [{
87
- label: "Total users",
88
- value: summary[:total_users],
89
- percentage: 100,
90
- color: "info"
91
- }, {
92
- label: "Deactivated users",
93
- value: summary[:total_users_deactivated],
94
- percentage: percentage(summary[:total_users_deactivated], summary[:total_users]),
95
- color: "warning"
96
- }, {
97
- label: "Locked users",
98
- value: summary[:total_users_locked],
99
- percentage: percentage(summary[:total_users_locked], summary[:total_users]),
100
- color: "danger"
101
- }, {
102
- label: "Unconfirmed users",
103
- value: summary[:total_users_unconfirmed],
104
- percentage: percentage(summary[:total_users_unconfirmed], summary[:total_users]),
105
- color: "warning",
106
- }, {
107
- label: "Deleted users",
108
- value: summary[:total_users_deleted],
109
- percentage: percentage(summary[:total_users_deleted], summary[:total_users]),
110
- color: "danger"
111
- }],
112
- attention_needed: [{
113
- label: "Unconfirmed users",
114
- value: summary[:total_users_unconfirmed],
115
- color: "info",
116
- icon: "user-add-line"
117
- }, {
118
- label: "Never signed in",
119
- value: summary[:total_users_never_signed_in],
120
- color: "warning",
121
- icon: "time-line"
122
- }, {
123
- label: "Failed login attempts",
124
- value: summary[:total_users_with_failed_attempts],
125
- color: "danger",
126
- icon: "shield-keyhole-line"
127
- }, {
128
- label: "Locked users",
129
- value: summary[:total_users_locked],
130
- color: "danger",
131
- icon: "lock-line"
132
- }]
62
+ unconfirmed: current_users.where(confirmed_at: nil).count,
63
+ never_signed_in: current_users.where(last_sign_in_at: nil).count,
64
+ failed_sign_ins: current_users.where(failed_attempts: 1..).count,
65
+ locked: locked_users.count
133
66
  }
134
67
  end
135
68
 
136
- def working_hours
69
+ def locked_users
70
+ locked_at = current_users.where.not(locked_at: nil)
71
+ locked_until = current_users.where(locked_until: Time.current..)
137
72
 
138
- group = 'day'
73
+ locked_at.or(locked_until)
74
+ end
139
75
 
140
- group_by = "DATE_TRUNC('month', lesli_audit_user_requests.date)" if group == 'month'
141
- group_by = "DATE_TRUNC('week', lesli_audit_user_requests.date)" if group == 'week'
142
- group_by = "DATE_TRUNC('day', lesli_audit_user_requests.date)" if group == 'day'
76
+ def registrations
77
+ counts = all_users
78
+ .where(created_at: registration_start.beginning_of_day..)
79
+ .group(Arel.sql(registration_month_group))
80
+ .count
81
+ .to_h do |month, count|
82
+ [ month.to_date.beginning_of_month, count ]
83
+ end
143
84
 
144
- # compatibility for SQLite
145
- if ActiveRecord::Base.connection.adapter_name == "SQLite"
146
- group_by = "strftime('%Y-%m-%d', lesli_audit_user_requests.date)"
85
+ registration_months.map do |month|
86
+ {
87
+ "xaxiskey" => month.iso8601,
88
+ "yaxiskey" => counts.fetch(month, 0)
89
+ }
147
90
  end
91
+ end
148
92
 
149
- user_requests = current_user.account.users.joins(:requests)
150
-
151
- user_requests = user_requests.select(
152
- :id,
153
- "lesli_users.id as user_id",
154
- "lesli_users.email as user_email",
155
- "#{group_by} date",
156
- "min(lesli_audit_user_requests.created_at) as first_activity",
157
- "max(lesli_audit_user_requests.updated_at) as last_activity",
158
- "count(lesli_audit_user_requests.id) resources",
159
- "sum(lesli_audit_user_requests.request_count) requests"
160
- )
161
-
162
- user_requests = user_requests.group(:user_id, group_by)
163
-
164
- user_requests.map do |request|
165
- request[:first_activity] = Date2.new(request[:first_activity]).time
166
- request[:last_activity] = Date2.new(request[:last_activity]).time
167
- request
93
+ def registration_months
94
+ REGISTRATION_MONTHS.times.map do |offset|
95
+ registration_start >> offset
168
96
  end
169
-
170
- user_requests.reverse
171
97
  end
172
98
 
173
- def registrations
99
+ def registration_start
100
+ (Date.current << (REGISTRATION_MONTHS - 1)).beginning_of_month
101
+ end
174
102
 
175
- #Get filters from the request
176
- group = query[:group]
177
- group = "month"
103
+ # PostgreSQL and SQLite expose different date-grouping functions. Both
104
+ # expressions return a month that is normalized to a Date immediately.
105
+ def registration_month_group
106
+ return "strftime('%Y-%m-01', lesli_users.created_at)" if sqlite?
178
107
 
179
- #Get period only if the request have filters
180
- period = group unless group.blank?
108
+ "DATE_TRUNC('month', lesli_users.created_at)"
109
+ end
181
110
 
182
- group_by = "DATE_TRUNC('month', created_at)" if group == 'month'
183
- group_by = "DATE_TRUNC('week', created_at)" if group == 'week'
184
- group_by = "DATE_TRUNC('day', created_at)" if group == 'day'
111
+ def working_hours
112
+ # Journals are reduced to a daily boundary instead of exposed as a
113
+ # request list. Requests keeps ownership of endpoint-level detail.
114
+ journals = audit_account.user_journals
115
+ .retained
116
+ .where(date: activity_start..Date.current)
117
+
118
+ account_users
119
+ .joins(:journals)
120
+ .merge(journals)
121
+ .select(
122
+ "lesli_users.id AS user_id",
123
+ "lesli_users.email AS user_email",
124
+ "#{activity_day_group} AS activity_date",
125
+ "MIN(lesli_audit_user_journals.created_at) AS first_activity",
126
+ "MAX(lesli_audit_user_journals.created_at) AS last_activity"
127
+ )
128
+ .group("lesli_users.id", "lesli_users.email", Arel.sql(activity_day_group))
129
+ .order(Arel.sql("#{activity_day_group} DESC"), "lesli_users.email ASC")
130
+ .limit(ACTIVITY_LIMIT)
131
+ .map { |activity| normalize_activity(activity) }
132
+ end
185
133
 
186
- # compatibility for SQLite
187
- if ActiveRecord::Base.connection.adapter_name == "SQLite"
188
- group_by = "strftime('%Y-%m', created_at)"
189
- end
134
+ def activity_start
135
+ (ACTIVITY_DAYS - 1).days.ago.to_date
136
+ end
190
137
 
191
- registrations = []
138
+ def activity_day_group
139
+ return "strftime('%Y-%m-%d', lesli_audit_user_journals.date)" if sqlite?
192
140
 
193
- if ["day", "week", "month", "year"].include?(period)
141
+ "DATE_TRUNC('day', lesli_audit_user_journals.date)"
142
+ end
194
143
 
195
- registrations = current_user.account.users
196
- .group(group_by)
197
- .count.map do |request|
198
- {
199
- :xaxiskey => request[0],
200
- :yaxiskey => request[1]
201
- }
202
- end
144
+ def normalize_activity(activity)
145
+ {
146
+ user_id: activity[:user_id],
147
+ user_email: activity[:user_email],
148
+ date: activity[:activity_date].to_date,
149
+ first_activity: normalize_time(activity[:first_activity]),
150
+ last_activity: normalize_time(activity[:last_activity])
151
+ }
152
+ end
153
+
154
+ def normalize_time(value)
155
+ time = if value.respond_to?(:in_time_zone)
156
+ value.in_time_zone
157
+ else
158
+ Time.zone.parse(value.to_s)
203
159
  end
204
160
 
205
- registrations
161
+ time.strftime("%H:%M")
206
162
  end
207
163
 
208
- private
164
+ def account_users
165
+ current_user.account.users
166
+ end
167
+
168
+ def all_users
169
+ @all_users ||= account_users.with_deleted
170
+ end
171
+
172
+ def current_users
173
+ @current_users ||= all_users.where(deleted_at: nil)
174
+ end
175
+
176
+ def audit_account
177
+ @audit_account ||= LesliAudit::Account.find_by!(account_id: current_user.account_id)
178
+ end
209
179
 
210
- def percentage(value, total)
211
- return 0 if total.to_i.zero?
212
- ((value.to_f / total) * 100).round
180
+ def sqlite?
181
+ ActiveRecord::Base.connection.adapter_name == "SQLite"
213
182
  end
214
183
  end
215
184
  end
@@ -1,26 +1,32 @@
1
1
 
2
2
  <%
3
- visitors = @visitors.reverse
4
- top_days = visitors.last(3)
3
+ request_trend = @request_trend.reverse
4
+ top_days = request_trend.last(3)
5
5
  %>
6
6
 
7
7
  <%= render(LesliView::Layout::Container.new("audit-analytics")) do %>
8
- <%= render(LesliView::Components::Header.new("Analytics")) %>
8
+ <%= render(LesliView::Components::Header.new(
9
+ t("lesli_audit.analytics.title", default: "Analytics")
10
+ )) %>
9
11
 
10
12
  <section
11
13
  class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-5"
12
- aria-label="Visitor overview">
14
+ aria-label="<%= t("lesli_audit.analytics.overview", default: "Authenticated usage overview") %>">
13
15
  <article class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
14
- <h2 class="text-sm font-medium text-slate-500">Controllers</h2>
16
+ <h2 class="text-sm font-medium text-slate-500">
17
+ <%= t("lesli_audit.analytics.controllers", default: "Controllers") %>
18
+ </h2>
15
19
  <p class="mt-3 text-3xl font-semibold tracking-tight text-slate-900 tabular-nums">
16
- <%= @visits[:controllers] %>
20
+ <%= @summary[:controllers] %>
17
21
  </p>
18
22
  </article>
19
23
 
20
24
  <article class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
21
- <h2 class="text-sm font-medium text-slate-500">Requests</h2>
25
+ <h2 class="text-sm font-medium text-slate-500">
26
+ <%= t("lesli_audit.analytics.requests", default: "Requests") %>
27
+ </h2>
22
28
  <p class="mt-3 text-3xl font-semibold tracking-tight text-slate-900 tabular-nums">
23
- <%= @visits[:requests] %>
29
+ <%= @summary[:requests] %>
24
30
  </p>
25
31
  </article>
26
32
 
@@ -36,21 +42,23 @@ top_days = visitors.last(3)
36
42
 
37
43
  <section class="mt-6 rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
38
44
  <%= render(LesliView::Charts::Line.new(
39
- title: "Visitors",
40
- database_to_dataset: visitors
45
+ database_to_dataset: request_trend,
46
+ title: t("lesli_audit.analytics.requests", default: "Requests")
41
47
  )) %>
42
48
  </section>
43
49
 
44
- <section class="mt-6 grid grid-cols-1 gap-6 lg:grid-cols-3" aria-label="Visitor breakdown">
50
+ <section
51
+ class="mt-6 grid grid-cols-1 gap-6 lg:grid-cols-3"
52
+ aria-label="<%= t("lesli_audit.analytics.login_breakdown", default: "Successful login breakdown") %>">
45
53
  <article class="min-w-0">
46
54
  <%= render(LesliView::Elements::Table.new(
47
55
  columns: [
48
- { label: "Browsers", align: :left },
49
- { label: "Visitors", align: :center }
56
+ { label: t("lesli_audit.analytics.browsers", default: "Browsers"), align: :left },
57
+ { label: t("lesli_audit.analytics.logins", default: "Logins"), align: :center }
50
58
  ],
51
59
  class_name: "!min-w-0",
52
60
  compact: true,
53
- caption: "Visitors by browser"
61
+ caption: t("lesli_audit.analytics.logins_by_browser", default: "Successful logins by browser")
54
62
  )) do |table| %>
55
63
  <% @browsers.each do |browser| %>
56
64
  <% percentage = browser[:percentage].to_i.clamp(0, 100) %>
@@ -80,15 +88,15 @@ top_days = visitors.last(3)
80
88
  <article class="min-w-0">
81
89
  <%= render(LesliView::Elements::Table.new(
82
90
  columns: [
83
- { label: "OS", align: :left },
84
- { label: "Visitors", align: :center }
91
+ { label: t("lesli_audit.analytics.operating_systems", default: "OS"), align: :left },
92
+ { label: t("lesli_audit.analytics.logins", default: "Logins"), align: :center }
85
93
  ],
86
94
  class_name: "!min-w-0",
87
95
  compact: true,
88
- caption: "Visitors by operating system"
96
+ caption: t("lesli_audit.analytics.logins_by_operating_system", default: "Successful logins by operating system")
89
97
  )) do |table| %>
90
- <% @os.each do |device| %>
91
- <% percentage = device[:percentage].to_i.clamp(0, 100) %>
98
+ <% @operating_systems.each do |operating_system| %>
99
+ <% percentage = operating_system[:percentage].to_i.clamp(0, 100) %>
92
100
  <% table.with_row do |row| %>
93
101
  <% row.with_cell(class_name: "!p-0") do %>
94
102
  <div class="relative isolate overflow-hidden px-3 py-2.5">
@@ -98,14 +106,14 @@ top_days = visitors.last(3)
98
106
  aria-hidden="true"></span>
99
107
  <span class="flex items-center gap-2 text-slate-700">
100
108
  <span class="inline-flex h-7 w-7 shrink-0 items-center justify-center text-slate-500">
101
- <span class="ri-<%= device[:icon].downcase %> text-lg leading-none" aria-hidden="true"></span>
109
+ <span class="ri-<%= operating_system[:icon].downcase %> text-lg leading-none" aria-hidden="true"></span>
102
110
  </span>
103
- <span class="truncate"><%= device[:device] %></span>
111
+ <span class="truncate"><%= operating_system[:operating_system] %></span>
104
112
  </span>
105
113
  </div>
106
114
  <% end %>
107
115
  <% row.with_cell(class_name: "font-semibold tabular-nums text-slate-900", align: :center) do %>
108
- <%= device[:count] %>
116
+ <%= operating_system[:count] %>
109
117
  <% end %>
110
118
  <% end %>
111
119
  <% end %>
@@ -115,12 +123,12 @@ top_days = visitors.last(3)
115
123
  <article class="min-w-0">
116
124
  <%= render(LesliView::Elements::Table.new(
117
125
  columns: [
118
- { label: "Device", align: :left },
119
- { label: "Visitors", align: :center }
126
+ { label: t("lesli_audit.analytics.devices", default: "Devices"), align: :left },
127
+ { label: t("lesli_audit.analytics.logins", default: "Logins"), align: :center }
120
128
  ],
121
129
  class_name: "!min-w-0",
122
130
  compact: true,
123
- caption: "Visitors by device"
131
+ caption: t("lesli_audit.analytics.logins_by_device", default: "Successful logins by device")
124
132
  )) do |table| %>
125
133
  <% @devices.each do |device| %>
126
134
  <% percentage = device[:percentage].to_i.clamp(0, 100) %>
@@ -148,17 +156,19 @@ top_days = visitors.last(3)
148
156
  </article>
149
157
  </section>
150
158
 
151
- <section class="mt-6 pb-8" aria-label="Top controllers">
159
+ <section
160
+ class="mt-6 pb-8"
161
+ aria-label="<%= t("lesli_audit.analytics.top_controllers", default: "Top controllers") %>">
152
162
  <%= render(LesliView::Elements::Table.new(
153
163
  columns: [{
154
- label: "Top controllers",
164
+ label: t("lesli_audit.analytics.top_controllers", default: "Top controllers"),
155
165
  field: "request_controller"
156
166
  }, {
157
- label: "Requests",
167
+ label: t("lesli_audit.analytics.requests", default: "Requests"),
158
168
  field: "requests"
159
169
  }],
160
- records: @requests,
161
- caption: "Requests by controller"
170
+ records: @top_controllers,
171
+ caption: t("lesli_audit.analytics.requests_by_controller", default: "Requests by controller")
162
172
  )) %>
163
173
  </section>
164
174
  <% end %>