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.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -0
  3. data/app/assets/stylesheets/lesli/application.css +43 -3
  4. data/app/controllers/lesli/application_devise_controller.rb +9 -5
  5. data/app/controllers/lesli/application_lesli_controller.rb +31 -0
  6. data/app/controllers/lesli/items/attachments_controller.rb +200 -0
  7. data/app/controllers/lesli/items/discussions_controller.rb +94 -67
  8. data/app/controllers/lesli/items/tasks_controller.rb +132 -62
  9. data/app/controllers/lesli/roles_controller.rb +1 -6
  10. data/app/controllers/lesli/users_controller.rb +1 -5
  11. data/app/helpers/lesli/announcements_helper.rb +14 -0
  12. data/app/helpers/lesli/navigation_helper.rb +1 -1
  13. data/app/helpers/lesli/turbo_helper.rb +0 -18
  14. data/app/interfaces/lesli/responder_interface.rb +65 -38
  15. data/app/mailers/lesli/application_lesli_mailer.rb +34 -8
  16. data/app/models/concerns/lesli/account_initializer.rb +5 -37
  17. data/app/models/concerns/lesli/account_logs.rb +5 -16
  18. data/app/models/concerns/lesli/items/activities.rb +29 -33
  19. data/app/models/concerns/lesli/items/attachments.rb +88 -0
  20. data/app/models/concerns/lesli/items/discussions.rb +25 -11
  21. data/app/models/concerns/lesli/items/ownership.rb +27 -0
  22. data/app/models/concerns/lesli/items/tasks.rb +26 -6
  23. data/app/models/concerns/lesli/user_extensions.rb +8 -10
  24. data/app/models/lesli/account.rb +10 -14
  25. data/app/models/lesli/items/activity.rb +25 -2
  26. data/app/models/lesli/items/attachment.rb +117 -0
  27. data/app/models/lesli/items/discussion.rb +6 -2
  28. data/app/models/lesli/items/task.rb +3 -1
  29. data/app/models/lesli/role.rb +14 -2
  30. data/app/models/lesli/user.rb +19 -21
  31. data/app/operators/lesli/account_operator.rb +84 -0
  32. data/app/operators/lesli/resource_operator.rb +123 -0
  33. data/app/services/lesli/application_lesli_service.rb +33 -116
  34. data/app/services/lesli/resource_service.rb +12 -159
  35. data/app/services/lesli/role_service.rb +11 -229
  36. data/app/services/lesli/user_service.rb +37 -117
  37. data/app/views/lesli/abouts/welcome.html.erb +2 -5
  38. data/app/views/lesli/errors/not_found.html.erb +7 -21
  39. data/app/views/lesli/errors/unauthorized.html.erb +11 -27
  40. data/app/views/lesli/layouts/application-devise.html.erb +10 -9
  41. data/app/views/lesli/layouts/application-lesli.html.erb +2 -2
  42. data/app/views/lesli/partials/_application-lesli-announcements.html.erb +28 -0
  43. data/app/views/lesli/partials/_application-lesli-assets.html.erb +3 -3
  44. data/app/views/lesli/partials/_application-lesli-header.html.erb +8 -11
  45. data/app/views/lesli/partials/_application-lesli-turbo.html.erb +5 -0
  46. data/config/initializers/lesli.rb +10 -2
  47. data/config/locales/translations.en.yml +57 -14
  48. data/config/locales/translations.es.yml +55 -11
  49. data/db/migrate/v1/0000000210_create_lesli_users.rb +1 -0
  50. data/db/seed/accounts.rb +5 -5
  51. data/db/seed/users.rb +8 -16
  52. data/db/seed/xyz.rb +36 -17
  53. data/lib/generators/lesli/base_generator.rb +41 -3
  54. data/lib/generators/lesli/controller/controller_generator.rb +1 -1
  55. data/lib/generators/lesli/controller/templates/controller.rb.tt +12 -7
  56. data/lib/generators/lesli/model/model_generator.rb +1 -1
  57. data/lib/generators/lesli/resource/resource_generator.rb +290 -0
  58. data/lib/generators/lesli/resource/templates/controller.rb.tt +99 -0
  59. data/lib/generators/lesli/resource/templates/locale.en.yml.tt +13 -0
  60. data/lib/generators/lesli/resource/templates/migration.rb.tt +28 -0
  61. data/lib/generators/lesli/resource/templates/model.rb.tt +38 -0
  62. data/lib/generators/lesli/resource/templates/operator.rb.tt +15 -0
  63. data/lib/generators/lesli/resource/templates/service.rb.tt +52 -0
  64. data/lib/generators/lesli/resource/templates/tests/controller_test.rb.tt +14 -0
  65. data/lib/generators/lesli/resource/templates/tests/model_test.rb.tt +24 -0
  66. data/lib/generators/lesli/resource/templates/tests/operator_test.rb.tt +15 -0
  67. data/lib/generators/lesli/resource/templates/tests/service_test.rb.tt +17 -0
  68. data/lib/generators/lesli/resource/templates/views/_form.html.erb.tt +17 -0
  69. data/lib/generators/lesli/resource/templates/views/edit.html.erb.tt +4 -0
  70. data/lib/generators/lesli/resource/templates/views/index.html.erb.tt +22 -0
  71. data/lib/generators/lesli/resource/templates/views/new.html.erb.tt +4 -0
  72. data/lib/generators/lesli/resource/templates/views/show.html.erb.tt +17 -0
  73. data/lib/generators/lesli/scaffold/scaffold_generator.rb +4 -39
  74. data/lib/generators/lesli/service/service_generator.rb +1 -1
  75. data/lib/generators/lesli/service/templates/service.rb.tt +15 -7
  76. data/lib/generators/lesli/views/views_generator.rb +1 -1
  77. data/lib/generators/lesli_generator.rb +11 -0
  78. data/lib/lesli/courier.rb +66 -34
  79. data/lib/lesli/database_tasks.rb +145 -0
  80. data/lib/lesli/engine.rb +0 -4
  81. data/lib/lesli/router.rb +5 -2
  82. data/lib/lesli/version.rb +2 -2
  83. data/lib/migrate/items/activity_structure.rb +8 -8
  84. data/lib/migrate/items/attachment_structure.rb +9 -14
  85. data/lib/migrate/items/discussion_structure.rb +5 -5
  86. data/lib/migrate/items/task_structure.rb +2 -3
  87. data/lib/migrate/shared/account_structure.rb +1 -1
  88. data/lib/tasks/lesli/db.rake +16 -93
  89. data/lib/tasks/lesli/resources.rake +1 -1
  90. data/lib/tasks/lesli_tasks.rake +2 -3
  91. data/readme.md +6 -4
  92. data/test/fixtures/lesli_accounts.yml +18 -0
  93. data/test/fixtures/lesli_users.yml +23 -0
  94. metadata +39 -26
  95. data/app/assets/stylesheets/lesli/application.tailwind.css +0 -33
  96. data/app/views/lesli/partials/_application-lesli-sidebar.html.erb +0 -50
  97. data/config/brakeman.yml +0 -44
  98. data/config/initializers/devise.rb +0 -27
