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

Add missing isValidNewName legacy route #8252

Merged
merged 2 commits into from
Nov 29, 2024

Conversation

MichaelBuessemeyer
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer commented Nov 29, 2024

This PR add the missing legacy route for isValidNewName. This was forgotten in #8075.

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • test /api/v7/datasets//TestThisName/isValidNewName
  • should return { isValid: true }

Issues:


(Please delete unneeded items, merge only when none are left open)

Copy link

coderabbitai bot commented Nov 29, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several updates to the WEBKNOSSOS application, including a new feature for pasting remote URIs from Neuroglancer without format prefixes. It enhances the asynchronous image file reading process and allows for dataset renaming with potential duplicates. Improvements in error messaging and registration processes are implemented, along with the removal of bounding box restrictions for super users. Additionally, logging has been improved, and multiple bug fixes have been applied. Support for certain HTTP API versions has been removed, and a new method for validating dataset names has been added.

Changes

File Path Change Summary
CHANGELOG.unreleased.md Updated to reflect new features, asynchronous file reading, dataset renaming, improved error messages, and bug fixes.
app/controllers/LegacyApiController.scala Added method isValidNewNameV8 for validating dataset names asynchronously.
conf/webknossos.versioned.routes Updated API routes for versions 5-9 to include new endpoint for dataset name validation and changes in dataset identification.

Possibly related PRs

Suggested labels

new feature

Poem

🐰 In a world of data, bright and new,
With names and URIs, we bid adieu,
Asynchronous reads, oh what a delight,
Bugs are squashed, everything's right!
So hop along, let’s celebrate,
With datasets dancing, it’s never too late! 🎉


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

@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

🧹 Outside diff range and nitpick comments (3)
CHANGELOG.unreleased.md (1)

31-31: Consider adding more context to the changelog entry.

The entry correctly documents the change, but could be more informative for users migrating between versions.

Consider expanding the entry to provide more context:

