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

Programming exercises: Add ProgrammingExercise by ProjectKey endpoint #9406

Open
wants to merge 9 commits into
base: feature/re-key
Choose a base branch
from

Conversation

janthoXO
Copy link
Contributor

@janthoXO janthoXO commented Oct 1, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).
  • I tested all changes and their related features with all corresponding user types on a test server configured with Gitlab and Jenkins.

Description

Adds an endpoint that fetches a programming exercise by its projectKey

Steps for Testing

Postman testing or code review:
Postman Testing:

  1. Send a request to POST {{base_url}}/api/public/authenticate?tool=SCORPIO
  2. Send a request to GET {{base_url}}/api/courses/for-dashboard
  3. Take any projectKey from one of the exercises
  4. Send a request to GET {{base_url}}/api/programming-exercises/project-key/{{projectKey}}

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

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Class/File Line Coverage Confirmation (assert/expect)
ProgrammingExerciseResource 82%

Screenshots

Summary by CodeRabbit

  • New Features
    • Introduced a new endpoint to query programming exercises by project key, enhancing access to specific exercises for users with student roles.
  • Bug Fixes
    • Improved error handling by returning a 404 Not Found response when a programming exercise is not found.
      @coderabbitai pause

@janthoXO janthoXO self-assigned this Oct 1, 2024
@janthoXO janthoXO requested a review from a team as a code owner October 1, 2024 19:57
Copy link

coderabbitai bot commented Oct 1, 2024

Walkthrough

The pull request introduces a new method getExerciseByProjectKey in the ProgrammingExerciseResource class, allowing users to query a programming exercise by its project key. This method, annotated with @GetMapping("programming-exercises/project-key/{projectKey}"), requires a student role for access and retrieves a ProgrammingExercise using the programmingExerciseRepository.findOneByProjectKeyOrThrow(projectKey, false) method. If the exercise is found, it returns a ResponseEntity; otherwise, it triggers a 404 Not Found response. The existing methods remain unchanged.

Changes

Files Change Summary
src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.java Added method getExerciseByProjectKey to retrieve a programming exercise by its project key. This method is annotated with @GetMapping for HTTP GET requests and requires student-level access.

Possibly related PRs

Suggested labels

tests, small

Suggested reviewers

  • Jan-Thurner
  • b-fein
  • pzdr7
  • DominikRemo

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.

@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) programming Pull requests that affect the corresponding module labels Oct 1, 2024
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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between b7a816e and fc69fca.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.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

@janthoXO
Copy link
Contributor Author

janthoXO commented Oct 1, 2024

@EnforceAtLeastStudent

should be replaced by AtLeastStudentInExercise but this has to be implemented without the macro, because no exerciseID is passed

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: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between fc69fca and 83ef1a5.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.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

@janthoXO janthoXO changed the title Add ProgrammingExercise by ProjectKey endpoint ProgrammingExercise: Add ProgrammingExercise by ProjectKey endpoint Oct 2, 2024
@janthoXO janthoXO changed the title ProgrammingExercise: Add ProgrammingExercise by ProjectKey endpoint Programming Exercise: Add ProgrammingExercise by ProjectKey endpoint Oct 2, 2024
@janthoXO janthoXO changed the title Programming Exercise: Add ProgrammingExercise by ProjectKey endpoint Programming exercises: Add ProgrammingExercise by ProjectKey endpoint Oct 2, 2024
Copy link
Contributor

@Strohgelaender Strohgelaender left a comment

Choose a reason for hiding this comment

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

Looks good, but you also should add some simple server tests.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 3, 2024
@janthoXO
Copy link
Contributor Author

janthoXO commented Oct 3, 2024

Looks good, but you also should add some simple server tests.

good point thanks

Copy link

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 11, 2024
@janthoXO janthoXO removed the stale label Oct 16, 2024
Copy link

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 24, 2024
@janthoXO janthoXO added ready for review too-long-open !!! This is an antipattern, we should aim for small PRs that are only open for a short time !!! and removed stale labels Oct 25, 2024
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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 83ef1a5 and 490692e.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.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

pzdr7
pzdr7 previously approved these changes Oct 26, 2024
Copy link
Contributor

@pzdr7 pzdr7 left a comment

Choose a reason for hiding this comment

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

Code

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/programming/web/ProgrammingExerciseResource.java (1)

553-560: Enhance method documentation.

The method documentation should include more details about the possible response status codes and parameter description.

Apply this diff to improve the documentation:

     /**
      * GET /programming-exercises : Queries a programming exercise by its project key.
      *
-     *
+     * @param projectKey the unique identifier of the programming exercise in the version control system
      *
-     * @return the ProgrammingExercise of this project key in an ResponseEntity or 404 Not Found if no exercise exists
+     * @return the ResponseEntity with status:
+     *         - 200 (OK) and the ProgrammingExercise in body
+     *         - 403 (Forbidden) if the user doesn't have access
+     *         - 404 (Not Found) if no exercise exists for the given project key
      */
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 490692e and 056fcc9.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.java (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/programming/web/ProgrammingExerciseResource.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/programming/web/ProgrammingExerciseResource.java (1)

561-568: ⚠️ Potential issue

Optimize authorization check and enhance error handling.

The current implementation has the following issues:

  1. Performs authorization check after fetching the exercise, which is inefficient
  2. Lacks request logging
  3. Missing explicit error handling

Apply this diff to improve the implementation:

     @GetMapping("programming-exercises/project-key/{projectKey}")
     @EnforceAtLeastStudent
     public ResponseEntity<ProgrammingExercise> getExerciseByProjectKey(@PathVariable String projectKey) {
+        log.debug("REST request to get ProgrammingExercise by project key : {}", projectKey);
+        try {
             final ProgrammingExercise exercise = programmingExerciseRepository.findOneByProjectKeyOrThrow(projectKey, false);
-            authCheckService.checkIsAtLeastRoleInExerciseElseThrow(Role.STUDENT, exercise.getId());
+            // Check if user has access to this specific exercise
+            authCheckService.checkIsAtLeastRoleInExerciseElseThrow(Role.STUDENT, exercise.getId());
 
             return ResponseEntity.ok(exercise);
+        } catch (EntityNotFoundException e) {
+            return ResponseEntity.notFound().build();
+        } catch (AccessForbiddenException e) {
+            return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
+        }
     }

Likely invalid or redundant comment.

Copy link

github-actions bot commented Nov 4, 2024

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@janthoXO janthoXO changed the base branch from develop to feature/re-key November 12, 2024 12:23
@janthoXO janthoXO added the stacked-pr PR that depends on another PR label Nov 12, 2024
Copy link

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 20, 2024
@github-actions github-actions bot added the tests label Nov 26, 2024
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 the new endpoint on TS9, works as expected

Copy link
Contributor

@SimonEntholzer SimonEntholzer left a comment

Choose a reason for hiding this comment

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

Works on Ts9, code lgtm

Copy link
Contributor

@iyannsch iyannsch left a comment

Choose a reason for hiding this comment

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

Code LGTM

@github-actions github-actions bot removed the stale label Nov 28, 2024
@Mtze Mtze added the maintainer-approved The feature maintainer has approved the PR label Nov 29, 2024
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 programming Pull requests that affect the corresponding module ready to merge server Pull requests that update Java code. (Added Automatically!) stacked-pr PR that depends on another PR tests too-long-open !!! This is an antipattern, we should aim for small PRs that are only open for a short time !!!
Projects
Status: Maintainer Approved
Development

Successfully merging this pull request may close these issues.

7 participants