plutonium 0.14.1 → 0.15.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/README copy.md +1 -1
  3. data/README.md +1 -1
  4. data/app/assets/plutonium.css +1 -1
  5. data/app/views/{application → plutonium}/_resource_header.html copy.erb +1 -1
  6. data/app/views/{application → plutonium}/_resource_header.html.erb +1 -1
  7. data/app/views/{application → plutonium}/_resource_sidebar.html.erb +2 -0
  8. data/app/views/resource/_resource_details.html.erb +1 -36
  9. data/app/views/resource/_resource_form.html.erb +1 -5
  10. data/app/views/resource/_resource_table.html.erb +315 -85
  11. data/app/views/resource/edit.html.erb +1 -5
  12. data/app/views/resource/index.html.erb +1 -5
  13. data/app/views/resource/new.html.erb +1 -5
  14. data/app/views/resource/show.html.erb +1 -5
  15. data/config/initializers/pagy.rb +1 -0
  16. data/config/initializers/rabl.rb +27 -20
  17. data/gemfiles/rails_7.gemfile.lock +5 -1
  18. data/lib/generators/pu/core/install/templates/app/controllers/plutonium_controller.rb.tt +2 -0
  19. data/lib/generators/pu/core/install/templates/app/controllers/resource_controller.rb.tt +21 -1
  20. data/lib/generators/pu/core/install/templates/app/definitions/resource_definition.rb.tt +2 -0
  21. data/lib/generators/pu/core/install/templates/app/models/resource_record.rb.tt +0 -2
  22. data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +1 -8
  23. data/lib/generators/pu/eject/shell/shell_generator.rb +2 -2
  24. data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +1 -1
  25. data/lib/generators/pu/lib/plutonium_generators/concerns/logger.rb +1 -1
  26. data/lib/generators/pu/lib/plutonium_generators/generator.rb +5 -3
  27. data/lib/generators/pu/lib/plutonium_generators/model_generator_base.rb +26 -2
  28. data/lib/generators/pu/pkg/{feature/feature_generator.rb → package/package_generator.rb} +4 -4
  29. data/lib/generators/pu/pkg/{feature → package}/templates/app/controllers/resource_controller.rb.tt +0 -2
  30. data/lib/generators/pu/pkg/package/templates/app/definitions/resource_definition.rb.tt +4 -0
  31. data/lib/generators/pu/pkg/package/templates/app/query_objects/resource_query_object.rb.tt +4 -0
  32. data/lib/generators/pu/pkg/{app/app_generator.rb → portal/portal_generator.rb} +10 -8
  33. data/lib/generators/pu/pkg/{app → portal}/templates/app/controllers/concerns/controller.rb.tt +3 -7
  34. data/lib/generators/pu/pkg/{app → portal}/templates/app/controllers/dashboard_controller.rb.tt +1 -1
  35. data/lib/generators/pu/pkg/portal/templates/app/controllers/plutonium_controller.rb.tt +5 -0
  36. data/lib/generators/pu/pkg/{app/templates/app/controllers/controller.rb.tt → portal/templates/app/controllers/resource_controller.rb.tt} +1 -1
  37. data/lib/generators/pu/pkg/portal/templates/app/definitions/resource_definition.rb.tt +4 -0
  38. data/lib/generators/pu/pkg/{app → portal}/templates/app/views/package/dashboard/index.html.erb +2 -1
  39. data/lib/generators/pu/res/conn/conn_generator.rb +78 -3
  40. data/lib/generators/pu/res/conn/templates/app/controllers/resource_controller.rb.tt +1 -1
  41. data/lib/generators/pu/res/conn/templates/app/definitions/resource_definition.rb.tt +3 -0
  42. data/lib/generators/pu/res/conn/templates/app/policies/resource_policy.rb.tt +29 -1
  43. data/lib/generators/pu/res/conn/templates/app/presenters/resource_presenter.rb.tt +1 -1
  44. data/lib/generators/pu/res/conn/templates/app/query_objects/resource_query_object.rb.tt +1 -1
  45. data/lib/generators/pu/res/model/model_generator.rb +0 -7
  46. data/lib/generators/pu/res/model/templates/model.rb.tt +4 -1
  47. data/lib/generators/pu/res/scaffold/scaffold_generator.rb +22 -4
  48. data/lib/generators/pu/res/scaffold/templates/controller.rb.tt +0 -1
  49. data/lib/generators/pu/res/scaffold/templates/definition.rb.tt +4 -0
  50. data/lib/generators/pu/res/scaffold/templates/policy.rb.tt +2 -2
  51. data/lib/generators/pu/rodauth/templates/app/controllers/rodauth_controller.rb.tt +1 -1
  52. data/lib/generators/pu/rodauth/templates/app/rodauth/account_rodauth_plugin.rb.tt +270 -0
  53. data/lib/plutonium/action/README.md +0 -0
  54. data/lib/plutonium/action/base.rb +103 -0
  55. data/lib/plutonium/action/interactive.rb +117 -0
  56. data/lib/plutonium/action/route_options.rb +65 -0
  57. data/lib/plutonium/action/simple.rb +8 -0
  58. data/lib/plutonium/auth.rb +1 -1
  59. data/lib/plutonium/configuration.rb +0 -8
  60. data/lib/plutonium/core/actions/collection.rb +1 -1
  61. data/lib/plutonium/core/associations/renderers/factory.rb +3 -1
  62. data/lib/plutonium/core/controller.rb +110 -0
  63. data/lib/plutonium/core/controllers/authorizable.rb +12 -35
  64. data/lib/plutonium/core/controllers/bootable.rb +38 -7
  65. data/lib/plutonium/core/controllers/entity_scoping.rb +6 -2
  66. data/lib/plutonium/core/fields/renderers/association_renderer.rb +1 -1
  67. data/lib/plutonium/core/ui/collection.rb +1 -1
  68. data/lib/plutonium/core/ui/detail.rb +1 -1
  69. data/lib/plutonium/core/ui/form.rb +1 -1
  70. data/lib/plutonium/definition/actions.rb +50 -0
  71. data/lib/plutonium/definition/base.rb +92 -0
  72. data/lib/plutonium/definition/config_attr.rb +30 -0
  73. data/lib/plutonium/definition/defineable_props.rb +96 -0
  74. data/lib/plutonium/definition/search.rb +21 -0
  75. data/lib/plutonium/engine/validator.rb +30 -0
  76. data/lib/plutonium/engine.rb +25 -0
  77. data/lib/plutonium/helpers/form_helper.rb +1 -3
  78. data/lib/plutonium/interaction/README.md +369 -0
  79. data/lib/plutonium/interaction/base.rb +75 -0
  80. data/lib/plutonium/interaction/concerns/presentable.rb +61 -0
  81. data/lib/plutonium/interaction/concerns/workflow_dsl.rb +82 -0
  82. data/lib/plutonium/interaction/outcome.rb +129 -0
  83. data/lib/plutonium/interaction/response/base.rb +63 -0
  84. data/lib/plutonium/interaction/response/null.rb +33 -0
  85. data/lib/plutonium/interaction/response/redirect.rb +30 -0
  86. data/lib/plutonium/interaction/response/render.rb +28 -0
  87. data/lib/plutonium/lib/bit_flags.rb +70 -9
  88. data/lib/plutonium/{config → lib}/overlayed_hash.rb +1 -1
  89. data/lib/plutonium/lib/smart_cache.rb +171 -0
  90. data/lib/plutonium/models/has_cents.rb +170 -0
  91. data/lib/plutonium/{pkg/base.rb → package/engine.rb} +10 -2
  92. data/lib/plutonium/{application → portal}/controller.rb +3 -11
  93. data/lib/plutonium/{application → portal}/dynamic_controllers.rb +4 -4
  94. data/lib/plutonium/portal/engine.rb +15 -0
  95. data/lib/plutonium/railtie.rb +33 -1
  96. data/lib/plutonium/reloader.rb +5 -5
  97. data/lib/plutonium/resource/controller.rb +51 -34
  98. data/lib/plutonium/resource/controllers/authorizable.rb +128 -0
  99. data/lib/plutonium/{core → resource}/controllers/crud_actions.rb +23 -22
  100. data/lib/plutonium/resource/controllers/defineable.rb +26 -0
  101. data/lib/plutonium/{core → resource}/controllers/interactive_actions.rb +12 -12
  102. data/lib/plutonium/resource/controllers/presentable.rb +41 -0
  103. data/lib/plutonium/resource/controllers/queryable.rb +44 -0
  104. data/lib/plutonium/resource/definition.rb +6 -0
  105. data/lib/plutonium/resource/policy.rb +25 -13
  106. data/lib/plutonium/resource/query_object.rb +50 -51
  107. data/lib/plutonium/resource/record.rb +6 -89
  108. data/lib/plutonium/resource/register.rb +82 -0
  109. data/lib/plutonium/routing/mapper_extensions.rb +1 -1
  110. data/lib/plutonium/routing/resource_registration.rb +1 -1
  111. data/lib/plutonium/routing/route_set_extensions.rb +6 -18
  112. data/lib/plutonium/ui/action_button.rb +125 -0
  113. data/lib/plutonium/ui/breadcrumbs.rb +163 -0
  114. data/lib/plutonium/ui/component/base.rb +13 -0
  115. data/lib/plutonium/ui/component/behaviour.rb +38 -0
  116. data/lib/plutonium/ui/component/kit.rb +31 -0
  117. data/lib/plutonium/ui/component/methods.rb +54 -0
  118. data/lib/plutonium/ui/display/base.rb +25 -0
  119. data/lib/plutonium/ui/display/component/association.rb +26 -0
  120. data/lib/plutonium/ui/display/resource.rb +77 -0
  121. data/lib/plutonium/ui/display/theme.rb +27 -0
  122. data/lib/plutonium/ui/dyna_frame/content.rb +20 -0
  123. data/lib/plutonium/ui/empty_card.rb +20 -0
  124. data/lib/plutonium/ui/form/base.rb +37 -0
  125. data/lib/plutonium/ui/form/resource.rb +75 -0
  126. data/lib/plutonium/ui/form/theme.rb +42 -0
  127. data/lib/plutonium/ui/page/base.rb +112 -0
  128. data/lib/plutonium/ui/page/edit.rb +23 -0
  129. data/lib/plutonium/ui/page/index.rb +27 -0
  130. data/lib/plutonium/ui/page/new.rb +23 -0
  131. data/lib/plutonium/ui/page/show.rb +27 -0
  132. data/lib/plutonium/ui/page_header.rb +49 -0
  133. data/lib/plutonium/ui/table/base.rb +13 -0
  134. data/lib/plutonium/ui/table/components/pagy_info.rb +70 -0
  135. data/lib/plutonium/ui/table/components/pagy_page_info.rb +70 -0
  136. data/lib/plutonium/ui/table/components/pagy_pagination.rb +105 -0
  137. data/lib/plutonium/ui/table/components/scopes_bar.rb +136 -0
  138. data/lib/plutonium/ui/table/components/search_bar.rb +158 -0
  139. data/lib/plutonium/ui/table/display_theme.rb +21 -0
  140. data/lib/plutonium/ui/table/resource.rb +98 -0
  141. data/lib/plutonium/ui/table/theme.rb +35 -0
  142. data/lib/plutonium/ui.rb +9 -0
  143. data/lib/plutonium/version.rb +5 -1
  144. data/lib/plutonium.rb +14 -1
  145. data/package-lock.json +19 -22
  146. data/package.json +4 -4
  147. data/src/css/plutonium.css +15 -0
  148. data/tailwind.options.js +11 -3
  149. metadata +218 -81
  150. data/lib/generators/pu/core/install/templates/app/presenters/resource_presenter.rb.tt +0 -2
  151. data/lib/generators/pu/core/install/templates/app/query_objects/resource_query_object.rb.tt +0 -2
  152. data/lib/generators/pu/pkg/feature/templates/app/query_objects/resource_query_object.rb.tt +0 -4
  153. data/lib/plutonium/concerns/resource_validatable.rb +0 -34
  154. data/lib/plutonium/config.rb +0 -9
  155. data/lib/plutonium/core/controllers/base.rb +0 -101
  156. data/lib/plutonium/core/controllers/presentable.rb +0 -65
  157. data/lib/plutonium/core/controllers/queryable.rb +0 -28
  158. data/lib/plutonium/pkg/app.rb +0 -35
  159. data/lib/plutonium/pkg/concerns/resource_validatable.rb +0 -36
  160. data/lib/plutonium/pkg/feature.rb +0 -18
  161. data/lib/plutonium/policy/initializer.rb +0 -22
  162. data/lib/plutonium/policy/scope.rb +0 -19
  163. data/lib/plutonium/pundit/context.rb +0 -18
  164. data/lib/plutonium/pundit/policy_finder.rb +0 -25
  165. data/lib/plutonium/resource/policy_context.rb +0 -5
  166. data/lib/plutonium/resource_register.rb +0 -83
  167. data/lib/plutonium/smart_cache.rb +0 -151
  168. /data/app/views/{application → plutonium}/_flash.html.erb +0 -0
  169. /data/app/views/{application → plutonium}/_flash_alerts.html.erb +0 -0
  170. /data/app/views/{application → plutonium}/_flash_toasts.html.erb +0 -0
  171. /data/lib/generators/pu/pkg/{app/templates/app/views/package → package/templates}/.keep +0 -0
  172. /data/lib/generators/pu/pkg/{feature → package}/templates/app/interactions/resource_interaction.rb.tt +0 -0
  173. /data/lib/generators/pu/pkg/{feature → package}/templates/app/models/resource_record.rb.tt +0 -0
  174. /data/lib/generators/pu/pkg/{feature → package}/templates/app/policies/resource_policy.rb.tt +0 -0
  175. /data/lib/generators/pu/pkg/{feature → package}/templates/app/presenters/resource_presenter.rb.tt +0 -0
  176. /data/lib/generators/pu/pkg/{feature → package}/templates/lib/engine.rb.tt +0 -0
  177. /data/lib/generators/pu/pkg/{app → portal}/templates/app/policies/resource_policy.rb.tt +0 -0
  178. /data/lib/generators/pu/pkg/{app → portal}/templates/app/presenters/resource_presenter.rb.tt +0 -0
  179. /data/lib/generators/pu/pkg/{app → portal}/templates/app/query_objects/resource_query_object.rb.tt +0 -0
  180. /data/lib/generators/pu/pkg/{feature/templates → portal/templates/app/views/package}/.keep +0 -0
  181. /data/lib/generators/pu/pkg/{app → portal}/templates/config/routes.rb.tt +0 -0
  182. /data/lib/generators/pu/pkg/{app → portal}/templates/lib/engine.rb.tt +0 -0
@@ -287,7 +287,7 @@ module PlutoniumGenerators
287
287
  replace_existing.call file, data
288
288
  break if File.read(file).match? regexify_config(data)
289
289
 
290
- inject_into_file file, data, before: /.*# Configure plutonium above this.*/, verbose: false
290
+ inject_into_file file, data, before: /.*# Configure plutonium above.*/, verbose: false
291
291
  end
292
292
  end
293
293
 
@@ -21,7 +21,7 @@ module PlutoniumGenerators
21
21
  end
22
22
 
23
23
  def exception(msg, err)
24
- error "#{msg}\n\n#{err}\n#{err.backtrace.join("\n")}"
24
+ error "#{msg}\n\n#{err.class}: #{err}\n#{err.backtrace.join("\n")}"
25
25
  end
26
26
 
27
27
  private
@@ -19,11 +19,13 @@ module PlutoniumGenerators
19
19
  protected
20
20
 
21
21
  def reserved_packages
22
- %w[core reactor app main]
22
+ %w[core reactor app main plutonium pluton8 plutonate]
23
23
  end
24
24
 
25
25
  def validate_package_name(package_name)
26
+ package_name = package_name.underscore
26
27
  error("Package name is reserved\n\n#{reserved_packages.join "\n"}") if reserved_packages.include?(package_name)