@@ -40,7 +40,8 @@ Building a better future, one line of code at a time.
40
40
 
41
41
  dashboard_label = I18n.t("lesli.header.dashboard", default: "Lesli Dashboard")
42
42
  notifications_label = if notifications_count.positive?
43
- I18n.t("lesli.header.notifications_unread", count: notifications_count, default: "%{count} unread notifications")
43
+ plural = notifications_count == 1 ? "one" : "other"
44
+ I18n.t("lesli.header.notifications_unread_#{plural}", count: notifications_count, default: "%{count} unread notifications")
44
45
  else
45
46
  I18n.t("lesli.header.notifications", default: "Notifications")
46
47
  end
@@ -51,7 +52,7 @@ Building a better future, one line of code at a time.
51
52
  action_class = ->(path) {
52
53
  class_names(
53
54
  header_action_class,
54
- current_page?(path) && "bg-sky-50 text-sky-700"
55
+ current_page?(path) && "text-sky-700"
55
56
  )
56
57
  }
57
58
  %>
@@ -107,20 +108,16 @@ Building a better future, one line of code at a time.
107
108
  <i class="ri-apps-2-line text-[24px] leading-none" aria-hidden="true"></i>
108
109
  <% end %>
109
110
 
110
- <% if defined?(LesliAdmin) %>
111
- <%= link_to lesli_admin.profile_path,
112
- class: action_class.call(lesli_admin.profile_path),
113
- aria: {
114
- label: profile_label,
115
- current: current_page?(lesli_admin.profile_path) ? "page" : nil
116
- },
111
+ <% if defined?(LesliShield) %>
112
+
113
+ <%= link_to lesli_shield.profile_path,
114
+ class: header_action_class,
115
+ aria: { label: profile_label },
117
116
  title: profile_label,
