Skip to content

Conversation

@AnujChhikara
Copy link

@AnujChhikara AnujChhikara commented Jun 10, 2025

Date: 10th June 2025

Developer Name: @Shyam-Vishwakarma

Issue Ticket Number

PRs going to sync

Description

  • Added integration tests for PATCH /v1/endorsements/{id} endpoint
  • Fixed authorization to ensure only the endorser can update their endorsement
  • Added validation to prevent updating endorsement with an empty message
  • Changes made to does not update endorsement if user details fetch fails
  • Above fixes are under feature-flag i.e. dev mode so endorsement update is restricted in non-dev mode

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1
demo.-.1-1749547788272.1.mp4
Screenshot 2
demo-2-403-1749548312568.1.mp4

Test Coverage

Screenshot 1

{0EDA4F4F-FAC8-469C-8B24-41CE30DB3CEC}

Description by Korbit AI

What change is being made?

Add the ability to update endorsements based on a development mode check, introduce a more comprehensive exception handling mechanism, and refactor error messages into a centralized constants class.

Why are these changes being made?

These changes allow for the controlled update of endorsements, restricted to development mode for enhanced security. Consolidating error messages in a constants file helps maintain consistency across the codebase and simplifies maintenance. Furthermore, the newly added integration tests ensure reliable validation of update operations and exception handling under various scenarios.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

test: add integration tests for PATCH v1/endorsements/{id} endpoint
* fix: ensure empty endorsements msg not allowed

* fix: add feature-flag in endorsement controller

* fix: update service impl to ensure no unauthorized endorsement update, user-not-found bug

* fix: enable disabled test cases

* fix: disable endorsements update when not in dev mode

* fix: run all tests in dev mode, add test case to validate updation is no allowed in non-dev mode

* fix: update name of test case

* fix: import only used exceptions

* fix: update control flow
@coderabbitai
Copy link

coderabbitai bot commented Jun 10, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Readability Unclear Boolean Parameter Name ▹ view 🧠 Incorrect
Error Handling Inconsistent Error Message for User Not Found Scenario ▹ view
Readability Deep Nesting in Update Method ▹ view
Security Exposed Development Flag in Production API ▹ view 🧠 Not in scope
Files scanned
File Path Reviewed
skill-tree/src/main/java/com/RDS/skilltree/viewmodels/UpdateEndorsementViewModel.java
skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementService.java
skill-tree/src/main/java/com/RDS/skilltree/apis/EndorsementsApi.java
skill-tree/src/main/java/com/RDS/skilltree/services/external/RdsServiceImplementation.java
skill-tree/src/main/java/com/RDS/skilltree/utils/Constants.java
skill-tree/src/main/java/com/RDS/skilltree/exceptions/GlobalExceptionHandler.java
skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X


EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewModel endorsement);
EndorsementViewModel update(
Integer endorsementId, UpdateEndorsementViewModel endorsement, boolean isDev);

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

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

In this repository, isDev is used as a feature flag, which is descriptive enough to indicate dev mode

Copy link

Choose a reason for hiding this comment

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

Fair point. If 'isDev' is the standard feature flag naming in your codebase, keeping it consistent makes sense. I'll resolve this comment.

return new ResponseEntity<>(endorsementService.update(id, body), HttpStatus.OK);
@PathVariable Integer id,
@Valid @RequestBody UpdateEndorsementViewModel body,
@RequestParam(name = "dev", required = false, defaultValue = "false") boolean isDev) {

This comment was marked as resolved.

Copy link
Contributor

Choose a reason for hiding this comment

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

  • currently we are using this method only for feature flags or dev mode

Copy link

Choose a reason for hiding this comment

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

While I understand it's used for feature flags, exposing dev flags via API parameters creates security risks. Consider using a proper feature flag management system or environment-based configuration instead. This provides better security and control over feature rollouts.

Comment on lines +136 to +167
if (isDev) {
Optional<Endorsement> existingEndorsement = endorsementRepository.findById(endorsementId);

if (existingEndorsement.isEmpty()) {
log.info("Endorsement with id: {} not found", endorsementId);
throw new EndorsementNotFoundException(ExceptionMessages.ENDORSEMENT_NOT_FOUND);
}

Endorsement endorsement = existingEndorsement.get();

JwtUser jwtDetails =
(JwtUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String userId = jwtDetails.getRdsUserId();

if (endorsement.getEndorserId().equals(userId)) {
RdsGetUserDetailsResDto endorseDetails =
rdsService.getUserDetails(endorsement.getEndorseId());
RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(userId);

endorsement.setMessage(body.getMessage());
Endorsement savedEndorsementDetails = endorsementRepository.save(endorsement);

return EndorsementViewModel.toViewModel(
savedEndorsementDetails,
UserViewModel.toViewModel(endorseDetails.getUser()),
UserViewModel.toViewModel(endorserDetails.getUser()));
} else {
log.warn("User: {} is not authorized to update endorsement: {}", userId, endorsementId);
throw new ForbiddenException(ExceptionMessages.UNAUTHORIZED_ENDORSEMENT_UPDATE);
}
}

Endorsement endorsement = exitingEndorsement.get();
String updatedMessage = body.getMessage();

if (updatedMessage != null) {
endorsement.setMessage(updatedMessage);
}

Endorsement savedEndorsementDetails = endorsementRepository.save(endorsement);
RdsGetUserDetailsResDto endorseDetails =
rdsService.getUserDetails(savedEndorsementDetails.getEndorseId());
RdsGetUserDetailsResDto endorserDetails =
rdsService.getUserDetails(savedEndorsementDetails.getEndorserId());

return EndorsementViewModel.toViewModel(
savedEndorsementDetails,
UserViewModel.toViewModel(endorseDetails.getUser()),
UserViewModel.toViewModel(endorserDetails.getUser()));
throw new IllegalStateException(ExceptionMessages.UPDATE_DISABLED_IN_NON_DEV_MODE);
Copy link

Choose a reason for hiding this comment

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

Deep Nesting in Update Method category Readability

Tell me more
What is the issue?

The update method has deeply nested logic within an if-statement, making the code flow harder to follow. The dev mode check should be inverted to handle the non-dev case first.

Why this matters

Deep nesting reduces code readability and makes it harder to understand the main flow of the method. Early returns improve code clarity by reducing cognitive load.

Suggested change ∙ Feature Preview
public EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewModel body, boolean isDev) {
    if (!isDev) {
        throw new IllegalStateException(ExceptionMessages.UPDATE_DISABLED_IN_NON_DEV_MODE);
    }
    
    Optional<Endorsement> existingEndorsement = endorsementRepository.findById(endorsementId);
    // ... rest of the logic ...
}
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

public static final String ENDORSEMENT_ALREADY_EXISTS = "Endorsement already exists";
public static final String ENDORSEMENT_NOT_FOUND = "Endorsement not found";
public static final String ENDORSEMENT_MESSAGE_EMPTY = "Endorsement message cannot be empty";
public static final String USER_NOT_FOUND = "Error getting user details";
Copy link

Choose a reason for hiding this comment

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

Inconsistent Error Message for User Not Found Scenario category Error Handling

Tell me more
What is the issue?

The error message 'Error getting user details' does not accurately reflect the USER_NOT_FOUND constant name and scenario.

Why this matters

Using a generic error message instead of a specific one can make debugging harder and may confuse users about the actual issue - that the user was not found in the system.

Suggested change ∙ Feature Preview

Change the message to be consistent with the constant name and specific to the scenario:

public static final String USER_NOT_FOUND = "User not found";
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

@iamitprakash iamitprakash merged commit 334be48 into main Jun 10, 2025
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.

4 participants