autolab / Autolab

Course management service that enables auto-graded programming assignments.
http://www.autolabproject.com/
Apache License 2.0
757 stars 215 forks source link

Order assessment attachments correctly #2145

Closed NicholasMy closed 5 months ago

NicholasMy commented 5 months ago

Description

This update fixes the sorting order of assessment attachments.

Motivation and Context

When rendering attachments on the assessment page, they're ordered how the database returns them instead of by the desired "release_at ASC, name ASC" ordering constant. Course attachments are correct and it already calls .ordered in the same way I did here. If an instructor wants to re-order attachments, they currently need to delete them and re-upload them. This fix would allow them to only update the release date to re-order them. I also believe this was the intended behavior, but forgetting to call .ordered was an oversight.

How Has This Been Tested?

I created two course attachments, A and B, with B's release date after A's. I verified B appears after A in the list. I updated B's release date to be before A's. I verified B appears before A in the list.

Types of changes

Potentially breaking change: Some instructors may depend on the "manual" method of ordering attachments as described above. That was ultimately a bug, and it never should have behaved that way, but maybe this should wait until the semester is over.

Checklist:

Summary by CodeRabbit

coderabbitai[bot] commented 5 months ago
Walkthrough ## Walkthrough The recent update in the codebase focuses on enhancing the attachment handling logic within the `assessments_controller` to cater to user roles effectively. This refinement ensures a more structured approach to fetching and ordering attachments based on user roles. ## Changes | File | Summary of Changes | |------|--------------------| | `app/controllers/assessments_controller.rb`
`app/views/assessments/index.html.erb` | - Updated attachment fetching logic in the `show` method of the controller to include additional ordering based on user role.
- Removed the `ordered` method call in the view template, impacting attachment fetching logic related to categories. |

Recent Review Details **Configuration used: CodeRabbit UI**
Commits Files that changed from the base of the PR and between 7823e9f46f1ba68cfdfc68e47f2bad5d0b7acf58 and 32cd3d7877d54c7738032c158ca8c0c80686749c.
Files selected for processing (2) * app/controllers/assessments_controller.rb (2 hunks) * app/views/assessments/index.html.erb (1 hunks)
Files skipped from review as they are similar to previous changes (1) * app/controllers/assessments_controller.rb
Additional comments not posted (1)
app/views/assessments/index.html.erb (1)
`198-198`: Ensure backend ordering is correctly implemented.
Verification successful --- The backend ordering logic for attachments appears to be correctly implemented. The `.ordered` scope is actively used in various controller files for handling attachments, which aligns with the expected behavior following the removal of `.ordered` from the view layer. This confirms that the ordering is managed at the controller or model level, ensuring that the data is correctly ordered before reaching the view.
Scripts Executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Verify that the backend ordering logic for attachments is correctly implemented. # This script checks for the presence of the `.ordered` scope in the `CourseAttachment` model. rg --type ruby --glob '*_controller.rb' '.ordered' ``` Length of output: 899
--- 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.
damianhxy commented 5 months ago

Thanks for catching this - it was an oversight on my part

Just a thought: course attachments are ordered on the course page due to @course_attachments.from_category(cat).ordered.

For consistency, I think either

  1. course attachments should be ordered on the backend instead, inside assessments_controller.rb#index
  2. assessment attachments should be ordered on the frontend instead, e.g. render @attachments.ordered

Option (1) is probably better, in which case the same .ordered scope should be applied when defining @course_attachments. This presumes that applying a where filter (via from_category) preserves order, although I can't find anything information online regarding this.

What do you think?

NicholasMy commented 5 months ago

I originally experimented with option 2 while I was tracing the source of the lack of ordering, but I settled on option 1 (for assessment attachments) because I can't think of a scenario where we'd want the unordered attachments. I think doing the same for course attachments makes sense.

where appears to preserve the order, but I also can't find any concrete confirmation online. I tested making these modifications. If I keep the incorrect order (by not calling ordered anywhere) and apply the where, it keeps the incorrect order. The SQL query doesn't include any ordering:

SELECT `attachments`.* FROM `attachments` WHERE `attachments`.`course_id` = 28 AND `attachments`.`assessment_id` IS NULL AND `attachments`.`category_name` = 'General3'

If I correctly order them before applying the where, it keeps the correct order, and the resulting SQL still explicitly orders it, so I don't think this is a coincidence.

SELECT `attachments`.* FROM `attachments` WHERE `attachments`.`course_id` = 28 AND `attachments`.`assessment_id` IS NULL AND `attachments`.`category_name` = 'General3' ORDER BY release_at ASC, name ASC
damianhxy commented 5 months ago

I think doing the same for course attachments makes sense.

That sounds good to me, could you make the change to order course attachments on the backend too?

If I correctly order them before applying the where, it keeps the correct order, and the resulting SQL still explicitly orders it, so I don't think this is a coincidence.

In that case, I think it's safe to remove the ordering for course attachments on the frontend. Thanks for investigating this!

NicholasMy commented 5 months ago

No problem, how does this look?