igorsimb / mp-monitor

Django app for scraping Wildberries
1 stars 0 forks source link

fix(forms): remove "seconds" and "minutes" for non-staff and non-superusers #121

Closed igorsimb closed 2 months ago

igorsimb commented 2 months ago

Fixes #120 Note that any initialization of ScrapeIntervalForm now requires user parameter, e.g.: scrape_interval_form = ScrapeIntervalForm(user=request.user)

Summary by CodeRabbit

coderabbitai[bot] commented 2 months ago
Walkthrough ## Walkthrough The recent updates focus on refining user access and testing capabilities within a Django application. Key changes include restricting time interval options in a dropdown menu to only staff and superusers, updating terminology in the UI, and enhancing test coverage to validate these modifications. These adjustments improve both the usability for regular users and the flexibility for administrative testing. ## Changes | File Path | Change Summary | |-------------------------|-----------------------------------------------------------------------------------------------------| | `main/forms.py`
`main/views.py` | - Added user model initialization.
- Modified `ScrapeIntervalForm` to restrict time choices for non-privileged users. | | `main/.../base.html` | - Updated the text for the login link from "Логин" to "Войти". | | `tests/main/.../test_main_forms.py`
`tests/main/.../test_main_views.py` | - Enhanced testing for user roles and form data.
- Updated test logic to reflect changes in time period handling. | ## Assessment against linked issues | Objective | Addressed | Explanation | |---------------------------------------------------------------------------|-----------|-----------------------------------------------------------------------------------------------------| | Keep "seconds" and "minutes" in `period` dropdown menu only for staff and superusers (#120) | ✅ | |

Recent Review Details **Configuration used: CodeRabbit UI**
Commits Files that changed from the base of the PR and between 4579c0a2a14b24349b79505bb62a37ad5d084bdd and 966d27668d1327a5ac7db58aaee3a8f099b9ea81.
Files selected for processing (5) * main/forms.py (2 hunks) * main/templates/main/base.html (1 hunks) * main/views.py (5 hunks) * tests/main/test_main_forms.py (3 hunks) * tests/main/test_main_views.py (1 hunks)
Additional comments not posted (8)
main/forms.py (1)
`44-58`: Ensure that the `user` is always passed when instantiating `ScrapeIntervalForm`. The form now depends on the `user` being passed to function correctly. It would be prudent to add checks or documentation in all places where this form is instantiated to ensure that the `user` is always provided. This can prevent runtime errors from a missing `user` argument.
tests/main/test_main_forms.py (2)
`48-67`: Parameterized tests in `TestTaskForm` enhance coverage and maintainability. The addition of parameterized tests for different interval values is a good practice as it ensures that various edge cases are automatically tested, making the tests easier to extend and maintain. --- `95-118`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [71-118] Role-based tests in `TestScrapeIntervalForm` correctly verify dropdown choices. The implementation of tests to verify the dropdown choices based on user roles is essential for ensuring that the form behaves as expected. Using a constant for defining choices is a good practice as it centralizes the choice definitions, making the tests more maintainable.
main/templates/main/base.html (1)
`67-67`: Text change in login link improves language consistency. The update from "Логин" to "Войти" in the login link is a minor but meaningful change that improves the consistency or preference in language use within the application.
main/views.py (3)
`57-57`: Correct implementation of user role-based form instantiation in `ItemListView`. Passing the `user` to `ScrapeIntervalForm` in the `ItemListView` ensures that the form's behavior is correctly adjusted based on the user's role, aligning with the PR's objectives. --- `186-192`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [189-279] Proper handling of form instantiation and error scenarios in `create_scrape_interval_task`. The view correctly handles the instantiation of `ScrapeIntervalForm` with the `user`, and includes comprehensive error handling and user feedback mechanisms. This ensures robustness and a good user experience. --- `297-303`: > :memo: **NOTE** > This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [300-327] Correct user role handling and form validation in `update_scrape_interval`. The view correctly handles the instantiation of `ScrapeIntervalForm` with the `user` and includes proper form validation and task argument updating. This ensures that the application behaves as expected based on user roles.
tests/main/test_main_views.py (1)
`494-494`: Update in `valid_form_data` aligns tests with new form logic. The change from "seconds" to "hours" in the `valid_form_data` function ensures that the tests are consistent with the updated logic in `ScrapeIntervalForm`, reflecting the application's current behavior accurately.
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.