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

Quiz exercises: Disable practice mode for imported exercises #9683

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

Hialus
Copy link
Member

@Hialus Hialus commented Nov 6, 2024

Checklist

General

Server

  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I documented the Java code using JavaDoc style.

Motivation and Context

We encountered the case that the practice mode was active for quiz exercises, despite no instructor pressing the button to release it for practice. After some digging I found out that this was, because the flag for this is kept when importing quiz exercises. This means that importing quiz exercises that have the practice mode enabled, will result in a quiz exercise that also has the flag enabled, even before the quiz has even started. Once the quiz ended, the practice mode will immediately be available.

Description

I fixed one line where the old flag was copied and instead ensure that it is false

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 2 Students
  • 1 Programming Exercise with Complaints enabled
  1. Log in to Artemis
  2. Create a quiz
  3. Start the quiz
  4. Start the practice mode after quiz ended
  5. Import the quiz exercise
  6. Start the imported quiz
  7. Wait for it to finish
  8. Quiz is immediately open for practice

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Unchanged

Summary by CodeRabbit

  • New Features

    • Imported quiz exercises will now default to being closed for practice, regardless of their original settings.
  • Bug Fixes

    • Adjusted the behavior of the quiz exercise import process to ensure consistent initialization for practice availability.
  • Tests

    • Enhanced test coverage for quiz exercise import functionality, including new tests for the isOpenForPractice field and validation of import processes between different contexts.

@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) quiz Pull requests that affect the corresponding module labels Nov 6, 2024
@Hialus Hialus marked this pull request as ready for review November 6, 2024 14:44
@Hialus Hialus requested a review from a team as a code owner November 6, 2024 14:44
@Hialus Hialus added this to the 7.7.0 milestone Nov 6, 2024
@ls1intum ls1intum deleted a comment from github-actions bot Nov 6, 2024
@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Nov 6, 2024
@Hialus Hialus removed the deployment-error Added by deployment workflows if an error occured label Nov 6, 2024
Copy link

coderabbitai bot commented Nov 6, 2024

Walkthrough

The QuizExerciseImportService class has been modified to change the behavior of the copyQuizExerciseBasis method. The isOpenForPractice property of the QuizExercise object is now set to false unconditionally during the import process, ensuring that all imported quiz exercises will not be open for practice, regardless of their original state. The overall control flow and error handling mechanisms remain unchanged, with no new exceptions introduced or existing ones modified.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java Modified copyQuizExerciseBasis method to unconditionally set isOpenForPractice to false.
src/test/java/de/tum/cit/aet/artemis/quiz/QuizExerciseIntegrationTest.java Added and modified tests to verify the behavior of the new isOpenForPractice field and import functionality.

Possibly related PRs

Suggested labels

feature, bugfix, component:Quiz

Suggested reviewers

  • krusche
  • az108

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7a618f8 and 38aed0e.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java (1 hunks)
  • src/test/java/de/tum/cit/aet/artemis/quiz/QuizExerciseIntegrationTest.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java
🧰 Additional context used
📓 Path-based instructions (1)
src/test/java/de/tum/cit/aet/artemis/quiz/QuizExerciseIntegrationTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

🔇 Additional comments (2)
src/test/java/de/tum/cit/aet/artemis/quiz/QuizExerciseIntegrationTest.java (2)

1245-1245: Properly setting up the initial state for practice mode

Setting quizExercise.setIsOpenForPractice(true); ensures that the quiz exercise initially has practice mode enabled before the import operation. This setup is essential to verify that the import process correctly disables practice mode.


1265-1265: Assertion correctly verifies practice mode is disabled after import

The assertion assertThat(importedExercise.isIsOpenForPractice()).isFalse(); confirms that the isOpenForPractice flag is set to false after importing the quiz exercise. This effectively tests that the import process resets the practice mode as intended.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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

@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: 0

🧹 Outside diff range and nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java (1)

116-118: Add a comment explaining the practice mode behavior.

Consider adding a comment to explain why practice mode is explicitly disabled during import, making it clear this is intentional behavior rather than a default value.

+        // Practice mode is intentionally disabled on import to prevent immediate access after quiz ends
         newExercise.setIsOpenForPractice(false);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fdc2501 and 7a618f8.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

🔇 Additional comments (1)
src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java (1)

117-117: LGTM! Verify practice mode behavior.

The change correctly implements the requirement to disable practice mode for imported exercises by explicitly setting isOpenForPractice to false.

Let's verify that this is the only place where practice mode is set during import:

✅ Verification successful

Practice mode is correctly disabled during import

The verification confirms that setIsOpenForPractice(false) in QuizExerciseImportService.copyQuizExerciseBasis() is the only place where practice mode is set during the import process. Other occurrences of setIsOpenForPractice in the codebase are used in different contexts:

  • Test cases and mock data setup
  • Quiz exercise initialization
  • Quiz exercise reset functionality
  • Practice mode management endpoints

The change aligns with the codebase's behavior and doesn't conflict with other functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any other potential locations where practice mode might be set during import
rg -l "setIsOpenForPractice|isOpenForPractice" | xargs -I {} rg -A 5 -B 5 "setIsOpenForPractice|isOpenForPractice" {}

Length of output: 17630

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 6, 2024
Copy link
Contributor

@MarkusPaulsen MarkusPaulsen left a comment

Choose a reason for hiding this comment

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

Tested importing a quiz with an activated open-for-practice mode on TS5. As expected, the open-for-practice mode was not activated in the imported quiz. Code looks also good.

Copy link

@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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7a618f8 and 38aed0e.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java (1 hunks)
  • src/test/java/de/tum/cit/aet/artemis/quiz/QuizExerciseIntegrationTest.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/de/tum/cit/aet/artemis/quiz/service/QuizExerciseImportService.java
🧰 Additional context used
📓 Path-based instructions (1)
src/test/java/de/tum/cit/aet/artemis/quiz/QuizExerciseIntegrationTest.java (1)

Pattern src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

🔇 Additional comments (1)
src/test/java/de/tum/cit/aet/artemis/quiz/QuizExerciseIntegrationTest.java (1)

1265-1265: Duplicate Getter Method Naming Issue

The method isIsOpenForPractice() arises due to the field being named isOpenForPractice, leading to a redundant 'is' in the method name. Renaming the field to openForPractice will produce the cleaner and more conventional getter isOpenForPractice().

Copy link

@sachmii sachmii left a comment

Choose a reason for hiding this comment

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

Tested on TS5, practice mode did not start after finishing an imported practice-mode-on quiz.

Copy link
Contributor

@muradium muradium left a comment

Choose a reason for hiding this comment

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

Tested on TS5, problem doesn't occur anymore. Code looks good as well

Copy link
Contributor

@dmytropolityka dmytropolityka left a comment

Choose a reason for hiding this comment

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

I tested importing a quiz with open-for-practice mode enabled on TS5. Works as expected.

Copy link
Member

@bensofficial bensofficial left a comment

Choose a reason for hiding this comment

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

Code changes look good to me.

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

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

Tested on TS5. Practice mode didnt start for imported exercise

@krusche krusche added the maintainer-approved The feature maintainer has approved the PR label Nov 7, 2024
@krusche krusche merged commit b42126a into develop Nov 7, 2024
60 of 67 checks passed
@krusche krusche deleted the bugfix/quiz/disable-practice-on-import branch November 7, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer-approved The feature maintainer has approved the PR quiz Pull requests that affect the corresponding module ready to merge server Pull requests that update Java code. (Added Automatically!) tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants