lesli 5.1.13 → 5.1.15

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/app/assets/stylesheets/lesli/application.css +527 -10
  3. data/app/controllers/lesli/application_lesli_controller.rb +27 -0
  4. data/app/controllers/lesli/items/attachments_controller.rb +3 -3
  5. data/app/controllers/lesli/items/discussions_controller.rb +2 -2
  6. data/app/controllers/lesli/items/tasks_controller.rb +2 -2
  7. data/app/controllers/lesli/roles_controller.rb +1 -6
  8. data/app/controllers/lesli/users_controller.rb +1 -5
  9. data/app/helpers/lesli/html_helper.rb +5 -5
  10. data/app/helpers/lesli/navigation_helper.rb +5 -5
  11. data/app/interfaces/lesli/customization_interface.rb +11 -31
  12. data/app/interfaces/lesli/responder_interface.rb +11 -4
  13. data/app/models/concerns/lesli/account_initializer.rb +5 -45
  14. data/app/models/concerns/lesli/user_extensions.rb +4 -2
  15. data/app/models/lesli/items/attachment.rb +3 -3
  16. data/app/models/lesli/role.rb +14 -2
  17. data/app/models/lesli/user.rb +7 -0
  18. data/app/operators/lesli/account_operator.rb +84 -0
  19. data/app/operators/lesli/resource_operator.rb +123 -0
  20. data/app/services/lesli/application_lesli_service.rb +33 -116
  21. data/app/services/lesli/resource_service.rb +12 -159
  22. data/app/services/lesli/role_service.rb +11 -229
  23. data/app/services/lesli/user_service.rb +37 -117
  24. data/app/views/lesli/abouts/welcome.html.erb +4 -4
  25. data/app/views/lesli/apps/show.html.erb +1 -1
  26. data/app/views/lesli/errors/not_found.html.erb +9 -16
  27. data/app/views/lesli/errors/unauthorized.html.erb +19 -28
  28. data/app/views/lesli/layouts/application-devise.html.erb +1 -0
  29. data/app/views/lesli/layouts/application-lesli.html.erb +1 -1
  30. data/app/views/lesli/partials/_application-lesli-announcements.html.erb +18 -0
  31. data/app/views/lesli/partials/_application-lesli-assets.html.erb +16 -19
  32. data/app/views/lesli/partials/_application-lesli-header.html.erb +45 -100
  33. data/app/views/lesli/partials/_application-lesli-notifications.html.erb +2 -27
  34. data/app/views/lesli/partials/_application-lesli-turbo.html.erb +5 -0
  35. data/app/views/lesli/shared/dashboards/edit.html.erb +1 -1
  36. data/app/views/lesli/shared/dashboards/show.html.erb +1 -1
  37. data/config/initializers/lesli.rb +7 -2
  38. data/config/locales/translations.en.yml +56 -48
  39. data/config/locales/translations.es.yml +54 -45
  40. data/db/migrate/v1/0000000210_create_lesli_users.rb +1 -0
  41. data/db/seed/xyz.rb +1 -3
  42. data/lib/generators/lesli/base_generator.rb +41 -3
  43. data/lib/generators/lesli/controller/controller_generator.rb +1 -1
  44. data/lib/generators/lesli/controller/templates/controller.rb.tt +12 -7
  45. data/lib/generators/lesli/model/model_generator.rb +1 -1
  46. data/lib/generators/lesli/resource/resource_generator.rb +290 -0
  47. data/lib/generators/lesli/resource/templates/controller.rb.tt +99 -0
  48. data/lib/generators/lesli/resource/templates/locale.en.yml.tt +13 -0
  49. data/lib/generators/lesli/resource/templates/migration.rb.tt +28 -0
  50. data/lib/generators/lesli/resource/templates/model.rb.tt +38 -0
  51. data/lib/generators/lesli/resource/templates/operator.rb.tt +15 -0
  52. data/lib/generators/lesli/resource/templates/service.rb.tt +52 -0
  53. data/lib/generators/lesli/resource/templates/tests/controller_test.rb.tt +14 -0
  54. data/lib/generators/lesli/resource/templates/tests/model_test.rb.tt +24 -0
  55. data/lib/generators/lesli/resource/templates/tests/operator_test.rb.tt +15 -0
  56. data/lib/generators/lesli/resource/templates/tests/service_test.rb.tt +17 -0
  57. data/lib/generators/lesli/resource/templates/views/_form.html.erb.tt +17 -0
  58. data/lib/generators/lesli/resource/templates/views/edit.html.erb.tt +4 -0
  59. data/lib/generators/lesli/resource/templates/views/index.html.erb.tt +22 -0
  60. data/lib/generators/lesli/resource/templates/views/new.html.erb.tt +4 -0
  61. data/lib/generators/lesli/resource/templates/views/show.html.erb.tt +17 -0
  62. data/lib/generators/lesli/scaffold/scaffold_generator.rb +4 -39
  63. data/lib/generators/lesli/service/service_generator.rb +1 -1
  64. data/lib/generators/lesli/service/templates/service.rb.tt +15 -7
  65. data/lib/generators/lesli/views/views_generator.rb +1 -1
  66. data/lib/generators/lesli_generator.rb +11 -0
  67. data/lib/lesli/courier.rb +66 -34
  68. data/lib/lesli/database_tasks.rb +145 -0
  69. data/lib/lesli/version.rb +2 -2
  70. data/lib/tasks/lesli/db.rake +16 -93
  71. data/lib/tasks/lesli/resources.rake +1 -1
  72. data/readme.md +3 -1
  73. metadata +23 -4
  74. data/app/views/lesli/partials/_application-lesli-footer.html.erb +0 -82
  75. data/app/views/lesli/partials/_application-lesli-sidebar.html.erb +0 -50
