lesli 5.1.12 → 5.1.14
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 +3 -0
- data/app/assets/stylesheets/lesli/application.css +43 -3
- data/app/controllers/lesli/application_devise_controller.rb +9 -5
- data/app/controllers/lesli/application_lesli_controller.rb +31 -0
- data/app/controllers/lesli/items/attachments_controller.rb +200 -0
- data/app/controllers/lesli/items/discussions_controller.rb +94 -67
- data/app/controllers/lesli/items/tasks_controller.rb +132 -62
- data/app/controllers/lesli/roles_controller.rb +1 -6
- data/app/controllers/lesli/users_controller.rb +1 -5
- data/app/helpers/lesli/announcements_helper.rb +14 -0
- data/app/helpers/lesli/navigation_helper.rb +1 -1
- data/app/helpers/lesli/turbo_helper.rb +0 -18
- data/app/interfaces/lesli/responder_interface.rb +65 -38
- data/app/mailers/lesli/application_lesli_mailer.rb +34 -8
- data/app/models/concerns/lesli/account_initializer.rb +5 -37
- data/app/models/concerns/lesli/account_logs.rb +5 -16
- data/app/models/concerns/lesli/items/activities.rb +29 -33
- data/app/models/concerns/lesli/items/attachments.rb +88 -0
- data/app/models/concerns/lesli/items/discussions.rb +25 -11
- data/app/models/concerns/lesli/items/ownership.rb +27 -0
- data/app/models/concerns/lesli/items/tasks.rb +26 -6
- data/app/models/concerns/lesli/user_extensions.rb +8 -10
- data/app/models/lesli/account.rb +10 -14
- data/app/models/lesli/items/activity.rb +25 -2
- data/app/models/lesli/items/attachment.rb +117 -0
- data/app/models/lesli/items/discussion.rb +6 -2
- data/app/models/lesli/items/task.rb +3 -1
- data/app/models/lesli/role.rb +14 -2
- data/app/models/lesli/user.rb +19 -21
- data/app/operators/lesli/account_operator.rb +84 -0
- data/app/operators/lesli/resource_operator.rb +123 -0
- data/app/services/lesli/application_lesli_service.rb +33 -116
- data/app/services/lesli/resource_service.rb +12 -159
- data/app/services/lesli/role_service.rb +11 -229
- data/app/services/lesli/user_service.rb +37 -117
- data/app/views/lesli/abouts/welcome.html.erb +2 -5
- data/app/views/lesli/errors/not_found.html.erb +7 -21
- data/app/views/lesli/errors/unauthorized.html.erb +11 -27
- data/app/views/lesli/layouts/application-devise.html.erb +10 -9
- data/app/views/lesli/layouts/application-lesli.html.erb +2 -2
- data/app/views/lesli/partials/_application-lesli-announcements.html.erb +28 -0
- data/app/views/lesli/partials/_application-lesli-assets.html.erb +3 -3
- data/app/views/lesli/partials/_application-lesli-header.html.erb +8 -11
- data/app/views/lesli/partials/_application-lesli-turbo.html.erb +5 -0
- data/config/initializers/lesli.rb +10 -2
- data/config/locales/translations.en.yml +57 -14
- data/config/locales/translations.es.yml +55 -11
- data/db/migrate/v1/0000000210_create_lesli_users.rb +1 -0
- data/db/seed/accounts.rb +5 -5
- data/db/seed/users.rb +8 -16
- data/db/seed/xyz.rb +36 -17
- data/lib/generators/lesli/base_generator.rb +41 -3
- data/lib/generators/lesli/controller/controller_generator.rb +1 -1
- data/lib/generators/lesli/controller/templates/controller.rb.tt +12 -7
- data/lib/generators/lesli/model/model_generator.rb +1 -1
- data/lib/generators/lesli/resource/resource_generator.rb +290 -0
- data/lib/generators/lesli/resource/templates/controller.rb.tt +99 -0
- data/lib/generators/lesli/resource/templates/locale.en.yml.tt +13 -0
- data/lib/generators/lesli/resource/templates/migration.rb.tt +28 -0
- data/lib/generators/lesli/resource/templates/model.rb.tt +38 -0
- data/lib/generators/lesli/resource/templates/operator.rb.tt +15 -0
- data/lib/generators/lesli/resource/templates/service.rb.tt +52 -0
- data/lib/generators/lesli/resource/templates/tests/controller_test.rb.tt +14 -0
- data/lib/generators/lesli/resource/templates/tests/model_test.rb.tt +24 -0
- data/lib/generators/lesli/resource/templates/tests/operator_test.rb.tt +15 -0
- data/lib/generators/lesli/resource/templates/tests/service_test.rb.tt +17 -0
- data/lib/generators/lesli/resource/templates/views/_form.html.erb.tt +17 -0
- data/lib/generators/lesli/resource/templates/views/edit.html.erb.tt +4 -0
- data/lib/generators/lesli/resource/templates/views/index.html.erb.tt +22 -0
- data/lib/generators/lesli/resource/templates/views/new.html.erb.tt +4 -0
- data/lib/generators/lesli/resource/templates/views/show.html.erb.tt +17 -0
- data/lib/generators/lesli/scaffold/scaffold_generator.rb +4 -39
- data/lib/generators/lesli/service/service_generator.rb +1 -1
- data/lib/generators/lesli/service/templates/service.rb.tt +15 -7
- data/lib/generators/lesli/views/views_generator.rb +1 -1
- data/lib/generators/lesli_generator.rb +11 -0
- data/lib/lesli/courier.rb +66 -34
- data/lib/lesli/database_tasks.rb +145 -0
- data/lib/lesli/engine.rb +0 -4
- data/lib/lesli/router.rb +5 -2
- data/lib/lesli/version.rb +2 -2
- data/lib/migrate/items/activity_structure.rb +8 -8
- data/lib/migrate/items/attachment_structure.rb +9 -14
- data/lib/migrate/items/discussion_structure.rb +5 -5
- data/lib/migrate/items/task_structure.rb +2 -3
- data/lib/migrate/shared/account_structure.rb +1 -1
- data/lib/tasks/lesli/db.rake +16 -93
- data/lib/tasks/lesli/resources.rake +1 -1
- data/lib/tasks/lesli_tasks.rake +2 -3
- data/readme.md +6 -4
- data/test/fixtures/lesli_accounts.yml +18 -0
- data/test/fixtures/lesli_users.yml +23 -0
- metadata +39 -26
- data/app/assets/stylesheets/lesli/application.tailwind.css +0 -33
- data/app/views/lesli/partials/_application-lesli-sidebar.html.erb +0 -50
- data/config/brakeman.yml +0 -44
- data/config/initializers/devise.rb +0 -27
|
@@ -33,93 +33,163 @@ Building a better future, one line of code at a time.
|
|
|
33
33
|
module Lesli
|
|
34
34
|
module Items
|
|
35
35
|
class TasksController < ApplicationLesliController
|
|
36
|
-
before_action :
|
|
37
|
-
before_action :
|
|
36
|
+
before_action :set_taskable, only: :create
|
|
37
|
+
before_action :set_task, only: :update
|
|
38
38
|
|
|
39
|
-
def
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
def create
|
|
40
|
+
task = @taskable.add_task!(
|
|
41
|
+
creator: current_user,
|
|
42
|
+
title: task_params[:title]
|
|
43
|
+
)
|
|
44
|
+
refresh_tasks
|
|
45
|
+
|
|
46
|
+
message = I18n.t("lesli.items.tasks_created")
|
|
47
|
+
respond_with_lesli(
|
|
48
|
+
turbo: [
|
|
49
|
+
stream_notification_success(message),
|
|
50
|
+
tasks_stream
|
|
51
|
+
],
|
|
52
|
+
json: {
|
|
53
|
+
message: message,
|
|
54
|
+
task: task_payload(task)
|
|
55
|
+
},
|
|
56
|
+
status: :created
|
|
57
|
+
)
|
|
58
|
+
rescue ActiveRecord::RecordInvalid => error
|
|
59
|
+
respond_with_task_errors(error.record)
|
|
44
60
|
end
|
|
45
61
|
|
|
46
|
-
def
|
|
62
|
+
def update
|
|
63
|
+
@task.update!(done: !@task.done?)
|
|
64
|
+
|
|
65
|
+
message = task_status_message
|
|
66
|
+
respond_with_lesli(
|
|
67
|
+
turbo: [
|
|
68
|
+
stream_notification_success(message),
|
|
69
|
+
turbo_stream.replace(
|
|
70
|
+
helpers.dom_id(@task, scope_key)
|
|
71
|
+
) do
|
|
72
|
+
render_task(@task)
|
|
73
|
+
end
|
|
74
|
+
],
|
|
75
|
+
json: {
|
|
76
|
+
message: message,
|
|
77
|
+
task: task_payload(@task)
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
rescue ActiveRecord::RecordInvalid => error
|
|
81
|
+
respond_with_task_errors(error.record)
|
|
47
82
|
end
|
|
48
83
|
|
|
49
|
-
|
|
50
|
-
task = task_class.new(task_params)
|
|
84
|
+
private
|
|
51
85
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
86
|
+
def scope_key
|
|
87
|
+
ActiveSupport::Inflector
|
|
88
|
+
.underscore(task_class.name)
|
|
89
|
+
.tr("/", "_")
|
|
90
|
+
end
|
|
55
91
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
stream_notification_success("Task created"),
|
|
59
|
-
turbo_stream.prepend("#{scope_key}-lesli-items-tasks-list") do
|
|
60
|
-
LesliView::Items::Task.new(task, scope_key).render_in(view_context)
|
|
61
|
-
end
|
|
62
|
-
])
|
|
63
|
-
else
|
|
64
|
-
respond_with_lesli(
|
|
65
|
-
:turbo => stream_notification_danger(task.errors.full_messages)
|
|
66
|
-
)
|
|
67
|
-
end
|
|
92
|
+
def task_class
|
|
93
|
+
self.class.module_parent.const_get("Task")
|
|
68
94
|
end
|
|
69
95
|
|
|
70
|
-
def
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
])
|
|
96
|
+
def taskable_class
|
|
97
|
+
allowed_taskable_classes.find do |klass|
|
|
98
|
+
klass.name == params.require(:taskable_type)
|
|
99
|
+
end || raise(
|
|
100
|
+
ActiveRecord::RecordNotFound,
|
|
101
|
+
"Unauthorized taskable type"
|
|
102
|
+
)
|
|
79
103
|
end
|
|
80
104
|
|
|
81
|
-
|
|
105
|
+
def allowed_taskable_classes
|
|
106
|
+
[]
|
|
107
|
+
end
|
|
82
108
|
|
|
83
|
-
|
|
84
|
-
|
|
109
|
+
def set_task
|
|
110
|
+
@task = task_class.find(params[:id])
|
|
111
|
+
ensure_taskable_access!(@task.taskable)
|
|
112
|
+
end
|
|
85
113
|
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
def set_taskable
|
|
115
|
+
@taskable = taskable_class.find(
|
|
116
|
+
params.require(:taskable_id)
|
|
117
|
+
)
|
|
118
|
+
ensure_taskable_access!(@taskable)
|
|
119
|
+
end
|
|
88
120
|
|
|
89
|
-
|
|
90
|
-
|
|
121
|
+
def ensure_taskable_access!(taskable)
|
|
122
|
+
allowed = taskable.respond_to?(:lesli_item_accessible_by?) &&
|
|
123
|
+
taskable.lesli_item_accessible_by?(current_user)
|
|
91
124
|
|
|
92
|
-
|
|
93
|
-
|
|
125
|
+
raise ActiveRecord::RecordNotFound unless allowed
|
|
126
|
+
end
|
|
94
127
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
render json: { error: "Unauthorized taskable type" }, status: :forbidden and return
|
|
99
|
-
end
|
|
128
|
+
def task_params
|
|
129
|
+
params.require(scope_key.to_sym).permit(:title)
|
|
130
|
+
end
|
|
100
131
|
|
|
101
|
-
|
|
132
|
+
def render_task(task)
|
|
133
|
+
LesliView::Items::Task
|
|
134
|
+
.new(task, scope_key)
|
|
135
|
+
.render_in(view_context)
|
|
102
136
|
end
|
|
103
137
|
|
|
104
|
-
def
|
|
105
|
-
|
|
138
|
+
def task_payload(task)
|
|
139
|
+
{
|
|
140
|
+
id: task.id,
|
|
141
|
+
title: task.title,
|
|
142
|
+
done: task.done?,
|
|
143
|
+
taskable_type: task.taskable_type,
|
|
144
|
+
taskable_id: task.taskable_id,
|
|
145
|
+
creator: {
|
|
146
|
+
id: task.user_id,
|
|
147
|
+
name: task.user.name
|
|
148
|
+
},
|
|
149
|
+
created_at: task.created_at,
|
|
150
|
+
updated_at: task.updated_at
|
|
151
|
+
}
|
|
106
152
|
end
|
|
107
153
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
type = params[:taskable_type].presence
|
|
112
|
-
id = params[:taskable_id].presence
|
|
113
|
-
return if type.blank? || id.blank?
|
|
154
|
+
def refresh_tasks
|
|
155
|
+
association_name =
|
|
156
|
+
@taskable.class.lesli_tasks_association_name
|
|
114
157
|
|
|
115
|
-
taskable
|
|
158
|
+
@taskable.public_send(association_name).reset
|
|
159
|
+
end
|
|
116
160
|
|
|
117
|
-
|
|
118
|
-
|
|
161
|
+
def task_status_message
|
|
162
|
+
status = @task.done? ? :completed : :reopened
|
|
163
|
+
I18n.t("lesli.items.tasks_#{status}")
|
|
119
164
|
end
|
|
120
165
|
|
|
121
|
-
def
|
|
122
|
-
|
|
166
|
+
def tasks_stream(task: nil)
|
|
167
|
+
turbo_stream.replace(
|
|
168
|
+
helpers.dom_id(@taskable, :tasks)
|
|
169
|
+
) do
|
|
170
|
+
LesliView::Items::Tasks
|
|
171
|
+
.new(@taskable, task: task)
|
|
172
|
+
.render_in(view_context)
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def respond_with_task_errors(task)
|
|
177
|
+
turbo = [
|
|
178
|
+
stream_notification_danger(
|
|
179
|
+
task.errors.full_messages.to_sentence
|
|
180
|
+
)
|
|
181
|
+
]
|
|
182
|
+
|
|
183
|
+
if task.new_record?
|
|
184
|
+
refresh_tasks
|
|
185
|
+
turbo << tasks_stream(task: task)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
respond_with_lesli(
|
|
189
|
+
turbo: turbo,
|
|
190
|
+
json: { errors: task.errors },
|
|
191
|
+
status: :unprocessable_content
|
|
192
|
+
)
|
|
123
193
|
end
|
|
124
194
|
end
|
|
125
195
|
end
|
|
@@ -32,14 +32,9 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
|
|
33
33
|
module Lesli
|
|
34
34
|
class RolesController < ApplicationLesliController
|
|
35
|
-
before_action :set_role, only: []
|
|
36
35
|
|
|
37
36
|
def list
|
|
38
|
-
|
|
39
|
-
format.json {
|
|
40
|
-
respond_with_successful(RoleService.new(current_user, query).list(params))
|
|
41
|
-
}
|
|
42
|
-
end
|
|
37
|
+
respond_with_lesli(json: RoleService.new(current_user, query).list)
|
|
43
38
|
end
|
|
44
39
|
end
|
|
45
40
|
end
|
|
@@ -35,11 +35,7 @@ module Lesli
|
|
|
35
35
|
|
|
36
36
|
# GET /users/list
|
|
37
37
|
def list
|
|
38
|
-
|
|
39
|
-
format.json {
|
|
40
|
-
respond_with_successful(UserService.new(current_user, query).list(params))
|
|
41
|
-
}
|
|
42
|
-
end
|
|
38
|
+
respond_with_lesli(json: UserService.new(current_user, query).list(role: params[:role]))
|
|
43
39
|
end
|
|
44
40
|
end
|
|
45
41
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Lesli
|
|
2
|
+
module AnnouncementsHelper
|
|
3
|
+
ANNOUNCEMENT_STYLES = {
|
|
4
|
+
"info" => { icon: "info", classes: "border-info-300 bg-info-50 text-info-900" },
|
|
5
|
+
"success" => { icon: "check_circle", classes: "border-success-300 bg-success-50 text-success-900" },
|
|
6
|
+
"warning" => { icon: "warning", classes: "border-warning-300 bg-warning-50 text-warning-900" },
|
|
7
|
+
"danger" => { icon: "error", classes: "border-danger-300 bg-danger-50 text-danger-900" }
|
|
8
|
+
}.freeze
|
|
9
|
+
|
|
10
|
+
def announcement_style(category)
|
|
11
|
+
ANNOUNCEMENT_STYLES.fetch(category, ANNOUNCEMENT_STYLES.fetch("info"))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -75,7 +75,7 @@ module Lesli
|
|
|
75
75
|
item_class = class_names(
|
|
76
76
|
"group flex items-center gap-4 rounded-2xl px-4 py-3 text-base font-medium transition focus:outline-none focus:ring-2 focus:ring-sky-500/30",
|
|
77
77
|
"lg:gap-2 lg:rounded-xl lg:px-4 lg:py-2 lg:text-md",
|
|
78
|
-
active ? "
|
|
78
|
+
active ? "text-sky-700" : "text-slate-600 hover:bg-slate-50 hover:text-slate-950 lg:text-slate-500"
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
icon_class = class_names(
|
|
@@ -37,24 +37,6 @@ module Lesli
|
|
|
37
37
|
link_to(body, url, class: "link", data: { turbo_frame: '_top' })
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
# Meta-programming to define flash setter methods dynamically
|
|
41
|
-
# success("Everything worked!")
|
|
42
|
-
# danger("Oops, there was an error.")
|
|
43
|
-
# info("Just an informational message.")
|
|
44
|
-
# warning("This is a warning.")
|
|
45
|
-
[:info, :success, :warning, :danger].each do |flash_type|
|
|
46
|
-
define_method(flash_type) do |message|
|
|
47
|
-
flash[flash_type] = message
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def stream_notification_success(message)
|
|
52
|
-
success(message)
|
|
53
|
-
turbo_stream.replace("application-lesli-notifications") do
|
|
54
|
-
render("lesli/partials/application-lesli-notifications")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
40
|
def render_form_stream(partial_path, locals = {})
|
|
59
41
|
|
|
60
42
|
# Detect the current engine's namespace
|
|
@@ -32,6 +32,11 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
|
|
33
33
|
module Lesli
|
|
34
34
|
module ResponderInterface
|
|
35
|
+
NATIVE_TURBO_REDIRECTS = true
|
|
36
|
+
|
|
37
|
+
# Lesli-specific response status used to tell JSON clients that they
|
|
38
|
+
# must execute the action included in the response body.
|
|
39
|
+
ACTION_REQUIRED_STATUS = 490
|
|
35
40
|
|
|
36
41
|
# Standard json structure for paginated data,
|
|
37
42
|
# this is compatible for json, html and turbo responses
|
|
@@ -58,25 +63,43 @@ module Lesli
|
|
|
58
63
|
}
|
|
59
64
|
end
|
|
60
65
|
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
# Build a response for HTML, JSON, or Turbo Stream requests.
|
|
67
|
+
#
|
|
68
|
+
# `html` is passed to `render`. When omitted, Rails renders the current
|
|
69
|
+
# action's template. Use `redirect` for HTML and Turbo redirects instead
|
|
70
|
+
# of invoking `redirect_to` before calling this method. `status` applies
|
|
71
|
+
# to rendered responses; redirects use `redirect_status`.
|
|
72
|
+
def respond_with_lesli(
|
|
73
|
+
turbo: nil,
|
|
74
|
+
json: nil,
|
|
75
|
+
html: nil,
|
|
76
|
+
redirect: nil,
|
|
77
|
+
status: :ok,
|
|
78
|
+
redirect_status: :see_other
|
|
79
|
+
)
|
|
80
|
+
if html && redirect
|
|
81
|
+
raise ArgumentError, "Use either html: or redirect:, not both"
|
|
82
|
+
end
|
|
83
|
+
|
|
76
84
|
respond_to do |format|
|
|
77
|
-
format.html
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
format.html do
|
|
86
|
+
if redirect
|
|
87
|
+
redirect_to(redirect, status: redirect_status)
|
|
88
|
+
elsif html
|
|
89
|
+
render(html, status: status)
|
|
90
|
+
else
|
|
91
|
+
render(status: status)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
format.json { respond_with_http(status, json) }
|
|
96
|
+
format.turbo_stream do
|
|
97
|
+
if redirect && turbo.nil?
|
|
98
|
+
redirect_to(redirect, status: redirect_status)
|
|
99
|
+
else
|
|
100
|
+
render(turbo_stream: turbo, status: status)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
80
103
|
end
|
|
81
104
|
end
|
|
82
105
|
|
|
@@ -95,12 +118,13 @@ module Lesli
|
|
|
95
118
|
end
|
|
96
119
|
end
|
|
97
120
|
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
|
|
121
|
+
# Respond with HTTP 403 when an authenticated user does not have the
|
|
122
|
+
# privileges required to perform the requested action.
|
|
123
|
+
#
|
|
124
|
+
# This method is used by LesliShield's authorization interface after
|
|
125
|
+
# authentication has succeeded. `respond_with_unauthorized` remains
|
|
126
|
+
# available as a backwards-compatible alias for existing engines.
|
|
127
|
+
def respond_with_forbidden(details = {})
|
|
104
128
|
|
|
105
129
|
@error_object = {
|
|
106
130
|
error_role: nil,
|
|
@@ -117,11 +141,13 @@ module Lesli
|
|
|
117
141
|
|
|
118
142
|
respond_to do |format|
|
|
119
143
|
format.json { respond_with_json_unauthorized(@error_object) }
|
|
120
|
-
format.html { render('lesli/errors/unauthorized', status: :
|
|
121
|
-
format.turbo_stream { render('lesli/errors/unauthorized', status: :
|
|
144
|
+
format.html { render('lesli/errors/unauthorized', status: :forbidden) }
|
|
145
|
+
format.turbo_stream { render('lesli/errors/unauthorized', status: :forbidden) }
|
|
122
146
|
end
|
|
123
147
|
end
|
|
124
148
|
|
|
149
|
+
alias_method :respond_with_unauthorized, :respond_with_forbidden
|
|
150
|
+
|
|
125
151
|
|
|
126
152
|
# ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
|
|
127
153
|
# Auxiliar methods for responders
|
|
@@ -143,7 +169,7 @@ module Lesli
|
|
|
143
169
|
|
|
144
170
|
# Return the stream object so you can call:
|
|
145
171
|
# render turbo_stream: stream_notification_success("Done!")
|
|
146
|
-
turbo_stream.
|
|
172
|
+
turbo_stream.replace(
|
|
147
173
|
"application-lesli-notifications",
|
|
148
174
|
partial: "lesli/partials/application-lesli-notifications"
|
|
149
175
|
)
|
|
@@ -162,7 +188,7 @@ module Lesli
|
|
|
162
188
|
|
|
163
189
|
# Just a simple json success response for JSON
|
|
164
190
|
def respond_with_json(payload = nil)
|
|
165
|
-
respond_with_http(
|
|
191
|
+
respond_with_http(:ok, payload)
|
|
166
192
|
end
|
|
167
193
|
|
|
168
194
|
# Just a simple json not found response for JSON
|
|
@@ -185,19 +211,20 @@ module Lesli
|
|
|
185
211
|
end
|
|
186
212
|
|
|
187
213
|
# Just a simple http response for JSON
|
|
188
|
-
def respond_with_http(status, payload)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
:json => payload.nil? ? "" : payload.to_json
|
|
193
|
-
)
|
|
214
|
+
def respond_with_http(status, payload = nil)
|
|
215
|
+
return head(status) if payload.nil?
|
|
216
|
+
|
|
217
|
+
render(:status => status, :json => payload)
|
|
194
218
|
end
|
|
195
219
|
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
220
|
+
# Tell a JSON client to execute an action before it can continue.
|
|
221
|
+
# Clients using the Lesli API must handle ACTION_REQUIRED_STATUS and
|
|
222
|
+
# dispatch the action included in the response body.
|
|
199
223
|
def respond_with_action(action, message = "Action Required")
|
|
200
|
-
respond_with_http(
|
|
224
|
+
respond_with_http(
|
|
225
|
+
ACTION_REQUIRED_STATUS,
|
|
226
|
+
{ :message => message, :action => action }
|
|
227
|
+
)
|
|
201
228
|
end
|
|
202
229
|
end
|
|
203
230
|
end
|
|
@@ -34,7 +34,12 @@ module Lesli
|
|
|
34
34
|
class ApplicationLesliMailer < ActionMailer::Base
|
|
35
35
|
|
|
36
36
|
# Set a dynamic template according to the engine that is sending the email
|
|
37
|
-
default(
|
|
37
|
+
default(
|
|
38
|
+
template_path: (Lesli.config.mailer || {}).fetch(
|
|
39
|
+
:templates,
|
|
40
|
+
"lesli_assets/emails"
|
|
41
|
+
)
|
|
42
|
+
)
|
|
38
43
|
|
|
39
44
|
#after_action :log_mail_requests
|
|
40
45
|
|
|
@@ -48,9 +53,16 @@ module Lesli
|
|
|
48
53
|
end
|
|
49
54
|
|
|
50
55
|
def build_url(path, params = {})
|
|
51
|
-
default_url =
|
|
56
|
+
default_url = mailer_url_options
|
|
52
57
|
host = default_url[:host].to_s.sub(/\Ahttps?:\/\//, "")
|
|
53
|
-
scheme = default_url[:protocol]&.delete(":") || "http"
|
|
58
|
+
scheme = default_url[:protocol].presence&.to_s&.delete(":") || "http"
|
|
59
|
+
|
|
60
|
+
if host.blank?
|
|
61
|
+
raise ArgumentError, <<~MESSAGE.squish
|
|
62
|
+
Action Mailer requires default_url_options[:host] to build
|
|
63
|
+
absolute links in Lesli emails
|
|
64
|
+
MESSAGE
|
|
65
|
+
end
|
|
54
66
|
|
|
55
67
|
URI::Generic.build(
|
|
56
68
|
scheme: scheme,
|
|
@@ -63,19 +75,32 @@ module Lesli
|
|
|
63
75
|
|
|
64
76
|
protected
|
|
65
77
|
|
|
66
|
-
def email(
|
|
78
|
+
def email(
|
|
79
|
+
params = {},
|
|
80
|
+
user: nil,
|
|
81
|
+
to:,
|
|
82
|
+
subject:,
|
|
83
|
+
template_name:,
|
|
84
|
+
**headers
|
|
85
|
+
)
|
|
67
86
|
|
|
68
87
|
@params = @params.merge(params)
|
|
69
88
|
|
|
70
89
|
build_app_from_params(params)
|
|
71
90
|
|
|
72
91
|
mail(
|
|
73
|
-
to: to,
|
|
92
|
+
to: to,
|
|
74
93
|
subject: subject,
|
|
94
|
+
**headers,
|
|
75
95
|
template_name: template_name
|
|
76
96
|
)
|
|
77
97
|
end
|
|
78
98
|
|
|
99
|
+
def mailer_url_options
|
|
100
|
+
options = Rails.application.config.action_mailer.default_url_options
|
|
101
|
+
(options || {}).to_h.symbolize_keys
|
|
102
|
+
end
|
|
103
|
+
|
|
79
104
|
|
|
80
105
|
private
|
|
81
106
|
|
|
@@ -88,11 +113,12 @@ module Lesli
|
|
|
88
113
|
tag_line: "",
|
|
89
114
|
}
|
|
90
115
|
|
|
91
|
-
|
|
116
|
+
account = params[:user]&.account
|
|
117
|
+
return if account.blank?
|
|
92
118
|
|
|
93
119
|
@app[:company] = {
|
|
94
|
-
id:
|
|
95
|
-
name:
|
|
120
|
+
id: account.id,
|
|
121
|
+
name: account.name,
|
|
96
122
|
#tag_line: params[:user].account.company_tag_line,
|
|
97
123
|
}
|
|
98
124
|
end
|
|
@@ -34,46 +34,14 @@ module Lesli
|
|
|
34
34
|
module AccountInitializer
|
|
35
35
|
extend ActiveSupport::Concern
|
|
36
36
|
|
|
37
|
-
#
|
|
37
|
+
# Keep automatic account provisioning for every creation path,
|
|
38
|
+
# including seeders and console usage.
|
|
38
39
|
def initialize_account
|
|
39
|
-
|
|
40
|
-
# platform role for owners
|
|
41
|
-
owner = self.roles
|
|
42
|
-
.create_with({ permission_level: 2147483647 })
|
|
43
|
-
.find_or_create_by(:name => "owner")
|
|
44
|
-
|
|
45
|
-
# platform role for administrators
|
|
46
|
-
admin = self.roles
|
|
47
|
-
.create_with({ permission_level: 100000})
|
|
48
|
-
.find_or_create_by(name: "admin")
|
|
49
|
-
|
|
50
|
-
# platform role for guests
|
|
51
|
-
guest = self.roles
|
|
52
|
-
.create_with({ permission_level: 10, path_default: "/administration/profile" })
|
|
53
|
-
.find_or_create_by(name: "guest")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
# Add base privileges to roles
|
|
57
|
-
if defined?(LesliShield)
|
|
58
|
-
LesliShield::RoleActionService.new(nil).add_owner_actions(owner)
|
|
59
|
-
LesliShield::RoleActionService.new(nil).add_owner_actions(admin)
|
|
60
|
-
LesliShield::RoleActionService.new(nil).add_guest_actions(guest)
|
|
61
|
-
end
|
|
40
|
+
AccountOperator.new(account: self).initialize_roles!
|
|
62
41
|
end
|
|
63
42
|
|
|
64
|
-
|
|
65
|
-
# initialize engines for new accounts
|
|
66
43
|
def initialize_engines
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
next if ["Lesli", "LesliBabel", "Root"].include?(engine)
|
|
71
|
-
|
|
72
|
-
# Create an associated account if the attribute is blank
|
|
73
|
-
engine.constantize::Account.find_or_create_by!(account: self)
|
|
74
|
-
|
|
75
|
-
self.log(:account_initialization, "Engine: #{engine} initialized successfully")
|
|
76
|
-
end
|
|
77
|
-
end
|
|
44
|
+
AccountOperator.new(account: self).initialize_engines!
|
|
45
|
+
end
|
|
78
46
|
end
|
|
79
47
|
end
|
|
@@ -35,25 +35,14 @@ module Lesli
|
|
|
35
35
|
extend ActiveSupport::Concern
|
|
36
36
|
|
|
37
37
|
def log operation, description=nil, user:nil
|
|
38
|
-
return unless defined?(LesliAudit)
|
|
39
|
-
log_anonimous(operation, description) unless self.audit
|
|
40
|
-
log_account(operation, description) if self.audit
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
def log_anonimous operation, description
|
|
46
|
-
LesliAudit::AccountLog.create({
|
|
47
|
-
operation: operation,
|
|
48
|
-
description: description
|
|
49
|
-
})
|
|
50
|
-
end
|
|
38
|
+
return unless defined?(LesliAudit::ActivityAudit)
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
LesliAudit::ActivityAudit.record_account!(
|
|
41
|
+
account: self,
|
|
42
|
+
actor: user,
|
|
54
43
|
operation: operation,
|
|
55
44
|
description: description
|
|
56
|
-
|
|
45
|
+
)
|
|
57
46
|
end
|
|
58
47
|
end
|
|
59
48
|
end
|