Project: show search settings in separate form#12843
Open
Conversation
Member
Author
|
@copilot write a test for this view |
Contributor
…ew bugs (#12844) `ProjectSearchSettingsUpdate` had no tests and contained two bugs that were caught while writing them. ## Bugs fixed - **Missing `PrivateViewMixin`**: The view didn't inherit from `PrivateViewMixin`, so unauthenticated users were never redirected to login — they'd hit `get_object_or_404` directly and get a 404 instead of a redirect. - **`get_success_url()` crash on POST**: Used `self.object.slug`, but Django's `ModelFormMixin.form_valid()` reassigns `self.object = form.save()` — and since the form saves an `AddonsConfig` instance (not `Project`), this raised `AttributeError: 'AddonsConfig' object has no attribute 'slug'`. Fixed to use `self.get_project().slug`. ## Tests added `TestProjectSearchSettingsUpdate` in `readthedocs/projects/tests/test_views.py`: - `test_get_returns_200_for_admin` - `test_get_returns_404_for_non_admin` - `test_get_redirects_unauthenticated_user` - `test_post_updates_search_settings` — verifies `AddonsConfig.search_enabled` and `search_show_subprojects_filter` are persisted and redirects to the form URL - `test_post_updates_partial_search_settings` — verifies partial field updates work correctly ## Template Added a placeholder `projects/search_settings_form.html` following the same pattern as `pull_requests_form.html` (real implementation lives in ext-theme). <!-- START COPILOT CODING AGENT TIPS --> --- 📍 Connect Copilot coding agent with [Jira](https://gh.io/cca-jira-docs), [Azure Boards](https://gh.io/cca-azure-boards-docs) or [Linear](https://gh.io/cca-linear-docs) to delegate work to Copilot in one click without leaving your project management tool. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stsewd <4975310+stsewd@users.noreply.github.com>
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.
I didn't include the option to disable search indexing here since its from a separate model and it's only shown when we have disabled search indexing, but isn't that complex to integrate if we wanted 11f16a1.
Closes #11533
Requires readthedocs/ext-theme#709