-Added missing legacy support for `isValidNewName` route. [#8252](https://github.com/scalableminds/webknossos/pull/8252)
+Added missing legacy support for `isValidNewName` route for dataset name validation (supports pre-v8 API calls). [#8252](https://github.com/scalableminds/webknossos/pull/8252)
app/controllers/LegacyApiController.scala (2)

62-68: Architectural consistency check needed

The implementation pattern differs across versions v5-v8:

  • v5 (assertValidNewNameV5): Direct validation with organization check
  • v8 (isValidNewNameV8): Delegates to datasetController

Consider:

  1. Document why the implementation differs between versions
  2. Add deprecation notice for v5 if it's being replaced
  3. Ensure consistent error responses across versions

62-68: Add logging for validation failures

While the method logs the request via logVersioned, it doesn't log validation failures which could be useful for monitoring and debugging.

 def isValidNewNameV8(datasetName: String, organizationId: String): Action[AnyContent] = sil.SecuredAction.async {
   implicit request =>
     for {
       _ <- Fox.successful(logVersioned(request))
-      result <- datasetController.isValidNewName(datasetName)(request)
+      result <- datasetController.isValidNewName(datasetName)(request).recoverWith {
+        case e =>
+          logger.warn(s"Dataset name validation failed: ${e.getMessage}")
+          Fox.failure(e)
+      }
     } yield result
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec72322 and d64b667.

📒 Files selected for processing (3)
  • CHANGELOG.unreleased.md (1 hunks)
  • app/controllers/LegacyApiController.scala (1 hunks)
  • conf/webknossos.versioned.routes (4 hunks)
🔇 Additional comments (4)
CHANGELOG.unreleased.md (1)

Line range hint 1-42: LGTM! Changelog structure is well-maintained.

The changelog properly documents both the addition of the legacy route and its relationship to the removal of older API versions. The entries are well-organized and provide good traceability through PR references.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~29-~29: Possible missing comma found.
Context: ... the datasource setting of the advanced tab making the form not submittable. [#8245...

(AI_HYDRA_LEO_MISSING_COMMA)

conf/webknossos.versioned.routes (2)

23-23: LGTM! Consistent implementation of isValidNewName routes.

The new routes for versions v6-v8 are consistently implemented with the same path pattern and controller method.

Let's verify that the controller methods exist:

Also applies to: 37-37, 55-55, 75-75

✅ Verification successful

Both controller methods exist and match the route configuration

The verification confirms that both controller methods are present in LegacyApiController.scala:

  • isValidNewNameV8(datasetName: String, organizationId: String) - matches routes for v6-v8
  • assertValidNewNameV5(organizationName: String, datasetName: String) - matches v5 route with different parameter naming
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the controller methods exist in the LegacyApiController

# Search for the controller methods
rg "def (isValidNewNameV8|assertValidNewNameV5)" -t scala

Length of output: 355


75-75: Verify the impact of different controller methods in v5.

The v5 routes use different controller methods for the same functionality:

  • New route uses isValidNewNameV8
  • Existing route uses assertValidNewNameV5

This might lead to inconsistent behavior within v5.

Let's verify the differences between these methods:

Also applies to: 89-89

app/controllers/LegacyApiController.scala (1)

62-68: ⚠️ Potential issue

Verify organization ID validation

The method delegates to datasetController.isValidNewName but doesn't validate the organizationId parameter. This differs from the v5 implementation (assertValidNewNameV5) which explicitly checks organization access.

Consider adding organization validation similar to v5:

 def isValidNewNameV8(datasetName: String, organizationId: String): Action[AnyContent] = sil.SecuredAction.async {
   implicit request =>
     for {
       _ <- Fox.successful(logVersioned(request))
+      organization <- organizationDAO.findOne(organizationId)
+      _ <- bool2Fox(organization._id == request.identity._organization) ~> FORBIDDEN
       result <- datasetController.isValidNewName(datasetName)(request)
     } yield result
 }

@@ -69,6 +72,7 @@ GET /v6/datasets/:organizationName/:datasetName co
PATCH /v5/datasets/:organizationId/:datasetName controllers.LegacyApiController.updateDatasetV8(organizationId: String, datasetName: String)
GET /v5/datasets/:organizationId/:datasetName/sharingToken controllers.LegacyApiController.getDatasetSharingTokenV8(organizationId: String, datasetName: String)
PATCH /v5/datasets/:organizationId/:datasetName/teams controllers.LegacyApiController.updateDatasetTeamsV8(organizationId: String, datasetName: String)
GET /v5/datasets/:organizationId/:datasetName/isValidNewName controllers.LegacyApiController.isValidNewNameV8(datasetName: String, organizationId: String)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent parameter naming between v5 routes.

There's an inconsistency in parameter naming between the new v5 route and the existing v5 route:

  • New route (L75): Uses organizationId
  • Existing route (L89): Uses organizationName

This might cause confusion for API consumers using v5.

Consider using consistent parameter naming within the same API version. Either:

  1. Update the new v5 route to use organizationName to match the existing pattern:
-GET      /v5/datasets/:organizationId/:datasetName/isValidNewName             controllers.LegacyApiController.isValidNewNameV8(datasetName: String, organizationId: String)
+GET      /v5/datasets/:organizationName/:datasetName/isValidNewName           controllers.LegacyApiController.isValidNewNameV8(datasetName: String, organizationName: String)
  1. Or document the difference in the version changelog if this is intentional.

Also applies to: 89-89

Comment on lines +62 to +68
def isValidNewNameV8(datasetName: String, organizationId: String): Action[AnyContent] = sil.SecuredAction.async {
implicit request =>
for {
_ <- Fox.successful(logVersioned(request))
result <- datasetController.isValidNewName(datasetName)(request)
} yield result
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing implementations for v5-v7

The PR objective mentions testing via v7 endpoint (/api/v7/datasets/<some orga>/TestThisName/isValidNewName), but only v8 implementation is present. Implementations for v6 and v7 appear to be missing.

Add implementations for v6 and v7:

def isValidNewNameV7(datasetName: String, organizationId: String): Action[AnyContent] =
  isValidNewNameV8(datasetName, organizationId)

def isValidNewNameV6(datasetName: String, organizationId: String): Action[AnyContent] =
  isValidNewNameV8(datasetName, organizationId)

@MichaelBuessemeyer MichaelBuessemeyer merged commit 991ca91 into master Nov 29, 2024
3 checks passed
@MichaelBuessemeyer MichaelBuessemeyer deleted the add-missing-is-valid-new-name-legacy-route branch November 29, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants