Files
computer-playbook/roles/web-app-decidim/files/ruby/ensure/organization.rb
kevinveenbirkenbachandClaude Opus 5 ad7913d41a fix(decidim): create the organization that db:seed skips in production
Every task after the seed step reads `Decidim::Organization.first`
(ensure/default_pages.rb, set_organization_host.rb, ensure/admin_user.rb,
configure_oidc.rb), and only `rails db:seed` ever creates one. Decidim guards
its core seeds with `if !Rails.env.production? || ENV.fetch("SEED", nil)`
(decidim-core db/seeds.rb, v0.31.6) and this role sets no SEED, so in
production the seed step creates nothing, and `failed_when: false` hides it.
The next task then calls `CreateDefaultPages.call(nil)`, whose
`StaticPage.find_or_create_by!(organization:, slug:)` raises, and
set_organization_host.rb would follow with `nil.host =`.

The regular matrix deploys RAILS_ENV=development, where the seeds run, so
only the README replay step, which provisions a production inventory, gets
here. It has not got this far yet: the healthcheck stopped it first
(87ce146d8).

ensure/organization.rb creates the organization when there is none, with the
attributes Decidim's two creation paths agree on (the core seeds and
Decidim::System::CreateOrganization), plus the help pages and content blocks
CreateOrganization adds. It leaves out the admin invitation, because
ensure/admin_user.rb creates the administrator itself, and tos_version,
which the terms-of-service page sets when the next task creates it. Name and
reference prefix come from DECIDIM_ORGANIZATION_NAME, the host from the same
domain the other tasks use.

The task runs only where the seeds skip, with ENVIRONMENT == 'production'. In
development nothing changes, and a seed that fails there still surfaces at the
next task instead of being covered by a bare organization.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-10 10:53:55 +02:00

27 lines
1.1 KiB
Ruby

# nocheck: mirrored-unit-test - runs in the Decidim console against Decidim::Organization; the model only exists once Rails has booted
organization = Decidim::Organization.first
if organization
puts "Organization present: #{organization.host}"
else
name = ENV.fetch("DECIDIM_ORG_NAME")
ActiveRecord::Base.transaction do
organization = Decidim::Organization.create!(
name: { Decidim.default_locale => name },
host: ENV.fetch("DECIDIM_ORG_HOST"),
reference_prefix: name,
default_locale: Decidim.default_locale,
available_locales: Decidim.available_locales,
available_authorizations: [],
external_domain_allowlist: ["decidim.org", "github.com"],
users_registration_mode: :enabled,
badges_enabled: true,
send_welcome_notification: true,
file_upload_settings: Decidim::OrganizationSettings.default(:upload),
colors: { primary: "#53bf40", secondary: "#4053bf", tertiary: "#bf4053" }
)
Decidim::System::CreateDefaultHelpPages.call(organization)
Decidim::System::CreateDefaultContentBlocks.call(organization)
end
puts "Organization created: #{organization.host}"
end