118
117
  data: { turbo_frame: "_top" } do %>
119
118
  <i class="ri-user-smile-line text-[24px] leading-none" aria-hidden="true"></i>
120
119
  <% end %>
121
- <% end %>
122
120
 
123
- <% if defined?(LesliShield) %>
124
121
  <%= link_to main_app.destroy_user_session_path,
125
122
  class: logout_action_class,
126
123
  aria: { label: logout_label },
@@ -38,4 +38,9 @@ Building a better future, one line of code at a time.
38
38
 
39
39
  <%# enable turbo %>
40
40
  <meta name="turbo-prefetch" content="false">
41
+ <%# Reload page-specific banners on history navigation instead of restoring
42
+ announcements that another request may have dismissed or expired. %>
43
+ <% if @lesli_announcements_enabled %>
44
+ <meta name="turbo-cache-control" content="no-cache">
45
+ <% end %>
41
46
  <meta name="view-transition" content="same-origin" />
@@ -97,6 +97,7 @@ Lesli.configure do |config|
97
97
  }
98
98
 
99
99
  config.babel = {
100
+ allow_web_deploy: true,
100
101
  locales: {
101
102
  :en => "English", # English
102
103
  :es => "Español", # Español/Spanish
@@ -118,7 +119,11 @@ Lesli.configure do |config|
118
119
  # Shield module configuration
119
120
  config.shield = {
120
121
  path_after_login: defined?(LesliDashboard) ? "/dashboard" : "/",
121
- default_role: "guest"
122
+ default_role: "guest",
123
+
124
+ # Invitations verify ownership of the recipient's email address. The
125
+ # invited user does not exist until the signed link is accepted.
126
+ invitation_expiration: 7.days
122
127
  }
123
128
 
124
129
 
@@ -127,7 +132,10 @@ Lesli.configure do |config|
127
132
  prefix: 'LA',
128
133
  enable_logs: true,
129
134
  enable_journals: true,
130
- enable_analytics: true
135
+ enable_analytics: true,
136
+ analytics_retention_days: 400,
137
+ traffic_retention_days: 400,
138
+ audit_retention_days: nil
131
139
  }
132
140
 
133
141
 
@@ -1,18 +1,61 @@
1
1
  ---
2
- :en:
2
+ en:
3
3
  lesli:
4
+ announcements:
5
+ title: "Announcements"
6
+ open_link: "View details"
7
+ dismiss: "Dismiss announcement"
8
+ categories:
9
+ info: "Information"
10
+ success: "Success"
11
+ warning: "Warning"
12
+ danger: "Important notice"
13
+ abouts: {}
14
+ apps: {}
4
15
  header:
5
- applications: Applications
6
- dashboard: Lesli Dashboard
7
- logout: Logout
8
- notifications: Notifications
9
- notifications_unread:
10
- one: "%{count} unread notification"
11
- other: "%{count} unread notifications"
12
- profile: Profile
16
+ applications: "Applications"
17
+ dashboard: "Lesli Dashboard"
18
+ logout: "Logout"
19
+ notifications: "Notifications"
20
+ notifications_unread_one: "%{count} unread notification"
21
+ notifications_unread_other: "%{count} unread notifications"
22
+ profile: "Profile"
23
+ items:
24
+ activities_empty: "No activities have been recorded yet."
25
+ activities_unknown_actor: "Unknown user"
26
+ attachments_add: "Add file"
27
+ attachments_category: "Category"
28
+ attachments_choose_file: "Choose a file"
29
+ attachments_confirm_remove: "Remove this file?"
30
+ attachments_created: "File uploaded successfully"
31
+ attachments_deleted: "File removed successfully"
32
+ attachments_download: "Download"
33
+ attachments_empty: "No files have been attached yet."
34
+ attachments_errors_required: "must be attached"
35
+ attachments_errors_too_large: "must be smaller than %{size}"
36
+ attachments_errors_unsupported_type: "has an unsupported file type"
37
+ attachments_label: "Label"
38
+ attachments_remove: "Remove"
39
+ attachments_uploading: "Uploading..."
40
+ discussions_add: "Add comment"
41
+ discussions_created: "Comment added successfully"
42
+ discussions_empty: "No comments have been added yet."
43
+ discussions_invalid: "Comment could not be added"
44
+ discussions_unknown_author: "Unknown user"
45
+ tasks_add: "Add task"
46
+ tasks_complete_action: "Mark task as complete"
47
+ tasks_completed: "Task completed successfully"
48
+ tasks_created: "Task created successfully"
49
+ tasks_empty: "No tasks have been added yet."
50
+ tasks_reopen_action: "Mark task as incomplete"
51
+ tasks_reopened: "Task reopened successfully"
52
+ resources: {}
13
53
  shared:
14
- message_error_not_found: Not found
15
- message_error_resource_not_found: The resource you are looking for was not found.
16
- message_error_unauthorized: Unauthorized
17
- message_error_unauthorized_credentials: 'We could not validate your privileges.
18
- Please ask the administrator to send you an invite to see this content. '
54
+ message_error_not_found: "Not found"
55
+ message_error_resource_not_found: "The resource you are looking for was not found."
56
+ message_error_unauthorized: "Unauthorized"
57
+ message_error_unauthorized_credentials: "We could not validate your privileges. Please ask the administrator to send you an invite to see this content. "
58
+ users/confirmations: {}
59
+ users/passwords: {}
60
+ users/registrations: {}
61
+ users/sessions: {}
@@ -1,17 +1,61 @@
1
1
  ---
2
- :es:
2
+ es:
3
3
  lesli:
4
+ announcements:
5
+ title: "Anuncios"
6
+ open_link: "Ver detalles"
7
+ dismiss: "Cerrar anuncio"
8
+ categories:
9
+ info: "Información"
10
+ success: "Éxito"
11
+ warning: "Advertencia"
12
+ danger: "Aviso importante"
13
+ abouts: {}
14
+ apps: {}
4
15
  header:
5
- applications: Aplicaciones
6
- dashboard: Panel de Lesli
7
- logout: Cerrar sesión
8
- notifications: Notificaciones
9
- notifications_unread:
10
- one: "%{count} notificación sin leer"
11
- other: "%{count} notificaciones sin leer"
12
- profile: Perfil
16
+ applications: "Aplicaciones"
17
+ dashboard: "Panel de Lesli"
18
+ logout: "Cerrar sesión"
19
+ notifications: "Notificaciones"
20
+ notifications_unread_one: "%{count} notificación sin leer"
21
+ notifications_unread_other: "%{count} notificaciones sin leer"
22
+ profile: "Perfil"
23
+ items:
24
+ activities_empty: "Todavía no se ha registrado actividad."
25
+ activities_unknown_actor: "Usuario desconocido"
26
+ attachments_add: "Agregar archivo"
27
+ attachments_category: "Categoría"
28
+ attachments_choose_file: "Seleccionar archivo"
29
+ attachments_confirm_remove: "¿Eliminar este archivo?"
30
+ attachments_created: "Archivo subido exitosamente"
31
+ attachments_deleted: "Archivo eliminado exitosamente"
32
+ attachments_download: "Descargar"
33
+ attachments_empty: "Todavía no se han adjuntado archivos."
34
+ attachments_errors_required: "debe ser adjuntado"
35
+ attachments_errors_too_large: "debe ser menor de %{size}"
36
+ attachments_errors_unsupported_type: "tiene un tipo de archivo no permitido"
37
+ attachments_label: "Etiqueta"
38
+ attachments_remove: "Eliminar"
39
+ attachments_uploading: "Subiendo..."
40
+ discussions_add: "Agregar comentario"
41
+ discussions_created: "Comentario agregado exitosamente"
42
+ discussions_empty: "Todavía no se han agregado comentarios."
43
+ discussions_invalid: "No se pudo agregar el comentario"
44
+ discussions_unknown_author: "Usuario desconocido"
45
+ tasks_add: "Agregar tarea"
46
+ tasks_complete_action: "Marcar tarea como completada"
47
+ tasks_completed: "Tarea completada exitosamente"
48
+ tasks_created: "Tarea creada exitosamente"
49
+ tasks_empty: "Todavía no se han agregado tareas."
50
+ tasks_reopen_action: "Marcar tarea como pendiente"
51
+ tasks_reopened: "Tarea reabierta exitosamente"
52
+ resources: {}
13
53
  shared:
14
54
  message_error_not_found: ":lesli.shared.message_error_not_found:"
15
- message_error_resource_not_found: El recurso que estás buscando no fue encontrado
16
- message_error_unauthorized: No autorizado
55
+ message_error_resource_not_found: "El recurso que estás buscando no fue encontrado"
56
+ message_error_unauthorized: "No autorizado"
17
57
  message_error_unauthorized_credentials: ":lesli.shared.message_error_unauthorized_credentials:"
58
+ users/confirmations: {}
59
+ users/passwords: {}
60
+ users/registrations: {}
61
+ users/sessions: {}
@@ -46,6 +46,7 @@ class CreateLesliUsers < ActiveRecord::Migration[7.2]
46
46
  t.string :salutation
47
47
  t.string :first_name
48
48
  t.string :last_name
49
+ t.string :time_zone
49
50
 
50
51
  # Authenticable
51
52
  t.string :email, null: false, default: ""
data/db/seed/accounts.rb CHANGED
@@ -41,14 +41,14 @@ account = Lesli::Account.find_or_create_by(email: company[:email]) do |account|
41
41
  account.status = 'active'
42
42
  account.save!
43
43
 
44
- # account.detail.company_name = company[:name]
45
- # account.detail.public_email = company[:email]
46
- # account.detail.company_tagline = company[:tag_line] || ""
44
+ # account.admin.detail.company_name = company[:name]
45
+ # account.admin.detail.public_email = company[:email]
46
+ # account.admin.detail.company_tagline = company[:tag_line] || ""
47
47
  # #account.registered!
48
- # account.detail.save!
48
+ # account.admin.detail.save!
49
49
 
50
50
  end
51
51
 
52
52
  # print some separators so will be easy to find these messages later
53
- Termline.br(3);
53
+ Termline.br(2);
54
54
  Termline.success("Account #{ account.name } <#{ account.email }> successfully created!")
data/db/seed/users.rb CHANGED
@@ -31,17 +31,17 @@ Building a better future, one line of code at a time.
31
31
  =end
32
32
 
33
33
 
34
-
35
34
  # get the account information
36
- account = Lesli::Account.first
35
+ account = Lesli::Account.find_by!(email: Lesli.config.company.fetch(:email))
37
36
 
38
37
 
39
- # try to extract the domain name from the main email address
40
- email_domain = account[:email].scan(/.*@(\S+)/)&.first&.first
38
+ # extract the domain name from the main email address
39
+ email_domain = account.email.to_s.split("@", 2).second
40
+ raise ArgumentError, "The account email must include a domain" if email_domain.blank?
41
41
 
42
42
 
43
43
  # get the emails for the initial accounts
44
- emailowner = account[:email]
44
+ emailowner = account.email
45
45
  emailadmin = "admin@#{email_domain}"
46
46
  emailguest = "guest@#{email_domain}"
47
47
 
@@ -64,17 +64,9 @@ end
64
64
 
65
65
 
66
66
  # create the owner user for the account,
67
- userowner = create_account_user(emailowner, "owner", "Owner", account[:company_name], passowner)
68
- useradmin = create_account_user(emailadmin, "admin", "Admin", account[:company_name], passadmin)
69
- userguest = create_account_user(emailguest, "guest", "Guest", account[:company_name], passguest)
70
-
71
-
72
- # print the owner user credentials, so we can save those credentials
73
- Termline.success(
74
- "Owner user created successfully with email: #{emailowner} and password: #{passowner}",
75
- "Admin user created successfully with email: #{emailadmin} and password: #{passadmin}",
76
- "Admin user created successfully with email: #{emailguest} and password: #{passguest}"
77
- )
67
+ create_account_user(account: account, email: emailowner, role_name: "owner", first_name: "Owner", last_name: account.name, password: passowner)
68
+ create_account_user(account: account, email: emailadmin, role_name: "admin", first_name: "Admin", last_name: account.name, password: passadmin)
69
+ create_account_user(account: account, email: emailguest, role_name: "guest", first_name: "Guest", last_name: account.name, password: passguest)
78
70
 
79
71
 
80
72
  # print some separators so will be easy to find these messages later
data/db/seed/xyz.rb CHANGED
@@ -30,27 +30,46 @@ Building a better future, one line of code at a time.
30
30
  // ·
31
31
  =end
32
32
 
33
- def create_account_user email, rolename, firstname, lastname, password
34
-
35
- account = Lesli::Account.find_by(email: Lesli.config.company.dig(:email))
36
-
37
- # create development users if email is not registered yet
38
- Lesli::User.find_or_create_by(email: email) do |user|
39
- user.account = account
40
- user.password = password
41
- user.password_confirmation = password
42
-
43
- # confirm user through device
44
- user.confirm unless user.confirmed?
33
+ def create_account_user(account:, email:, role_name:, first_name:, last_name:, password: nil)
34
+ user = Lesli::User.find_or_initialize_by(email: email)
35
+ authentication_enabled = user.respond_to?(:password=) && user.respond_to?(:password_confirmation=)
36
+ credentials_created = false
37
+
38
+ Lesli::User.transaction do
39
+ user.assign_attributes(
40
+ account: account,
41
+ first_name: first_name,
42
+ last_name: last_name
43
+ )
44
+
45
+ # LesliShield installs Devise directly on the Core user model. Checking
46
+ # the model capability keeps this seeder independent from Devise and
47
+ # allows Lesli Core to seed users without an authentication engine.
48
+ if authentication_enabled && user.encrypted_password.blank?
49
+ raise ArgumentError, "A password is required when authentication is enabled" if password.blank?
50
+
51
+ user.password = password
52
+ user.password_confirmation = password
53
+ user.skip_confirmation! if user.respond_to?(:skip_confirmation!)
54
+ credentials_created = true
55
+ end
45
56
 
46
- user.first_name = firstname
47
- user.last_name = lastname
48
57
  user.save!
49
58
 
50
- if(defined?(LesliShield))
51
- user.user_roles.create!({ role: Lesli::Role.find_by(:name => rolename) })
59
+ # Role assignments are owned by LesliShield and should only be created
60
+ # when its concrete join model is available.
61
+ if authentication_enabled && defined?(LesliShield::User::Role)
62
+ role = account.roles.find_by!(name: role_name)
63
+ user.user_roles.find_or_create_by!(role: role)
52
64
  end
65
+ end
53
66
 
54
- user
67
+ if credentials_created
68
+ Termline.success(
69
+ "#{role_name.capitalize} user created successfully with " \
70
+ "email: #{email} and password: #{password}"
71
+ )
55
72
  end
73
+
74
+ user
56
75
  end
@@ -15,9 +15,25 @@ module Lesli
15
15
  #
16
16
  # This avoids duplicating the same helper methods in every generator.
17
17
  class BaseGenerator < Rails::Generators::NamedBase
18
+ class_option :engine_root,
19
+ type: :string,
20
+ desc: "Target Rails engine root"
21
+
22
+ class_option :engine_namespace,
23
+ type: :string,
24
+ desc: "Target Rails engine Ruby namespace"
18
25
 
19
26
  private
20
27
 
28
+ def engine_root
29
+ configured_root = options[:engine_root]
30
+ configured_root = ENGINE_ROOT if configured_root.blank? && defined?(ENGINE_ROOT)
31
+
32
+ raise Thor::Error, "Lesli generators must run inside a Rails engine or receive --engine-root" if configured_root.blank?
33
+
34
+ Pathname.new(configured_root).expand_path
35
+ end
36
+
21
37
  # Returns the current engine folder name in snake_case.
22
38
  #
23
39
  # Examples:
@@ -25,7 +41,7 @@ module Lesli
25
41
  # "/code/my_engine" -> "my_engine"
26
42
  # "/code/store" -> "store"
27
43
  def engine_name
28
- File.basename(ENGINE_ROOT.to_s).underscore
44
+ engine_root.basename.to_s.underscore
29
45
  end
30
46
 
31
47
  # Returns the current engine Ruby namespace in CamelCase.
@@ -35,7 +51,7 @@ module Lesli
35
51
  # "my_engine" -> "MyEngine"
36
52
  # "store" -> "Store"
37
53
  def engine_namespace
38
- engine_name.camelize
54
+ options[:engine_namespace].presence || engine_name.camelize
39
55
  end
40
56
 
41
57
  # Returns the domain name derived from the engine namespace.
@@ -161,12 +177,34 @@ module Lesli
161
177
  def permitted_attributes
162
178
  return [] unless respond_to?(:attributes)
163
179
 
164
- attributes.map(&:name)
180
+ attributes.map(&:column_name)
165
181
  end
166
182
 
167
183
  def namespaced_model_name
168
184
  "#{engine_namespace}::#{resource_class_name}"
169
185
  end
186
+
187
+ def table_name
188
+ "#{engine_name}_#{resource_collection_name}"
189
+ end
190
+
191
+ def account_table_name
192
+ "#{engine_name}_accounts"
193
+ end
194
+
195
+ def account_model_path
196
+ engine_root.join("app/models", engine_name, "account.rb")
197
+ end
198
+
199
+ def routes_path
200
+ engine_root.join("config/routes.rb")
201
+ end
202
+
203
+ def account_resource_scope
204
+ return "current_user.account.#{resource_collection_name}" if engine_namespace == "Lesli"
205
+
206
+ "current_user.account.#{engine_domain_name}.#{resource_collection_name}"
207
+ end
170
208
  end
171
209
  end
172
210
  end
@@ -25,7 +25,7 @@ module Lesli
25
25
  # app/controllers/my_engine
26
26
  # app/controllers/store
27
27
  def controller_directory
28
- File.join(ENGINE_ROOT, "app/controllers", engine_name)
28
+ engine_root.join("app/controllers", engine_name)
29
29
  end
30
30
 
31
31
  # Returns the final controller file path.
@@ -11,7 +11,7 @@ module <%= engine_namespace %>
11
11
  end
12
12
 
13
13
  def show
14
- <%= resource_instance %> = <%= resource_instance %>.show
14
+ <%= resource_instance %> = <%= resource_instance %>_service.show
15
15
  end
16
16
 
17
17
  def new
@@ -40,13 +40,16 @@ module <%= engine_namespace %>
40
40
  end
41
41
 
42
42
  def update
43
- if <%= resource_instance %>.update(<%= params_method_name %>)
43
+ <%= resource_name %> = <%= resource_instance %>_service.update(<%= params_method_name %>)
44
+ <%= resource_instance %> = <%= resource_name %>.result
45
+
46
+ if <%= resource_name %>.successful?
44
47
  respond_with_lesli(
45
48
  turbo: stream_notification_success("<%= resource_class_name %> updated successfully")
46
49
  )
47
50
  else
48
51
  respond_with_lesli(
49
- turbo: stream_notification_danger(<%= resource_instance %>.errors)
52
+ turbo: stream_notification_danger(<%= resource_name %>.errors_as_sentence)
50
53
  )
51
54
  end
52
55
  end
@@ -55,20 +58,22 @@ module <%= engine_namespace %>
55
58
  return respond_with_not_found unless <%= resource_instance %>
56
59
  return respond_with_unauthorized unless <%= resource_instance %>.is_editable_by?(current_user)
57
60
 
58
- <%= resource_name %>_destroy_response = <%= service_class_name %>.destroy(current_user, <%= resource_instance %>)
61
+ <%= resource_name %>_destroy_response = <%= resource_instance %>_service.destroy
59
62
 
60
63
  if <%= resource_name %>_destroy_response.successful?
61
64
  respond_with_successful
62
65
  else
63
- respond_with_error(<%= resource_name %>_destroy_response.payload.errors.full_messages.to_sentence)
66
+ respond_with_error(<%= resource_name %>_destroy_response.errors_as_sentence)
64
67
  end
65
68
  end
66
69
 
67
70
  private
68
71
 
69
72
  def <%= set_resource_method_name %>
70
- <%= resource_instance %> = <%= service_class_name %>.new(current_user, query).find(id: params[:id])
71
- return respond_with_not_found unless <%= resource_instance %>.found?
73
+ <%= resource_instance %>_service = <%= service_class_name %>.new(current_user, query).find(id: params[:id])
74
+ return respond_with_not_found unless <%= resource_instance %>_service.found?
75
+
76
+ <%= resource_instance %> = <%= resource_instance %>_service.result
72
77
  end
73
78
 
74
79
  def <%= params_method_name %>
@@ -29,7 +29,7 @@ module Lesli
29
29
  # Example:
30
30
  # app/models/lesli_support
31
31
  def model_directory
32
- File.join(ENGINE_ROOT, "app/models", engine_name)
32
+ engine_root.join("app/models", engine_name)
33
33
  end
34
34
 
35
35
  # Returns the final path of the generated model file.