28
+ error("Package name cannot end in `_app` or `_portal`") if /(_app|_portal)$/i.match?(package_name)
27
29
  end
28
30
 
29
31
  def available_packages
@@ -34,11 +36,11 @@ module PlutoniumGenerators
34
36
  end
35
37
 
36
38
  def available_apps
37
- @available_apps ||= ["main_app"] + available_packages.select { |pkg| pkg.ends_with? "_app" }.sort
39
+ @available_apps ||= ["main_app"] + available_packages.select { |pkg| pkg.ends_with?("_app") || pkg.ends_with?("_portal") }.sort
38
40
  end
39
41
 
40
42
  def available_features
41
- @available_features ||= ["main_app"] + available_packages.select { |pkg| !pkg.ends_with?("_app") }.sort
43
+ @available_features ||= ["main_app"] + available_packages.select { |pkg| !(pkg.ends_with?("_app") || pkg.ends_with?("_portal")) }.sort
42
44
  end
43
45
 
44
46
  def select_package(selected_package = nil, msg: "Select package", pkgs: nil)
@@ -111,6 +111,19 @@ module PlutoniumGenerators
111
111
 
112
112
  private
113
113
 
114
+ def parse_type_and_options(type)
115
+ parsed_type, parsed_options = super
116
+
117
+ if type&.ends_with?("?")
118
+ parsed_type.remove!("?")
119
+ parsed_options[:null] = true
120
+ end
121
+
122
+ [parsed_type, parsed_options]
123
+ end
124
+
125
+ private
126
+
114
127
  def find_shared_namespace(model1, model2, separator: "::")
