## Implementation Plan: Dynamic Comment Max Length via Env Config ### Files to Modify | # | File | Change | |---|------|--------| | 1 | `devplacepy/config.py` | Add `COMMENT_MAX_LENGTH = int(environ.get("DEVPLACE_COMMENT_MAX_LENGTH", "1000"))` | | 2 | `devplacepy/templating.py` | Inject `comment_max_length` as a Jinja2 global: `from devplacepy.config import COMMENT_MAX_LENGTH` and add to `globals` dict | | 3 | `devplacepy/models.py` | Replace `max_length=1000` in `CommentForm.content` (line 160) and `CommentEditForm.content` (line 175) with `max_length=COMMENT_MAX_LENGTH` (import from config) | | 4 | `devplacepy/templates/_comment_form.html` | Change `maxlength="1000"` to `maxlength="{{ comment_max_length }}"` | | 5 | `devplacepy/static/js/CommentManager.js` | In the inline-edit textarea creation (lines 81-86), add `textarea.maxLength = ...` reading from a data attribute (e.g., `data-maxlength` on the nearest container) or from a global JS variable set in the template. For simplicity, pass `comment_max_length` via a hidden element or a `data-maxlength` on the `
` element. | | 6 | `devplacepy/routers/devrant/rants.py` | Replace hardcoded `1000` with `config.COMMENT_MAX_LENGTH` (import from config) on line 230 | | 7 | `devplacepy/routers/devrant/comments.py` | Replace hardcoded `1000` with `config.COMMENT_MAX_LENGTH` on line 72 | | 8 | `devplacepy/services/devii/actions/catalog/comments.py` | Make the description string dynamic: replace `"3-1000 characters."` with `f"3-{config.COMMENT_MAX_LENGTH} characters."` | | 9 | `devplacepy/docs_devrant.py` | Replace `"1-1000 chars."` with `f"1-{config.COMMENT_MAX_LENGTH} chars."` (line 240) | | 10 | `devplacepy/docs_api/groups/content.py` | Replace `"3-1000 characters."` in both endpoint descriptions (lines 232, 293) with `f"3-{config.COMMENT_MAX_LENGTH} characters."` | | 11 | `.env.example` | Add line: `DEVPLACE_COMMENT_MAX_LENGTH=1000` with a comment | | 12 | `README.md` | Add row in environment variables table: `DEVPLACE_COMMENT_MAX_LENGTH` – default `1000`, description "Max length of comment text" | | 13 | `tests/api/comments/create.py` | Add `test_create_comment_too_long_rejected` – send comment with body > `COMMENT_MAX_LENGTH` (use config value, e.g. 1001), expect 422 | | 14 | `tests/api/comments/edit.py` | Add `test_edit_comment_too_long_rejected` – edit a comment with body > `COMMENT_MAX_LENGTH`, expect 422 | | 15 | (optional) `tests/api/devrant/comments.py` | Add max-length rejection test for devRant comment endpoint | | 16 | (optional) `tests/api/devrant/rants.py` | Add max-length rejection test for devRant rant comment endpoint | ### Implementation Notes - The inline-edit JS fix: embed the value in the base template (e.g. ``), then in `CommentManager.js` read `document.getElementById('comment-max-length').dataset.value`. - All Python files importing `config` must do `from devplacepy.config import COMMENT_MAX_LENGTH`. - The config value is live-changeable only via environment variable restart; no runtime reload is required per ticket. - Do **not** change issue comment models (they stay at 5000). ### Definition of Done - [ ] All 9 hardcoded occurrences of `1000` (or `1000` in strings) in the source files listed above are replaced with the config value. - [ ] Client-side inline-edit textarea has `maxLength` attribute set to the config value. - [ ] `.env.example` and `README.md` document the new variable. - [ ] All existing unit tests pass (including devRant tests). - [ ] New API tests `test_create_comment_too_long_rejected` and `test_edit_comment_too_long_rejected` pass. - [ ] The project's own verification commands succeed: - `pip install -e '.[dev]' -q` (if needed, create a virtualenv first to avoid PEP 668) - `make test-unit` (or `python3 -m pytest tests/unit/...`) – exit code 0 - `ruff check .` – exit code 0