@@ -35,11 +35,7 @@ module Lesli
35
35
 
36
36
  # GET /users/list
37
37
  def list
38
- respond_to do |format|
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
@@ -76,19 +76,19 @@ module Lesli
76
76
  [lesli_instance_code, controller_path.sub("_","-").split("/"), action_name].join(" ")
77
77
  end
78
78
 
79
- # Return a string path to load the template stylesheet
80
- # by default we always return the latest version of the template
79
+ # Return the logical asset path for the current engine or an explicit package.
80
+ # Rails asset helpers resolve the fingerprinted URL.
81
81
  #
82
82
  # stylesheet from main App
83
- # lesli_stylesheet_path()
83
+ # lesli_asset_path()
84
84
  # /assets/application.css
85
85
  #
86
86
  # Specific stylesheet from Engine
87
- # lesli_stylesheet_path(:lesli, 'application')
87
+ # lesli_asset_path(:lesli, 'application')
88
88
  # /assets/lesli/application.css
89
89
  #
90
90
  # Specific stylesheet from gem
91
- # lesli_stylesheet_path(:lesli_assets, 'templates/application')
91
+ # lesli_asset_path(:lesli_assets, 'templates/application')
92
92
  # /assets/lesli_assets/templates/application.css
93
93
  def lesli_asset_path(engine = nil, stylesheet = 'application')
94
94
 
@@ -73,15 +73,15 @@ module Lesli
73
73
  active = current_page?(path)
74
74
 
75
75
  item_class = class_names(
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",
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-primary/30",
77
77
  "lg:gap-2 lg:rounded-xl lg:px-4 lg:py-2 lg:text-md",
78
- active ? "bg-sky-50 text-sky-700" : "text-slate-600 hover:bg-slate-50 hover:text-slate-950 lg:text-slate-500"
78
+ active ? "text-primary-strong" : "text-neutral-600 hover:bg-neutral-50 hover:text-neutral-900 lg:text-neutral-500"
79
79
  )
80
80
 
81
81
  icon_class = class_names(
82
82
  icon,
83
83
  "text-[24px] leading-none transition lg:text-[18px]",
84
- active ? "text-sky-600" : "text-slate-500 group-hover:text-slate-900"
84
+ active ? "text-primary" : "text-neutral-500 group-hover:text-neutral-900"
85
85
  )
86
86
 
87
87
  link_to(path, { class: item_class }, data: { turbo_frame: "_top" }) do
@@ -362,7 +362,7 @@ module Lesli
362
362
  "transition-all duration-200 ease-out",
363
363
  "hover:-translate-y-0.5 hover:border-[var(--lesli-color-primary)] hover:shadow-lg",
364
364
  "focus:outline-none focus-visible:ring-4 focus-visible:ring-[var(--lesli-color-primary)]/15",
365
- is_active ? "is-active border-[var(--lesli-color-primary)] bg-sky-50" : "border-slate-200"
365
+ is_active ? "is-active border-[var(--lesli-color-primary)] bg-primary-soft" : "border-neutral-200"
366
366
  )
367
367
 
368
368
  content_tag(:a, id: path.gsub("/", ""), href: path, class: card_classes, data: { turbo: false }) do
@@ -381,7 +381,7 @@ module Lesli
381
381
  content_tag(:div, class: "px-2") do
382
382
  safe_join([
383
383
  content_tag(:span, title, class: "block text-xl font-semibold leading-6 tracking-tight text-[var(--lesli-color-primary)]"),
384
- content_tag(:p, subtitle, class: "mt-2 font-[OpenSans] text-sm font-normal leading-5 text-slate-500")
384
+ content_tag(:p, subtitle, class: "mt-2 font-[OpenSans] text-sm font-normal leading-5 text-neutral-500")
385
385
  ])
386
386
  end,
387
387
 
@@ -1,42 +1,22 @@
1
1
  module Lesli
2
2
  module CustomizationInterface
3
3
 
4
- # set customization only for lesli_cloud instance
4
+ # Load the account theme for pages rendered by the shared application layout.
5
5
  def set_customizer
6
- =begin
7
- # @account is only for html and pdf requests
6
+ # Turbo redirects can negotiate HTML through the Turbo Stream MIME type.
8
7
  return unless request.format.html? || request.format.pdf?
8
+ return unless defined?(LesliAdmin) && respond_to?(:current_user, true) && current_user
9
9
 
10
- # return unless Lesli.instance[:code] == "lesli_cloud"
10
+ color = current_user.account.admin&.settings
11
+ &.where(name: "lesli_theme_color_primary", user_id: nil)
12
+ &.pick(:value)
11
13
 
