Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order assessment attachments correctly #2145

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

NicholasMy
Copy link
Contributor

@NicholasMy NicholasMy commented Apr 11, 2024

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

  • Bug fix (non-breaking change which fixes an issue)

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:

  • I have run rubocop and erblint for style check. If you haven't, run overcommit --install && overcommit --sign to use pre-commit hook for linting
  • My change requires a change to the documentation, which is located at Autolab Docs
  • I have updated the documentation accordingly, included in this PR

Summary by CodeRabbit

  • Bug Fixes
    • Updated the attachment fetching logic in assessments to include ordering based on user role, enhancing usability and accessibility.

Copy link
Contributor

coderabbitai bot commented Apr 11, 2024

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 7823e9f and 32cd3d7.
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:

#!/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
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@damianhxy
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Contributor Author

No problem, how does this look?

Copy link
Member

@damianhxy damianhxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested that attachments are ordered as expected on course / assessment pages

LGTM!

@damianhxy damianhxy added this pull request to the merge queue Apr 15, 2024
Merged via the queue into autolab:master with commit e0c5a05 Apr 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants