LCFS - Integrate CI applications into shared internal_comments system
- Dominant language
- Python
- Stars
- 6
- Forks
- 6
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 87
Description
**Describe the task**
Move the CI application comment thread (Step 5 — Government decision) off its current JSONB-on-history implementation and onto the shared internal_comments framework already used by transfers, transactions, and compliance reports. This gives CI applications the same comment capabilities those flows already enjoy: rich-text editing (ReactQuill), edit history, visibility toggle (Internal/Public for gov, Public-only for BCeID), and the standard `` widget.
**Purpose**
Today's Step 5 comments are a minimal piggyback on `ci_application_history` JSONB rows — no edit, no rich text, no visibility scoping, custom data shape. The product expectation is parity with how compliance reports do comments (commented on by both gov and BCeID, with edit + styling). Reusing the existing component is the right answer; the work is in the backend wiring to support a new entity type.
**Acceptance Criteria**
- [ ] `EntityTypeEnum` in `internal_comment/schema.py` includes `CI_APPLICATION = "ciApplication"`.
- [ ] New `CIApplicationInternalComment` association model + table (mirrors `ComplianceReportInternalComment` + `TransferInternalComment`).
- [ ] Alembic migration creates the join table with FKs to `ci_application.ci_application_id` and `internal_comment.internal_comment_id` (ON DELETE CASCADE on both sides).
- [ ] `internal_comment/repo.py` `create_internal_comment` and `get_internal_comments` branching extended to handle the new entity type.
- [ ] `internal_comment/services.py` visibility-rule branching updated so CI applicants (BCeID) can create and read Public comments on their own CI applications (similar to ComplianceReport rule).
- [ ] Backend access control: a CI applicant can only see/post comments on a CI application that belongs to their organization; gov users can see/post on any.
- [ ] Frontend `GovernmentDecisionStep.jsx` replaces the inline comment UI with ``.
- [ ] `useGetCIComments` and `useAddCIComment` hooks deleted; corresponding `/comments` routes on the CI application views removed.
- [ ] One-time data migration of any existing JSONB comment rows in `ci_application_history` into the new `internal_comment` + `ci_application_internal_comment` tables (preserving author, timestamp, text). If none exist in prod yet, document that in the migration.
- [ ] Tests updated: GovernmentDecisionStep test mocks the new widget; backend unit tests cover the new entity-type branch for create + list + edit; visibility-rule tests cover BCeID Public-only on CI applications.
**Additional context**
- Current implementation references:
- Backend storage: `backend/lcfs/web/api/ci_application/repo.py:300-340` (`add_comment` / `list_comments`)
- Backend service: `backend/lcfs/web/api/ci_application/services.py:631-680`
- Frontend Step 5 widget: `frontend/src/views/CarbonIntensity/components/GovernmentDecisionStep.jsx`
- Pattern to mirror:
- Compliance reports: `backend/lcfs/web/api/internal_comment/repo.py:91-95` + `db/models/comment/ComplianceReportInternalComment.py`
- Frontend usage: `frontend/src/views/ComplianceReports/EditViewComplianceReport.jsx` line ~891
- Use `commentMode="dual"` (matches transfers/transactions) so both BCeID and gov can post; gov toggles visibility, BCeID is locked to Public.
Contributor guide
Research direction
Start with backend/lcfs/web/api/ci_application/repo.py:300-340 and services.py:631-680, then compare the internal_comment repo, services, and ComplianceReportInternalComment patterns cited in the issue. Update the GovernmentDecisionStep.jsx integration and the related backend/frontend tests; done means CI applications use the shared Comments widget, enforce the stated visibility and organization rules, and migrate or document existing JSONB comments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, python, react
- Domain
- backend, databases, frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100