plutonium 0.43.2 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Rakefile +24 -6
- data/app/assets/plutonium.css +1 -1
- data/config/initializers/pagy.rb +1 -4
- data/gemfiles/rails_7.gemfile.lock +8 -3
- data/gemfiles/rails_8.0.gemfile.lock +7 -3
- data/gemfiles/rails_8.1.gemfile.lock +7 -3
- data/lib/generators/pu/invites/install_generator.rb +69 -11
- data/lib/generators/pu/invites/templates/INSTRUCTIONS +4 -1
- data/lib/generators/pu/invites/templates/app/interactions/invite_user_interaction.rb.tt +1 -1
- data/lib/generators/pu/invites/templates/app/interactions/user_invite_user_interaction.rb.tt +1 -1
- data/lib/generators/pu/invites/templates/packages/invites/app/controllers/invites/user_invitations_controller.rb.tt +5 -1
- data/lib/generators/pu/invites/templates/packages/invites/app/controllers/invites/welcome_controller.rb.tt +14 -24
- data/lib/generators/pu/invites/templates/packages/invites/app/mailers/invites/user_invite_mailer.rb.tt +2 -0
- data/lib/generators/pu/invites/templates/packages/invites/app/views/invites/user_invitations/show.html.erb.tt +3 -2
- data/lib/generators/pu/invites/templates/packages/invites/app/views/invites/welcome/pending_invitation.html.erb.tt +3 -2
- data/lib/generators/pu/lib/plutonium_generators/concerns/logger.rb +2 -0
- data/lib/generators/pu/lib/plutonium_generators/concerns/package_selector.rb +4 -6
- data/lib/generators/pu/lib/plutonium_generators/concerns/rodauth_redirects.rb +41 -0
- data/lib/generators/pu/lib/plutonium_generators/generator.rb +5 -1
- data/lib/generators/pu/lib/plutonium_generators/non_interactive_prompt.rb +27 -0
- data/lib/generators/pu/rodauth/templates/app/models/account.rb.tt +4 -0
- data/lib/generators/pu/saas/entity_generator.rb +16 -0
- data/lib/generators/pu/saas/membership_generator.rb +4 -3
- data/lib/generators/pu/saas/portal/USAGE +15 -0
- data/lib/generators/pu/saas/portal_generator.rb +122 -0
- data/lib/generators/pu/saas/setup/USAGE +17 -22
- data/lib/generators/pu/saas/setup_generator.rb +62 -9
- data/lib/generators/pu/saas/welcome/USAGE +27 -0
- data/lib/generators/pu/saas/welcome/templates/app/controllers/authenticated_controller.rb.tt +18 -0
- data/lib/generators/pu/saas/welcome/templates/app/controllers/welcome_controller.rb.tt +69 -0
- data/lib/generators/pu/saas/welcome/templates/app/views/layouts/welcome.html.erb.tt +33 -0
- data/lib/generators/pu/saas/welcome/templates/app/views/welcome/onboarding.html.erb.tt +51 -0
- data/lib/generators/pu/saas/welcome/templates/app/views/welcome/select_entity.html.erb.tt +22 -0
- data/lib/generators/pu/saas/welcome_generator.rb +197 -0
- data/lib/plutonium/auth/sequel_adapter.rb +1 -2
- data/lib/plutonium/core/controller.rb +18 -8
- data/lib/plutonium/core/controllers/association_resolver.rb +19 -6
- data/lib/plutonium/invites/concerns/cancel_invite.rb +3 -1
- data/lib/plutonium/invites/concerns/invite_user.rb +1 -1
- data/lib/plutonium/resource/controller.rb +2 -3
- data/lib/plutonium/resource/controllers/crud_actions/index_action.rb +1 -1
- data/lib/plutonium/resource/controllers/presentable.rb +2 -0
- data/lib/plutonium/ui/table/components/pagy_info.rb +1 -7
- data/lib/plutonium/ui/table/components/pagy_pagination.rb +4 -6
- data/lib/plutonium/version.rb +1 -1
- data/package.json +1 -1
- data/plutonium.gemspec +1 -1
- metadata +16 -8
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
Description:
|
|
2
|
-
Generate a complete SaaS setup with user account, entity,
|
|
3
|
-
|
|
2
|
+
Generate a complete SaaS setup with user account, entity, membership,
|
|
3
|
+
portal, welcome flow, invites, and profile.
|
|
4
|
+
|
|
5
|
+
This is the recommended way to bootstrap a multi-tenant SaaS app.
|
|
4
6
|
|
|
5
7
|
Example:
|
|
6
|
-
rails g pu:saas:setup --user
|
|
7
|
-
rails g pu:saas:setup --user Customer --entity Organization --roles=member,admin,owner
|
|
8
|
-
rails g pu:saas:setup --user Customer --entity Organization --no-allow-signup
|
|
9
|
-
rails g pu:saas:setup --user Customer --entity Organization --user-attributes=name:string
|
|
10
|
-
rails g pu:saas:setup --user Customer --entity Organization --skip-entity
|
|
8
|
+
rails g pu:saas:setup --user=User --entity=Organization
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
Full setup with all defaults:
|
|
11
|
+
- User model with Rodauth authentication
|
|
12
|
+
- Entity model with unique name and dynamic path parameter
|
|
13
|
+
- Membership model with owner/admin/member roles
|
|
14
|
+
- DashboardPortal with entity scoping
|
|
15
|
+
- Welcome/onboarding flow
|
|
16
|
+
- User invites package
|
|
17
|
+
- User profile resource
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
--user
|
|
19
|
-
--entity
|
|
20
|
-
|
|
21
|
-
--roles Comma-separated membership roles (default: member,owner)
|
|
22
|
-
--skip-entity Skip entity model generation
|
|
23
|
-
--skip-membership Skip membership model generation
|
|
24
|
-
--user-attributes Additional user model attributes
|
|
25
|
-
--entity-attributes Additional entity model attributes
|
|
26
|
-
--membership-attributes Additional membership model attributes
|
|
27
|
-
--dest Destination package (default: main_app)
|
|
19
|
+
Customize:
|
|
20
|
+
rails g pu:saas:setup --user=User --entity=Organization --portal-name=Customer
|
|
21
|
+
rails g pu:saas:setup --user=User --entity=Organization --no-invites --no-profile
|
|
22
|
+
rails g pu:saas:setup --user=User --entity=Organization --no-portal
|
|
@@ -8,10 +8,10 @@ module Pu
|
|
|
8
8
|
class SetupGenerator < ::Rails::Generators::Base
|
|
9
9
|
include PlutoniumGenerators::Generator
|
|
10
10
|
|
|
11
|
-
desc "Generate a complete SaaS setup with user, entity, and
|
|
11
|
+
desc "Generate a complete SaaS setup with user, entity, membership, portal, and welcome flow"
|
|
12
12
|
|
|
13
13
|
class_option :user, type: :string, required: true,
|
|
14
|
-
desc: "The user model name (e.g.,
|
|
14
|
+
desc: "The user model name (e.g., User)"
|
|
15
15
|
|
|
16
16
|
class_option :entity, type: :string, required: true,
|
|
17
17
|
desc: "The entity model name (e.g., Organization)"
|
|
@@ -19,8 +19,8 @@ module Pu
|
|
|
19
19
|
class_option :allow_signup, type: :boolean, default: true,
|
|
20
20
|
desc: "Whether to allow users to sign up to the platform"
|
|
21
21
|
|
|
22
|
-
class_option :roles, type: :array, default: %w[member
|
|
23
|
-
desc: "
|
|
22
|
+
class_option :roles, type: :array, default: %w[admin member],
|
|
23
|
+
desc: "Additional roles for memberships (owner is always included as the first role)"
|
|
24
24
|
|
|
25
25
|
class_option :skip_entity, type: :boolean, default: false,
|
|
26
26
|
desc: "Skip entity model generation"
|
|
@@ -37,6 +37,21 @@ module Pu
|
|
|
37
37
|
class_option :membership_attributes, type: :array, default: [],
|
|
38
38
|
desc: "Additional attributes for the membership model"
|
|
39
39
|
|
|
40
|
+
class_option :portal, type: :boolean, default: true,
|
|
41
|
+
desc: "Generate a portal with entity scoping"
|
|
42
|
+
|
|
43
|
+
class_option :portal_name, type: :string, default: "Dashboard",
|
|
44
|
+
desc: "Portal name (e.g., Dashboard generates DashboardPortal)"
|
|
45
|
+
|
|
46
|
+
class_option :welcome, type: :boolean, default: true,
|
|
47
|
+
desc: "Generate the welcome/onboarding flow"
|
|
48
|
+
|
|
49
|
+
class_option :invites, type: :boolean, default: true,
|
|
50
|
+
desc: "Generate the user invites package"
|
|
51
|
+
|
|
52
|
+
class_option :profile, type: :boolean, default: true,
|
|
53
|
+
desc: "Generate user profile resource"
|
|
54
|
+
|
|
40
55
|
class_option :api_client, type: :string, default: nil,
|
|
41
56
|
desc: "Generate an API client model (e.g., ApiClient)"
|
|
42
57
|
|
|
@@ -48,6 +63,10 @@ module Pu
|
|
|
48
63
|
generate_user
|
|
49
64
|
generate_entity unless options[:skip_entity]
|
|
50
65
|
generate_membership unless options[:skip_membership]
|
|
66
|
+
generate_portal if options[:portal] && !options[:skip_entity]
|
|
67
|
+
generate_profile if options[:profile]
|
|
68
|
+
generate_welcome if options[:welcome] && !options[:skip_entity] && options[:portal]
|
|
69
|
+
generate_invites if options[:invites] && !options[:skip_entity] && !options[:skip_membership]
|
|
51
70
|
generate_api_client if options[:api_client].present?
|
|
52
71
|
rescue => e
|
|
53
72
|
exception "#{self.class} failed:", e
|
|
@@ -62,7 +81,6 @@ module Pu
|
|
|
62
81
|
end
|
|
63
82
|
|
|
64
83
|
def generate_user
|
|
65
|
-
# Use class-based invocation to avoid Thor's invoke caching
|
|
66
84
|
klass = Rails::Generators.find_by_namespace("pu:saas:user")
|
|
67
85
|
klass.new(
|
|
68
86
|
[options[:user]],
|
|
@@ -76,7 +94,6 @@ module Pu
|
|
|
76
94
|
end
|
|
77
95
|
|
|
78
96
|
def generate_entity
|
|
79
|
-
# Use class-based invocation to avoid Thor's invoke caching
|
|
80
97
|
klass = Rails::Generators.find_by_namespace("pu:saas:entity")
|
|
81
98
|
klass.new(
|
|
82
99
|
[options[:entity]],
|
|
@@ -90,7 +107,6 @@ module Pu
|
|
|
90
107
|
end
|
|
91
108
|
|
|
92
109
|
def generate_membership
|
|
93
|
-
# Use class-based invocation to avoid Thor's invoke caching
|
|
94
110
|
klass = Rails::Generators.find_by_namespace("pu:saas:membership")
|
|
95
111
|
klass.new(
|
|
96
112
|
[],
|
|
@@ -106,8 +122,34 @@ module Pu
|
|
|
106
122
|
).invoke_all
|
|
107
123
|
end
|
|
108
124
|
|
|
125
|
+
def generate_portal
|
|
126
|
+
generate "pu:saas:portal",
|
|
127
|
+
"--entity-model=#{options[:entity]} --user-model=#{options[:user]}" \
|
|
128
|
+
" --portal-name=#{options[:portal_name]}" \
|
|
129
|
+
" --rodauth=#{rodauth_config}"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def generate_profile
|
|
133
|
+
generate "pu:profile:setup",
|
|
134
|
+
"--user-model=#{options[:user]} --dest=main_app" \
|
|
135
|
+
"#{" --portal=#{portal_package}" if options[:portal]}"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def generate_welcome
|
|
139
|
+
generate "pu:saas:welcome",
|
|
140
|
+
"--user-model=#{options[:user]} --entity-model=#{options[:entity]}" \
|
|
141
|
+
" --portal=#{portal_engine}" \
|
|
142
|
+
" --rodauth=#{rodauth_config}" \
|
|
143
|
+
"#{" --profile" if options[:profile]}"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def generate_invites
|
|
147
|
+
generate "pu:invites:install",
|
|
148
|
+
"--entity-model=#{options[:entity]} --user-model=#{options[:user]} --dest=main_app" \
|
|
149
|
+
" --rodauth=#{rodauth_config}"
|
|
150
|
+
end
|
|
151
|
+
|
|
109
152
|
def generate_api_client
|
|
110
|
-
# Use class-based invocation to avoid Thor's invoke caching
|
|
111
153
|
klass = Rails::Generators.find_by_namespace("pu:saas:api_client")
|
|
112
154
|
api_client_options = {
|
|
113
155
|
roles: options[:api_client_roles],
|
|
@@ -116,11 +158,22 @@ module Pu
|
|
|
116
158
|
skip: options[:skip]
|
|
117
159
|
}
|
|
118
160
|
|
|
119
|
-
# Scope to entity if entity is being generated
|
|
120
161
|
api_client_options[:entity] = options[:entity] unless options[:skip_entity]
|
|
121
162
|
|
|
122
163
|
klass.new([options[:api_client]], api_client_options).invoke_all
|
|
123
164
|
end
|
|
165
|
+
|
|
166
|
+
def rodauth_config
|
|
167
|
+
options[:user].underscore
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def portal_package
|
|
171
|
+
"#{options[:portal_name].underscore}_portal"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def portal_engine
|
|
175
|
+
"#{options[:portal_name].camelize}Portal"
|
|
176
|
+
end
|
|
124
177
|
end
|
|
125
178
|
end
|
|
126
179
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Generates a post-login welcome flow with onboarding and entity selection.
|
|
3
|
+
|
|
4
|
+
This creates the controllers, views, and routes needed to bridge
|
|
5
|
+
authentication and the main portal:
|
|
6
|
+
|
|
7
|
+
- AuthenticatedController: base controller requiring login
|
|
8
|
+
- WelcomeController: routing hub (invite check -> onboarding -> entity selection -> portal)
|
|
9
|
+
- Onboarding view: create first entity (and optional profile)
|
|
10
|
+
- Entity selection view: choose from multiple entities
|
|
11
|
+
|
|
12
|
+
Example:
|
|
13
|
+
rails g pu:saas:welcome --user-model=User --entity-model=Organization --portal=CustomerPortal
|
|
14
|
+
|
|
15
|
+
This generates:
|
|
16
|
+
app/controllers/authenticated_controller.rb
|
|
17
|
+
app/controllers/welcome_controller.rb
|
|
18
|
+
app/views/welcome/onboarding.html.erb
|
|
19
|
+
app/views/welcome/select_entity.html.erb
|
|
20
|
+
|
|
21
|
+
And adds routes:
|
|
22
|
+
GET /welcome -> welcome#index
|
|
23
|
+
GET /welcome/onboard -> welcome#new_entity
|
|
24
|
+
POST /welcome/onboard -> welcome#onboard
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--profile Include profile setup in onboarding form
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AuthenticatedController < ApplicationController
|
|
4
|
+
<% if rodauth? -%>
|
|
5
|
+
include Plutonium::Auth::Rodauth(:<%= rodauth_config %>)
|
|
6
|
+
|
|
7
|
+
before_action { rodauth.require_authentication }
|
|
8
|
+
<% else -%>
|
|
9
|
+
before_action :require_authenticated
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def require_authenticated
|
|
14
|
+
# TODO: Implement based on your authentication system
|
|
15
|
+
redirect_to "/login" unless current_user
|
|
16
|
+
end
|
|
17
|
+
<% end -%>
|
|
18
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class WelcomeController < AuthenticatedController
|
|
4
|
+
layout "welcome"
|
|
5
|
+
|
|
6
|
+
def index
|
|
7
|
+
entities = current_user.<%= entity_table.pluralize %>.to_a
|
|
8
|
+
if entities.none?
|
|
9
|
+
@<%= entity_table %> = <%= entity_model %>.new
|
|
10
|
+
<% if profile? -%>
|
|
11
|
+
@profile = current_user.profile || current_user.build_profile
|
|
12
|
+
<% end -%>
|
|
13
|
+
render :onboarding
|
|
14
|
+
elsif entities.one?
|
|
15
|
+
redirect_to portal_root_path(entities.first)
|
|
16
|
+
else
|
|
17
|
+
@entities = entities
|
|
18
|
+
render :select_entity
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def new_entity
|
|
23
|
+
@<%= entity_table %> = <%= entity_model %>.new
|
|
24
|
+
<% if profile? -%>
|
|
25
|
+
@profile = current_user.profile || current_user.build_profile
|
|
26
|
+
<% end -%>
|
|
27
|
+
render :onboarding
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def onboard
|
|
31
|
+
@<%= entity_table %> = <%= entity_model %>.new(<%= entity_table %>_params)
|
|
32
|
+
<% if profile? -%>
|
|
33
|
+
@profile = current_user.profile || current_user.build_profile
|
|
34
|
+
@profile.assign_attributes(profile_params)
|
|
35
|
+
|
|
36
|
+
if @<%= entity_table %>.valid? && @profile.valid?
|
|
37
|
+
<% else -%>
|
|
38
|
+
if @<%= entity_table %>.valid?
|
|
39
|
+
<% end -%>
|
|
40
|
+
ActiveRecord::Base.transaction do
|
|
41
|
+
@<%= entity_table %>.save!
|
|
42
|
+
<%= membership_model %>.create!(<%= entity_table %>: @<%= entity_table %>, <%= user_table %>: current_user, role: :owner)
|
|
43
|
+
<% if profile? -%>
|
|
44
|
+
@profile.save!
|
|
45
|
+
<% end -%>
|
|
46
|
+
end
|
|
47
|
+
redirect_to portal_root_path(@<%= entity_table %>), notice: "Welcome! Your workspace is ready."
|
|
48
|
+
else
|
|
49
|
+
render :onboarding, status: :unprocessable_entity
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def <%= entity_table %>_params
|
|
56
|
+
params.require(:<%= entity_table %>).permit(:name)
|
|
57
|
+
end
|
|
58
|
+
<% if profile? -%>
|
|
59
|
+
|
|
60
|
+
def profile_params
|
|
61
|
+
params.require(:profile).permit(:name)
|
|
62
|
+
end
|
|
63
|
+
<% end -%>
|
|
64
|
+
|
|
65
|
+
def portal_root_path(<%= entity_table %>)
|
|
66
|
+
<%= portal_engine %>::Engine.routes.url_helpers.<%= entity_table %>_root_path(<%= entity_table %>: <%= entity_table %>)
|
|
67
|
+
end
|
|
68
|
+
helper_method :portal_root_path
|
|
69
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Welcome</title>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
7
|
+
<meta name="csrf-param" content="authenticity_token" />
|
|
8
|
+
<meta name="csrf-token" content="<%%= form_authenticity_token %>" />
|
|
9
|
+
<%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
|
|
10
|
+
<%%= javascript_importmap_tags %>
|
|
11
|
+
</head>
|
|
12
|
+
<body class="antialiased min-h-screen bg-[var(--pu-body)]">
|
|
13
|
+
<main class="p-4 min-h-screen flex flex-col items-center justify-center gap-2 px-6 py-8 mx-auto lg:py-0">
|
|
14
|
+
<%% if flash.any? %>
|
|
15
|
+
<%% flash.each do |type, message| %>
|
|
16
|
+
<div class="fixed z-50 top-16 inset-x-0 mx-auto flex items-center w-full max-w-md p-4 rounded-[var(--pu-radius-lg)]"
|
|
17
|
+
style="box-shadow: var(--pu-shadow-md); background: <%%= type == 'alert' ? 'var(--color-danger-50)' : 'var(--color-success-50)' %>; color: <%%= type == 'alert' ? 'var(--color-danger-600)' : 'var(--color-success-600)' %>"
|
|
18
|
+
role="alert">
|
|
19
|
+
<div class="ms-3 text-sm font-normal"><%%= message %></div>
|
|
20
|
+
</div>
|
|
21
|
+
<%% end %>
|
|
22
|
+
<%% end %>
|
|
23
|
+
|
|
24
|
+
<!-- Main content card -->
|
|
25
|
+
<div class="w-full sm:max-w-md bg-[var(--pu-card-bg)] border border-[var(--pu-card-border)] rounded-[var(--pu-radius-lg)]"
|
|
26
|
+
style="box-shadow: var(--pu-shadow-lg)">
|
|
27
|
+
<div class="p-6 space-y-4 md:space-y-6 sm:p-8">
|
|
28
|
+
<%%= yield %>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</main>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<h1 class="text-lg font-bold leading-tight tracking-tight text-[var(--pu-text)] md:text-xl text-center">
|
|
2
|
+
Welcome! Let's get you set up.
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<%%= form_with(url: welcome_onboard_path, method: :post, class: "space-y-4 md:space-y-6") do |f| %>
|
|
6
|
+
<% if profile? -%>
|
|
7
|
+
<%% if @<%= entity_table %>.errors.any? || @profile.errors.any? %>
|
|
8
|
+
<% else -%>
|
|
9
|
+
<%% if @<%= entity_table %>.errors.any? %>
|
|
10
|
+
<% end -%>
|
|
11
|
+
<div class="p-4 rounded-[var(--pu-radius-lg)] bg-[color:var(--color-danger-50)] text-[color:var(--color-danger-600)]">
|
|
12
|
+
<ul class="list-disc list-inside text-sm">
|
|
13
|
+
<%% @<%= entity_table %>.errors.full_messages.each do |message| %>
|
|
14
|
+
<li><%%= message %></li>
|
|
15
|
+
<%% end %>
|
|
16
|
+
<% if profile? -%>
|
|
17
|
+
<%% @profile.errors.full_messages.each do |message| %>
|
|
18
|
+
<li><%%= message %></li>
|
|
19
|
+
<%% end %>
|
|
20
|
+
<% end -%>
|
|
21
|
+
</ul>
|
|
22
|
+
</div>
|
|
23
|
+
<%% end %>
|
|
24
|
+
<% if profile? -%>
|
|
25
|
+
|
|
26
|
+
<%%= f.fields_for :profile, @profile do |pf| %>
|
|
27
|
+
<div>
|
|
28
|
+
<%%= pf.label :name, "Your Name", class: "block mb-2 text-sm font-medium text-[var(--pu-text)]" %>
|
|
29
|
+
<%%= pf.text_field :name,
|
|
30
|
+
class: "pu-input w-full",
|
|
31
|
+
placeholder: "e.g. Jane Smith",
|
|
32
|
+
autofocus: true %>
|
|
33
|
+
</div>
|
|
34
|
+
<%% end %>
|
|
35
|
+
<% end -%>
|
|
36
|
+
|
|
37
|
+
<%%= f.fields_for :<%= entity_table %>, @<%= entity_table %> do |ef| %>
|
|
38
|
+
<div>
|
|
39
|
+
<%%= ef.label :name, "Workspace Name", class: "block mb-2 text-sm font-medium text-[var(--pu-text)]" %>
|
|
40
|
+
<%%= ef.text_field :name,
|
|
41
|
+
class: "pu-input w-full",
|
|
42
|
+
placeholder: "e.g. Acme Corp",
|
|
43
|
+
<% unless profile? -%>
|
|
44
|
+
autofocus: true,
|
|
45
|
+
<% end -%>
|
|
46
|
+
required: true %>
|
|
47
|
+
</div>
|
|
48
|
+
<%% end %>
|
|
49
|
+
|
|
50
|
+
<%%= f.submit "Get Started", class: "w-full pu-btn pu-btn-md pu-btn-primary" %>
|
|
51
|
+
<%% end %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<h1 class="text-lg font-bold leading-tight tracking-tight text-[var(--pu-text)] md:text-xl text-center">
|
|
2
|
+
Select a Workspace
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<div class="space-y-2">
|
|
6
|
+
<%% @entities.each do |<%= entity_table %>| %>
|
|
7
|
+
<a href="<%%= portal_root_path(<%= entity_table %>) %>"
|
|
8
|
+
class="flex items-center gap-3 w-full p-4 text-left bg-[var(--pu-surface-alt)] border border-[var(--pu-border)] rounded-[var(--pu-radius-lg)] hover:border-[var(--color-primary-500)] hover:bg-[var(--pu-surface)] transition-colors">
|
|
9
|
+
<div class="flex-1">
|
|
10
|
+
<p class="font-medium text-[var(--pu-text)]"><%%= <%= entity_table %>.name %></p>
|
|
11
|
+
</div>
|
|
12
|
+
<%%= render Phlex::TablerIcons::ChevronRight.new(class: "w-5 h-5 text-[var(--pu-text-muted)]") %>
|
|
13
|
+
</a>
|
|
14
|
+
<%% end %>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div class="pt-2">
|
|
18
|
+
<a href="<%%= welcome_onboard_path %>"
|
|
19
|
+
class="w-full block pu-btn pu-btn-md pu-btn-outline text-center">
|
|
20
|
+
Create New Workspace
|
|
21
|
+
</a>
|
|
22
|
+
</div>
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators/base"
|
|
4
|
+
require_relative "../lib/plutonium_generators"
|
|
5
|
+
|
|
6
|
+
module Pu
|
|
7
|
+
module Saas
|
|
8
|
+
class WelcomeGenerator < ::Rails::Generators::Base
|
|
9
|
+
include PlutoniumGenerators::Generator
|
|
10
|
+
include PlutoniumGenerators::Concerns::RodauthRedirects
|
|
11
|
+
|
|
12
|
+
source_root File.expand_path("welcome/templates", __dir__)
|
|
13
|
+
|
|
14
|
+
desc "Generate a post-login welcome flow with onboarding and entity selection"
|
|
15
|
+
|
|
16
|
+
class_option :user_model, type: :string, required: true,
|
|
17
|
+
desc: "The user model name (e.g., User)"
|
|
18
|
+
|
|
19
|
+
class_option :entity_model, type: :string, required: true,
|
|
20
|
+
desc: "The entity model name (e.g., Organization)"
|
|
21
|
+
|
|
22
|
+
class_option :portal, type: :string, required: true,
|
|
23
|
+
desc: "The portal engine name (e.g., CustomerPortal)"
|
|
24
|
+
|
|
25
|
+
class_option :membership_model, type: :string,
|
|
26
|
+
desc: "The membership model name (defaults to <Entity><User>)"
|
|
27
|
+
|
|
28
|
+
class_option :rodauth, type: :string, default: "user",
|
|
29
|
+
desc: "Rodauth configuration name"
|
|
30
|
+
|
|
31
|
+
class_option :profile, type: :boolean, default: false,
|
|
32
|
+
desc: "Include profile setup in onboarding"
|
|
33
|
+
|
|
34
|
+
def start
|
|
35
|
+
validate_requirements
|
|
36
|
+
create_authenticated_controller
|
|
37
|
+
create_welcome_controller
|
|
38
|
+
create_views
|
|
39
|
+
add_routes
|
|
40
|
+
configure_rodauth
|
|
41
|
+
show_instructions
|
|
42
|
+
rescue => e
|
|
43
|
+
exception "#{self.class} failed:", e
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def validate_requirements
|
|
49
|
+
errors = []
|
|
50
|
+
|
|
51
|
+
unless File.exist?(user_model_path)
|
|
52
|
+
errors << "User model not found: #{user_model_path.relative_path_from(Rails.root)}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
unless File.exist?(entity_model_path)
|
|
56
|
+
errors << "Entity model not found: #{entity_model_path.relative_path_from(Rails.root)}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
if File.exist?(user_model_path)
|
|
60
|
+
user_content = File.read(user_model_path)
|
|
61
|
+
unless user_content.include?("has_many :#{entity_table.pluralize}")
|
|
62
|
+
errors << "User model missing 'has_many :#{entity_table.pluralize}' — run the membership generator first"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
if errors.any?
|
|
67
|
+
errors.each { |e| say_status :error, e, :red }
|
|
68
|
+
raise Thor::Error, "Required files missing:\n - #{errors.join("\n - ")}"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def create_authenticated_controller
|
|
73
|
+
template "app/controllers/authenticated_controller.rb",
|
|
74
|
+
"app/controllers/authenticated_controller.rb"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def create_welcome_controller
|
|
78
|
+
template "app/controllers/welcome_controller.rb",
|
|
79
|
+
"app/controllers/welcome_controller.rb"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def create_views
|
|
83
|
+
template "app/views/layouts/welcome.html.erb",
|
|
84
|
+
"app/views/layouts/welcome.html.erb"
|
|
85
|
+
|
|
86
|
+
template "app/views/welcome/select_entity.html.erb",
|
|
87
|
+
"app/views/welcome/select_entity.html.erb"
|
|
88
|
+
|
|
89
|
+
template "app/views/welcome/onboarding.html.erb",
|
|
90
|
+
"app/views/welcome/onboarding.html.erb"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def add_routes
|
|
94
|
+
routes_file = "config/routes.rb"
|
|
95
|
+
routes_content = File.read(Rails.root.join(routes_file))
|
|
96
|
+
|
|
97
|
+
if routes_content.include?("# Welcome & onboarding")
|
|
98
|
+
say_status :skip, "Welcome routes already present", :yellow
|
|
99
|
+
return
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
route_code = <<-RUBY
|
|
103
|
+
|
|
104
|
+
# Welcome & onboarding
|
|
105
|
+
get "welcome", to: "welcome#index"
|
|
106
|
+
get "welcome/onboard", to: "welcome#new_entity", as: :welcome_onboard
|
|
107
|
+
post "welcome/onboard", to: "welcome#onboard"
|
|
108
|
+
RUBY
|
|
109
|
+
|
|
110
|
+
# Remove the standalone invites welcome route if it exists,
|
|
111
|
+
# since the main WelcomeController now handles /welcome
|
|
112
|
+
if routes_content.include?('get "welcome", to: "invites/welcome#index"')
|
|
113
|
+
gsub_file routes_file,
|
|
114
|
+
/\n\s*# Welcome route \(handled by invites.*\n\s*get "welcome", to: "invites\/welcome#index"\n/,
|
|
115
|
+
"\n"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
inject_into_file routes_file,
|
|
119
|
+
route_code,
|
|
120
|
+
before: /^end\s*\z/
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def configure_rodauth
|
|
124
|
+
return unless rodauth?
|
|
125
|
+
|
|
126
|
+
update_rodauth_redirects("app/rodauth/#{rodauth_config}_rodauth_plugin.rb")
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def show_instructions
|
|
130
|
+
say "\n"
|
|
131
|
+
say "=" * 79
|
|
132
|
+
say "\n"
|
|
133
|
+
say "Welcome flow installed successfully!"
|
|
134
|
+
say "\n"
|
|
135
|
+
say "Next steps:"
|
|
136
|
+
say "\n"
|
|
137
|
+
say "1. Run migrations (if you haven't already):"
|
|
138
|
+
say " rails db:migrate"
|
|
139
|
+
say "\n"
|
|
140
|
+
say "2. Customize the onboarding view to match your app:"
|
|
141
|
+
say " app/views/welcome/onboarding.html.erb"
|
|
142
|
+
say "\n"
|
|
143
|
+
if profile?
|
|
144
|
+
say "3. Ensure your User model has a `profile` association:"
|
|
145
|
+
say " has_one :profile"
|
|
146
|
+
say "\n"
|
|
147
|
+
end
|
|
148
|
+
say "=" * 79
|
|
149
|
+
say "\n"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def user_model
|
|
153
|
+
options[:user_model].camelize
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def user_table
|
|
157
|
+
options[:user_model].underscore
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def entity_model
|
|
161
|
+
options[:entity_model].camelize
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def entity_table
|
|
165
|
+
options[:entity_model].underscore
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def portal_engine
|
|
169
|
+
options[:portal].camelize
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def membership_model
|
|
173
|
+
options[:membership_model] || "#{entity_model}#{user_model}"
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def rodauth_config
|
|
177
|
+
options[:rodauth]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def rodauth?
|
|
181
|
+
rodauth_config.present?
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def profile?
|
|
185
|
+
options[:profile]
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def entity_model_path
|
|
189
|
+
Rails.root.join("app/models/#{entity_table}.rb")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def user_model_path
|
|
193
|
+
Rails.root.join("app/models/#{user_table}.rb")
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "sequel/core"
|
|
4
|
-
|
|
5
3
|
module Plutonium
|
|
6
4
|
module Auth
|
|
7
5
|
# Provides runtime detection of the database adapter for Sequel configuration.
|
|
@@ -26,6 +24,7 @@ module Plutonium
|
|
|
26
24
|
# @return [Sequel::Database] configured Sequel database connection
|
|
27
25
|
# @raise [RuntimeError] if the Sequel adapter initialization fails
|
|
28
26
|
def db
|
|
27
|
+
require "sequel/core"
|
|
29
28
|
adapter = sequel_adapter
|
|
30
29
|
begin
|
|
31
30
|
if RUBY_ENGINE == "jruby"
|
|
@@ -145,7 +145,10 @@ module Plutonium
|
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
# Build the named helper: e.g., "blogging_post_nested_post_metadata_path"
|
|
148
|
-
|
|
148
|
+
# For plural parent resources (resources :posts), nested routes use the singular member name (post_nested_...)
|
|
149
|
+
# For singular parent resources (resource :entities), nested routes use the route name as-is (entities_nested_...)
|
|
150
|
+
parent_is_singular_route = current_engine.routes.singular_resource_route?(parent.model_name.plural)
|
|
151
|
+
parent_prefix = parent_is_singular_route ? parent.model_name.plural : parent.model_name.singular
|
|
149
152
|
nested_resource_name = "#{prefix}#{association_name}"
|
|
150
153
|
|
|
151
154
|
# Determine if this is a collection action (no specific record)
|
|
@@ -158,12 +161,10 @@ module Plutonium
|
|
|
158
161
|
# - :new action uses singular (new_blogging_post_nested_comment)
|
|
159
162
|
# - member actions (show/edit/update/destroy) use singular (blogging_post_nested_comment)
|
|
160
163
|
is_collection_action = action == :index || action == :create || (no_record && action != :new)
|
|
161
|
-
helper_base = if is_singular
|
|
162
|
-
"#{
|
|
163
|
-
elsif is_collection_action
|
|
164
|
-
"#{parent_singular}_#{nested_resource_name}"
|
|
164
|
+
helper_base = if is_singular || is_collection_action
|
|
165
|
+
"#{parent_prefix}_#{nested_resource_name}"
|
|
165
166
|
else
|
|
166
|
-
"#{
|
|
167
|
+
"#{parent_prefix}_#{nested_resource_name.to_s.singularize}"
|
|
167
168
|
end
|
|
168
169
|
|
|
169
170
|
# Only add helper prefix for actions that have named route helpers (new, edit)
|
|
@@ -173,10 +174,19 @@ module Plutonium
|
|
|
173
174
|
else "#{action}_"
|
|
174
175
|
end
|
|
175
176
|
|
|
176
|
-
|
|
177
|
+
# Add entity scope prefix for path-based entity scoping
|
|
178
|
+
entity_prefix = if scoped_to_entity? && scoped_entity_strategy == :path
|
|
179
|
+
"#{scoped_entity_param_key}_"
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
helper_name = :"#{helper_suffix}#{entity_prefix}#{helper_base}_path"
|
|
177
183
|
|
|
178
184
|
# Build the arguments for the helper
|
|
179
|
-
helper_args = [
|
|
185
|
+
helper_args = []
|
|
186
|
+
# Add entity scope param for path-based entity scoping
|
|
187
|
+
helper_args << current_scoped_entity.to_param if entity_prefix
|
|
188
|
+
# Singular parent resources (resource :entity) have no :id param in the route
|
|
189
|
+
helper_args << parent.to_param unless parent_is_singular_route
|
|
180
190
|
# Include element ID for plural routes (has_many) when we have a record instance
|
|
181
191
|
# Skip ID for collection actions (:index, :create) which don't need a member ID
|
|
182
192
|
unless is_singular || no_record || is_collection_action
|