lesli_audit 0.5.0 → 1.0.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 +4 -4
- data/app/assets/config/lesli_audit_manifest.js +0 -1
- data/app/assets/javascripts/lesli_audit/application.js +1 -4081
- data/{db/migrate/v1.0/0503050210_create_lesli_audit_dashboard_components.rb → app/assets/stylesheets/lesli_audit/application.css} +6 -24
- data/app/controllers/lesli_audit/analytics_controller.rb +3 -13
- data/app/controllers/lesli_audit/dashboards_controller.rb +2 -0
- data/app/controllers/lesli_audit/requests_controller.rb +1 -6
- data/app/controllers/lesli_audit/users_controller.rb +32 -4
- data/app/interfaces/lesli_audit/logger_interface.rb +132 -0
- data/app/models/lesli_audit/dashboard.rb +0 -25
- data/app/services/lesli_audit/account/activity_services.rb +2 -2
- data/app/services/lesli_audit/analytic_service.rb +12 -7
- data/app/services/lesli_audit/analytics/trend_services.rb +2 -2
- data/app/services/lesli_audit/analytics/visitor_service.rb +155 -153
- data/app/services/lesli_audit/user_service.rb +71 -0
- data/app/services/lesli_audit/users/activity_services.rb +2 -2
- data/app/services/lesli_audit/users/log_services.rb +2 -2
- data/app/services/lesli_audit/users/registration_services.rb +2 -2
- data/app/services/lesli_audit/users/role_services.rb +2 -2
- data/app/services/lesli_audit/users/working_hour_services.rb +2 -2
- data/app/views/lesli_audit/analytics/index.html.erb +42 -1
- data/app/views/lesli_audit/dashboards/edit.html.erb +12 -1
- data/app/views/lesli_audit/dashboards/index.html.erb +2 -0
- data/app/views/lesli_audit/dashboards/new.html.erb +2 -0
- data/app/views/lesli_audit/dashboards/show.html.erb +33 -1
- data/app/views/lesli_audit/partials/{_engine-navigation.html.erb → _navigation.html.erb} +4 -4
- data/app/views/lesli_audit/requests/index.html.erb +23 -1
- data/app/views/lesli_audit/users/index.html.erb +14 -1
- data/config/locales/translations.en.yml +1 -19
- data/config/locales/translations.es.yml +1 -19
- data/config/locales/translations.fr.yml +2 -0
- data/config/locales/translations.it.yml +2 -0
- data/config/locales/translations.pt.yml +2 -0
- data/config/routes.rb +5 -21
- data/db/migrate/v1.0/0503000110_create_lesli_audit_accounts.rb +1 -6
- data/db/migrate/v1.0/0503050110_create_lesli_audit_dashboards.rb +1 -15
- data/db/seeds.rb +7 -10
- data/lib/lesli_audit/engine.rb +2 -0
- data/lib/lesli_audit/version.rb +2 -2
- data/{app/assets/stylesheets/lesli_audit → lib/scss}/application.scss +0 -4
- data/lib/vue/application.js +14 -14
- data/lib/vue/apps/analytics/index.vue +1 -1
- data/lib/vue/apps/analytics/trends.vue +2 -3
- data/lib/vue/apps/dashboards/components/roles.vue +3 -3
- data/lib/vue/apps/dashboards/components/users.vue +3 -3
- data/lib/vue/apps/dashboards/show.vue +1 -1
- data/lib/vue/apps/requests/index.vue +1 -1
- data/lib/vue/apps/users/index.vue +80 -22
- data/lib/vue/apps/users/registrations.vue +21 -46
- data/lib/vue/components/requests.vue +1 -1
- data/lib/vue/components/visitors.vue +4 -4
- data/lib/vue/stores/analytics.js +24 -9
- data/lib/vue/stores/translations.json +114 -0
- data/lib/vue/stores/users.js +56 -0
- metadata +17 -15
- data/app/assets/stylesheets/lesli_audit/dashboard.scss +0 -0
- data/app/controllers/lesli_audit/dashboard/components_controller.rb +0 -60
- data/db/seed/production.rb +0 -0
- data/db/seed/test.rb +0 -0
- /data/db/seed/{development.rb → requests.rb} +0 -0
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
/*!************************************************************************************************************************************************************!*\
|
2
|
+
!*** css ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[0].use[1]!./node_modules/sass-loader/dist/cjs.js!../LesliAudit/lib/scss/application.scss ***!
|
3
|
+
\************************************************************************************************************************************************************/
|
4
|
+
@charset "UTF-8";
|
5
|
+
/*
|
2
6
|
|
3
7
|
Lesli
|
4
8
|
|
@@ -28,26 +32,4 @@ Building a better future, one line of code at a time.
|
|
28
32
|
|
29
33
|
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
30
34
|
// ·
|
31
|
-
|
32
|
-
|
33
|
-
class CreateLesliAuditDashboardComponents < ActiveRecord::Migration[6.1]
|
34
|
-
def change
|
35
|
-
gem_path = Lesli::System.engine("Lesli", "dir")
|
36
|
-
table_base_structure = JSON.parse(File.read(File.join(gem_path, "db", "structure", "00000502_dashboard_components.json")))
|
37
|
-
create_table :lesli_audit_dashboard_components do |t|
|
38
|
-
table_base_structure.each do |column|
|
39
|
-
t.send(
|
40
|
-
column["type"].parameterize.underscore.to_sym,
|
41
|
-
column["name"].parameterize.underscore.to_sym
|
42
|
-
)
|
43
|
-
end
|
44
|
-
t.timestamps
|
45
|
-
end
|
46
|
-
|
47
|
-
add_reference(
|
48
|
-
:lesli_audit_dashboard_components, :dashboard,
|
49
|
-
foreign_key: { to_table: :lesli_audit_dashboards },
|
50
|
-
index: { name: "lesli_audit_dashboard_components_dashboards" }
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
35
|
+
*/
|
@@ -3,25 +3,15 @@ module LesliAudit
|
|
3
3
|
|
4
4
|
# GET /analytics
|
5
5
|
def index
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
respond_with_successful(AnalyticService.new(current_user, query).visitors)
|
10
|
-
end
|
11
|
-
|
12
|
-
def users
|
13
|
-
respond_with_successful(AnalyticService.new(current_user, query).users)
|
6
|
+
@visitors = respond_as_successful(AnalyticService.new(current_user, query).visitors)
|
7
|
+
@controllers = respond_as_successful(AnalyticService.new(current_user, query).controllers)
|
8
|
+
@users = respond_as_successful(AnalyticService.new(current_user, query).users)
|
14
9
|
end
|
15
10
|
|
16
11
|
def devices
|
17
12
|
respond_with_successful(AnalyticService.new(current_user, query).devices)
|
18
13
|
end
|
19
14
|
|
20
|
-
def controllers
|
21
|
-
respond_with_successful(AnalyticService.new(current_user, query).controllers)
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
15
|
private
|
26
16
|
|
27
17
|
# Use callbacks to share common setup or constraints between actions.
|
@@ -35,12 +35,7 @@ module LesliAudit
|
|
35
35
|
|
36
36
|
# GET /requests
|
37
37
|
def index
|
38
|
-
|
39
|
-
format.html
|
40
|
-
format.json {
|
41
|
-
respond_with_pagination(LesliAudit::RequestService.new(current_user, query).index)
|
42
|
-
}
|
43
|
-
end
|
38
|
+
@requests = respond_as_pagination(LesliAudit::RequestService.new(current_user, query).index)
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end
|
@@ -1,12 +1,40 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Lesli
|
4
|
+
|
5
|
+
Copyright (c) 2025, 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
|
1
32
|
module LesliAudit
|
2
33
|
class UsersController < ApplicationController
|
3
34
|
|
4
35
|
# GET /users
|
5
36
|
def index
|
37
|
+
@users = respond_as_successful(UserService.new(current_user, query).registrations)
|
6
38
|
end
|
7
|
-
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
39
|
end
|
12
40
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
Lesli
|
4
|
+
|
5
|
+
Copyright (c) 2023, 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 https://www.lesli.tech
|
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
|
+
module LesliAudit
|
34
|
+
module LoggerInterface
|
35
|
+
def get_user_agent(as_string=true)
|
36
|
+
|
37
|
+
http_user_agent = request.env["HTTP_USER_AGENT"]
|
38
|
+
|
39
|
+
# parse user agent
|
40
|
+
user_agent = UserAgent.parse(http_user_agent)
|
41
|
+
|
42
|
+
user_agent_version = user_agent.version.to_a.first(2).join(".")
|
43
|
+
|
44
|
+
# return user agent as object
|
45
|
+
if as_string == false
|
46
|
+
return {
|
47
|
+
platform: user_agent.platform,
|
48
|
+
os: user_agent.os,
|
49
|
+
browser: user_agent.browser,
|
50
|
+
version: user_agent_version
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
# return user agent info as string
|
55
|
+
"#{user_agent.platform} #{user_agent.os} - #{user_agent.browser} #{user_agent_version}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def log_requests
|
59
|
+
log_account_requests
|
60
|
+
log_user_requests
|
61
|
+
end
|
62
|
+
|
63
|
+
def log_account_requests
|
64
|
+
return unless Lesli.config.security.dig(:enable_analytics)
|
65
|
+
return unless defined?(LesliAudit)
|
66
|
+
return unless current_user
|
67
|
+
|
68
|
+
# Try to save a unique record for this request configuration
|
69
|
+
current_user.account.audit.account_requests.upsert(
|
70
|
+
{
|
71
|
+
request_controller: controller_path,
|
72
|
+
request_action: action_name,
|
73
|
+
request_count: 1,
|
74
|
+
created_at: Date2.new.date.to_s
|
75
|
+
},
|
76
|
+
|
77
|
+
# group of columns to consider a request as unique
|
78
|
+
unique_by: %i[request_controller request_action created_at account_id],
|
79
|
+
|
80
|
+
# if request id is not unique, increase the counter for this configuration
|
81
|
+
on_duplicate: Arel.sql("request_count = lesli_audit_account_requests.request_count + 1")
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Track all user activity
|
86
|
+
# this is disabled by default in the settings file
|
87
|
+
def log_user_requests
|
88
|
+
return unless Lesli.config.security.dig(:enable_analytics)
|
89
|
+
return unless defined?(LesliAudit)
|
90
|
+
return unless current_user
|
91
|
+
return unless session[:user_session_id]
|
92
|
+
|
93
|
+
# Try to save a unique record for this request configuration
|
94
|
+
current_user.account.audit.user_requests.upsert(
|
95
|
+
{
|
96
|
+
request_controller: controller_path,
|
97
|
+
request_action: action_name,
|
98
|
+
session_id: session[:user_session_id],
|
99
|
+
user_id: current_user.id,
|
100
|
+
request_count: 1,
|
101
|
+
created_at: Date2.new.date.to_s
|
102
|
+
},
|
103
|
+
|
104
|
+
# group of columns to consider a request as unique
|
105
|
+
unique_by: %i[request_controller request_action created_at user_id session_id],
|
106
|
+
|
107
|
+
# if request id is not unique
|
108
|
+
# - increase the counter for this configuration
|
109
|
+
# - update the datetime of the last request
|
110
|
+
on_duplicate: Arel.sql(
|
111
|
+
'request_count = lesli_audit_user_requests.request_count + 1'
|
112
|
+
)
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Track specific account activity
|
117
|
+
# this is disabled by default in the settings file
|
118
|
+
def log_account_activity(system_module, system_process, title = nil, payload = nil, description = nil)
|
119
|
+
# return unless Rails.application.config.lesli.dig(:security, :enable_analytics)
|
120
|
+
|
121
|
+
# account = Account.first
|
122
|
+
|
123
|
+
# account.activities.create({
|
124
|
+
# system_module:,
|
125
|
+
# system_process:,
|
126
|
+
# description:,
|
127
|
+
# payload:,
|
128
|
+
# title:
|
129
|
+
# })
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -3,30 +3,5 @@ module LesliAudit
|
|
3
3
|
class Dashboard < Lesli::Shared::Dashboard
|
4
4
|
self.table_name = "lesli_audit_dashboards"
|
5
5
|
belongs_to :account
|
6
|
-
|
7
|
-
has_many :components, inverse_of: :dashboard, autosave: true, dependent: :destroy
|
8
|
-
accepts_nested_attributes_for :components, allow_destroy: true
|
9
|
-
|
10
|
-
def self.initialize_account(account)
|
11
|
-
self.create!(
|
12
|
-
account: account,
|
13
|
-
name: "Audit Default Dashboard",
|
14
|
-
default: true,
|
15
|
-
main: false,
|
16
|
-
components_attributes: [{
|
17
|
-
name: "Total users",
|
18
|
-
component_id: "audit-users",
|
19
|
-
layout: 3,
|
20
|
-
query_configuration: {},
|
21
|
-
custom_configuration: {}
|
22
|
-
}, {
|
23
|
-
name: "Roles",
|
24
|
-
component_id: "audit-roles",
|
25
|
-
layout: 3,
|
26
|
-
query_configuration: {},
|
27
|
-
custom_configuration: {}
|
28
|
-
}]
|
29
|
-
)
|
30
|
-
end
|
31
6
|
end
|
32
7
|
end
|
@@ -30,8 +30,8 @@ Building a better future, one line of code at a time.
|
|
30
30
|
// ·
|
31
31
|
=end
|
32
32
|
|
33
|
-
module
|
34
|
-
class
|
33
|
+
module LesliAudit
|
34
|
+
class Account::ActivityServices < Lesli::ApplicationLesliService
|
35
35
|
|
36
36
|
def index
|
37
37
|
search_string = nil # query[:search].downcase.gsub(" ","%") unless query[:search].blank?
|
@@ -48,19 +48,24 @@ module LesliAudit
|
|
48
48
|
# only the users of the account
|
49
49
|
usrs = current_user.account.users
|
50
50
|
|
51
|
+
group_by = "DATE_TRUNC('month', created_at)" if group == 'month'
|
52
|
+
group_by = "DATE_TRUNC('week', created_at)" if group == 'week'
|
53
|
+
group_by = "DATE_TRUNC('day', created_at)" if group == 'day'
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
# compatibility for SQLite
|
56
|
+
if ActiveRecord::Base.connection.adapter_name == "SQLite"
|
57
|
+
group_by = "strftime('%Y-%m-%d', created_at)"
|
58
|
+
end
|
59
|
+
|
60
|
+
requests = current_user.account.audit.account_requests.group(group_by)
|
56
61
|
|
57
62
|
requests = apply_filters(requests, query)
|
58
63
|
|
59
|
-
requests.limit(
|
64
|
+
requests.limit(10).order("date desc").select(
|
60
65
|
"count(id) resources",
|
61
66
|
"sum(request_count) requests",
|
62
|
-
"
|
63
|
-
)
|
67
|
+
"#{group_by} date"
|
68
|
+
).as_json
|
64
69
|
end
|
65
70
|
|
66
71
|
def users
|
@@ -30,8 +30,8 @@ Building a better future, one line of code at a time.
|
|
30
30
|
// ·
|
31
31
|
=end
|
32
32
|
|
33
|
-
module
|
34
|
-
class Analytics::TrendServices <
|
33
|
+
module LesliAudit
|
34
|
+
class Analytics::TrendServices < Lesli::ApplicationLesliService
|
35
35
|
|
36
36
|
def index
|
37
37
|
|