115
128
  # Split the model names by separator to get the namespaces and class names as arrays
116
129
  parts1 = model1.split(separator)
@@ -134,8 +147,19 @@ module PlutoniumGenerators
134
147
  end
135
148
 
136
149
  def required?
137
- # TODO: make it such that we can override fields as nullable
138
- super || true
150
+ super || attr_options[:null] != true
151
+ end
152
+
153
+ def cents?
154
+ type == :integer && name.ends_with?("_cents")
155
+ end
156
+
157
+ def attribute_name
158
+ if cents?
159
+ name.sub("_cents", "")
160
+ else
161
+ name
162
+ end
139
163
  end
140
164
 
141
165
  def options_for_migration
@@ -4,12 +4,12 @@ require_relative "../../lib/plutonium_generators"
4
4
 
5
5
  module Pu
6
6
  module Pkg
7
- class FeatureGenerator < Rails::Generators::Base
7
+ class PackageGenerator < Rails::Generators::Base
8
8
  include PlutoniumGenerators::Generator
9
9
 
10
10
  source_root File.expand_path("templates", __dir__)
11
11
 
12
- desc "Create a plutonium feature package"
12
+ desc "Create a plutonium package"
13
13
 
14
14
  argument :name
15
15
 
@@ -18,7 +18,7 @@ module Pu
18
18
 
19
19
  template "lib/engine.rb", "packages/#{package_namespace}/lib/engine.rb"
20
20
 
21
- %w[controllers interactions models policies presenters query_objects].each do |dir|
21
+ %w[controllers interactions models policies definitions].each do |dir|
22
22
  directory "app/#{dir}", "packages/#{package_namespace}/app/#{dir}/#{package_namespace}"
23
23
  end
24
24
  create_file "packages/#{package_namespace}/app/views/#{package_namespace}/.keep"
@@ -37,7 +37,7 @@ module Pu
37
37
  end
38
38
 
39
39
  def package_type
40
- "Pkg::Feature"
40
+ "Package::Engine"
41
41
  end
42
42
  end
43
43
  end
@@ -1,7 +1,5 @@
1
1
  module <%= package_name %>
2
2
  class ResourceController < ::ResourceController
3
3
  # add concerns above.
4
-
5
- boot <%= package_name %>
6
4
  end
7
5
  end
@@ -0,0 +1,4 @@
1
+ module <%= package_name %>
2
+ class ResourceDefinition < ::ResourceDefinition
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module <%= package_name %>
2
+ class ResourceDefinition < ::ResourceDefinition
3
+ end
4
+ end
@@ -4,17 +4,17 @@ require_relative "../../lib/plutonium_generators"
4
4
 
5
5
  module Pu
6
6
  module Pkg
7
- class AppGenerator < Rails::Generators::Base
7
+ class PortalGenerator < Rails::Generators::Base
8
8
  include PlutoniumGenerators::Generator
9
9
 
10
10
  source_root File.expand_path("templates", __dir__)
11
11
 
12
- desc "Create a plutonium app package"
12
+ desc "Create a plutonium portal package"
13
13
 
14
14
  argument :name
15
15
 
16
16
  def start
17
- validate_package_name package_name
17
+ validate_package_name name
18
18
 
19
19
  if defined?(RodauthApp) && (rodauths = RodauthApp.opts[:rodauths].keys).present?
20
20
  rodauth_account = prompt.select("Select rodauth account to authenticate with:", rodauths + [:none])
@@ -30,15 +30,17 @@ module Pu
30
30
 
31
31
  template "app/controllers/concerns/controller.rb",
32
32
  "packages/#{package_namespace}/app/controllers/#{package_namespace}/concerns/controller.rb"
33
- template "app/controllers/controller.rb",
34
- "packages/#{package_namespace}/app/controllers/#{package_namespace}/controller.rb"
33
+ template "app/controllers/plutonium_controller.rb",
34
+ "packages/#{package_namespace}/app/controllers/#{package_namespace}/plutonium_controller.rb"
35
+ template "app/controllers/resource_controller.rb",
36
+ "packages/#{package_namespace}/app/controllers/#{package_namespace}/resource_controller.rb"
35
37
 
36
38
  template "app/controllers/dashboard_controller.rb",
37
39
  "packages/#{package_namespace}/app/controllers/#{package_namespace}/dashboard_controller.rb"
38
40
  copy_file "app/views/package/dashboard/index.html.erb",
39
41
  "packages/#{package_namespace}/app/views/#{package_namespace}/dashboard/index.html.erb"
40
42
 
41
- %w[policies presenters query_objects].each do |dir|
43
+ %w[policies definitions].each do |dir|
42
44
  directory "app/#{dir}", "packages/#{package_namespace}/app/#{dir}/#{package_namespace}"
43
45
  end
44
46
  create_file "packages/#{package_namespace}/app/views/#{package_namespace}/.keep"
@@ -55,7 +57,7 @@ module Pu
55
57
  attr_reader :rodauth_account
56
58
 
57
59
  def package_name
58
- name.camelize + "App"
60
+ name.camelize + "Portal"
59
61
  end
60
62
 
61
63
  def package_namespace
@@ -63,7 +65,7 @@ module Pu
63
65
  end
64
66
 
65
67
  def package_type
66
- "Pkg::App"
68
+ "Portal::Engine"
67
69
  end
68
70
 
69
71
  def public_access? = @public_access
@@ -2,22 +2,18 @@ module <%= package_name %>
2
2
  module Concerns
3
3
  module Controller
4
4
  extend ActiveSupport::Concern
5
- include Plutonium::Application::Controller
5
+ include Plutonium::Portal::Controller
6
6
  <%- if rodauth_account.present? -%>
7
- include Plutonium::Auth.rodauth(:<%= rodauth_account %>)
7
+ include Plutonium::Auth::Rodauth(:<%= rodauth_account %>)
8
8
  <%- elsif public_access? -%>
9
9
  include Plutonium::Auth::Public
10
10
  <%- end -%>
11
11
  # add concerns above.
12
+ <%- if bring_your_own_auth? -%>
12
13
 
13
14
  included do
14
- boot <%= package_name %>
15
- <%- if bring_your_own_auth? -%>
16
-
17
15
  helper_method :current_user
18
- <%- end -%>
19
16
  end
20
- <%- if bring_your_own_auth? -%>
21
17
 
22
18
  def current_user
23
19
  raise NotImplementedError, "#{self.class}#current_user must return a non nil value"
@@ -1,5 +1,5 @@
1
1
  module <%= package_name %>
2
- class DashboardController < Controller
2
+ class DashboardController < PlutoniumController
3
3
  def index
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ module <%= package_name %>
2
+ class PlutoniumController < ::PlutoniumController
3
+ include <%= package_name %>::Concerns::Controller
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module <%= package_name %>
2
- class Controller < ::ApplicationController
2
+ class ResourceController < ::ResourceController
3
3
  include <%= package_name %>::Concerns::Controller
4
4
  end
5
5
  end
@@ -0,0 +1,4 @@
1
+ module <%= package_name %>
2
+ module ResourceDefinition
3
+ end
4
+ end
@@ -5,6 +5,7 @@
5
5
  <div class="flow-root">
6
6
  <ul role="list" class="divide-y divide-gray-200 dark:divide-gray-700">
7
7
  <% registered_resources.each do |resource| %>
8
+ <% next unless allowed_to? :index?, resource %>
8
9
  <li class="py-3 sm:py-4">
9
10
  <div class="flex items-center">
10
11
  <div class="flex-1 min-w-0 ms-4">
@@ -13,7 +14,7 @@
13
14
  </a>
14
15
  </div>
15
16
  <div class="inline-flex items-center text-base font-semibold text-gray-900 dark:text-white">
16
- <%= resource.count %>
17
+ <%= authorized_resource_scope(resource).count %>
17
18
  </div>
18
19
  </div>
19
20
  </li>
@@ -19,6 +19,7 @@ module Pu
19
19
 
20
20
  Plutonium.eager_load_rails!
21
21
  available_resources = source_module.constantize.descendants.map(&:to_s).sort
22
+ error "No resources found" if available_resources.blank?
22
23
  selected_resources = prompt.multi_select("Select resources", available_resources)
23
24
 
24
25
  @app_namespace = select_app.camelize
@@ -27,9 +28,10 @@ module Pu
27
28
  @resource_class = resource
28
29
 
29
30
  template "app/controllers/resource_controller.rb", "packages/#{package_namespace}/app/controllers/#{package_namespace}/#{resource.pluralize.underscore}_controller.rb"
30
- # template "app/policies/resource_policy.rb", "packages/#{package_namespace}/app/policies/#{package_namespace}/#{resource.underscore}_policy.rb"
31
- # template "app/presenters/resource_presenter.rb", "packages/#{package_namespace}/app/presenters/#{package_namespace}/#{resource.underscore}_presenter.rb"
32
- # template "app/query_objects/resource_query_object.rb", "packages/#{package_namespace}/app/query_objects/#{package_namespace}/#{resource.underscore}_query_object.rb"
31
+ template "app/policies/resource_policy.rb", "packages/#{package_namespace}/app/policies/#{package_namespace}/#{resource.underscore}_policy.rb" unless expected_parent_policy
32
+ # template "app/presenters/resource_presenter.rb", "packages/#{package_namespace}/app/presenters/#{package_namespace}/#{resource.underscore}_presenter.rb" unless expected_parent_presenter
33
+ # template "app/query_objects/resource_query_object.rb", "packages/#{package_namespace}/app/query_objects/#{package_namespace}/#{resource.underscore}_query_object.rb" unless expected_parent_query_object
34
+ template "app/definitions/resource_definition.rb", "packages/#{package_namespace}/app/definitions/#{package_namespace}/#{resource.underscore}_definition.rb" unless expected_parent_definition
33
35
 
34
36
  insert_into_file "packages/#{package_namespace}/config/routes.rb",
35
37
  indent("register_resource ::#{resource}\n", 2),
@@ -50,6 +52,79 @@ module Pu
50
52
  def resource_namespace
51
53
  app_namespace.underscore
52
54
  end
