Skip to content

Add optional organization association to workshops and workshop ideas… - #2747

Open
1steve78 wants to merge 8 commits into
rubyforgood:mainfrom
1steve78:add-organization-to-workshop-and-ideas
Open

1steve78 wants to merge 8 commits into
rubyforgood:mainfrom
1steve78:add-organization-to-workshop-and-ideas

Conversation

@1steve78

@1steve78 1steve78 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2695

Summary

Workshop variation ideas and story ideas record which organization they originated from, but workshop ideas did not have an organization_id column or dropdown.

This PR implements organization tracking on workshop_ideas and workshops, following the #2693 scoping pattern:

  • Users with a single active affiliation have their organization automatically populated via a hidden field.
  • Users with multiple active affiliations (and admins, who see all organizations) are presented with an organization dropdown.
  • The organization field is optional on both models.
  • When promoting a WorkshopIdea to a Workshop, the organization_id is retained.
  • The organization is displayed on the index and show views for both WorkshopIdea and Workshop.

Key Changes

  1. Migrations & Schema

    • Added organization:references (type: :integer, null: true, foreign_key: true) to workshop_ideas.
    • Added organization:references (type: :integer, null: true, foreign_key: true) to workshops.
  2. Models

    • WorkshopIdea: Added belongs_to :organization, optional: true.
    • Workshop: Added belongs_to :organization, optional: true.
    • Organization: Added has_many :workshop_ideas and direct has_many :workshops.
  3. Controllers & Promotion

    • WorkshopIdeasController & WorkshopsController: Scoped @organizations in set_form_variables using authorized_scope(Organization.all, as: :currently_affiliated).order(:name) and permitted :organization_id in strong parameters.
    • WorkshopFromIdeaService: Preserves organization_id when promoting a WorkshopIdea to a Workshop.
  4. Views & Forms

    • workshop_ideas/_form.html.erb & workshops/_form.html.erb: Implemented the #2693 dropdown pattern (hidden input when @organizations.size == 1, select prompt when > 1 or admin).
    • workshop_ideas/show.html.erb & workshop_ideas/index.html.erb: Displays organization name / link.
    • workshops/_show_header.html.erb & workshops/_index_row.html.erb: Displays organization name / link.
  5. Tests

    • spec/models/workshop_idea_spec.rb & spec/models/workshop_spec.rb: Verified association and validity with and without an organization.
    • spec/models/organization_spec.rb: Verified have_many associations.
    • spec/services/workshop_from_idea_service_spec.rb: Verified organization_id persistence upon idea promotion.
    • spec/requests/workshop_ideas_spec.rb & spec/requests/workshops_spec.rb: Added admin and regular user request specs covering index, show, form rendering (hidden field vs dropdown), and CRUD actions.

How to Test

  1. Run migrations: bin/rails db:migrate
  2. Run test suites:
    • bundle exec rspec spec/models/workshop_idea_spec.rb spec/models/workshop_spec.rb spec/services/workshop_from_idea_service_spec.rb
    • bundle exec rspec spec/requests/workshop_ideas_spec.rb spec/requests/workshops_spec.rb
  3. Manual verification:
    • Sign in as an admin -> navigate to /workshop_ideas/new -> verify all organizations appear in the Organization dropdown with a prompt.
    • Sign in as a user with 1 active organization affiliation -> navigate to /workshop_ideas/new -> verify the organization dropdown is hidden and populated with the user's active organization.
    • Create a WorkshopIdea with an organization and promote it to a Workshop -> verify the new Workshop preserves the organization.
    • Visit show and index pages for both WorkshopIdea and Workshop with and without an organization to verify graceful rendering.

Verification

  • All RSpec tests pass (232 model/service specs, 67 request specs)
  • RuboCop passed with 0 offenses
  • Brakeman security scan passed with 0 warnings

1steve78 and others added 5 commits October 18, 2026 18:55
…rubyforgood#2695)

- Add nullable organization_id references to workshop_ideas and workshops tables

- Add belongs_to :organization, optional: true to WorkshopIdea and Workshop

- Update Organization with direct has_many :workshops and has_many :workshop_ideas

- Load scoped organizations in WorkshopIdeasController and WorkshopsController forms using currently_affiliated policy scope

- Preserve organization_id when promoting WorkshopIdea to Workshop in WorkshopFromIdeaService

- Update forms to follow rubyforgood#2693 pattern (single org hidden field vs multiple org select dropdown)

- Display organization on index and show views for WorkshopIdea and Workshop

- Add comprehensive unit, service, and request specs
- Guard @organizations with fallback to empty array to avoid NoMethodError when unassigned

- Update view specs to assign :organizations and verify organization_id select
- Set ActiveRecord::Schema version to 2026_10_18_123640 in db/schema.rb so parallel_rspec and test database setup recognize migrations as applied
# has_many through
has_many :categories, through: :categorizable_items
has_many :sectors, through: :sectorable_items
has_many :workshops, through: :users

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't in the spec, but on org profile we should put both workshops/ideas that are directly connected to the organization, and, also pull through the Affiliation > Person > Workshops/ideas authored (not user_id). would you be ok to add that this this pr so the list that shows on Org profile shows directly and indirectly associated workshops and ideas?

required: false,
disabled: promoted_to_workshop,
prompt: "Select organization",
selected: (params[:organization_id].presence || f.object.organization_id),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need include_blank: "Select organization" so they can remove an org/leave it blank

@maebeale

Copy link
Copy Markdown
Collaborator

thanks for working on this, @1steve78 ! left a few comments. and, would you add a seeds features file for this?

@1steve78

Copy link
Copy Markdown
Contributor Author

Thanks for the review! I'll address all three comments by adding directly and indirectly associated workshops and ideas to the organization profile, allowing the organization field to be cleared using include_blank, and adding a feature spec for the new functionality. I'll also resolve the db/schema.rb merge conflict and run the relevant tests before pushing the updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an organization to workshop ideas

2 participants