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

Use slugs for attachments urls, add badge for direct writeup downloads #2144

Merged
merged 13 commits into from
Apr 25, 2024

Conversation

damianhxy
Copy link
Member

@damianhxy damianhxy commented Apr 6, 2024

Description

  • Generate slugged URLs for attachments
  • Allow direct download of writeups from course landing page
  • Fix highlighting on docs

Motivation and Context

Some classes might use assessments as "placeholders" to distribute course materials (via writeups), as compared to attachments, since assessments can be easily bulk imported and the URL is "static" (only need to change course name between semesters). This PR further facilitates that workflow by allowing students to quickly download an assessment writeup from a course landing page by clicking on a badge. This is also useful for students to view writeups of normal assessments quickly.

This PR also switches to slugged URLs for attachments, i.e. the URL is generated from the attachment name. This would be helpful down the road if a way were added to mass import attachments since attachments would become a viable replacement for assessments.

This PR also fixes a docs syntax highlighting issue introduced by #2131.

Resolves #2035

How Has This Been Tested?

Slugged Attachments

  • Create a new course / assessment attachment -> observe that the URL now uses the attachment name as a slug
  • Update the name of an attachment -> observe that the slug updates accordingly
  • Cause a name collision -> id appended to ensure uniqueness

Writeup badges

Screenshot 2024-04-25 at 01 58 14

Badge appears only for assessments with writeups. Clicking on the badge brings you to the writeup.

Docs highlighting

Run mkdocs serve locally and ensure that the bash commands on e.g. the docker compose installation page now render correctly.

Before
Screenshot 2024-04-20 at 15 42 22

After
Screenshot 2024-04-20 at 15 42 12

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

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

@damianhxy damianhxy marked this pull request as ready for review April 20, 2024 19:45
@damianhxy damianhxy requested review from a team and KesterTan and removed request for a team April 20, 2024 19:45
Copy link
Contributor

coderabbitai bot commented Apr 20, 2024

Walkthrough

Walkthrough

The update focuses on improving attachment management by introducing slug functionality for attachments based on their names, enhancing URL readability. Additionally, styling adjustments were made to the assessment date element for better visual presentation.

Changes

File Path Change Summary
app/models/attachment.rb Added slug generation based on name and dynamic slug regeneration
app/assets/stylesheets/assessment_date.scss Added padding-top: 4px; to element styling in assessment_date.scss

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 75633c5 and 5dfb00c.
Files selected for processing (1)
  • app/assets/stylesheets/assessment_date.scss (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/assets/stylesheets/assessment_date.scss

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

app/models/attachment.rb Outdated Show resolved Hide resolved
app/controllers/attachments_controller.rb Show resolved Hide resolved
@damianhxy damianhxy changed the title Use slugs for attachments Use slugs for attachments urls, add badge for direct writeup downloads Apr 20, 2024
Copy link
Contributor

@KesterTan KesterTan left a comment

Choose a reason for hiding this comment

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

Not sure if this is desired but when for existing attachments, the url does not include the attachment name, it only includes after I rename the attachment or upon creating a new attachment

@KesterTan
Copy link
Contributor

Also, is there a way to shorten the url in the case of duplicates, "test778-cf1a1964-f358-4cff-8136-8c9791b40ec6" this seems a little too long. Would it make sense if we generated a random string usingSecureRandom and took the difference to get a shortened slug that is still unique.

@damianhxy
Copy link
Member Author

Also, is there a way to shorten the url in the case of duplicates, "test778-cf1a1964-f358-4cff-8136-8c9791b40ec6" this seems a little too long. Would it make sense if we generated a random string usingSecureRandom and took the difference to get a shortened slug that is still unique.

Modified the code to tiebreak by appending the attachment's id

@damianhxy
Copy link
Member Author

Not sure if this is desired but when for existing attachments, the url does not include the attachment name, it only includes after I rename the attachment or upon creating a new attachment

That was intended and IMO it's fine, attachments don't seem to be widely used yet, and this change is more to facilitate attachments in future courses.

According to the documentation, you'd have to do something similar to User.find_each(&:save). If you feel like it's important to generate slugs retroactively, I could put this in the migration

Copy link
Contributor

@KesterTan KesterTan left a comment

Choose a reason for hiding this comment

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

Small nit: I think some padding top: maybe .date p { padding-top: 4px} would be even more perfect.

Copy link
Contributor

@KesterTan KesterTan left a comment

Choose a reason for hiding this comment

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

LGTM, everything works as expected (slugs look nice and clean gj!)

@damianhxy damianhxy added this pull request to the merge queue Apr 25, 2024
Merged via the queue into master with commit 586e7e9 Apr 25, 2024
5 checks passed
@damianhxy damianhxy deleted the slugged-attachments branch April 25, 2024 06:06
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.

Add API/CLI endpoint for attachments
2 participants