55
+
56
+ def expected_parent_controller
57
+ expected_parent_controller = "::#{resource_class.pluralize}Controller".safe_constantize
58
+ expected_parent_controller if expected_parent_controller.present? && expected_parent_controller < ::ResourceController
59
+ end
60
+
61
+ def parent_controller
62
+ expected_parent_controller || "#{app_namespace}::ResourceController"
63
+ end
64
+
65
+ def expected_parent_policy
66
+ expected_parent_policy = "::#{resource_class.classify}Policy".safe_constantize
67
+ expected_parent_policy if expected_parent_policy.present? && expected_parent_policy < ::ResourcePolicy
68
+ end
69
+
70
+ def parent_policy
71
+ expected_parent_policy || "ResourcePolicy"
72
+ end
73
+
74
+ def expected_parent_presenter
75
+ expected_parent_presenter = "::#{resource_class.classify}Presenter".safe_constantize
76
+ expected_parent_presenter if expected_parent_presenter.present? && expected_parent_presenter < ::ResourcePresenter
77
+ end
78
+
79
+ def parent_presenter
80
+ expected_parent_presenter || "ResourcePresenter"
81
+ end
82
+
83
+ def expected_parent_query_object
84
+ expected_parent_query_object = "::#{resource_class.classify}QueryObject".safe_constantize
85
+ expected_parent_query_object if expected_parent_query_object.present? && expected_parent_query_object < ::ResourceQueryObject
86
+ end
87
+
88
+ def parent_query_object
89
+ expected_parent_query_object || "ResourceQueryObject"
90
+ end
91
+
92
+ def expected_parent_definition
93
+ expected_parent_definition = "::#{resource_class.classify}Definition".safe_constantize
94
+ expected_parent_definition if expected_parent_definition.present? && expected_parent_definition < ::ResourceDefinition
95
+ end
96
+
97
+ def parent_definition
98
+ expected_parent_definition || "ResourceDefinition"
99
+ end
100
+
101
+ def attributes
102
+ resource_klass = resource_class.constantize
103
+ unwanted_attrs = [
104
+ resource_klass.primary_key.to_sym, # primary_key
105
+ :created_at, :updated_at # timestamps
106
+ ]
107
+ resource_klass.content_columns.filter_map { |col|
108
+ next if unwanted_attrs.include? col.name.to_sym
109
+
110
+ PlutoniumGenerators::ModelGeneratorBase::GeneratedAttribute.parse resource_class, "#{col.name}:#{col.type}"
111
+ }
112
+ rescue ActiveRecord::StatementInvalid
113
+ say format_log("An error occurred while building attributes. Ensure any migrations have been run and try again.", :error), :red
114
+ []
115
+ end
116
+
117
+ def default_policy_attributes
118
+ attributes.select { |a| !a.rich_text? && !a.password_digest? && !a.token? }.map(&:attribute_name).map(&:to_sym)
119
+ end
120
+
121
+ def policy_attributes_for_create
122
+ default_policy_attributes
123
+ end
124
+
125
+ def policy_attributes_for_read
126
+ default_policy_attributes + [:created_at, :updated_at]
127
+ end
53
128
  end
54
129
  end
55
130
  end
@@ -1,3 +1,3 @@
1
- class <%= app_namespace %>::<%= resource_class.pluralize %>Controller < ::<%= resource_class.pluralize %>Controller
1
+ class <%= app_namespace %>::<%= resource_class.pluralize %>Controller < ::<%= parent_controller %>
2
2
  include <%= app_namespace %>::Concerns::Controller
3
3
  end
@@ -0,0 +1,3 @@
1
+ class <%= app_namespace %>::<%= resource_class %>Definition < ::<%= parent_definition %>
2
+ include <%= app_namespace %>::ResourceDefinition
3
+ end
@@ -1,3 +1,31 @@
1
- class <%= app_namespace %>::<%= resource_class %>Policy < ::<%= resource_class %>Policy
1
+ class <%= app_namespace %>::<%= resource_class %>Policy < ::<%= parent_policy %>
2
2
  include <%= app_namespace %>::ResourcePolicy
3
+ <%- unless expected_parent_policy -%>
4
+
5
+ # Core actions
6
+
7
+ def create?
8
+ true
9
+ end
10
+
11
+ def read?
12
+ true
13
+ end
14
+
15
+ # Core attributes
16
+
17
+ def permitted_attributes_for_create
18
+ <%= policy_attributes_for_create.inspect %>
19
+ end
20
+
21
+ def permitted_attributes_for_read
22
+ <%= policy_attributes_for_read.inspect %>
23
+ end
24
+
25
+ # Associations
26
+
27
+ def permitted_associations
28
+ %i[]
29
+ end
30
+ <%- end -%>
3
31
  end
@@ -1,3 +1,3 @@
1
- class <%= app_namespace %>::<%= resource_class %>Presenter < ::<%= resource_class %>Presenter
1
+ class <%= app_namespace %>::<%= resource_class %>Presenter < ::<%= parent_presenter %>
2
2
  include <%= app_namespace %>::ResourcePresenter
3
3
  end
