nitro_kit 2.0.0.beta.3 → 2.0.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 +37 -0
- data/LICENSE +21 -28
- data/README.md +10 -9
- data/app/assets/stylesheets/nitro_kit.css +1660 -1401
- data/app/components/nitro_kit/accordion.rb +1 -13
- data/app/components/nitro_kit/app_navigation.rb +0 -12
- data/app/components/nitro_kit/app_shell.rb +5 -11
- data/app/components/nitro_kit/appearance_picker.rb +1 -7
- data/app/components/nitro_kit/combobox.rb +366 -21
- data/app/components/nitro_kit/command_palette.rb +7 -20
- data/app/components/nitro_kit/details_table.rb +5 -11
- data/app/components/nitro_kit/dropzone.rb +3 -15
- data/app/components/nitro_kit/field.rb +20 -2
- data/app/components/nitro_kit/pagination.rb +2 -8
- data/app/components/nitro_kit/settings_layout.rb +3 -9
- data/app/javascript/controllers/nk/app_shell_controller.js +2 -2
- data/app/javascript/controllers/nk/combobox_controller.js +308 -22
- data/app/javascript/controllers/nk/combobox_remote.js +70 -0
- data/app/javascript/controllers/nk/dropzone_controller.js +2 -2
- data/app/javascript/controllers/nk/tabs_controller.js +2 -2
- data/config/locales/en.yml +3 -0
- data/docs/agent_guide.md +43 -13
- data/docs/component_contracts.md +90 -61
- data/docs/customization.md +173 -35
- data/docs/initialization_prompt.md +4 -5
- data/docs/migration_1_to_2.md +10 -8
- data/docs/patterns/application_foundation.md +5 -0
- data/docs/patterns/composition.md +61 -0
- data/docs/patterns/crud_resource.md +5 -0
- data/docs/patterns/inset_workspace.md +21 -22
- data/docs/patterns/resource_form.md +65 -0
- data/docs/rails_integration.md +214 -2
- data/lib/generators/nitro_kit/install_generator.rb +5 -4
- data/lib/nitro_kit/installation.rb +327 -68
- data/lib/nitro_kit/migration_inventory.rb +18 -3
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +2 -2
- data/patterns/README.md +21 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/account_deletion.rb +72 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/base.rb +44 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/page.rb +57 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/preferences.rb +68 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/profile.rb +86 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/security.rb +69 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/sessions.rb +86 -0
- data/patterns/account-settings/files/app/controllers/settings/account_deletions_controller.rb +35 -0
- data/patterns/account-settings/files/app/controllers/settings/base_controller.rb +12 -0
- data/patterns/account-settings/files/app/controllers/settings/other_sessions_controller.rb +8 -0
- data/patterns/account-settings/files/app/controllers/settings/preferences_controller.rb +27 -0
- data/patterns/account-settings/files/app/controllers/settings/profiles_controller.rb +20 -0
- data/patterns/account-settings/files/app/controllers/settings/securities_controller.rb +37 -0
- data/patterns/account-settings/files/app/controllers/settings/sessions_controller.rb +31 -0
- data/patterns/account-settings/files/app/models/account_settings/account_closure.rb +33 -0
- data/patterns/account-settings/files/app/models/account_settings/password_change.rb +42 -0
- data/patterns/account-settings/files/app/models/account_settings/session_summary.rb +45 -0
- data/patterns/account-settings/files/app/models/concerns/user/account_configurable.rb +18 -0
- data/patterns/account-settings/files/config/routes/account_settings.rb +10 -0
- data/patterns/account-settings/files/db/migrate/20260731020000_add_account_settings.rb +27 -0
- data/patterns/account-settings/files/test/controllers/settings/account_settings_flow_test.rb +84 -0
- data/patterns/account-settings/files/test/models/account_settings/password_change_test.rb +40 -0
- data/patterns/account-settings/files/test/system/account_settings_test.rb +52 -0
- data/patterns/account-settings/item.yml +4 -0
- data/patterns/account-settings/pattern.md +44 -0
- data/patterns/application-shell/files/app/assets/stylesheets/ui/application_shell.css +267 -0
- data/patterns/application-shell/files/app/components/ui/application_shell.rb +184 -0
- data/patterns/application-shell/item.yml +4 -0
- data/patterns/application-shell/pattern.md +110 -0
- data/patterns/authentication/files/app/components/ui/authentication/base.rb +11 -0
- data/patterns/authentication/files/app/components/ui/authentication/page.rb +53 -0
- data/patterns/authentication/files/app/components/ui/email_verifications/show.rb +62 -0
- data/patterns/authentication/files/app/components/ui/password_resets/new.rb +65 -0
- data/patterns/authentication/files/app/components/ui/passwords/edit.rb +72 -0
- data/patterns/authentication/files/app/components/ui/sessions/new.rb +58 -0
- data/patterns/authentication/files/app/components/ui/verification_emails/new.rb +59 -0
- data/patterns/authentication/files/app/controllers/concerns/authentication.rb +66 -0
- data/patterns/authentication/files/app/controllers/concerns/safe_return_navigation.rb +37 -0
- data/patterns/authentication/files/app/controllers/email_verifications_controller.rb +39 -0
- data/patterns/authentication/files/app/controllers/password_resets_controller.rb +33 -0
- data/patterns/authentication/files/app/controllers/passwords_controller.rb +51 -0
- data/patterns/authentication/files/app/controllers/sessions_controller.rb +42 -0
- data/patterns/authentication/files/app/controllers/verification_emails_controller.rb +33 -0
- data/patterns/authentication/files/app/jobs/authentication_delivery_job.rb +17 -0
- data/patterns/authentication/files/app/mailers/authentication_mailer.rb +15 -0
- data/patterns/authentication/files/app/models/authentication/credentials.rb +16 -0
- data/patterns/authentication/files/app/models/authentication/email_request.rb +17 -0
- data/patterns/authentication/files/app/models/concerns/user/email_verifiable.rb +40 -0
- data/patterns/authentication/files/app/models/session.rb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.text.erb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.text.erb +5 -0
- data/patterns/authentication/files/config/routes/authentication.rb +11 -0
- data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb +13 -0
- data/patterns/authentication/files/test/controllers/authentication_flow_test.rb +103 -0
- data/patterns/authentication/files/test/controllers/safe_return_navigation_test.rb +18 -0
- data/patterns/authentication/files/test/mailers/authentication_mailer_test.rb +21 -0
- data/patterns/authentication/files/test/models/user_email_verifiable_test.rb +36 -0
- data/patterns/authentication/files/test/system/authentication_flow_test.rb +23 -0
- data/patterns/authentication/item.yml +12 -0
- data/patterns/authentication/pattern.md +54 -0
- data/patterns/crud-resource/files/app/assets/stylesheets/ui/projects.css +4 -0
- data/patterns/crud-resource/files/app/components/ui/projects/form.rb +89 -0
- data/patterns/crud-resource/files/app/components/ui/projects/index.rb +161 -0
- data/patterns/crud-resource/files/app/components/ui/projects/show.rb +84 -0
- data/patterns/crud-resource/files/app/controllers/projects/archivals_controller.rb +23 -0
- data/patterns/crud-resource/files/app/controllers/projects_controller.rb +70 -0
- data/patterns/crud-resource/files/app/models/project/archival.rb +8 -0
- data/patterns/crud-resource/files/app/models/project/event.rb +12 -0
- data/patterns/crud-resource/files/app/models/project/filter.rb +41 -0
- data/patterns/crud-resource/files/app/models/project.rb +41 -0
- data/patterns/crud-resource/files/app/views/projects/edit.html.erb +19 -0
- data/patterns/crud-resource/files/app/views/projects/index.html.erb +18 -0
- data/patterns/crud-resource/files/app/views/projects/new.html.erb +16 -0
- data/patterns/crud-resource/files/app/views/projects/show.html.erb +28 -0
- data/patterns/crud-resource/files/config/routes/crud_resource.rb +7 -0
- data/patterns/crud-resource/files/db/migrate/20260720000000_create_crud_resource.rb +37 -0
- data/patterns/crud-resource/files/test/controllers/projects_controller_test.rb +64 -0
- data/patterns/crud-resource/files/test/models/project_test.rb +34 -0
- data/patterns/crud-resource/files/test/support/crud_resource_test_helpers.rb +25 -0
- data/patterns/crud-resource/files/test/system/projects_crud_test.rb +87 -0
- data/patterns/crud-resource/item.yml +6 -0
- data/patterns/crud-resource/pattern.md +48 -0
- data/patterns/file-uploads/files/app/assets/stylesheets/ui/uploads.css +133 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/base.rb +30 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/index.rb +188 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/page.rb +33 -0
- data/patterns/file-uploads/files/app/controllers/uploads/base_controller.rb +29 -0
- data/patterns/file-uploads/files/app/controllers/uploads/direct_uploads_controller.rb +55 -0
- data/patterns/file-uploads/files/app/controllers/uploads/retries_controller.rb +14 -0
- data/patterns/file-uploads/files/app/controllers/uploads_controller.rb +40 -0
- data/patterns/file-uploads/files/app/jobs/upload_blob_cleanup_job.rb +9 -0
- data/patterns/file-uploads/files/app/jobs/upload_processing_job.rb +10 -0
- data/patterns/file-uploads/files/app/jobs/upload_repair_job.rb +17 -0
- data/patterns/file-uploads/files/app/models/concerns/team/uploadable.rb +9 -0
- data/patterns/file-uploads/files/app/models/upload.rb +295 -0
- data/patterns/file-uploads/files/config/recurring/uploads.yml +7 -0
- data/patterns/file-uploads/files/config/routes/uploads.rb +5 -0
- data/patterns/file-uploads/files/db/migrate/20260802000000_add_file_uploads.rb +30 -0
- data/patterns/file-uploads/files/test/controllers/uploads_flow_test.rb +77 -0
- data/patterns/file-uploads/files/test/fixtures/files/workspace.png.base64 +1 -0
- data/patterns/file-uploads/files/test/fixtures/uploads.yml +17 -0
- data/patterns/file-uploads/files/test/models/upload_test.rb +55 -0
- data/patterns/file-uploads/files/test/system/file_uploads_test.rb +30 -0
- data/patterns/file-uploads/item.yml +4 -0
- data/patterns/file-uploads/pattern.md +71 -0
- data/patterns/nitro-kit-1-upgrade/files/docs/nitro_kit_1_upgrade.md +57 -0
- data/patterns/nitro-kit-1-upgrade/item.yml +4 -0
- data/patterns/nitro-kit-1-upgrade/pattern.md +30 -0
- data/patterns/onboarding/files/app/assets/stylesheets/ui/onboarding.css +55 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/base.rb +11 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/branch_form.rb +36 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/details_form.rb +67 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/invitation_plan_form.rb +48 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/page.rb +75 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/review.rb +51 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/show.rb +32 -0
- data/patterns/onboarding/files/app/controllers/concerns/requires_finished_onboarding.rb +14 -0
- data/patterns/onboarding/files/app/controllers/onboarding/base_controller.rb +30 -0
- data/patterns/onboarding/files/app/controllers/onboarding/branches_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/completions_controller.rb +13 -0
- data/patterns/onboarding/files/app/controllers/onboarding/details_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/invitation_plans_controller.rb +20 -0
- data/patterns/onboarding/files/app/controllers/onboardings_controller.rb +7 -0
- data/patterns/onboarding/files/app/jobs/onboarding_invitation_delivery_job.rb +15 -0
- data/patterns/onboarding/files/app/models/concerns/team/onboardable.rb +23 -0
- data/patterns/onboarding/files/app/models/onboarding/completion.rb +17 -0
- data/patterns/onboarding/files/app/models/onboarding/invitation_delivery.rb +14 -0
- data/patterns/onboarding/files/app/models/onboarding.rb +174 -0
- data/patterns/onboarding/files/config/routes/onboarding.rb +11 -0
- data/patterns/onboarding/files/db/migrate/20260731010000_create_onboarding.rb +60 -0
- data/patterns/onboarding/files/test/controllers/onboarding_flow_test.rb +62 -0
- data/patterns/onboarding/files/test/fixtures/onboarding_completions.yml +3 -0
- data/patterns/onboarding/files/test/fixtures/onboardings.yml +25 -0
- data/patterns/onboarding/files/test/jobs/onboarding_invitation_delivery_job_test.rb +18 -0
- data/patterns/onboarding/files/test/models/onboarding_test.rb +60 -0
- data/patterns/onboarding/files/test/system/onboarding_flow_test.rb +39 -0
- data/patterns/onboarding/item.yml +4 -0
- data/patterns/onboarding/pattern.md +53 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/base.rb +39 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/checkout_result.rb +64 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/page.rb +33 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/show.rb +149 -0
- data/patterns/subscription-billing/files/app/controllers/billing/base_controller.rb +16 -0
- data/patterns/subscription-billing/files/app/controllers/billing/checkouts_controller.rb +65 -0
- data/patterns/subscription-billing/files/app/controllers/billing/portals_controller.rb +18 -0
- data/patterns/subscription-billing/files/app/controllers/billing_controller.rb +17 -0
- data/patterns/subscription-billing/files/app/controllers/webhooks/stripe_events_controller.rb +21 -0
- data/patterns/subscription-billing/files/app/jobs/billing/stripe_event_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_sweep_job.rb +9 -0
- data/patterns/subscription-billing/files/app/models/billing/checkout.rb +58 -0
- data/patterns/subscription-billing/files/app/models/billing/plan.rb +19 -0
- data/patterns/subscription-billing/files/app/models/billing/stripe_event.rb +73 -0
- data/patterns/subscription-billing/files/app/models/billing/subscription.rb +106 -0
- data/patterns/subscription-billing/files/app/models/concerns/team/billable.rb +36 -0
- data/patterns/subscription-billing/files/config/initializers/stripe.rb +29 -0
- data/patterns/subscription-billing/files/config/routes/subscription_billing.rb +10 -0
- data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb +61 -0
- data/patterns/subscription-billing/files/test/controllers/billing_flow_test.rb +60 -0
- data/patterns/subscription-billing/files/test/models/billing/subscription_test.rb +40 -0
- data/patterns/subscription-billing/files/test/system/subscription_billing_test.rb +28 -0
- data/patterns/subscription-billing/item.yml +4 -0
- data/patterns/subscription-billing/pattern.md +59 -0
- data/patterns/team-management/files/app/components/ui/invitations/acceptance.rb +33 -0
- data/patterns/team-management/files/app/components/ui/teams/index.rb +87 -0
- data/patterns/team-management/files/app/components/ui/teams/invitation_form.rb +51 -0
- data/patterns/team-management/files/app/components/ui/teams/member_form.rb +78 -0
- data/patterns/team-management/files/app/components/ui/teams/members.rb +125 -0
- data/patterns/team-management/files/app/controllers/invitations/acceptances_controller.rb +29 -0
- data/patterns/team-management/files/app/controllers/teams/base_controller.rb +18 -0
- data/patterns/team-management/files/app/controllers/teams/invitations_controller.rb +42 -0
- data/patterns/team-management/files/app/controllers/teams/memberships_controller.rb +53 -0
- data/patterns/team-management/files/app/controllers/teams_controller.rb +30 -0
- data/patterns/team-management/files/app/mailers/team_invitation_mailer.rb +10 -0
- data/patterns/team-management/files/app/models/concerns/current_team.rb +13 -0
- data/patterns/team-management/files/app/models/concerns/user_teams.rb +37 -0
- data/patterns/team-management/files/app/models/invitation.rb +41 -0
- data/patterns/team-management/files/app/models/membership.rb +45 -0
- data/patterns/team-management/files/app/models/team.rb +25 -0
- data/patterns/team-management/files/app/views/invitations/acceptances/show.html.erb +1 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.html.erb +10 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.text.erb +7 -0
- data/patterns/team-management/files/app/views/teams/index.html.erb +15 -0
- data/patterns/team-management/files/app/views/teams/invitations/new.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/edit.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/index.html.erb +20 -0
- data/patterns/team-management/files/config/routes/team_management.rb +11 -0
- data/patterns/team-management/files/db/migrate/20260717000000_create_team_management.rb +31 -0
- data/patterns/team-management/files/test/models/invitation_test.rb +28 -0
- data/patterns/team-management/files/test/models/membership_test.rb +29 -0
- data/patterns/team-management/files/test/models/team_test.rb +31 -0
- data/patterns/team-management/files/test/support/team_management_test_helpers.rb +22 -0
- data/patterns/team-management/item.yml +4 -0
- data/patterns/team-management/pattern.md +47 -0
- data/patterns/webhook-deliveries/files/app/assets/stylesheets/ui/webhooks.css +179 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/base.rb +38 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/delivery.rb +160 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/endpoint.rb +149 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/form.rb +75 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/index.rb +142 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/page.rb +33 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/secret.rb +38 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries/replays_controller.rb +13 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries_controller.rb +7 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints/secrets_controller.rb +41 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints_controller.rb +67 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhooks/base_controller.rb +15 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_job.rb +9 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_repair_job.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/concerns/team/webhookable.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/attempt.rb +30 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/delivery.rb +268 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/endpoint.rb +58 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/event.rb +98 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/secret_reveal.rb +53 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/signature.rb +22 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/transport.rb +176 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_deliveries/show.html.erb +5 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/edit.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/index.html.erb +6 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/secrets/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/show.html.erb +7 -0
- data/patterns/webhook-deliveries/files/config/recurring/webhooks.yml +4 -0
- data/patterns/webhook-deliveries/files/config/routes/webhook_deliveries.rb +10 -0
- data/patterns/webhook-deliveries/files/db/migrate/20260803000000_add_webhook_deliveries.rb +126 -0
- data/patterns/webhook-deliveries/files/test/controllers/webhook_endpoints_flow_test.rb +48 -0
- data/patterns/webhook-deliveries/files/test/models/webhook/delivery_test.rb +70 -0
- data/patterns/webhook-deliveries/files/test/system/webhook_deliveries_test.rb +29 -0
- data/patterns/webhook-deliveries/item.yml +4 -0
- data/patterns/webhook-deliveries/pattern.md +120 -0
- data/plugins/nitro-kit/.codex-plugin/plugin.json +4 -4
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +7 -9
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +10 -9
- data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +27 -16
- data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +1 -1
- data/src/stylesheets/nitro_kit/components/accordion.css +40 -40
- data/src/stylesheets/nitro_kit/components/alert.css +7 -6
- data/src/stylesheets/nitro_kit/components/app_navigation.css +50 -41
- data/src/stylesheets/nitro_kit/components/app_shell.css +371 -280
- data/src/stylesheets/nitro_kit/components/appearance_picker.css +38 -38
- data/src/stylesheets/nitro_kit/components/avatar.css +3 -3
- data/src/stylesheets/nitro_kit/components/avatar_stack.css +18 -18
- data/src/stylesheets/nitro_kit/components/badge.css +5 -2
- data/src/stylesheets/nitro_kit/components/button.css +57 -49
- data/src/stylesheets/nitro_kit/components/button_group.css +14 -14
- data/src/stylesheets/nitro_kit/components/checkbox.css +24 -24
- data/src/stylesheets/nitro_kit/components/checkbox_group.css +13 -13
- data/src/stylesheets/nitro_kit/components/combobox.css +152 -25
- data/src/stylesheets/nitro_kit/components/command_palette.css +59 -59
- data/src/stylesheets/nitro_kit/components/control_group.css +71 -54
- data/src/stylesheets/nitro_kit/components/details_table.css +9 -9
- data/src/stylesheets/nitro_kit/components/dialog.css +8 -12
- data/src/stylesheets/nitro_kit/components/dropdown.css +22 -26
- data/src/stylesheets/nitro_kit/components/dropzone.css +97 -100
- data/src/stylesheets/nitro_kit/components/empty_state.css +1 -0
- data/src/stylesheets/nitro_kit/components/field.css +26 -30
- data/src/stylesheets/nitro_kit/components/fieldset.css +2 -2
- data/src/stylesheets/nitro_kit/components/input.css +6 -14
- data/src/stylesheets/nitro_kit/components/layout.css +165 -165
- data/src/stylesheets/nitro_kit/components/page_header.css +3 -3
- data/src/stylesheets/nitro_kit/components/pagination.css +66 -49
- data/src/stylesheets/nitro_kit/components/pagination_bar.css +6 -6
- data/src/stylesheets/nitro_kit/components/palette.css +24 -22
- data/src/stylesheets/nitro_kit/components/progressive_image.css +38 -41
- data/src/stylesheets/nitro_kit/components/radio_button.css +19 -19
- data/src/stylesheets/nitro_kit/components/radio_button_group.css +43 -43
- data/src/stylesheets/nitro_kit/components/rich_text_area.css +4 -4
- data/src/stylesheets/nitro_kit/components/select.css +2 -2
- data/src/stylesheets/nitro_kit/components/settings_layout.css +17 -18
- data/src/stylesheets/nitro_kit/components/settings_section.css +12 -12
- data/src/stylesheets/nitro_kit/components/sheet.css +10 -10
- data/src/stylesheets/nitro_kit/components/stat_grid.css +9 -9
- data/src/stylesheets/nitro_kit/components/switch.css +23 -23
- data/src/stylesheets/nitro_kit/components/table.css +27 -27
- data/src/stylesheets/nitro_kit/components/tabs.css +32 -34
- data/src/stylesheets/nitro_kit/components/toolbar.css +6 -6
- data/src/stylesheets/nitro_kit/components/tooltip.css +26 -28
- data/src/stylesheets/nitro_kit/layers.css +2 -1
- data/src/stylesheets/nitro_kit/reset.css +9 -9
- data/src/stylesheets/nitro_kit/tailwind.css +6 -2
- data/src/stylesheets/nitro_kit/tokens.css +18 -9
- metadata +238 -2
data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddSubscriptionBilling < ActiveRecord::Migration[8.1]
|
|
4
|
+
def change
|
|
5
|
+
team_key_type = primary_key_type_for(:teams)
|
|
6
|
+
|
|
7
|
+
add_column :teams, :stripe_customer_id, :string
|
|
8
|
+
add_index :teams, :stripe_customer_id, unique: true
|
|
9
|
+
|
|
10
|
+
create_table :billing_subscriptions do |t|
|
|
11
|
+
t.references :team,
|
|
12
|
+
type: team_key_type,
|
|
13
|
+
null: false,
|
|
14
|
+
foreign_key: { on_delete: :cascade },
|
|
15
|
+
index: { unique: true }
|
|
16
|
+
t.string :stripe_subscription_id, null: false
|
|
17
|
+
t.string :stripe_price_id, null: false
|
|
18
|
+
t.string :status, null: false
|
|
19
|
+
t.datetime :current_period_ends_at
|
|
20
|
+
t.boolean :cancel_at_period_end, null: false, default: false
|
|
21
|
+
t.timestamps
|
|
22
|
+
end
|
|
23
|
+
add_index :billing_subscriptions, :stripe_subscription_id, unique: true
|
|
24
|
+
|
|
25
|
+
create_table :billing_checkouts do |t|
|
|
26
|
+
t.references :team,
|
|
27
|
+
type: team_key_type,
|
|
28
|
+
null: false,
|
|
29
|
+
foreign_key: { on_delete: :cascade },
|
|
30
|
+
index: { unique: true }
|
|
31
|
+
t.string :plan_key, null: false
|
|
32
|
+
t.string :stripe_price_id, null: false
|
|
33
|
+
t.string :stripe_session_id
|
|
34
|
+
t.text :stripe_session_url
|
|
35
|
+
t.datetime :expires_at, null: false
|
|
36
|
+
t.boolean :active, null: false, default: true
|
|
37
|
+
t.timestamps
|
|
38
|
+
end
|
|
39
|
+
add_index :billing_checkouts, :stripe_session_id, unique: true
|
|
40
|
+
|
|
41
|
+
create_table :billing_stripe_events do |t|
|
|
42
|
+
t.string :stripe_id, null: false
|
|
43
|
+
t.string :event_type, null: false
|
|
44
|
+
t.datetime :event_created_at, null: false
|
|
45
|
+
t.string :stripe_customer_id
|
|
46
|
+
t.string :stripe_subscription_id
|
|
47
|
+
t.string :stripe_checkout_session_id
|
|
48
|
+
t.datetime :processed_at
|
|
49
|
+
t.integer :attempts, null: false, default: 0
|
|
50
|
+
t.text :last_error
|
|
51
|
+
t.timestamps
|
|
52
|
+
end
|
|
53
|
+
add_index :billing_stripe_events, :stripe_id, unique: true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
def primary_key_type_for(table)
|
|
58
|
+
column = connection.columns(table).find { |candidate| candidate.name == "id" }
|
|
59
|
+
column.sql_type.match?(/bigint/i) ? :bigint : column.type
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class BillingFlowTest < ActionDispatch::IntegrationTest
|
|
6
|
+
setup do
|
|
7
|
+
sign_in users(:ada)
|
|
8
|
+
Current.team = teams(:analytical_engines)
|
|
9
|
+
Current.team.update!(stripe_customer_id: "cus_team")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "checkout uses an allowlisted Stripe Price without fixed payment methods" do
|
|
13
|
+
checkout = Struct.new(:id, :url, :expires_at).new(
|
|
14
|
+
"cs_team",
|
|
15
|
+
"https://checkout.stripe.test/session",
|
|
16
|
+
1.hour.from_now.to_i
|
|
17
|
+
)
|
|
18
|
+
subscriptions = Struct.new(:data) do
|
|
19
|
+
def auto_paging_each = data.each
|
|
20
|
+
end.new([])
|
|
21
|
+
creation = lambda do |attributes, _options|
|
|
22
|
+
@checkout_attributes = attributes
|
|
23
|
+
checkout
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Stripe::Subscription.stub(:list, subscriptions) do
|
|
27
|
+
Stripe::Checkout::Session.stub(:create, creation) do
|
|
28
|
+
post billing_checkout_path, params: { plan: "growth" }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_redirected_to checkout.url
|
|
33
|
+
assert_equal "subscription", @checkout_attributes.fetch(:mode)
|
|
34
|
+
assert_equal [ { price: "price_growth", quantity: 1 } ], @checkout_attributes.fetch(:line_items)
|
|
35
|
+
refute @checkout_attributes.key?(:payment_method_types)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test "checkout result never creates a subscription" do
|
|
39
|
+
session = Struct.new(:client_reference_id, :customer, :status).new(
|
|
40
|
+
Current.team.id.to_s,
|
|
41
|
+
Current.team.stripe_customer_id,
|
|
42
|
+
"complete"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
Stripe::Checkout::Session.stub(:retrieve, session) do
|
|
46
|
+
assert_no_difference("Billing::Subscription.count") do
|
|
47
|
+
get billing_checkout_path(session_id: "cs_test")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
test "rejects a webhook with an invalid signature" do
|
|
53
|
+
post webhooks_stripe_event_path,
|
|
54
|
+
params: "{}",
|
|
55
|
+
headers: { "Stripe-Signature" => "invalid", "Content-Type" => "application/json" }
|
|
56
|
+
|
|
57
|
+
assert_response :bad_request
|
|
58
|
+
assert_equal 0, Billing::StripeEvent.count
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class Billing::SubscriptionTest < ActiveSupport::TestCase
|
|
6
|
+
Price = Data.define(:id)
|
|
7
|
+
Item = Data.define(:price, :current_period_end)
|
|
8
|
+
Items = Data.define(:data)
|
|
9
|
+
StripeSubscription = Data.define(:id, :items, :status, :cancel_at_period_end)
|
|
10
|
+
|
|
11
|
+
test "synchronizes the current Stripe snapshot" do
|
|
12
|
+
team = teams(:analytical_engines)
|
|
13
|
+
stripe_subscription = StripeSubscription.new(
|
|
14
|
+
id: "sub_current",
|
|
15
|
+
items: Items.new(data: [ Item.new(price: Price.new(id: "price_growth"), current_period_end: 1.month.from_now.to_i) ]),
|
|
16
|
+
status: "active",
|
|
17
|
+
cancel_at_period_end: false
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
subscription = Billing::Subscription.synchronize!(team:, stripe_subscription:)
|
|
21
|
+
|
|
22
|
+
assert_equal "sub_current", subscription.stripe_subscription_id
|
|
23
|
+
assert_equal "price_growth", subscription.stripe_price_id
|
|
24
|
+
assert subscription.entitled?
|
|
25
|
+
refute subscription.canceling?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test "scheduled cancellation remains entitled until Stripe cancels it" do
|
|
29
|
+
subscription = Billing::Subscription.new(
|
|
30
|
+
status: "active",
|
|
31
|
+
stripe_price_id: "price_growth",
|
|
32
|
+
current_period_ends_at: 1.month.from_now,
|
|
33
|
+
cancel_at_period_end: true
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
assert subscription.entitled?
|
|
37
|
+
assert subscription.canceling?
|
|
38
|
+
refute subscription.terminal?
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "application_system_test_case"
|
|
4
|
+
|
|
5
|
+
class SubscriptionBillingTest < ApplicationSystemTestCase
|
|
6
|
+
test "starts Checkout from an offered plan" do
|
|
7
|
+
sign_in users(:ada)
|
|
8
|
+
visit billing_path
|
|
9
|
+
|
|
10
|
+
assert_heading "Subscription billing"
|
|
11
|
+
assert_text "Plans and billing"
|
|
12
|
+
assert_button "Choose Growth"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test "shows webhook-synchronized payment recovery" do
|
|
16
|
+
sign_in users(:ada)
|
|
17
|
+
teams(:analytical_engines).create_billing_subscription!(
|
|
18
|
+
stripe_subscription_id: "sub_past_due",
|
|
19
|
+
stripe_price_id: "price_growth",
|
|
20
|
+
status: "past_due",
|
|
21
|
+
current_period_ends_at: 1.month.from_now
|
|
22
|
+
)
|
|
23
|
+
visit billing_path
|
|
24
|
+
|
|
25
|
+
assert_text "Payment needs attention"
|
|
26
|
+
assert_button "Fix payment"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Subscription billing with Stripe
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Use this pattern for a workspace-owned recurring subscription. It is intentionally Stripe-first: Checkout Sessions collect payment, Stripe Billing owns renewals and dunning, and the Customer Portal owns payment-method changes and cancellation. Do not start with a generic provider interface. Keep the Stripe boundary inside `Billing::*` so a real second implementation can introduce the right abstraction later.
|
|
6
|
+
|
|
7
|
+
Add the current `stripe` gem and pin the API version from `config/initializers/stripe.rb`. Store the restricted API key and webhook signing secret in the host's secret store. Grant only the Customer, Checkout Session, Billing Portal, Event, and Subscription permissions this flow uses. Use separate keys and webhook endpoints per environment. Never expose or log either secret.
|
|
8
|
+
|
|
9
|
+
## Ownership and prices
|
|
10
|
+
|
|
11
|
+
The subscription belongs to `Current.team`, not the user who completed Checkout. Include `Team::Billable` in the host `Team` model and keep the existing membership model as the authorization source. The host authentication layer must establish `Current.team` from the signed-in user's selected membership on every request; never accept an unscoped team ID. `Billing::BaseController` fails closed when that context is missing and permits only owners and admins; adapt that policy if only owners may buy or cancel.
|
|
12
|
+
|
|
13
|
+
Configure the offered Stripe Price IDs in `config/initializers/stripe.rb`. Price IDs are allowlisted server-side; a posted amount, product, or arbitrary Price ID is never trusted. Product names and displayed prices are presentation data and must match the configured recurring Stripe Prices. This exemplar assumes one subscription per team and quantity one. Add seats, usage records, taxes, or multiple subscription items only when the product actually needs them.
|
|
14
|
+
|
|
15
|
+
## Checkout and results
|
|
16
|
+
|
|
17
|
+
`Billing::CheckoutsController#create` creates or reuses the team's Stripe Customer, then creates a subscription Checkout Session. One reusable `Billing::Checkout` row per team serializes concurrent requests, rechecks subscription state under the team lock, and supplies a stable Stripe idempotency key. It deliberately omits `payment_method_types` so Stripe can use Dashboard-configured dynamic payment methods. The session carries the team ID in both `client_reference_id` and subscription metadata and redirects through a full-page non-Turbo form.
|
|
18
|
+
|
|
19
|
+
The Checkout result is a read-only `GET`. It retrieves the session from Stripe and verifies both the team reference and customer before rendering. It never grants access or writes subscription state. A completed Checkout may briefly show “processing” until its verified webhook is applied. Checkout cancellation returns to pricing without creating local state.
|
|
20
|
+
|
|
21
|
+
## Authoritative synchronization
|
|
22
|
+
|
|
23
|
+
`Webhooks::StripeEventsController` reads the unmodified request body and verifies `Stripe-Signature` before accepting an event. Relevant event IDs are recorded under a unique database constraint, then processed by `Billing::StripeEventJob`. Duplicate deliveries reuse the same event record and cannot apply twice.
|
|
24
|
+
|
|
25
|
+
The verified event record stores only routing identifiers, not the customer payload: Customer, Subscription, and Checkout Session IDs. The job retrieves that exact Subscription from Stripe before updating the local snapshot. It requires matching Customer and `team_id` metadata and refuses multiple current subscriptions or multiple subscription items. This avoids trusting browser redirects, remains recoverable after Stripe's Event-retention window, and prevents out-of-order webhook deliveries from switching to an unrelated subscription. Failed jobs retain the error and retry with backoff; `processed_at` is written only after successful reconciliation. Subscribe the endpoint to:
|
|
26
|
+
|
|
27
|
+
- `checkout.session.completed`
|
|
28
|
+
- `customer.subscription.created`
|
|
29
|
+
- `customer.subscription.updated`
|
|
30
|
+
- `customer.subscription.deleted`
|
|
31
|
+
- `invoice.paid`
|
|
32
|
+
- `invoice.payment_failed`
|
|
33
|
+
|
|
34
|
+
Verified events for Customers not owned by this application and one-off invoices without a Subscription are acknowledged without changing billing state. This matters when a Stripe account serves more than one product; use a dedicated endpoint and restricted key even so.
|
|
35
|
+
|
|
36
|
+
Keep the webhook endpoint outside browser authentication and CSRF checks. Signature verification is its authentication. Optionally allowlist Stripe webhook IPs as defense in depth.
|
|
37
|
+
|
|
38
|
+
## Entitlements and recovery
|
|
39
|
+
|
|
40
|
+
The local `Billing::Subscription` is a read model of Stripe state. Gate paid features through `team.billing_entitled?`. Active and trialing subscriptions grant entitlement only for an allowlisted Price and through the synchronized period end plus the explicit three-day delivery grace. `past_due` and `unpaid` show recovery UI and link to the Customer Portal; adapt the grace policy deliberately. `cancel_at_period_end` remains entitled through its paid period. Never infer entitlement from Checkout success, portal return parameters, flash state, or a user-supplied status.
|
|
41
|
+
|
|
42
|
+
Run `Billing::SubscriptionReconciliationSweepJob` daily from the host scheduler. It queues one bounded reconciliation per Stripe-backed team so a missed webhook cannot leave stale active access indefinitely. Monitor `Billing::StripeEvent.failed` and retry or investigate exhausted events. Webhooks are the fast path; periodic reconciliation is the repair path.
|
|
43
|
+
|
|
44
|
+
Customer Portal sessions are created only for an authorized team member and the team's stored Customer ID. Stripe handles payment-method changes, invoice history, plan changes, immediate cancellation, and scheduled cancellation according to the portal configuration. The billing screen reflects those changes after webhooks arrive.
|
|
45
|
+
|
|
46
|
+
## Verification
|
|
47
|
+
|
|
48
|
+
- Reject unknown plan keys before calling Stripe.
|
|
49
|
+
- Persist and reuse one active Checkout attempt per team so concurrent requests share one Stripe idempotency key and Session.
|
|
50
|
+
- Reuse one Stripe Customer per team with an idempotent creation key.
|
|
51
|
+
- Omit `payment_method_types` from subscription Checkout Sessions.
|
|
52
|
+
- Reject Checkout result sessions belonging to another team or Customer.
|
|
53
|
+
- Verify signatures against the exact raw request body and reject malformed signatures.
|
|
54
|
+
- Record each Stripe event once and retry processing failures without setting `processed_at`.
|
|
55
|
+
- Retrieve the exact application-owned subscription, validate Customer and team metadata, refuse entitlement for unrelated Prices, and reject multiple items or concurrent subscriptions.
|
|
56
|
+
- Bound entitlement by the synchronized paid-through date and verify periodic reconciliation repairs a missed webhook.
|
|
57
|
+
- Keep Checkout results read-only and grant entitlement only from the webhook-synchronized snapshot.
|
|
58
|
+
- Cover active, trialing, processing, canceled Checkout, scheduled cancellation, past-due recovery, canceled subscription, and no-plan configuration states.
|
|
59
|
+
- Browser-test external redirects with Stripe test mode, Turbo disabled, 390px layouts, keyboard navigation, both appearances, and webhook-driven refresh.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Invitations
|
|
5
|
+
class Acceptance < Phlex::HTML
|
|
6
|
+
include Phlex::Rails::Helpers::FormAuthenticityToken
|
|
7
|
+
include Phlex::Rails::Helpers::Routes
|
|
8
|
+
|
|
9
|
+
def initialize(invitation:)
|
|
10
|
+
@invitation = invitation
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def view_template
|
|
14
|
+
render NitroKit::Container.new(size: :sm) do
|
|
15
|
+
render NitroKit::Card.new do |card|
|
|
16
|
+
card.title("Join #{invitation.team.name}", level: 1)
|
|
17
|
+
card.description("#{invitation.invited_by.team_display_name} invited #{invitation.email} as #{invitation.role.humanize.downcase}.")
|
|
18
|
+
card.footer do
|
|
19
|
+
form(action: invitation_acceptance_path(token: invitation.to_token_for(:acceptance)), method: :post) do
|
|
20
|
+
input(type: :hidden, name: "authenticity_token", value: form_authenticity_token)
|
|
21
|
+
render NitroKit::Button.new("Accept invitation", type: :submit, variant: :primary)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
attr_reader :invitation
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Teams
|
|
5
|
+
class Index < Phlex::HTML
|
|
6
|
+
include Phlex::Rails::Helpers::FormWith
|
|
7
|
+
include Phlex::Rails::Helpers::Routes
|
|
8
|
+
|
|
9
|
+
def initialize(teams:, team:)
|
|
10
|
+
@teams = teams
|
|
11
|
+
@team = team
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def view_template
|
|
15
|
+
render NitroKit::Flex.new(dir: :col, gap: 6, align: :stretch) do
|
|
16
|
+
p { team_description }
|
|
17
|
+
render_team_list
|
|
18
|
+
render_new_team
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.form_id(team)
|
|
23
|
+
ActionView::RecordIdentifier.dom_id(team, :form)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
attr_reader :teams, :team
|
|
29
|
+
|
|
30
|
+
def team_description
|
|
31
|
+
teams.one? ? "Your workspace is ready when collaborators are." : "Choose a workspace or create another one."
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def render_team_list
|
|
35
|
+
render NitroKit::DataSection.new(
|
|
36
|
+
title: "Your teams",
|
|
37
|
+
description: "Access follows membership, so the same account can safely work across teams."
|
|
38
|
+
) do |section|
|
|
39
|
+
section.table NitroKit::Table.new(table_aria: { label: "Your teams" }) do |table|
|
|
40
|
+
table.thead do
|
|
41
|
+
table.tr do
|
|
42
|
+
table.th("Team")
|
|
43
|
+
table.th("Role")
|
|
44
|
+
table.th("Members", align: :right)
|
|
45
|
+
table.th("Open", align: :right)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
table.tbody do
|
|
49
|
+
teams.each do |candidate|
|
|
50
|
+
membership = candidate.membership_for(Current.user)
|
|
51
|
+
table.tr do
|
|
52
|
+
table.th(candidate.name, scope: :row)
|
|
53
|
+
table.td { render NitroKit::Badge.new(membership.role.humanize, variant: :outline, size: :sm) }
|
|
54
|
+
table.td(candidate.memberships.size.to_s, align: :right)
|
|
55
|
+
table.td(align: :right) do
|
|
56
|
+
render NitroKit::Button.new(
|
|
57
|
+
"Manage",
|
|
58
|
+
href: team_memberships_path(candidate),
|
|
59
|
+
size: :sm
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def render_new_team
|
|
70
|
+
render NitroKit::SettingsSection.new(
|
|
71
|
+
title: "Create another team",
|
|
72
|
+
description: "You become an owner. Existing memberships are unchanged."
|
|
73
|
+
) do |section|
|
|
74
|
+
section.form do
|
|
75
|
+
form_with(
|
|
76
|
+
model: team,
|
|
77
|
+
builder: NitroKit::FormBuilder,
|
|
78
|
+
id: self.class.form_id(team)
|
|
79
|
+
) do |form|
|
|
80
|
+
form.field(:name, label: "Team name", required: true, autocomplete: "organization")
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Teams
|
|
5
|
+
class InvitationForm < Phlex::HTML
|
|
6
|
+
include Phlex::Rails::Helpers::FormWith
|
|
7
|
+
include Phlex::Rails::Helpers::Routes
|
|
8
|
+
|
|
9
|
+
def initialize(team:, invitation:)
|
|
10
|
+
@team = team
|
|
11
|
+
@invitation = invitation
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def view_template
|
|
15
|
+
render NitroKit::Container.new(size: :md) { render_form }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.form_id(invitation)
|
|
19
|
+
ActionView::RecordIdentifier.dom_id(invitation, :form)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_reader :team, :invitation
|
|
25
|
+
|
|
26
|
+
def render_form
|
|
27
|
+
render NitroKit::Fieldset.new(
|
|
28
|
+
legend: "Invitation details",
|
|
29
|
+
description: "Admins can manage members. Only owners can manage other owners and admins."
|
|
30
|
+
) do
|
|
31
|
+
form_with(
|
|
32
|
+
model: [ team, invitation ],
|
|
33
|
+
builder: NitroKit::FormBuilder,
|
|
34
|
+
id: self.class.form_id(invitation)
|
|
35
|
+
) do |form|
|
|
36
|
+
form.group do
|
|
37
|
+
form.field(:email, as: :email, label: "Email address", required: true, autocomplete: "email")
|
|
38
|
+
form.field(
|
|
39
|
+
:role,
|
|
40
|
+
as: :select,
|
|
41
|
+
label: "Role",
|
|
42
|
+
options: [ [ "Member", "member" ], [ "Administrator", "admin" ] ],
|
|
43
|
+
required: true
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Teams
|
|
5
|
+
class MemberForm < Phlex::HTML
|
|
6
|
+
include Phlex::Rails::Helpers::FormWith
|
|
7
|
+
include Phlex::Rails::Helpers::Routes
|
|
8
|
+
|
|
9
|
+
def initialize(team:, membership:)
|
|
10
|
+
@team = team
|
|
11
|
+
@membership = membership
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def view_template
|
|
15
|
+
render NitroKit::Container.new(size: :lg) do
|
|
16
|
+
render NitroKit::Flex.new(dir: :col, gap: 8, align: :stretch) do
|
|
17
|
+
render_role_form
|
|
18
|
+
render_removal
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.form_id(membership)
|
|
24
|
+
ActionView::RecordIdentifier.dom_id(membership, :form)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
attr_reader :team, :membership
|
|
30
|
+
|
|
31
|
+
def render_role_form
|
|
32
|
+
render NitroKit::Fieldset.new(
|
|
33
|
+
legend: "Team role",
|
|
34
|
+
description: "Role changes apply immediately. A team must always keep an owner."
|
|
35
|
+
) do
|
|
36
|
+
form_with(
|
|
37
|
+
model: [ team, membership ],
|
|
38
|
+
builder: NitroKit::FormBuilder,
|
|
39
|
+
id: self.class.form_id(membership)
|
|
40
|
+
) do |form|
|
|
41
|
+
form.field(:role, as: :select, label: "Role", options: role_options, required: true)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def render_removal
|
|
47
|
+
render NitroKit::DangerZone.new(
|
|
48
|
+
title: "Remove from team",
|
|
49
|
+
description: "#{membership.user.team_display_name} immediately loses access to #{team.name}."
|
|
50
|
+
) do |zone|
|
|
51
|
+
zone.confirmation do
|
|
52
|
+
render NitroKit::Dialog.new(id: ActionView::RecordIdentifier.dom_id(membership, :remove_dialog)) do |dialog|
|
|
53
|
+
dialog.trigger("Remove member", variant: :destructive)
|
|
54
|
+
dialog.panel(
|
|
55
|
+
title: "Remove #{membership.user.team_display_name}?",
|
|
56
|
+
description: "They will immediately lose access to #{team.name}."
|
|
57
|
+
) do
|
|
58
|
+
render NitroKit::Flex.new(dir: :row, gap: 2, justify: :end, wrap: :wrap) do
|
|
59
|
+
render NitroKit::Button.new("Cancel", html: { command: "close", commandfor: "#{dialog.id}-panel" })
|
|
60
|
+
form_with(model: [ team, membership ], method: :delete, data: { turbo_frame: "_top" }) do
|
|
61
|
+
render NitroKit::Button.new("Remove member", type: :submit, variant: :destructive)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
zone.escape NitroKit::Button.new("Keep member", href: team_memberships_path(team))
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def role_options
|
|
72
|
+
options = [ [ "Member", "member" ], [ "Administrator", "admin" ] ]
|
|
73
|
+
options << [ "Owner", "owner" ] if Current.membership.owner?
|
|
74
|
+
options
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Teams
|
|
5
|
+
class Members < Phlex::HTML
|
|
6
|
+
include Phlex::Rails::Helpers::Routes
|
|
7
|
+
include Phlex::Rails::Helpers::FormWith
|
|
8
|
+
|
|
9
|
+
def initialize(team:, memberships:, invitations:)
|
|
10
|
+
@team = team
|
|
11
|
+
@memberships = memberships
|
|
12
|
+
@invitations = invitations
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def view_template
|
|
16
|
+
render NitroKit::Flex.new(dir: :col, gap: 6, align: :stretch) do
|
|
17
|
+
p do
|
|
18
|
+
memberships.one? ? "Just you for now." : "#{memberships.size} members."
|
|
19
|
+
end
|
|
20
|
+
render_members
|
|
21
|
+
render_invitations if invitations.any?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
attr_reader :team, :memberships, :invitations
|
|
28
|
+
|
|
29
|
+
def render_members
|
|
30
|
+
render NitroKit::DataSection.new(
|
|
31
|
+
title: "Members",
|
|
32
|
+
description: memberships.one? ? "Invite someone when this stops being a solo project." : "People with active access to this team."
|
|
33
|
+
) do |section|
|
|
34
|
+
section.table NitroKit::Table.new(table_aria: { label: "Team members" }) do |table|
|
|
35
|
+
table.caption("#{memberships.size} active #{"member".pluralize(memberships.size)}")
|
|
36
|
+
table.thead do
|
|
37
|
+
table.tr do
|
|
38
|
+
table.th("Member")
|
|
39
|
+
table.th("Role")
|
|
40
|
+
table.th("Joined")
|
|
41
|
+
table.th("Actions", align: :right)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
table.tbody do
|
|
45
|
+
memberships.each { |membership| render_member(table, membership) }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def render_member(table, membership)
|
|
52
|
+
table.tr do
|
|
53
|
+
table.th(scope: :row) do
|
|
54
|
+
render NitroKit::Avatar.new(alt: membership.user.team_display_name, size: :sm)
|
|
55
|
+
strong { membership.user.team_display_name }
|
|
56
|
+
small { membership.user.team_email }
|
|
57
|
+
end
|
|
58
|
+
table.td do
|
|
59
|
+
render NitroKit::Badge.new(
|
|
60
|
+
membership.role.humanize,
|
|
61
|
+
color: membership.owner? ? :info : :neutral,
|
|
62
|
+
variant: :outline,
|
|
63
|
+
size: :sm
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
table.td { time(datetime: membership.created_at.iso8601) { membership.created_at.to_date.to_fs(:long) } }
|
|
67
|
+
table.td(align: :right) do
|
|
68
|
+
next unless Current.membership.can_manage?(membership)
|
|
69
|
+
|
|
70
|
+
render NitroKit::Button.new(
|
|
71
|
+
"Manage",
|
|
72
|
+
href: edit_team_membership_path(team, membership),
|
|
73
|
+
size: :sm
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def render_invitations
|
|
80
|
+
render NitroKit::DataSection.new(
|
|
81
|
+
title: "Pending invitations",
|
|
82
|
+
description: "Invitation links expire after seven days."
|
|
83
|
+
) do |section|
|
|
84
|
+
section.table NitroKit::Table.new(table_aria: { label: "Pending team invitations" }) do |table|
|
|
85
|
+
table.thead do
|
|
86
|
+
table.tr do
|
|
87
|
+
table.th("Email")
|
|
88
|
+
table.th("Role")
|
|
89
|
+
table.th("Invited")
|
|
90
|
+
table.th("Actions", align: :right)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
table.tbody do
|
|
94
|
+
invitations.each do |invitation|
|
|
95
|
+
table.tr do
|
|
96
|
+
table.th(invitation.email, scope: :row)
|
|
97
|
+
table.td { render NitroKit::Badge.new(invitation.role.humanize, variant: :outline, size: :sm) }
|
|
98
|
+
table.td { time(datetime: invitation.created_at.iso8601) { invitation.created_at.to_date.to_fs(:long) } }
|
|
99
|
+
table.td(align: :right) { render_revocation(invitation) if Current.membership.manager? }
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def render_revocation(invitation)
|
|
108
|
+
render NitroKit::Dialog.new(id: ActionView::RecordIdentifier.dom_id(invitation, :revoke_dialog)) do |dialog|
|
|
109
|
+
dialog.trigger("Revoke invitation", size: :sm)
|
|
110
|
+
dialog.panel(
|
|
111
|
+
title: "Revoke invitation?",
|
|
112
|
+
description: "#{invitation.email} will no longer be able to join #{team.name} using this invitation."
|
|
113
|
+
) do
|
|
114
|
+
render NitroKit::Flex.new(dir: :row, gap: 2, justify: :end, wrap: :wrap) do
|
|
115
|
+
render NitroKit::Button.new("Cancel", html: { command: "close", commandfor: "#{dialog.id}-panel" })
|
|
116
|
+
form_with(model: [ team, invitation ], method: :delete, data: { turbo_frame: "_top" }) do
|
|
117
|
+
render NitroKit::Button.new("Revoke invitation", type: :submit, variant: :destructive)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Invitations
|
|
4
|
+
class AcceptancesController < ApplicationController
|
|
5
|
+
before_action :require_user
|
|
6
|
+
|
|
7
|
+
def show
|
|
8
|
+
@invitation = find_invitation
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create
|
|
12
|
+
invitation = find_invitation
|
|
13
|
+
membership = invitation.accept!(Current.user)
|
|
14
|
+
redirect_to team_memberships_path(membership.team),
|
|
15
|
+
status: :see_other,
|
|
16
|
+
notice: "Invitation accepted"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def find_invitation
|
|
22
|
+
Invitation.find_by_token_for(:acceptance, params[:token]) || raise(ActiveRecord::RecordNotFound)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def require_user
|
|
26
|
+
head :unauthorized unless Current.user
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|