12
- @lesli[:customization] = {}
14
+ # Only emit a hex color. Missing or invalid settings keep the CSS fallback.
15
+ return unless color.to_s.match?(/\A#(?:\h{3}|\h{6})\z/)
13
16
 
14
- logos = {}
15
- # logo_identifiers = Account::File.file_types.keys
16
- # custom_logos = current_user.account.files.where("file_type in (?)", logo_identifiers).order(id: :desc).all
17
- # logo_identifiers.each do |logo_identifier|
18
- # custom_logo = custom_logos.find { |logo| logo.file_type == logo_identifier}
19
- # next unless custom_logo
20
-
21
- # custom_logo_url = "/administration/account/files/#{custom_logo.id}"
22
- # custo_logo_url = custom_logo.attachment_url if custom_logo.attachment_identifier
23
- # custom_logo_url = custom_logo.attachment_public_url if custom_logo.attachment_public_identifier
24
-
25
- # logos[logo_identifier.to_sym] = custom_logo_url
26
- # end
27
- @lesli[:customization][:logos] = logos
28
-
29
- colors = {}
30
- # color_identifiers = ::Account::Setting.theme_settings_keys
31
- # custom_colors = current_user.account.settings.where("name in (?)", color_identifiers).all
32
- # color_identifiers.each do |color_identifier|
33
- # custom_color = custom_colors.find { |color| color.name == color_identifier}
34
- # next unless custom_color
35
-
36
- # colors[color_identifier.to_sym] = custom_color.value
37
- # end
38
- @lesli[:customization][:colors] = colors
39
- =end
17
+ @lesli[:customization] ||= {}
18
+ @lesli[:customization][:colors] ||= {}
19
+ @lesli[:customization][:colors][:lesli_theme_color_primary] = color
40
20
  end
41
21
  end
42
22
  end
@@ -32,6 +32,7 @@ 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
35
36
 
36
37
  # Lesli-specific response status used to tell JSON clients that they
37
38
  # must execute the action included in the response body.
@@ -65,9 +66,9 @@ module Lesli
65
66
  # Build a response for HTML, JSON, or Turbo Stream requests.
66
67
  #
67
68
  # `html` is passed to `render`. When omitted, Rails renders the current
68
- # action's template. Use `redirect` for HTML redirects instead of
69
- # invoking `redirect_to` before calling this method. `status` applies to
70
- # rendered responses; redirects use `redirect_status`.
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`.
71
72
  def respond_with_lesli(
72
73
  turbo: nil,
73
74
  json: nil,
@@ -92,7 +93,13 @@ module Lesli
92
93
  end
93
94
 
94
95
  format.json { respond_with_http(status, json) }
95
- format.turbo_stream { render(turbo_stream: turbo, status: status) }
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
96
103
  end
97
104
  end
98
105
 
@@ -34,54 +34,14 @@ module Lesli
34
34
  module AccountInitializer
35
35
  extend ActiveSupport::Concern
36
36
 
37
- # initialize minimum resources needed for the account
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, active: true })
43
- .find_or_create_by(:name => "owner")
44
-
45
- # platform role for administrators
46
- admin = self.roles
47
- .create_with({ permission_level: 100000, active: true })
48
- .find_or_create_by(name: "admin")
49
-
50
- # platform role for guests
51
- guest = self.roles
52
- .create_with({ permission_level: 10, active: true , 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
- initialized_engines = []
68
-
69
- LesliSystem.engines.each do |engine, data|
70
-
71
- next if ["Lesli", "LesliBabel", "Root"].include?(engine)
72
-
73
- # Create an associated account if the attribute is blank
74
- engine.constantize::Account.find_or_create_by!(account: self)
75
-
76
- initialized_engines << engine
77
- end
78
-
79
- # Emit initialization events only after every engine account exists.
80
- # In particular, this makes the result independent from the position
81
- # of LesliAudit in the engine registry.
82
- initialized_engines.each do |engine|
83
- self.log(:account_initialization, "Engine: #{engine} initialized successfully")
84
- end
85
- end
44
+ AccountOperator.new(account: self).initialize_engines!
45
+ end
86
46
  end
87
47
  end
@@ -91,7 +91,8 @@ module Lesli
91
91
  operation:nil, # two word action description
92
92
  description:nil, # human readable description
93
93
  session_id:nil, # must come from server session
94
- subject:nil # resource related to the log
94
+ subject:nil, # resource related to the log
95
+ details:{} # explicit domain data, never raw request parameters
95
96
  )
96
97
 
97
98
  return unless defined?(LesliAudit::ActivityAudit)
@@ -104,7 +105,8 @@ module Lesli
104
105
  operation: operation,
105
106
  description: description,
106
107
  session_id: session_id,
107
- subject: subject
108
+ subject: subject,
109
+ details: details
108
110
  )
109
111
  end
110
112
  end
@@ -82,7 +82,7 @@ module Lesli
82
82
 
83
83
  errors.add(
84
84
  :file,
85
- I18n.t("lesli.items.attachments.errors.required")
85
+ I18n.t("lesli.items.attachments_errors_required")
86
86
  )
87
87
  end
88
88
 
@@ -93,7 +93,7 @@ module Lesli
93
93
  errors.add(
94
94
  :file,
95
95
  I18n.t(
96
- "lesli.items.attachments.errors.too_large",
96
+ "lesli.items.attachments_errors_too_large",
97
97
  size: ActiveSupport::NumberHelper.number_to_human_size(
98
98
  self.class.lesli_attachment_max_file_size
99
99
  )
@@ -109,7 +109,7 @@ module Lesli
109
109
 
110
110
  errors.add(
111
111
  :file,
112
- I18n.t("lesli.items.attachments.errors.unsupported_type")
112
+ I18n.t("lesli.items.attachments_errors_unsupported_type")
113
113
  )
114
114
  end
115
115
  end
@@ -40,8 +40,20 @@ module Lesli
40
40
  has_many :privileges, dependent: :delete_all, class_name: 'LesliShield::Role::Privilege'
41
41
 
42
42
  # validations
43
- validates :name, presence: :true
44
- validates :permission_level, presence: :true
43
+ validates :name,
44
+ presence: true,
45
+ uniqueness: {
46
+ scope: :account_id,
47
+ case_sensitive: false,
48
+ conditions: -> { where(deleted_at: nil) }
49
+ }
50
+ validates :permission_level,
51
+ presence: true,
52
+ numericality: {
53
+ only_integer: true,
54
+ greater_than_or_equal_to: 0
55
+ }
56
+ validates :active, inclusion: { in: [true, false] }
45
57
 
46
58
  # initializers for new roles
47
59
  after_create :after_create_role
@@ -34,6 +34,8 @@ module Lesli
34
34
  class User < ApplicationLesliRecord
35
35
  include Lesli::UserExtensions
36
36
 
37
+ validates :time_zone, inclusion: { in: TZInfo::Timezone.all_identifiers }, allow_nil: true
38
+
37
39
  # user required configuration
38
40
  validates(:email,
39
41
  format: { with: URI::MailTo::EMAIL_REGEXP },
@@ -72,6 +74,11 @@ module Lesli
72
74
 
73
75
  before_create :before_create_user
74
76
 
77
+ # Resolve the display zone without storing the fallback as a user preference.
78
+ def effective_time_zone
79
+ Time.find_zone!(time_zone || Lesli.config.datetime&.dig(:time_zone).presence || Rails.application.config.time_zone)
80
+ end
81
+
75
82
  private
76
83
 
77
84
  def before_create_user
@@ -0,0 +1,84 @@
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
+ class AccountOperator
35
+ def initialize(account:)
36
+ @account = account
37
+ end
38
+
39
+ def initialize_roles!
40
+ Account.transaction do
41
+ owner = account.roles.create_with(permission_level: 2147483647, active: true)
42
+ .find_or_create_by!(name: "owner")
43
+ admin = account.roles.create_with(permission_level: 100000, active: true)
44
+ .find_or_create_by!(name: "admin")
45
+ guest = account.roles.create_with(
46
+ permission_level: 10, active: true, path_default: "/administration/profile"
47
+ ).find_or_create_by!(name: "guest")
48
+
49
+ if defined?(LesliShield)
50
+ actions = LesliShield::RoleActionService.new(nil)
51
+ actions.add_owner_actions(owner)
52
+ actions.add_owner_actions(admin)
53
+ actions.add_guest_actions(guest)
54
+ end
55
+ end
56
+
57
+ account
58
+ end
59
+
60
+ def initialize_engines!
61
+ Account.transaction do
62
+ initialized_engines = []
63
+ LesliSystem.engines.each_key do |engine|
64
+ next if %w[Lesli LesliBabel Root].include?(engine)
65
+
66
+ engine_account = engine.constantize::Account.find_or_create_by!(account: account)
67
+ initialized_engines << engine if engine_account.previously_new_record?
68
+ end
69
+
70
+ # Audit must exist before recording initialization, regardless
71
+ # of registry order. Repeated runs do not repeat these events.
72
+ initialized_engines.each do |engine|
73
+ account.log(:account_initialization, "Engine: #{engine} initialized successfully")
74
+ end
75
+ end
76
+
77
+ account
78
+ end
79
+
80
+ private
81
+
82
+ attr_reader :account
83
+ end
84
+ end
@@ -0,0 +1,123 @@
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
+ module Lesli
34
+ class ResourceOperator
35
+ DEVISE_CONTROLLERS = %w[
36
+ users/registrations users/sessions users/passwords users/confirmations
37
+ ].freeze
38
+
39
+ HOST_INTERNAL_CONTROLLERS = %w[
40
+ rails action_mailbox active_storage view_components
41
+ turbo/native/navigation lesli/abouts
42
+ ].freeze
43
+
44
+ # Scan routes from the main application and installed engines,
45
+ # then register their controllers and actions as Lesli resources.
46
+ # Repeated runs retain existing resource IDs.
47
+ def register!
48
+ # Register the complete catalog in one transaction so a failed
49
+ # action does not leave a partially updated resource catalog.
50
+ Resource.transaction do
51
+ routes_by_engine.each do |engine, controllers|
52
+ controllers.each do |route, actions|
53
+ # Build the standard controller name from its route.
54
+ # Examples:
55
+ # users -> Users
56
+ # lesli_bell/notifications -> LesliBell::Notifications
57
+ # account/currency/exchange_rates -> Account::Currency::ExchangeRates
58
+ identifier = route.camelize
59
+ # Create the controller descriptor or update its existing metadata.
60
+ controller = Resource.find_or_initialize_by(route: route)
61
+ controller.update!(
62
+ label: identifier.demodulize.humanize,
63
+ engine: engine,
64
+ identifier: identifier
65
+ )
66
+
67
+ # Register each action only once. Different HTTP verbs can
68
+ # point to the same controller action.
69
+ actions.uniq.each do |action|
70
+ controller.children.find_or_create_by!(
71
+ action: action,
72
+ identifier: action,
73
+ label: action.humanize
74
+ )
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def routes_by_engine
84
+ # Group the available actions by engine and controller.
85
+ # Example: { "lesli_bell" => { "lesli_bell/notifications" => ["index"] } }
86
+ controllers = { "rails_app" => {}, "lesli" => {} }
87
+
88
+ # Get controllers and actions from the main Rails application.
89
+ Rails.application.routes.routes.each do |route|
90
+ controller = route.defaults[:controller]
91
+ action = route.defaults[:action]
92
+ next if controller.blank? || action.blank?
93
+ # Exclude internal Rails routes and the default welcome page.
94
+ next if HOST_INTERNAL_CONTROLLERS.any? { |name| controller.include?(name) }
95
+
96
+ # Devise routes belong to Lesli's access-control catalog,
97
+ # even though they are mounted in the main application.
98
+ engine = DEVISE_CONTROLLERS.include?(controller) ? "lesli" : "rails_app"
99
+ (controllers[engine][controller] ||= []) << action
100
+ end
101
+
102
+ # Get controllers and actions from each installed engine.
103
+ LesliSystem.engines.each do |engine, info|
104
+ # The main application was already processed above.
105
+ next if engine == "Root"
106
+
107
+ engine.constantize::Engine.routes.routes.each do |route|
108
+ controller = route.defaults[:controller]
109
+ action = route.defaults[:action]
110
+ # Mounted apps and redirects do not necessarily name an action.
111
+ next if controller.blank? || action.blank?
112
+ next if controller.include?("rails/health")
113
+
114
+ # Create the engine/controller containers before adding the action.
115
+ controllers[info[:code]] ||= {}
116
+ (controllers[info[:code]][controller] ||= []) << action
117
+ end
118
+ end
119
+
120
+ controllers
121
+ end
122
+ end
123
+ end