@@ -1,3 +1,3 @@
1
- class <%= app_namespace %>::<%= resource_class %>QueryObject < ::<%= resource_class %>QueryObject
1
+ class <%= app_namespace %>::<%= resource_class %>QueryObject < ::<%= parent_query_object %>
2
2
  include <%= app_namespace %>::ResourceQueryObject
3
3
  end
@@ -12,13 +12,6 @@ module Pu
12
12
  end
13
13
 
14
14
  def run_create_model
15
- model_class = class_name.safe_constantize
16
- if model_class.present? && !model_class.include?(Plutonium::Resource::Record)
17
- gsub_file File.join("app/models", class_path, "#{file_name}.rb"),
18
- "< ApplicationRecord",
19
- "< ResourceRecord"
20
- end
21
-
22
15
  create_model_file if create_files?
23
16
  end
24
17
 
@@ -6,6 +6,9 @@ require_relative "../<%= class_path.last.underscore %>"
6
6
  class <%= class_name %> < <%= [feature_package_name, "ResourceRecord"].join "::" %>
7
7
  # add concerns above.
8
8
 
9
+ <% attributes.select(&:cents?).each do |attribute| -%>
10
+ has_cents :<%= attribute.name %>
11
+ <% end -%>
9
12
  # add model configurations above.
10
13
 
11
14
  <% attributes.select(&:reference?).each do |attribute| -%>
@@ -29,7 +32,7 @@ class <%= class_name %> < <%= [feature_package_name, "ResourceRecord"].join "::"
29
32
 
30
33
  <% attributes.select(&:required?).each do |attribute| -%>
31
34
  <%- next if attribute.reference? || attribute.rich_text? || attribute.token? || attribute.password_digest? -%>
32
- validates :<%= attribute.name %>, presence: true
35
+ validates :<%= attribute.attribute_name %>, presence: true
33
36
  <% end -%>
34
37
  # add validations above.
35
38
 
@@ -37,12 +37,30 @@ module Pu
37
37
  template "policy.rb", File.join("app/policies", class_path, "#{file_name}_policy.rb")
38
38
  end
39
39
 
40
- def create_presenter
41
- template "presenter.rb", File.join("app/presenters", class_path, "#{file_name}_presenter.rb")
40
+ def create_definition
41
+ template "definition.rb", File.join("app/definitions", class_path, "#{file_name}_definition.rb")
42
42
  end
43
43
 
44
- def create_query_object
45
- template "query_object.rb", File.join("app/query_objects", class_path, "#{file_name}_query_object.rb")
44
+ # def create_presenter
45
+ # template "presenter.rb", File.join("app/presenters", class_path, "#{file_name}_presenter.rb")
46
+ # end
47
+
48
+ # def create_query_object
49
+ # template "query_object.rb", File.join("app/query_objects", class_path, "#{file_name}_query_object.rb")
50
+ # end
51
+
52
+ private
53
+
54
+ def default_policy_attributes
55
+ attributes.select { |a| !a.rich_text? && !a.password_digest? && !a.token? }.map(&:attribute_name).map(&:to_sym)
56
+ end
57
+
58
+ def policy_attributes_for_create
59
+ default_policy_attributes
60
+ end
61
+
62
+ def policy_attributes_for_read
63
+ default_policy_attributes + [:created_at, :updated_at]
46
64
  end
47
65
  end
48
66
  end
@@ -1,5 +1,4 @@
1
1
  <% module_namespacing do -%>
2
2
  class <%= class_name.pluralize %>Controller < <%= [feature_package_name, "ResourceController"].join "::" %>
3
- controller_for ::<%= class_name %>
4
3
  end
5
4
  <% end -%>
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Definition < <%= [feature_package_name, "ResourceDefinition"].join "::" %>
3
+ end
4
+ <% end -%>
@@ -13,11 +13,11 @@ class <%= class_name %>Policy < <%= [feature_package_name, "ResourcePolicy"].joi
13
13
  # Core attributes
14
14
 
15
15
  def permitted_attributes_for_create
16
- <%= attributes.select{ |a| !a.rich_text? && !a.password_digest? && !a.token? }.map(&:name).map(&:to_sym).inspect %>
16
+ <%= policy_attributes_for_create.inspect %>
17
17
  end
18
18
 
19
19
  def permitted_attributes_for_read
20
- <%= attributes.select{ |a| !a.rich_text? && !a.password_digest? && !a.token? }.map(&:name).map(&:to_sym).inspect %>
20
+ <%= policy_attributes_for_read.inspect %>
21
21
  end
22
22
 
23
23
  # Associations
@@ -1,4 +1,4 @@
1
1
  # Base rodauth controller. Inherited by all account controllers.
2
- class RodauthController < ApplicationController
2
+ class RodauthController < PlutoniumController
3
3
  include Plutonium::Rodauth::ControllerMethods
4
4
  end