lesli 5.0.20 → 5.0.22
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/Rakefile +5 -0
- data/app/assets/images/lesli/brand/register-background.jpg +0 -0
- data/app/assets/stylesheets/lesli/application.css +191 -1
- data/app/helpers/lesli/assets_helper.rb +23 -59
- data/app/models/concerns/lesli/account_initializer.rb +79 -0
- data/app/models/concerns/lesli/user_activities.rb +165 -0
- data/app/models/concerns/lesli/user_extensions.rb +133 -0
- data/app/models/concerns/lesli/user_security.rb +220 -0
- data/app/models/lesli/user.rb +15 -15
- data/app/services/lesli/role_service.rb +4 -4
- data/app/views/lesli/abouts/welcome.html.erb +11 -11
- data/app/views/lesli/errors/unauthorized.html.erb +1 -1
- data/app/views/lesli/layouts/application-devise.html.erb +3 -6
- data/app/views/lesli/layouts/application-lesli.html.erb +4 -5
- data/app/views/lesli/layouts/application-public.html.erb +2 -16
- data/app/views/lesli/partials/_application-analytics.html.erb +4 -6
- data/app/views/lesli/partials/_application-head.html.erb +4 -4
- data/app/views/lesli/partials/{_application-lesli-scss.html.erb → _application-lesli-css.html.erb} +4 -10
- data/app/views/lesli/partials/{_application-data.html.erb → _application-lesli-data.html.erb} +4 -1
- data/app/views/lesli/partials/_application-lesli-header.html.erb +0 -15
- data/app/views/lesli/partials/_application-lesli-javascript.html.erb +3 -5
- data/db/seed/accounts.rb +1 -1
- data/db/seed/users.rb +1 -1
- data/db/seeds.rb +6 -6
- data/lib/lesli/engine.rb +3 -4
- data/lib/lesli/version.rb +2 -2
- data/lib/rspec/helpers/lesli_helper.rb +11 -0
- data/lib/tasks/lesli/controllers.rake +1 -1
- data/lib/tasks/lesli/db.rake +26 -26
- data/lib/tasks/lesli_tasks.rake +0 -2
- metadata +19 -41
- data/app/models/concerns/account_initializer.rb +0 -82
- data/app/models/concerns/user_activities.rb +0 -163
- data/app/models/concerns/user_extensions.rb +0 -152
- data/app/models/concerns/user_security.rb +0 -277
- data/app/operators/lesli/user_registration_operator.rb +0 -122
- data/app/views/lesli/partials/_application-lesli-chatbox.html.erb +0 -35
- data/app/views/lesli/partials/_application-lesli-panels.html.erb +0 -58
- data/app/views/lesli/partials/_application-public-footer.html.erb +0 -51
- data/app/views/lesli/partials/_application-public-javascript.html.erb +0 -49
- data/app/views/lesli/partials/_application-public-scss.html.erb +0 -35
- data/config/initializers/devise_rails_8_patch.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6745cdd0cef2e17bdfbcfbeaa98b764cc17a0e4a08973a1f0f9602437aa36f05
|
4
|
+
data.tar.gz: ced2199cfd580ff4b713088317764bac7b3c9c4c6b27011f1567abcc11d96171
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df7919455d0486fa70cd31dac4cb448bfe766b1b71707f243efca570a9197bd15f179e61d80bcc7f6f871426bf057e8575c0965d0d235109e69b4953e920a29
|
7
|
+
data.tar.gz: d94812f844319558b726d5f701091260ffaa3ccee39a12330f293fc8907c4fe745107a4eebb36b51ad740f536663066141202ee6be9684d32cc2a93f08cfadcd
|
data/Rakefile
CHANGED
Binary file
|
@@ -1 +1,191 @@
|
|
1
|
-
|
1
|
+
@charset "UTF-8";
|
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
|
+
*/
|
32
|
+
/*
|
33
|
+
Lesli
|
34
|
+
|
35
|
+
Copyright (c) 2025, Lesli Technologies, S. A.
|
36
|
+
|
37
|
+
This program is free software: you can redistribute it and/or modify
|
38
|
+
it under the terms of the GNU General Public License as published by
|
39
|
+
the Free Software Foundation, either version 3 of the License, or
|
40
|
+
(at your option) any later version.
|
41
|
+
|
42
|
+
This program is distributed in the hope that it will be useful,
|
43
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
44
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
45
|
+
GNU General Public License for more details.
|
46
|
+
|
47
|
+
You should have received a copy of the GNU General Public License
|
48
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
49
|
+
|
50
|
+
Lesli · Ruby on Rails SaaS Development Framework.
|
51
|
+
|
52
|
+
Made with ♥ by LesliTech
|
53
|
+
Building a better future, one line of code at a time.
|
54
|
+
|
55
|
+
@contact hello@lesli.tech
|
56
|
+
@website https://www.lesli.tech
|
57
|
+
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
58
|
+
|
59
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
60
|
+
// ·
|
61
|
+
*/
|
62
|
+
/**
|
63
|
+
Lesli
|
64
|
+
|
65
|
+
Copyright (c) 2025, Lesli Technologies, S. A.
|
66
|
+
|
67
|
+
This program is free software: you can redistribute it and/or modify
|
68
|
+
it under the terms of the GNU General Public License as published by
|
69
|
+
the Free Software Foundation, either version 3 of the License, or
|
70
|
+
(at your option) any later version.
|
71
|
+
|
72
|
+
This program is distributed in the hope that it will be useful,
|
73
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
74
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
75
|
+
GNU General Public License for more details.
|
76
|
+
|
77
|
+
You should have received a copy of the GNU General Public License
|
78
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
79
|
+
|
80
|
+
Lesli - SCSS Utilities for websites, apps and web applications
|
81
|
+
|
82
|
+
Made with ♥ by LesliTech
|
83
|
+
Building a better future, one line of code at a time.
|
84
|
+
|
85
|
+
@contact hello@lesli.tech
|
86
|
+
@website https://www.lesli.tech
|
87
|
+
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
88
|
+
|
89
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
90
|
+
// ·
|
91
|
+
*/
|
92
|
+
/*
|
93
|
+
Lesli
|
94
|
+
|
95
|
+
Copyright (c) 2025, Lesli Technologies, S. A.
|
96
|
+
|
97
|
+
This program is free software: you can redistribute it and/or modify
|
98
|
+
it under the terms of the GNU General Public License as published by
|
99
|
+
the Free Software Foundation, either version 3 of the License, or
|
100
|
+
(at your option) any later version.
|
101
|
+
|
102
|
+
This program is distributed in the hope that it will be useful,
|
103
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
104
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
105
|
+
GNU General Public License for more details.
|
106
|
+
|
107
|
+
You should have received a copy of the GNU General Public License
|
108
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
109
|
+
|
110
|
+
Lesli - SCSS Utilities for websites, apps and web applications
|
111
|
+
|
112
|
+
Made with ♥ by LesliTech
|
113
|
+
Building a better future, one line of code at a time.
|
114
|
+
|
115
|
+
@contact hello@lesli.tech
|
116
|
+
@website https://www.lesli.tech
|
117
|
+
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
118
|
+
|
119
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
120
|
+
// ·
|
121
|
+
*/
|
122
|
+
/**
|
123
|
+
Lesli
|
124
|
+
|
125
|
+
Copyright (c) 2025, Lesli Technologies, S. A.
|
126
|
+
|
127
|
+
This program is free software: you can redistribute it and/or modify
|
128
|
+
it under the terms of the GNU General Public License as published by
|
129
|
+
the Free Software Foundation, either version 3 of the License, or
|
130
|
+
(at your option) any later version.
|
131
|
+
|
132
|
+
This program is distributed in the hope that it will be useful,
|
133
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
134
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
135
|
+
GNU General Public License for more details.
|
136
|
+
|
137
|
+
You should have received a copy of the GNU General Public License
|
138
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
139
|
+
|
140
|
+
Lesli - SCSS Utilities for websites, apps and web applications
|
141
|
+
|
142
|
+
Made with ♥ by LesliTech
|
143
|
+
Building a better future, one line of code at a time.
|
144
|
+
|
145
|
+
@contact hello@lesli.tech
|
146
|
+
@website https://www.lesli.tech
|
147
|
+
@license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
|
148
|
+
|
149
|
+
// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
150
|
+
// ·
|
151
|
+
*/
|
152
|
+
body.lesli.apps.show .lesli-element-header {
|
153
|
+
margin-bottom: 5rem !important;
|
154
|
+
}
|
155
|
+
body.lesli.apps.show .engines {
|
156
|
+
gap: 24px;
|
157
|
+
margin-inline-end: auto;
|
158
|
+
margin-inline-start: auto;
|
159
|
+
}
|
160
|
+
body.lesli.apps.show .engines a {
|
161
|
+
flex-basis: 318px;
|
162
|
+
text-align: center;
|
163
|
+
padding: 2rem 0.4rem 2.8rem;
|
164
|
+
border: white 1px solid;
|
165
|
+
border-radius: 6px;
|
166
|
+
background-color: white;
|
167
|
+
transition: all ease-in-out 0.2s;
|
168
|
+
box-shadow: rgba(9, 30, 66, 0.25) 0px 4px 8px -2px, rgba(9, 30, 66, 0.08) 0px 0px 0px 1px;
|
169
|
+
}
|
170
|
+
body.lesli.apps.show .engines a:hover {
|
171
|
+
border-color: var(--lesli-color-primary);
|
172
|
+
transform: translateY(-2px);
|
173
|
+
}
|
174
|
+
body.lesli.apps.show .engines a.is-active {
|
175
|
+
background-color: #F0F4FF;
|
176
|
+
border-color: var(--lesli-color-primary);
|
177
|
+
}
|
178
|
+
body.lesli.apps.show .engines a svg {
|
179
|
+
margin-right: 0.4rem;
|
180
|
+
fill: var(--lesli-color-primary);
|
181
|
+
}
|
182
|
+
body.lesli.apps.show .engines a p {
|
183
|
+
font-size: 14;
|
184
|
+
}
|
185
|
+
body.lesli.apps.show .engines a span {
|
186
|
+
font-weight: 600;
|
187
|
+
font-size: 20px;
|
188
|
+
}
|
189
|
+
body.lesli.apps.show .engines a span, body.lesli.apps.show .engines a p {
|
190
|
+
color: var(--lesli-color-primary);
|
191
|
+
}
|
@@ -34,77 +34,41 @@ module Lesli
|
|
34
34
|
module AssetsHelper
|
35
35
|
# Return a string path to load the template stylesheet
|
36
36
|
# by default we always return the latest version of the template
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
|
37
|
+
#
|
38
|
+
# stylesheet from main App
|
39
|
+
# lesli_asset_path()
|
40
|
+
# /assets/application.css
|
41
|
+
#
|
42
|
+
# Specific stylesheet from Engine
|
43
|
+
# lesli_asset_path(:lesli, 'application')
|
44
|
+
# /assets/lesli/application.css
|
45
|
+
#
|
46
|
+
# Specific stylesheet from gem
|
47
|
+
# lesli_asset_path(:lesli_assets, 'templates/application')
|
48
|
+
# /assets/lesli_assets/templates/application.css
|
49
|
+
def lesli_asset_path(engine = nil, stylesheet = 'application')
|
42
50
|
|
43
51
|
# Stylesheets from specific engine
|
44
|
-
return "#{engine}
|
52
|
+
return "#{engine}/#{stylesheet}" if engine.present?
|
45
53
|
|
46
54
|
# Get current engine information
|
47
|
-
|
55
|
+
engine_code = lesli_engine(:code)
|
48
56
|
|
49
57
|
# Rails main host app stylesheets
|
50
|
-
return
|
58
|
+
return 'application' if engine_code == 'root'
|
51
59
|
|
52
60
|
# Rails engines stylesheets
|
53
|
-
"#{
|
54
|
-
end
|
55
|
-
|
56
|
-
# Return a string path to load the main engine stylesheet
|
57
|
-
def application_stylesheet_engine_path
|
58
|
-
lesli_engine = lesli_engine(:code)
|
59
|
-
return "administration/application" if is_lesli_administration?
|
60
|
-
return "onboardings/application" if is_lesli_onboarding?
|
61
|
-
|
62
|
-
"#{lesli_engine}/application"
|
63
|
-
end
|
64
|
-
|
65
|
-
# Return a string path to load the main javascript app of the engine
|
66
|
-
def lesli_application_javascript_path
|
67
|
-
# get the namespace to load specific javascript file
|
68
|
-
# for engine or specific javascript file for core controller
|
69
|
-
# path_segments = controller_path.split("/")
|
70
|
-
# lesli_engine = path_segments.shift
|
71
|
-
|
72
|
-
# return "onboardings/application" if is_lesli_onboarding?
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
# Get current engine information
|
77
|
-
lesli_engine_code = lesli_engine(:code)
|
78
|
-
|
79
|
-
# Rails main host app stylesheets
|
80
|
-
return "application" if lesli_engine_code == "root"
|
81
|
-
|
82
|
-
# Rails engines stylesheets
|
83
|
-
"#{lesli_engine_code}/application"
|
84
|
-
end
|
85
|
-
|
86
|
-
def javascript_googlemaps_sdk
|
87
|
-
"<script type=\"application/javascript\" src=\"https://maps.googleapis.com/maps/api/js?key=#{Rails.application.credentials.dig(
|
88
|
-
:providers, :google, :maps_sdk_token
|
89
|
-
)}\"></script>".html_safe
|
90
|
-
end
|
91
|
-
|
92
|
-
def javascript_apple_mapkit_js
|
93
|
-
token = Rails.application.credentials.dig(:providers, :apple, :mapkit_token)
|
94
|
-
|
95
|
-
"<script type=\"application/javascript\" src=\"https://cdn.apple-mapkit.com/mk/5.45.0/mapkit.js\"></script>
|
96
|
-
<script type=\"application/javascript\">
|
97
|
-
const ampkt = \"#{token}\"
|
98
|
-
</script>".html_safe
|
61
|
+
"#{engine_code}/#{stylesheet}"
|
99
62
|
end
|
100
63
|
|
101
64
|
def favicon
|
102
65
|
icon_path = customization_instance_logo_url(logo: "favicon")
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
66
|
+
|
67
|
+
safe_join([
|
68
|
+
tag.link(href: icon_path, rel: "alternate icon"),
|
69
|
+
tag.link(href: icon_path, rel: "icon", type: "image/svg+xml"),
|
70
|
+
tag.link(href: icon_path, rel: "mask-icon", color: "#ff8a01")
|
71
|
+
])
|
108
72
|
end
|
109
73
|
end
|
110
74
|
end
|
@@ -0,0 +1,79 @@
|
|
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
|
32
|
+
|
33
|
+
module Lesli
|
34
|
+
module AccountInitializer
|
35
|
+
extend ActiveSupport::Concern
|
36
|
+
|
37
|
+
# initialize minimum resources needed for the account
|
38
|
+
def initialize_account
|
39
|
+
|
40
|
+
|
41
|
+
# create default roles for the new account
|
42
|
+
owner = self.roles
|
43
|
+
.create_with({ permission_level: 2147483647 })
|
44
|
+
.find_or_create_by(:name => "owner")
|
45
|
+
|
46
|
+
|
47
|
+
# platform administrator role
|
48
|
+
admin = self.roles
|
49
|
+
.create_with({ permission_level: 100000})
|
50
|
+
.find_or_create_by(name: "admin")
|
51
|
+
|
52
|
+
|
53
|
+
# access only to user profile
|
54
|
+
limited = self.roles
|
55
|
+
.create_with({ permission_level: 10, path_default: "/administration/profile" })
|
56
|
+
.find_or_create_by(name: "limited")
|
57
|
+
|
58
|
+
|
59
|
+
# Add base privileges to roles
|
60
|
+
Lesli::RoleOperator.new(owner).add_owner_actions
|
61
|
+
Lesli::RoleOperator.new(admin).add_owner_actions
|
62
|
+
Lesli::RoleOperator.new(limited).add_profile_actions
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# initialize engines for new accounts
|
68
|
+
def initialize_engines
|
69
|
+
|
70
|
+
LesliSystem.engines.each do |engine, data|
|
71
|
+
|
72
|
+
next if ["Lesli", "LesliBabel", "Root"].include?(engine)
|
73
|
+
|
74
|
+
# Create an associated account if the attribute is blank
|
75
|
+
engine.constantize::Account.create!(account: self)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,165 @@
|
|
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 platform.
|
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
|
+
|
34
|
+
# User Activities methods
|
35
|
+
# Methods related to cloudobject/activities and user_logs
|
36
|
+
module Lesli
|
37
|
+
module UserActivities
|
38
|
+
extend ActiveSupport::Concern
|
39
|
+
|
40
|
+
|
41
|
+
# @return [void]
|
42
|
+
# @description Register a new log for the current user
|
43
|
+
# @param description String Details about the process
|
44
|
+
# @param session String Current or active session id
|
45
|
+
def log description, session=nil
|
46
|
+
self.logs.create(session, description)
|
47
|
+
end
|
48
|
+
|
49
|
+
def log_activity_update(current_user, user, old_attributes, new_attributes)
|
50
|
+
old_attributes.except!("id", "users_id", "created_at", "updated_at", "deleted_at")
|
51
|
+
old_attributes.each do |key, value|
|
52
|
+
if value != new_attributes[key]
|
53
|
+
value_from = value
|
54
|
+
value_to = new_attributes[key]
|
55
|
+
value_from = Courier::Core::Date.to_string_datetime(value_from) if value_from.is_a?(Time) || value_from.is_a?(Date)
|
56
|
+
value_to = Courier::Core::Date.to_string_datetime(value_to) if value_to.is_a?(Time) || value_to.is_a?(Date)
|
57
|
+
|
58
|
+
user.activities.create!(
|
59
|
+
assigned: current_user,
|
60
|
+
category: "action_update",
|
61
|
+
field_name: key,
|
62
|
+
value_from: value_from,
|
63
|
+
value_to: value_to
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Define class methods from given block
|
71
|
+
# This allows to inject class methods to the User model, so we can use:
|
72
|
+
# User.log_activity_create
|
73
|
+
class_methods do
|
74
|
+
|
75
|
+
|
76
|
+
# @return [void]
|
77
|
+
# @param current_user [::User] The user that created the user
|
78
|
+
# @param [User] The user that was created
|
79
|
+
# @description Creates an activity for this user indicating who created it.
|
80
|
+
# Example
|
81
|
+
# params = {...}
|
82
|
+
# user = User.create(params)
|
83
|
+
# User.log_activity_create(User.find(1), user)
|
84
|
+
def log_activity_create(current_user, user)
|
85
|
+
user.activities.create(
|
86
|
+
assigned: current_user,
|
87
|
+
category: "action_create"
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# @return [void]
|
93
|
+
# @param current_user [::User] The user that created the user
|
94
|
+
# @param user [User] The User that was created
|
95
|
+
# @param old_attributes[Hash] The data of the record before update
|
96
|
+
# @param new_attributes[Hash] The data of the record after update
|
97
|
+
# @description Creates an activity for this user if someone changed any of this values
|
98
|
+
# Example
|
99
|
+
# user = User.find(1)
|
100
|
+
# old_attributes = user.attributes.merge({detail_attributes: user.detail.attributes})
|
101
|
+
# user.update(main_employee: User.find(33))
|
102
|
+
# new_attributes = user.attributes.merge({detail_attributes: user.detail.attributes})
|
103
|
+
# User.log_activity_update(User.find(1), user, old_attributes, new_attributes)
|
104
|
+
def log_activity_update(current_user, user, old_attributes, new_attributes)
|
105
|
+
old_attributes.except!("id", "users_id", "created_at", "updated_at", "deleted_at")
|
106
|
+
old_attributes.each do |key, value|
|
107
|
+
if value != new_attributes[key]
|
108
|
+
value_from = value
|
109
|
+
value_to = new_attributes[key]
|
110
|
+
value_from = Courier::Core::Date.to_string_datetime(value_from) if value_from.is_a?(Time) || value_from.is_a?(Date)
|
111
|
+
value_to = Courier::Core::Date.to_string_datetime(value_to) if value_to.is_a?(Time) || value_to.is_a?(Date)
|
112
|
+
|
113
|
+
user.activities.create(
|
114
|
+
owner: current_user,
|
115
|
+
category: "action_update",
|
116
|
+
field_name: key,
|
117
|
+
value_from: value_from,
|
118
|
+
value_to: value_to
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
# @return [void]
|
126
|
+
# @param current_user [::User] The user that created the user
|
127
|
+
# @param user [User] The User that was created
|
128
|
+
# @param user [Role] The Role assigned to the user
|
129
|
+
# @description Creates an activity for this user if someone adds a new role
|
130
|
+
# Example
|
131
|
+
# user = User.find(1)
|
132
|
+
# role = User.find(1)
|
133
|
+
# User.log_activity_create_user_role(current_user, user, role)
|
134
|
+
def log_activity_create_user_role(current_user, user, role)
|
135
|
+
role_name = role.name
|
136
|
+
|
137
|
+
user.activities.create(
|
138
|
+
assigned: current_user,
|
139
|
+
category: "action_create_user_role",
|
140
|
+
value_to: role_name
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
# @return [void]
|
146
|
+
# @param current_user [::User] The user that created the user
|
147
|
+
# @param user [User] The User that was created
|
148
|
+
# @param user [Role] The Role assigned to the user
|
149
|
+
# @description Creates an activity for this user if someone removes a role
|
150
|
+
# Example
|
151
|
+
# user = User.find(1)
|
152
|
+
# role = User.find(1)
|
153
|
+
# User.log_activity_destroy_user_role(current_user, user, role)
|
154
|
+
def log_activity_destroy_user_role(current_user, user, role)
|
155
|
+
role_name = role.name
|
156
|
+
|
157
|
+
user.activities.create(
|
158
|
+
assigned: current_user,
|
159
|
+
category: "action_destroy_user_role",
|
160
|
+
value_to: role_name
|
161
|
+
)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|