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.
- checksums.yaml +4 -4
- data/README copy.md +1 -1
- data/README.md +1 -1
- data/app/assets/plutonium.css +1 -1
- data/app/views/{application → plutonium}/_resource_header.html copy.erb +1 -1
- data/app/views/{application → plutonium}/_resource_header.html.erb +1 -1
- data/app/views/{application → plutonium}/_resource_sidebar.html.erb +2 -0
- data/app/views/resource/_resource_details.html.erb +1 -36
- data/app/views/resource/_resource_form.html.erb +1 -5
- data/app/views/resource/_resource_table.html.erb +315 -85
- data/app/views/resource/edit.html.erb +1 -5
- data/app/views/resource/index.html.erb +1 -5
- data/app/views/resource/new.html.erb +1 -5
- data/app/views/resource/show.html.erb +1 -5
- data/config/initializers/pagy.rb +1 -0
- data/config/initializers/rabl.rb +27 -20
- data/gemfiles/rails_7.gemfile.lock +5 -1
- data/lib/generators/pu/core/install/templates/app/controllers/plutonium_controller.rb.tt +2 -0
- data/lib/generators/pu/core/install/templates/app/controllers/resource_controller.rb.tt +21 -1
- data/lib/generators/pu/core/install/templates/app/definitions/resource_definition.rb.tt +2 -0
- data/lib/generators/pu/core/install/templates/app/models/resource_record.rb.tt +0 -2
- data/lib/generators/pu/core/install/templates/config/initializers/plutonium.rb +1 -8
- data/lib/generators/pu/eject/shell/shell_generator.rb +2 -2
- data/lib/generators/pu/lib/plutonium_generators/concerns/actions.rb +1 -1
- data/lib/generators/pu/lib/plutonium_generators/concerns/logger.rb +1 -1
- data/lib/generators/pu/lib/plutonium_generators/generator.rb +5 -3
- data/lib/generators/pu/lib/plutonium_generators/model_generator_base.rb +26 -2
- data/lib/generators/pu/pkg/{feature/feature_generator.rb → package/package_generator.rb} +4 -4
- data/lib/generators/pu/pkg/{feature → package}/templates/app/controllers/resource_controller.rb.tt +0 -2
- data/lib/generators/pu/pkg/package/templates/app/definitions/resource_definition.rb.tt +4 -0
- data/lib/generators/pu/pkg/package/templates/app/query_objects/resource_query_object.rb.tt +4 -0
- data/lib/generators/pu/pkg/{app/app_generator.rb → portal/portal_generator.rb} +10 -8
- data/lib/generators/pu/pkg/{app → portal}/templates/app/controllers/concerns/controller.rb.tt +3 -7
- data/lib/generators/pu/pkg/{app → portal}/templates/app/controllers/dashboard_controller.rb.tt +1 -1
- data/lib/generators/pu/pkg/portal/templates/app/controllers/plutonium_controller.rb.tt +5 -0
- data/lib/generators/pu/pkg/{app/templates/app/controllers/controller.rb.tt → portal/templates/app/controllers/resource_controller.rb.tt} +1 -1
- data/lib/generators/pu/pkg/portal/templates/app/definitions/resource_definition.rb.tt +4 -0
- data/lib/generators/pu/pkg/{app → portal}/templates/app/views/package/dashboard/index.html.erb +2 -1
- data/lib/generators/pu/res/conn/conn_generator.rb +78 -3
- data/lib/generators/pu/res/conn/templates/app/controllers/resource_controller.rb.tt +1 -1
- data/lib/generators/pu/res/conn/templates/app/definitions/resource_definition.rb.tt +3 -0
- data/lib/generators/pu/res/conn/templates/app/policies/resource_policy.rb.tt +29 -1
- data/lib/generators/pu/res/conn/templates/app/presenters/resource_presenter.rb.tt +1 -1
- data/lib/generators/pu/res/conn/templates/app/query_objects/resource_query_object.rb.tt +1 -1
- data/lib/generators/pu/res/model/model_generator.rb +0 -7
- data/lib/generators/pu/res/model/templates/model.rb.tt +4 -1
- data/lib/generators/pu/res/scaffold/scaffold_generator.rb +22 -4
- data/lib/generators/pu/res/scaffold/templates/controller.rb.tt +0 -1
- data/lib/generators/pu/res/scaffold/templates/definition.rb.tt +4 -0
- data/lib/generators/pu/res/scaffold/templates/policy.rb.tt +2 -2
- data/lib/generators/pu/rodauth/templates/app/controllers/rodauth_controller.rb.tt +1 -1
- data/lib/generators/pu/rodauth/templates/app/rodauth/account_rodauth_plugin.rb.tt +270 -0
- data/lib/plutonium/action/README.md +0 -0
- data/lib/plutonium/action/base.rb +103 -0
- data/lib/plutonium/action/interactive.rb +117 -0
- data/lib/plutonium/action/route_options.rb +65 -0
- data/lib/plutonium/action/simple.rb +8 -0
- data/lib/plutonium/auth.rb +1 -1
- data/lib/plutonium/configuration.rb +0 -8
- data/lib/plutonium/core/actions/collection.rb +1 -1
- data/lib/plutonium/core/associations/renderers/factory.rb +3 -1
- data/lib/plutonium/core/controller.rb +110 -0
- data/lib/plutonium/core/controllers/authorizable.rb +12 -35
- data/lib/plutonium/core/controllers/bootable.rb +38 -7
- data/lib/plutonium/core/controllers/entity_scoping.rb +6 -2
- data/lib/plutonium/core/fields/renderers/association_renderer.rb +1 -1
- data/lib/plutonium/core/ui/collection.rb +1 -1
- data/lib/plutonium/core/ui/detail.rb +1 -1
- data/lib/plutonium/core/ui/form.rb +1 -1
- data/lib/plutonium/definition/actions.rb +50 -0
- data/lib/plutonium/definition/base.rb +92 -0
- data/lib/plutonium/definition/config_attr.rb +30 -0
- data/lib/plutonium/definition/defineable_props.rb +96 -0
- data/lib/plutonium/definition/search.rb +21 -0
- data/lib/plutonium/engine/validator.rb +30 -0
- data/lib/plutonium/engine.rb +25 -0
- data/lib/plutonium/helpers/form_helper.rb +1 -3
- data/lib/plutonium/interaction/README.md +369 -0
- data/lib/plutonium/interaction/base.rb +75 -0
- data/lib/plutonium/interaction/concerns/presentable.rb +61 -0
- data/lib/plutonium/interaction/concerns/workflow_dsl.rb +82 -0
- data/lib/plutonium/interaction/outcome.rb +129 -0
- data/lib/plutonium/interaction/response/base.rb +63 -0
- data/lib/plutonium/interaction/response/null.rb +33 -0
- data/lib/plutonium/interaction/response/redirect.rb +30 -0
- data/lib/plutonium/interaction/response/render.rb +28 -0
- data/lib/plutonium/lib/bit_flags.rb +70 -9
- data/lib/plutonium/{config → lib}/overlayed_hash.rb +1 -1
- data/lib/plutonium/lib/smart_cache.rb +171 -0
- data/lib/plutonium/models/has_cents.rb +170 -0
- data/lib/plutonium/{pkg/base.rb → package/engine.rb} +10 -2
- data/lib/plutonium/{application → portal}/controller.rb +3 -11
- data/lib/plutonium/{application → portal}/dynamic_controllers.rb +4 -4
- data/lib/plutonium/portal/engine.rb +15 -0
- data/lib/plutonium/railtie.rb +33 -1
- data/lib/plutonium/reloader.rb +5 -5
- data/lib/plutonium/resource/controller.rb +51 -34
- data/lib/plutonium/resource/controllers/authorizable.rb +128 -0
- data/lib/plutonium/{core → resource}/controllers/crud_actions.rb +23 -22
- data/lib/plutonium/resource/controllers/defineable.rb +26 -0
- data/lib/plutonium/{core → resource}/controllers/interactive_actions.rb +12 -12
- data/lib/plutonium/resource/controllers/presentable.rb +41 -0
- data/lib/plutonium/resource/controllers/queryable.rb +44 -0
- data/lib/plutonium/resource/definition.rb +6 -0
- data/lib/plutonium/resource/policy.rb +25 -13
- data/lib/plutonium/resource/query_object.rb +50 -51
- data/lib/plutonium/resource/record.rb +6 -89
- data/lib/plutonium/resource/register.rb +82 -0
- data/lib/plutonium/routing/mapper_extensions.rb +1 -1
- data/lib/plutonium/routing/resource_registration.rb +1 -1
- data/lib/plutonium/routing/route_set_extensions.rb +6 -18
- data/lib/plutonium/ui/action_button.rb +125 -0
- data/lib/plutonium/ui/breadcrumbs.rb +163 -0
- data/lib/plutonium/ui/component/base.rb +13 -0
- data/lib/plutonium/ui/component/behaviour.rb +38 -0
- data/lib/plutonium/ui/component/kit.rb +31 -0
- data/lib/plutonium/ui/component/methods.rb +54 -0
- data/lib/plutonium/ui/display/base.rb +25 -0
- data/lib/plutonium/ui/display/component/association.rb +26 -0
- data/lib/plutonium/ui/display/resource.rb +77 -0
- data/lib/plutonium/ui/display/theme.rb +27 -0
- data/lib/plutonium/ui/dyna_frame/content.rb +20 -0
- data/lib/plutonium/ui/empty_card.rb +20 -0
- data/lib/plutonium/ui/form/base.rb +37 -0
- data/lib/plutonium/ui/form/resource.rb +75 -0
- data/lib/plutonium/ui/form/theme.rb +42 -0
- data/lib/plutonium/ui/page/base.rb +112 -0
- data/lib/plutonium/ui/page/edit.rb +23 -0
- data/lib/plutonium/ui/page/index.rb +27 -0
- data/lib/plutonium/ui/page/new.rb +23 -0
- data/lib/plutonium/ui/page/show.rb +27 -0
- data/lib/plutonium/ui/page_header.rb +49 -0
- data/lib/plutonium/ui/table/base.rb +13 -0
- data/lib/plutonium/ui/table/components/pagy_info.rb +70 -0
- data/lib/plutonium/ui/table/components/pagy_page_info.rb +70 -0
- data/lib/plutonium/ui/table/components/pagy_pagination.rb +105 -0
- data/lib/plutonium/ui/table/components/scopes_bar.rb +136 -0
- data/lib/plutonium/ui/table/components/search_bar.rb +158 -0
- data/lib/plutonium/ui/table/display_theme.rb +21 -0
- data/lib/plutonium/ui/table/resource.rb +98 -0
- data/lib/plutonium/ui/table/theme.rb +35 -0
- data/lib/plutonium/ui.rb +9 -0
- data/lib/plutonium/version.rb +5 -1
- data/lib/plutonium.rb +14 -1
- data/package-lock.json +19 -22
- data/package.json +4 -4
- data/src/css/plutonium.css +15 -0
- data/tailwind.options.js +11 -3
- metadata +218 -81
- data/lib/generators/pu/core/install/templates/app/presenters/resource_presenter.rb.tt +0 -2
- data/lib/generators/pu/core/install/templates/app/query_objects/resource_query_object.rb.tt +0 -2
- data/lib/generators/pu/pkg/feature/templates/app/query_objects/resource_query_object.rb.tt +0 -4
- data/lib/plutonium/concerns/resource_validatable.rb +0 -34
- data/lib/plutonium/config.rb +0 -9
- data/lib/plutonium/core/controllers/base.rb +0 -101
- data/lib/plutonium/core/controllers/presentable.rb +0 -65
- data/lib/plutonium/core/controllers/queryable.rb +0 -28
- data/lib/plutonium/pkg/app.rb +0 -35
- data/lib/plutonium/pkg/concerns/resource_validatable.rb +0 -36
- data/lib/plutonium/pkg/feature.rb +0 -18
- data/lib/plutonium/policy/initializer.rb +0 -22
- data/lib/plutonium/policy/scope.rb +0 -19
- data/lib/plutonium/pundit/context.rb +0 -18
- data/lib/plutonium/pundit/policy_finder.rb +0 -25
- data/lib/plutonium/resource/policy_context.rb +0 -5
- data/lib/plutonium/resource_register.rb +0 -83
- data/lib/plutonium/smart_cache.rb +0 -151
- /data/app/views/{application → plutonium}/_flash.html.erb +0 -0
- /data/app/views/{application → plutonium}/_flash_alerts.html.erb +0 -0
- /data/app/views/{application → plutonium}/_flash_toasts.html.erb +0 -0
- /data/lib/generators/pu/pkg/{app/templates/app/views/package → package/templates}/.keep +0 -0
- /data/lib/generators/pu/pkg/{feature → package}/templates/app/interactions/resource_interaction.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{feature → package}/templates/app/models/resource_record.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{feature → package}/templates/app/policies/resource_policy.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{feature → package}/templates/app/presenters/resource_presenter.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{feature → package}/templates/lib/engine.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{app → portal}/templates/app/policies/resource_policy.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{app → portal}/templates/app/presenters/resource_presenter.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{app → portal}/templates/app/query_objects/resource_query_object.rb.tt +0 -0
- /data/lib/generators/pu/pkg/{feature/templates → portal/templates/app/views/package}/.keep +0 -0
- /data/lib/generators/pu/pkg/{app → portal}/templates/config/routes.rb.tt +0 -0
- /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
|
290
|
+
inject_into_file file, data, before: /.*# Configure plutonium above.*/, verbose: false
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
@@ -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?
|
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
|
-
|
138
|
-
|
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
|
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
|
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
|
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
|
-
"
|
40
|
+
"Package::Engine"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -4,17 +4,17 @@ require_relative "../../lib/plutonium_generators"
|
|
4
4
|
|
5
5
|
module Pu
|
6
6
|
module Pkg
|
7
|
-
class
|
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
|
12
|
+
desc "Create a plutonium portal package"
|
13
13
|
|
14
14
|
argument :name
|
15
15
|
|
16
16
|
def start
|
17
|
-
validate_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/
|
34
|
-
"packages/#{package_namespace}/app/controllers/#{package_namespace}/
|
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
|
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 + "
|
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
|
-
"
|
68
|
+
"Portal::Engine"
|
67
69
|
end
|
68
70
|
|
69
71
|
def public_access? = @public_access
|
data/lib/generators/pu/pkg/{app → portal}/templates/app/controllers/concerns/controller.rb.tt
RENAMED
@@ -2,22 +2,18 @@ module <%= package_name %>
|
|
2
2
|
module Concerns
|
3
3
|
module Controller
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
include Plutonium::
|
5
|
+
include Plutonium::Portal::Controller
|
6
6
|
<%- if rodauth_account.present? -%>
|
7
|
-
include Plutonium::Auth
|
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"
|
data/lib/generators/pu/pkg/{app → portal}/templates/app/views/package/dashboard/index.html.erb
RENAMED
@@ -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
|
-
|
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 < ::<%=
|
1
|
+
class <%= app_namespace %>::<%= resource_class.pluralize %>Controller < ::<%= parent_controller %>
|
2
2
|
include <%= app_namespace %>::Concerns::Controller
|
3
3
|
end
|
@@ -1,3 +1,31 @@
|
|
1
|
-
class <%= app_namespace %>::<%= 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
|
@@ -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.
|
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
|
41
|
-
template "
|
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
|
45
|
-
|
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
|
@@ -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
|
-
<%=
|
16
|
+
<%= policy_attributes_for_create.inspect %>
|
17
17
|
end
|
18
18
|
|
19
19
|
def permitted_attributes_for_read
|
20
|
-
<%=
|
20
|
+
<%= policy_attributes_for_read.inspect %>
|
21
21
|
end
|
22
22
|
|
23
23
|
# Associations
|