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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Teams
|
|
4
|
+
class BaseController < ApplicationController
|
|
5
|
+
before_action :set_current_team
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def set_current_team
|
|
10
|
+
Current.team = Current.user&.teams&.find(params[:team_id])
|
|
11
|
+
Current.membership = Current.team.membership_for(Current.user)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def require_manager
|
|
15
|
+
head :forbidden unless Current.team_manager?
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Teams
|
|
4
|
+
class InvitationsController < BaseController
|
|
5
|
+
before_action :require_manager
|
|
6
|
+
before_action :set_invitation, only: :destroy
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
@invitation = Current.team.invitations.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create
|
|
13
|
+
@invitation = Current.team.invitations.new(invitation_params.merge(invited_by: Current.user))
|
|
14
|
+
|
|
15
|
+
if @invitation.save
|
|
16
|
+
TeamInvitationMailer.invite(@invitation).deliver_later
|
|
17
|
+
redirect_to team_memberships_path(Current.team),
|
|
18
|
+
status: :see_other,
|
|
19
|
+
notice: "Invitation sent"
|
|
20
|
+
else
|
|
21
|
+
render :new, status: :unprocessable_entity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def destroy
|
|
26
|
+
@invitation.destroy!
|
|
27
|
+
redirect_to team_memberships_path(Current.team),
|
|
28
|
+
status: :see_other,
|
|
29
|
+
notice: "Invitation cancelled"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def set_invitation
|
|
35
|
+
@invitation = Current.team.invitations.find(params[:id])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def invitation_params
|
|
39
|
+
params.expect(invitation: %i[email role])
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Teams
|
|
4
|
+
class MembershipsController < BaseController
|
|
5
|
+
before_action :set_membership, only: %i[edit update destroy]
|
|
6
|
+
before_action :require_manager, only: %i[edit update destroy]
|
|
7
|
+
before_action :require_permission, only: %i[edit update destroy]
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
@memberships = Current.team.memberships.includes(:user).order(:created_at)
|
|
11
|
+
@invitations = Current.team_manager? ? Current.team.invitations.order(:created_at) : Invitation.none
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def edit
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def update
|
|
18
|
+
if @membership.update(membership_params)
|
|
19
|
+
redirect_to team_memberships_path(Current.team),
|
|
20
|
+
status: :see_other,
|
|
21
|
+
notice: "Role updated"
|
|
22
|
+
else
|
|
23
|
+
render :edit, status: :unprocessable_entity
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def destroy
|
|
28
|
+
destination = @membership.user == Current.user ? teams_path : team_memberships_path(Current.team)
|
|
29
|
+
|
|
30
|
+
if @membership.destroy
|
|
31
|
+
redirect_to destination, status: :see_other, notice: "Member removed"
|
|
32
|
+
else
|
|
33
|
+
redirect_to team_memberships_path(Current.team),
|
|
34
|
+
status: :see_other,
|
|
35
|
+
alert: @membership.errors.full_messages.to_sentence
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def set_membership
|
|
42
|
+
@membership = Current.team.memberships.includes(:user).find(params[:id])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def require_permission
|
|
46
|
+
head :forbidden unless Current.membership.can_manage?(@membership)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def membership_params
|
|
50
|
+
params.expect(membership: [ :role ])
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class TeamsController < ApplicationController
|
|
4
|
+
before_action :require_user
|
|
5
|
+
|
|
6
|
+
def index
|
|
7
|
+
@teams = Current.user.teams.order(:name)
|
|
8
|
+
@team = Team.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create
|
|
12
|
+
@team = Team.create_for!(user: Current.user, name: team_params.fetch(:name))
|
|
13
|
+
redirect_to team_memberships_path(@team),
|
|
14
|
+
status: :see_other,
|
|
15
|
+
notice: "Team created"
|
|
16
|
+
rescue ActiveRecord::RecordInvalid
|
|
17
|
+
@teams = Current.user.teams.order(:name)
|
|
18
|
+
render :index, status: :unprocessable_entity
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def require_user
|
|
24
|
+
head :unauthorized unless Current.user
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def team_params
|
|
28
|
+
params.expect(team: [ :name ])
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class TeamInvitationMailer < ApplicationMailer
|
|
4
|
+
def invite(invitation)
|
|
5
|
+
@invitation = invitation
|
|
6
|
+
@acceptance_url = invitation_acceptance_url(token: invitation.to_token_for(:acceptance))
|
|
7
|
+
|
|
8
|
+
mail to: invitation.email, subject: "Join #{invitation.team.name}"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UserTeams
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
has_many :memberships, dependent: :destroy
|
|
8
|
+
has_many :teams, through: :memberships
|
|
9
|
+
has_many :sent_invitations, class_name: "Invitation", foreign_key: :invited_by_id, dependent: :restrict_with_error
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class_methods do
|
|
13
|
+
def create_with_team!(attributes, team_name: nil)
|
|
14
|
+
transaction do
|
|
15
|
+
create!(attributes).tap do |user|
|
|
16
|
+
user.bootstrap_team!(name: team_name || user.default_team_name)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def bootstrap_team!(name: default_team_name)
|
|
23
|
+
memberships.first&.team || Team.create_for!(user: self, name:)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def team_email
|
|
27
|
+
respond_to?(:email_address) ? email_address : email
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def team_display_name
|
|
31
|
+
respond_to?(:name) && name.present? ? name : team_email
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def default_team_name
|
|
35
|
+
"#{team_display_name}'s team"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Invitation < ApplicationRecord
|
|
4
|
+
belongs_to :team
|
|
5
|
+
belongs_to :invited_by, class_name: "User"
|
|
6
|
+
|
|
7
|
+
enum :role, { member: 0, admin: 1 }, default: :member, validate: true
|
|
8
|
+
|
|
9
|
+
generates_token_for :acceptance, expires_in: 7.days do
|
|
10
|
+
email
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
normalizes :email, with: ->(email) { email.strip.downcase }
|
|
14
|
+
|
|
15
|
+
validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }, uniqueness: { scope: :team_id }
|
|
16
|
+
validate :email_is_not_already_a_member
|
|
17
|
+
|
|
18
|
+
def accept!(user)
|
|
19
|
+
unless user.team_email.to_s.casecmp?(email)
|
|
20
|
+
errors.add(:email, "does not match the signed-in account")
|
|
21
|
+
raise ActiveRecord::RecordInvalid, self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
transaction do
|
|
25
|
+
membership = team.memberships.find_or_initialize_by(user:)
|
|
26
|
+
membership.role = role if membership.new_record?
|
|
27
|
+
membership.save!
|
|
28
|
+
destroy!
|
|
29
|
+
membership
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def email_is_not_already_a_member
|
|
36
|
+
return if email.blank?
|
|
37
|
+
return unless team&.users&.any? { |user| user.team_email.to_s.casecmp?(email) }
|
|
38
|
+
|
|
39
|
+
errors.add(:email, "already belongs to this team")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Membership < ApplicationRecord
|
|
4
|
+
belongs_to :team
|
|
5
|
+
belongs_to :user
|
|
6
|
+
|
|
7
|
+
enum :role, { member: 0, admin: 1, owner: 2 }, default: :member, validate: true
|
|
8
|
+
|
|
9
|
+
validates :user_id, uniqueness: { scope: :team_id }
|
|
10
|
+
validate :preserve_owner_role, if: :leaving_owner_role?
|
|
11
|
+
|
|
12
|
+
before_destroy :prevent_last_owner_removal
|
|
13
|
+
|
|
14
|
+
scope :owner, -> { where(role: roles.fetch(:owner)) }
|
|
15
|
+
|
|
16
|
+
def manager?
|
|
17
|
+
owner? || admin?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def can_manage?(other)
|
|
21
|
+
owner? || (admin? && other.member?)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def leaving_owner_role?
|
|
27
|
+
will_save_change_to_role?(from: "owner")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def preserve_owner_role
|
|
31
|
+
team.with_lock do
|
|
32
|
+
errors.add(:role, "cannot remove the team's last owner") if team.sole_owner?(self)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def prevent_last_owner_removal
|
|
37
|
+
return unless role_in_database == "owner"
|
|
38
|
+
|
|
39
|
+
team.with_lock do
|
|
40
|
+
next unless team.sole_owner?(self)
|
|
41
|
+
errors.add(:role, "cannot remove the team's last owner")
|
|
42
|
+
throw :abort
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Team < ApplicationRecord
|
|
4
|
+
has_many :memberships, dependent: :delete_all
|
|
5
|
+
has_many :users, through: :memberships
|
|
6
|
+
has_many :invitations, dependent: :delete_all
|
|
7
|
+
|
|
8
|
+
validates :name, presence: true
|
|
9
|
+
|
|
10
|
+
def self.create_for!(user:, name: user.default_team_name)
|
|
11
|
+
transaction do
|
|
12
|
+
create!(name:).tap do |team|
|
|
13
|
+
team.memberships.create!(user:, role: :owner)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def membership_for(user)
|
|
19
|
+
memberships.find_by(user:)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def sole_owner?(membership)
|
|
23
|
+
memberships.owner.where.not(id: membership.id).none?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render UI::Invitations::Acceptance.new(invitation: @invitation) %>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<h1>Join <%= @invitation.team.name %></h1>
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
<%= @invitation.invited_by.team_display_name %> invited you to join as
|
|
5
|
+
<%= @invitation.role.humanize.downcase %>.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p><%= link_to "Accept invitation", @acceptance_url %></p>
|
|
9
|
+
|
|
10
|
+
<p>This link expires in seven days.</p>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% content_for :title, "Teams" %>
|
|
2
|
+
<%= render UI::ApplicationShell.new(
|
|
3
|
+
title: "Teams",
|
|
4
|
+
current: :team,
|
|
5
|
+
actions: [
|
|
6
|
+
{
|
|
7
|
+
label: "Create team",
|
|
8
|
+
form: UI::Teams::Index.form_id(@team),
|
|
9
|
+
type: :submit,
|
|
10
|
+
variant: :primary
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
) do %>
|
|
14
|
+
<%= render UI::Teams::Index.new(teams: @teams, team: @team) %>
|
|
15
|
+
<% end %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<% content_for :title, "Invite a teammate" %>
|
|
2
|
+
<%= render UI::ApplicationShell.new(
|
|
3
|
+
title: "Invite a teammate",
|
|
4
|
+
current: :team,
|
|
5
|
+
back: {
|
|
6
|
+
label: "Back to team",
|
|
7
|
+
href: team_memberships_path(Current.team)
|
|
8
|
+
},
|
|
9
|
+
actions: [
|
|
10
|
+
{
|
|
11
|
+
label: "Send invitation",
|
|
12
|
+
form: UI::Teams::InvitationForm.form_id(@invitation),
|
|
13
|
+
type: :submit,
|
|
14
|
+
variant: :primary
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
) do %>
|
|
18
|
+
<%= render UI::Teams::InvitationForm.new(
|
|
19
|
+
team: Current.team,
|
|
20
|
+
invitation: @invitation
|
|
21
|
+
) %>
|
|
22
|
+
<% end %>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<% content_for :title, @membership.user.team_display_name %>
|
|
2
|
+
<%= render UI::ApplicationShell.new(
|
|
3
|
+
title: @membership.user.team_display_name,
|
|
4
|
+
current: :team,
|
|
5
|
+
back: {
|
|
6
|
+
label: "Back to team",
|
|
7
|
+
href: team_memberships_path(Current.team)
|
|
8
|
+
},
|
|
9
|
+
actions: [
|
|
10
|
+
{
|
|
11
|
+
label: "Update role",
|
|
12
|
+
form: UI::Teams::MemberForm.form_id(@membership),
|
|
13
|
+
type: :submit,
|
|
14
|
+
variant: :primary
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
) do %>
|
|
18
|
+
<%= render UI::Teams::MemberForm.new(
|
|
19
|
+
team: Current.team,
|
|
20
|
+
membership: @membership
|
|
21
|
+
) %>
|
|
22
|
+
<% end %>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<% content_for :title, Current.team.name %>
|
|
2
|
+
<% actions = [ { label: "All teams", href: teams_path } ] %>
|
|
3
|
+
<% if Current.team_manager? %>
|
|
4
|
+
<% actions << {
|
|
5
|
+
label: "Invite teammate",
|
|
6
|
+
href: new_team_invitation_path(Current.team),
|
|
7
|
+
variant: :primary
|
|
8
|
+
} %>
|
|
9
|
+
<% end %>
|
|
10
|
+
<%= render UI::ApplicationShell.new(
|
|
11
|
+
title: Current.team.name,
|
|
12
|
+
current: :team,
|
|
13
|
+
actions:
|
|
14
|
+
) do %>
|
|
15
|
+
<%= render UI::Teams::Members.new(
|
|
16
|
+
team: Current.team,
|
|
17
|
+
memberships: @memberships,
|
|
18
|
+
invitations: @invitations
|
|
19
|
+
) %>
|
|
20
|
+
<% end %>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
resources :teams, only: %i[index create] do
|
|
4
|
+
scope module: :teams do
|
|
5
|
+
resources :memberships, only: %i[index edit update destroy]
|
|
6
|
+
resources :invitations, only: %i[new create destroy]
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
get "invitations/:token/accept", to: "invitations/acceptances#show", as: :invitation_acceptance
|
|
11
|
+
post "invitations/:token/accept", to: "invitations/acceptances#create"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class CreateTeamManagement < ActiveRecord::Migration[8.1]
|
|
4
|
+
def change
|
|
5
|
+
create_table :teams do |t|
|
|
6
|
+
t.string :name, null: false
|
|
7
|
+
t.timestamps
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
create_table :memberships do |t|
|
|
11
|
+
t.references :team, null: false, foreign_key: true
|
|
12
|
+
t.references :user, null: false, foreign_key: true
|
|
13
|
+
t.integer :role, null: false, default: 0
|
|
14
|
+
t.timestamps
|
|
15
|
+
|
|
16
|
+
t.index [ :team_id, :user_id ], unique: true
|
|
17
|
+
t.check_constraint "role IN (0, 1, 2)", name: "memberships_role"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
create_table :invitations do |t|
|
|
21
|
+
t.references :team, null: false, foreign_key: true
|
|
22
|
+
t.references :invited_by, null: false, foreign_key: { to_table: :users }
|
|
23
|
+
t.string :email, null: false
|
|
24
|
+
t.integer :role, null: false, default: 0
|
|
25
|
+
t.timestamps
|
|
26
|
+
|
|
27
|
+
t.index [ :team_id, :email ], unique: true
|
|
28
|
+
t.check_constraint "role IN (0, 1)", name: "invitations_role"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
require "support/team_management_test_helpers"
|
|
5
|
+
|
|
6
|
+
class InvitationTest < ActiveSupport::TestCase
|
|
7
|
+
setup do
|
|
8
|
+
owner = create_team_user(email: "owner@example.test")
|
|
9
|
+
@team = Team.create_for!(user: owner, name: "27 Seagulls")
|
|
10
|
+
@invitation = @team.invitations.create!(email: "new@example.test", role: :admin, invited_by: owner)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "acceptance creates membership and consumes the invitation" do
|
|
14
|
+
user = create_team_user(email: "new@example.test")
|
|
15
|
+
|
|
16
|
+
membership = @invitation.accept!(user)
|
|
17
|
+
|
|
18
|
+
assert_predicate membership, :admin?
|
|
19
|
+
assert_not Invitation.exists?(@invitation.id)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test "acceptance requires the signed-in invited email" do
|
|
23
|
+
other_user = create_team_user(email: "someone-else@example.test")
|
|
24
|
+
|
|
25
|
+
assert_raises(ActiveRecord::RecordInvalid) { @invitation.accept!(other_user) }
|
|
26
|
+
assert Invitation.exists?(@invitation.id)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
require "support/team_management_test_helpers"
|
|
5
|
+
|
|
6
|
+
class MembershipTest < ActiveSupport::TestCase
|
|
7
|
+
setup do
|
|
8
|
+
@owner = create_team_user(email: "owner@example.test")
|
|
9
|
+
@team = Team.create_for!(user: @owner, name: "27 Seagulls")
|
|
10
|
+
@membership = @team.membership_for(@owner)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "the final owner cannot be downgraded" do
|
|
14
|
+
assert_not @membership.update(role: :member)
|
|
15
|
+
assert_includes @membership.errors[:role], "cannot remove the team's last owner"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test "the final owner cannot be removed" do
|
|
19
|
+
assert_not @membership.destroy
|
|
20
|
+
assert_includes @membership.errors[:role], "cannot remove the team's last owner"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test "an owner can step down after appointing another owner" do
|
|
24
|
+
successor = create_team_user(email: "successor@example.test")
|
|
25
|
+
@team.memberships.create!(user: successor, role: :owner)
|
|
26
|
+
|
|
27
|
+
assert @membership.update(role: :admin)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
require "support/team_management_test_helpers"
|
|
5
|
+
|
|
6
|
+
class TeamTest < ActiveSupport::TestCase
|
|
7
|
+
test "creating a team makes the user its owner" do
|
|
8
|
+
user = create_team_user(email: "owner@example.test")
|
|
9
|
+
|
|
10
|
+
team = Team.create_for!(user:, name: "27 Seagulls")
|
|
11
|
+
|
|
12
|
+
assert_equal "27 Seagulls", team.name
|
|
13
|
+
assert_predicate team.membership_for(user), :owner?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test "self signup creates its default team in the same transaction" do
|
|
17
|
+
user = User.create_with_team!(team_management_user_attributes(email: "new@example.test"))
|
|
18
|
+
|
|
19
|
+
assert_equal 1, user.teams.count
|
|
20
|
+
assert_predicate user.memberships.first, :owner?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test "the same user can own more than one team" do
|
|
24
|
+
user = create_team_user(email: "owner@example.test")
|
|
25
|
+
|
|
26
|
+
Team.create_for!(user:, name: "27 Seagulls")
|
|
27
|
+
Team.create_for!(user:, name: "Second company")
|
|
28
|
+
|
|
29
|
+
assert_equal 2, user.teams.count
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module TeamManagementTestHelpers
|
|
4
|
+
def create_team_user(email:)
|
|
5
|
+
User.create!(team_management_user_attributes(email:))
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def team_management_user_attributes(email:)
|
|
9
|
+
attributes = {}
|
|
10
|
+
attributes[User.column_names.include?("email_address") ? :email_address : :email] = email
|
|
11
|
+
attributes[:name] = email.split("@").first.humanize if User.column_names.include?("name")
|
|
12
|
+
|
|
13
|
+
if User.column_names.include?("password_digest")
|
|
14
|
+
attributes[:password] = "correct horse battery staple"
|
|
15
|
+
attributes[:password_confirmation] = attributes[:password]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
attributes
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
ActiveSupport::TestCase.include TeamManagementTestHelpers
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Team management
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Use this pattern when an account can grow from one owner into a shared workspace with invitations and explicit roles. It fits products where people may belong to more than one team and every managed record must remain scoped to the selected team.
|
|
6
|
+
|
|
7
|
+
## Composition checklist
|
|
8
|
+
|
|
9
|
+
Run the page composition checklist in the installed gem's `docs/patterns/composition.md` (`bundle show nitro_kit`) before calling any adapted route finished: the shell owns the gutter and the `h1`; member and invitation rows use plain Edit links or default-treatment Dialog triggers. Destructive button treatment appears only in the member edit route's `DangerZone` and on confirming submits inside Dialogs, never in table rows. Inspect populated, empty, invalid, and 390px states.
|
|
10
|
+
|
|
11
|
+
## Composition decisions
|
|
12
|
+
|
|
13
|
+
- Represent membership explicitly. A user-team join owns the role; neither User nor Team carries a global role.
|
|
14
|
+
- Bootstrap signup through the same Team and Membership records used later. Avoid a second personal-account model.
|
|
15
|
+
- Keep pending invitations separate from memberships so acceptance is an explicit transition with its own expiry and recipient checks.
|
|
16
|
+
- Protect the last owner in the domain model, not only by hiding a button.
|
|
17
|
+
- Scope controllers through the current team before loading memberships or invitations.
|
|
18
|
+
- Compose member, invitation, and team settings routes through the host shell with one toolbar and one outer gutter.
|
|
19
|
+
|
|
20
|
+
## Tradeoffs
|
|
21
|
+
|
|
22
|
+
The owner/admin/member vocabulary is intentionally small. Products with billing, security, or project-specific permissions should extend authorization around memberships rather than adding booleans to User. Invitation email delivery is included because the acceptance path is part of the workflow, but authentication remains application-owned.
|
|
23
|
+
|
|
24
|
+
## Adaptation
|
|
25
|
+
|
|
26
|
+
Map the user email and display-name methods, current request context, sign-in flow, mailer host, and authorization rules. Preserve team scoping, invitation identity, and last-owner protection. Add roles only when they correspond to real capabilities.
|
|
27
|
+
|
|
28
|
+
## Verification
|
|
29
|
+
|
|
30
|
+
- Prove that every membership and invitation query is scoped to the current team.
|
|
31
|
+
- Exercise signup bootstrap, invitation creation, expiry/revocation, acceptance, role changes, removal, and last-owner rejection.
|
|
32
|
+
- Verify labels, inline errors, semantic tables, and destructive action names.
|
|
33
|
+
- Test a user with multiple teams so implicit first-team assumptions cannot pass unnoticed.
|
|
34
|
+
- Run the supplied model tests and add host request/system coverage for its authentication boundary.
|
|
35
|
+
|
|
36
|
+
## Width and destructive actions
|
|
37
|
+
|
|
38
|
+
Tables fill the shell canvas. Form pages own a centered Container inside the
|
|
39
|
+
shared gutter; never constrain every route through the shell. Simple forms use
|
|
40
|
+
a single-column Fieldset with full-width controls, not the split SettingsSection
|
|
41
|
+
layout. Use Container lg for resource forms and md for short invitations. Use Nitro Dialog
|
|
42
|
+
for destructive confirmations, including member removal and invitation
|
|
43
|
+
revocation. Keep a real Rails form inside the dialog and a clear Cancel or
|
|
44
|
+
Keep action. Do not replace these with native browser confirmation.
|
|
45
|
+
|
|
46
|
+
Keep an explicit Cancel button beside the destructive submit in a right-aligned
|
|
47
|
+
Flex row. `dialog.close_button` only configures the corner X.
|