feat: create Students/Coaches groups on chapter creation - #2824
Merged
mroderick merged 5 commits intoAug 31, 2026
Conversation
mroderick
added a commit
that referenced
this pull request
Aug 30, 2026
Addresses ce-code-review findings on PR #2824: - (P0) Admin::ChaptersController#create persisted the chapter and groups before Pundit authorize, so a chapter-scoped organiser was denied after commit, leaving phantom data. Authorize the unsaved chapter first, as #new and the pre-refactor code did, with a denial regression spec. - The 'rolls back chapter if groups fail' spec never forced a group failure (a blank chapter name failed chapter.save! first). Force a real Group inclusion-validation failure and assert the saved chapter is rolled back; the chapter-validation example is kept separately under its true name. - Added a feature scenario for the create failure branch: an invalid form re-renders with validation errors and persists nothing. Verified: 51 examples, 0 failures; rubocop clean on changed files.
mroderick
force-pushed
the
feature/auto-create-groups-on-chapter-creation
branch
from
August 30, 2026 18:21
8147e39 to
cbbefdd
Compare
ChapterCreationService wraps chapter + groups creation in a single transaction, so a new chapter always has its required Students and Coaches groups (issue #2823). Missing groups meant no subscription buttons on the chapter page and workshop invitations silently sent to zero members. - Admin::ChaptersController#create authorizes the unsaved chapter before calling the service, so a denied request persists nothing - The service rolls back the chapter if group creation fails - Service spec proves the rollback with a real group validation failure; controller spec covers the denial path; feature spec covers group creation and the invalid-form failure branch
mroderick
force-pushed
the
feature/auto-create-groups-on-chapter-creation
branch
from
August 30, 2026 18:27
cbbefdd to
2325fd7
Compare
Now that every chapter gets its Students and Coaches groups automatically on creation, the manual group creation flow is dead code (follow-up to #2823). - Remove Admin::GroupsController#new/#create and the new.html.haml view (also drops the last Chosen-enhanced admin <select>) - Remove the "New group" link from the admin menu - Remove the new/create group routes, plus the already-stale index route (the controller has no index action) - Remove GroupPolicy#create? and its spec coverage - Remove the admin group creation feature spec Kept: the group show page (members, eligible count, subscriptions). Deferring the chapter_with_groups fabricator fold into the base chapter fabricator - it touches ~63 Fabricate(:chapter) call sites and belongs in its own cleanup. Stacked on feature/auto-create-groups-on-chapter-creation (PR #2824).
mroderick
marked this pull request as ready for review
August 30, 2026 18:49
…ation refactor: remove manual group creation UI
| @@ -0,0 +1,17 @@ | |||
| class ChapterCreationService | |||
| Result = Struct.new(:chapter, :success, :errors, keyword_init: true) | |||
Collaborator
There was a problem hiding this comment.
Not a blocker, but can use Data.define rather than Struct.new to make this class, I guess.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Creating a chapter via
/admin/chapters/newdid not automatically create the required Students and Coaches groups. Admins had to manually visit/admin/groups/newtwice to create them.This caused:
@chapter.groups)Solution
Added
ChapterCreationServicethat creates chapter + groups in a single transaction:Admin::ChaptersController#createauthorizes the unsaved chapter before calling the service, so a denied request persists nothingChanges
app/services/chapter_creation_service.rb— service object with transactionspec/services/chapter_creation_service_spec.rb— unit tests, including a real group-failure rollback testAdmin::ChaptersController#create— authorizes first, then delegates to the serviceTesting
All tests pass (51 examples, 0 failures). Code-reviewed with ce-code-review: the initial implementation persisted before authorizing (a chapter-scoped organiser would be denied after the commit, leaving phantom data) — fixed and covered by the denial regression spec.
Follow-up
Once merged, can remove the manual group creation UI (
admin/groups/new,Admin::GroupsController#new/#create, and the admin menu link) as a separate PR.Related
#2823 — Auto-create Students and Coaches groups when a new chapter is created (linked only — this PR intentionally does not close the issue; the follow-up that removes the manual group creation UI will)