Skip to content

feat(akka): Plugin Js relative entrypoint and refactor of pluginManifests parameter - #21485

Merged
antobinary merged 3 commits into
bigbluebutton:v3.0.x-releasefrom
GuiLeme:js-relative-endpoint-refactors
Oct 21, 2024
Merged

antobinary merged 3 commits into
bigbluebutton:v3.0.x-releasefrom
GuiLeme:js-relative-endpoint-refactors

Conversation

@GuiLeme

@GuiLeme GuiLeme commented Oct 21, 2024

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR basically refactors the name pluginsManifests to pluginManifests parameter and makes necessary changes. Outside of that, it adds the possibility of sending a relative plugin js entrypoint in manifest. So now, the structure can Also be as follows:

{
  "requiredSdkVersion": "~0.0.59",
  "name": "H5pPlugin",
  "javascriptEntrypointUrl": "H5pPlugin.js",
  "localesBaseUrl": "https://cdn.dominio.com/pluginabc/",
  "eventPersistence": {
      "isEnabled": true,
      "maximumPayloadSizeInBytes": 1024,
      "rateLimiting": {
          "messagesAllowedPerSecond": 10,
          "messagesAllowedPerMinute": 20
      }
  },
  "dataChannels": [
      {
          "name": "testResult",
          "pushPermission": ["moderator"],
          "replaceOrDeletePermission": ["creator", "moderator"]
      }
  ]
}

And the absolute js entrypoint would be the baseUrl of the manifest.json concatenated with the relative js entrypoint.

If, on the other hand, we already have an absolute js entrypoint with http or https at the begining of the string, this new flow will be ignored.
n

@coderabbitai

coderabbitai Bot commented Oct 21, 2024 •

Copy link
Copy Markdown
Contributor

Walkthrough

The pull request introduces several modifications across multiple files, primarily focusing on the handling of plugin manifests within the BigBlueButton application. Key changes include the addition of a new method, replaceRelativeJavascriptEntrypoint, in the PluginModel object, which updates the javascriptEntrypointUrl of a Plugin instance to an absolute URL if it does not already start with "http://" or "https://". The createPluginModelFromJson method has been updated to utilize this new method, ensuring that all plugins processed from JSON have their JavaScript entry points correctly set.

Additionally, renaming conventions have been standardized throughout the codebase, changing instances of "PluginsManifest" to "PluginManifest" to reflect a singular form. This includes updates in various classes such as ApiParams, MeetingService, ParamsProcessorUtil, and Meeting, ensuring consistency in naming. Configuration files have also been updated to align with these changes, specifically in bigbluebutton.properties and resources.xml. Overall, the modifications enhance clarity and consistency in the handling of plugin manifests.

Possibly related PRs

Suggested reviewers

  • TiagoJacobs
  • gustavotrott
  • ramonlsouza

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java (2)

431-455: Approved: Method renaming and consistent updates

The renaming of processPluginsManifests to processPluginManifests and the corresponding updates to parameter and variable names are consistent with the PR objectives. The logic remains unchanged, which is good for maintaining functionality.

However, there are a couple of suggestions for improvement:

  1. Consider using a more specific exception instead of the generic Exception in the catch block.
  2. The error message could be more informative by including the actual exception details.

Consider updating the error handling as follows:

-    } catch(Exception e) {
-        log.error("Couldn't decode the filters");
+    } catch(JsonSyntaxException e) {
+        log.error("Error parsing pluginManifests JSON: {}", e.getMessage(), e);

This change would provide more specific error handling and logging, making it easier to diagnose issues in the future.


577-587: Approved: Consistent processing of plugin manifests

The changes in this segment are consistent with the renaming convention and properly handle both default and parameter-provided plugin manifests.

Suggestions for improvement:

  1. Consider extracting the plugin manifest processing logic into a separate method to improve readability and maintainability.
  2. Use StringUtils.isNotEmpty() for consistency with other parts of the code.

Consider refactoring the code as follows:

 ArrayList<PluginManifest> listOfPluginManifests = new ArrayList<PluginManifest>();
-//Process plugins from config
-if(defaultPluginManifests != null && !defaultPluginManifests.isEmpty()) {
-    ArrayList<PluginManifest> pluginManifestsFromConfig = processPluginManifests(defaultPluginManifests);
-    listOfPluginManifests.addAll(pluginManifestsFromConfig);
-}
-//Process plugins from /create param
-String pluginManifestsParam = params.get(ApiParams.PLUGIN_MANIFESTS);
-if (!StringUtils.isEmpty(pluginManifestsParam)) {
-    ArrayList<PluginManifest> pluginManifestsFromParam = processPluginManifests(pluginManifestsParam);
-    listOfPluginManifests.addAll(pluginManifestsFromParam);
-}
+listOfPluginManifests.addAll(processPluginManifestsSource(defaultPluginManifests));
+listOfPluginManifests.addAll(processPluginManifestsSource(params.get(ApiParams.PLUGIN_MANIFESTS)));
+
+private ArrayList<PluginManifest> processPluginManifestsSource(String source) {
+    if (StringUtils.isNotEmpty(source)) {
+        return processPluginManifests(source);
+    }
+    return new ArrayList<>();
+}

This refactoring improves code readability and reduces duplication.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 873b590 and a033164.

📒 Files selected for processing (8)
  • akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Plugins.scala (2 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/ApiParams.java (1 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (3 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java (5 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/domain/Meeting.java (5 hunks)
  • bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java (1 hunks)
  • bigbluebutton-web/grails-app/conf/bigbluebutton.properties (1 hunks)
  • bigbluebutton-web/grails-app/conf/spring/resources.xml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • bigbluebutton-web/grails-app/conf/bigbluebutton.properties
🧰 Additional context used
🔇 Additional comments (19)
bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java (3)

7-12: LGTM! Constructor updated correctly.

The constructor has been properly renamed to match the new class name PluginManifest. The parameters and functionality remain unchanged, which is correct.


13-15: LGTM! Second constructor updated correctly.

The second constructor has also been properly renamed to match the new class name PluginManifest. The parameter and functionality remain unchanged, which is correct.


3-3: LGTM! Verify usage across the codebase.

The class renaming from PluginsManifest to PluginManifest aligns with the PR objectives and improves consistency. Ensure that all references to this class have been updated throughout the codebase.

Run the following script to verify the class usage:

✅ Verification successful

Verified: Class renaming is complete.

All references to PluginsManifest have been successfully updated to PluginManifest across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of PluginManifest (new) and PluginsManifest (old) in the codebase.

# Test: Search for the new class name. Expect: Only occurrences of the new name.
echo "Occurrences of new class name 'PluginManifest':"
rg -i 'PluginManifest'

# Test: Search for the old class name. Expect: No occurrences of the old name.
echo "Occurrences of old class name 'PluginsManifest':"
rg -i 'PluginsManifest'

Length of output: 7538

bbb-common-web/src/main/java/org/bigbluebutton/api/ApiParams.java (1)

76-76: LGTM! Verify usage across the codebase.

The renaming of PLUGINS_MANIFESTS to PLUGIN_MANIFESTS and its value from "pluginsManifests" to "pluginManifests" aligns with the PR objectives and improves consistency. This change looks good, but it's important to ensure that all references to this constant throughout the codebase have been updated accordingly.

To verify the constant usage, run the following script:

bigbluebutton-web/grails-app/conf/spring/resources.xml (3)

204-204: LGTM: Consistent property renaming

The change from pluginsManifests to pluginManifests is approved. This renaming aligns with similar updates across the codebase, improving consistency and adhering to standard naming conventions. The singular form is more appropriate for this context.


Line range hint 220-221: Note on configuration management

The comment about moving the import of 'turn-stun-servers.xml' to 'resources.groovy' indicates an ongoing effort to improve configuration management. This change allows for more flexible overlay configuration of TURN/STUN servers. While not part of the current PR's changes, it's worth noting for developers working on related system components.


Line range hint 1-222: Summary: Consistent refactoring and noted configuration changes

The changes in this file are minimal but align well with the PR's objectives. The renaming of pluginsManifests to pluginManifests contributes to the overall consistency of the codebase. The commented-out import statement, while not part of the active changes, provides insight into ongoing configuration management improvements. Overall, these changes maintain the file's integrity as a Spring configuration file while enhancing code consistency.

bbb-common-web/src/main/java/org/bigbluebutton/api/domain/Meeting.java (4)

82-82: LGTM: Field renamed consistently with PR objective.

The field has been correctly renamed from pluginsManifests to pluginManifests, maintaining consistency with the PR's goal. The type ArrayList<PluginManifest> suggests that related changes have been made elsewhere in the codebase.


455-456: LGTM: Getter method renamed consistently.

The getter method has been correctly renamed from getPluginsManifests() to getPluginManifests(), maintaining consistency with the field renaming and adhering to Java naming conventions for getter methods.


1081-1082: LGTM: Builder method renamed consistently.

The builder method has been correctly renamed from withPluginsManifests to withPluginManifests, maintaining consistency with the field renaming and adhering to the builder pattern naming convention.


82-82: Verify external references and usage of renamed elements.

The renaming from pluginsManifests to pluginManifests has been consistently applied across the Meeting class. However, it's crucial to ensure that this change doesn't break any existing functionality or external references.

Please run the following script to check for any remaining occurrences of pluginsManifests in the codebase and verify that all usages have been updated:

Also applies to: 455-456, 1081-1082

✅ Verification successful

Renaming Verified Successfully

The renaming from pluginsManifests to pluginManifests has been successfully applied across the codebase with no remaining occurrences of pluginsManifests.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining occurrences of 'pluginsManifests' and verify usage updates

# Search for any remaining occurrences of 'pluginsManifests'
echo "Searching for remaining occurrences of 'pluginsManifests':"
rg -i 'pluginsManifests'

# Search for usages of the new 'pluginManifests' to verify updates
echo "Verifying usage of the new 'pluginManifests':"
rg -i 'pluginManifests'

Length of output: 5115

bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java (5)

407-407: Refactoring: Singular form used for plugin manifest iteration

The change from pluginsManifests to pluginManifests aligns with the PR objectives of refactoring the parameter name. This improves consistency throughout the codebase.


410-410: Improved error handling and logging

The error handling has been enhanced with more specific logging. This change provides better context for debugging and monitoring.

-        log.error("Failed to get content from " + urlString);
+        log.error("Failed with the following plugin manifest URL: {}. Error: ",
+                pluginManifest.getUrl(), e);
+        log.error("Therefore this plugin will not be loaded");

Also applies to: 424-424, 429-429, 432-432, 461-461


Line range hint 407-461: Overall improvement in plugin manifest handling

The changes to the requestPluginManifests method significantly improve the handling of plugin manifests:

  1. Consistent naming convention (singular form) is used.
  2. Each plugin manifest is processed individually, increasing flexibility.
  3. Error handling and logging have been enhanced.
  4. JSON parsing now uses the Jackson library, which is more robust.
  5. A new feature for metadata parameter replacement has been added.

These changes align well with the PR objectives and should improve the overall functionality and maintainability of the plugin system.


Line range hint 439-457: New feature: Metadata parameter replacement in manifest content

A new feature has been added to replace metadata parameters in the manifest content. This enhances the flexibility of plugin configurations.

However, we should verify if this new feature is properly documented:

#!/bin/bash
# Check if the new metadata replacement feature is documented
rg -i 'metadata\s+parameter\s+replacement' --type md

Line range hint 410-438: Enhanced plugin manifest processing

The method now processes each plugin manifest individually, fetches its content, and performs various operations such as checksum validation and JSON parsing. This approach is more flexible and robust.

However, there's a potential issue with the checksum validation:

✅ Verification successful

It seems there was a syntax error in your shell script due to an unmatched backtick. Here's the corrected script to verify if the checksum validation using DigestUtils.sha256Hex is consistent across the Java codebase:


Checksum Validation Consistent Across Codebase

The checksum validation using DigestUtils.sha256Hex is consistently implemented in bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.java. No inconsistencies found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify if the checksum validation is consistent across the codebase
rg -U 'String\s+hash\s*=\s*DigestUtils\.sha256Hex\(' --type java

Length of output: 148


Script:

#!/bin/bash
# Verify if the checksum validation using DigestUtils.sha256Hex is consistent across the Java codebase
rg -U 'String\s+hash\s*=\s*DigestUtils\.sha256Hex\(' --type java

Length of output: 204


Script:

#!/bin/bash
# Verify if the checksum validation using DigestUtils.sha256Hex is consistent across the Java codebase
rg -U 'String\s+hash\s*=\s*DigestUtils\.sha256Hex\(' --type java

Length of output: 204

bbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.java (3)

102-102: Approved: Consistent renaming of variable

The renaming of defaultPluginsManifests to defaultPluginManifests is consistent with the PR objectives and improves naming consistency throughout the codebase.


1623-1624: Approved: Consistent renaming of setter method

The renaming of setPluginsManifests to setPluginManifests is consistent with the PR objectives and improves naming consistency throughout the codebase.


Line range hint 1-1624: Summary: Consistent renaming with minor improvement suggestions

The changes in this file successfully implement the renaming of "pluginsManifests" to "pluginManifests" throughout the ParamsProcessorUtil class. This improves naming consistency and aligns with the PR objectives. The functionality remains unchanged, which is good for maintaining backwards compatibility.

A few minor suggestions for improvement have been made:

  1. Enhancing error handling in the processPluginManifests method.
  2. Refactoring the plugin manifest processing logic for better readability and maintainability.

These suggestions are not critical and can be addressed in a future PR if desired. Overall, the changes meet the objectives and maintain the existing functionality.

Comment on lines +38 to +48
var javascriptEntrypointUrl: String,
javascriptEntrypointIntegrity: Option[String] = None,
localesBaseUrl: Option[String] = None,
eventPersistence: Option[EventPersistence] = None,
dataChannels: Option[List[DataChannel]] = None,
remoteDataSources: Option[List[RemoteDataSource]] = None
)
) {
def setJavascriptEntrypointUrl(newUrl: String) = {
this.javascriptEntrypointUrl = newUrl
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider keeping PluginManifestContent immutable

Changing javascriptEntrypointUrl from a val to a var introduces mutability into PluginManifestContent, which is a case class. In Scala, it's best practice to keep case classes immutable for thread safety and maintainability. Instead of making the field mutable and adding a setter method, consider creating a new instance with the updated javascriptEntrypointUrl.

Apply this diff to keep PluginManifestContent immutable:

 case class PluginManifestContent(
     requiredSdkVersion:            String,
     name:                          String,
-    var javascriptEntrypointUrl:   String,
+    javascriptEntrypointUrl:       String,
     javascriptEntrypointIntegrity: Option[String]                 = None,
     localesBaseUrl:                Option[String]                 = None,
     eventPersistence:              Option[EventPersistence]       = None,
     dataChannels:                  Option[List[DataChannel]]      = None,
     remoteDataSources:             Option[List[RemoteDataSource]] = None
 ) {
-  def setJavascriptEntrypointUrl(newUrl: String) = {
-    this.javascriptEntrypointUrl = newUrl
-  }
 }

Then, update replaceRelativeJavascriptEntrypoint to return a new Plugin instance with the updated javascriptEntrypointUrl:

 def replaceRelativeJavascriptEntrypoint(plugin: Plugin): Plugin = {
-  val pluginWithAbsoluteJavascriptEntrypoint = plugin.copy()
   val jsEntrypoint = plugin.manifest.content.javascriptEntrypointUrl
   if (jsEntrypoint.startsWith("http://") || jsEntrypoint.startsWith("https://")) {
-    pluginWithAbsoluteJavascriptEntrypoint
+    plugin
   } else {
-    val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
-    val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
-    pluginWithAbsoluteJavascriptEntrypoint.manifest.content.setJavascriptEntrypointUrl(absoluteJavascriptEntrypoint)
-    pluginWithAbsoluteJavascriptEntrypoint
+    val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
+    val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
+    val updatedContent = plugin.manifest.content.copy(
+      javascriptEntrypointUrl = absoluteJavascriptEntrypoint
+    )
+    val updatedManifest = plugin.manifest.copy(
+      content = updatedContent
+    )
+    plugin.copy(
+      manifest = updatedManifest
+    )
   }
 }

This approach maintains immutability and avoids unintended side effects caused by mutating shared objects.

Committable suggestion was skipped due to low confidence.

Comment on lines +74 to +76
val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
pluginWithAbsoluteJavascriptEntrypoint.manifest.content.setJavascriptEntrypointUrl(absoluteJavascriptEntrypoint)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use java.net.URL for safer URL manipulation

Manually manipulating URLs using substring and concatenation can be error-prone, especially with complex URLs. Consider using java.net.URL to handle URL resolution more robustly.

Apply this diff to use URL for resolving the JavaScript entry point:

     val jsEntrypoint = plugin.manifest.content.javascriptEntrypointUrl
     if (jsEntrypoint.startsWith("http://") || jsEntrypoint.startsWith("https://")) {
       pluginWithAbsoluteJavascriptEntrypoint
     } else {
-      val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
-      val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
+      val manifestUrl = new java.net.URL(plugin.manifest.url)
+      val absoluteJavascriptEntrypoint = new java.net.URL(manifestUrl, jsEntrypoint).toString
       val updatedContent = pluginWithAbsoluteJavascriptEntrypoint.manifest.content.copy(
         javascriptEntrypointUrl = absoluteJavascriptEntrypoint
       )

This approach correctly resolves relative paths against the manifest URL, handling edge cases effectively.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
pluginWithAbsoluteJavascriptEntrypoint.manifest.content.setJavascriptEntrypointUrl(absoluteJavascriptEntrypoint)
val manifestUrl = new java.net.URL(plugin.manifest.url)
val absoluteJavascriptEntrypoint = new java.net.URL(manifestUrl, jsEntrypoint).toString
val updatedContent = pluginWithAbsoluteJavascriptEntrypoint.manifest.content.copy(
javascriptEntrypointUrl = absoluteJavascriptEntrypoint
)

Comment on lines +68 to +79
def replaceRelativeJavascriptEntrypoint(plugin: Plugin): Plugin = {
val pluginWithAbsoluteJavascriptEntrypoint = plugin.copy()
val jsEntrypoint = plugin.manifest.content.javascriptEntrypointUrl
if (jsEntrypoint.startsWith("http://") || jsEntrypoint.startsWith("https://")) {
pluginWithAbsoluteJavascriptEntrypoint
} else {
val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
pluginWithAbsoluteJavascriptEntrypoint.manifest.content.setJavascriptEntrypointUrl(absoluteJavascriptEntrypoint)
pluginWithAbsoluteJavascriptEntrypoint
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure deep copying to prevent unintended side effects

The plugin.copy() method creates a shallow copy of the Plugin, so nested objects like manifest and content are still shared between the original and the copy. Mutating pluginWithAbsoluteJavascriptEntrypoint.manifest.content could inadvertently affect the original plugin. To prevent this, perform a deep copy of the nested objects.

Apply this diff to perform a deep copy:

 def replaceRelativeJavascriptEntrypoint(plugin: Plugin): Plugin = {
-  val pluginWithAbsoluteJavascriptEntrypoint = plugin.copy()
+  val pluginWithAbsoluteJavascriptEntrypoint = plugin.copy(
+    manifest = plugin.manifest.copy(
+      content = plugin.manifest.content.copy()
+    )
+  )
   val jsEntrypoint = plugin.manifest.content.javascriptEntrypointUrl
   if (jsEntrypoint.startsWith("http://") || jsEntrypoint.startsWith("https://")) {
     pluginWithAbsoluteJavascriptEntrypoint
   } else {
     val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
     val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
-    pluginWithAbsoluteJavascriptEntrypoint.manifest.content.setJavascriptEntrypointUrl(absoluteJavascriptEntrypoint)
+    val updatedContent = pluginWithAbsoluteJavascriptEntrypoint.manifest.content.copy(
+      javascriptEntrypointUrl = absoluteJavascriptEntrypoint
+    )
+    val updatedManifest = pluginWithAbsoluteJavascriptEntrypoint.manifest.copy(
+      content = updatedContent
+    )
+    pluginWithAbsoluteJavascriptEntrypoint.copy(
+      manifest = updatedManifest
+    )
   }
 }

This ensures that modifications do not affect the original plugin instance.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def replaceRelativeJavascriptEntrypoint(plugin: Plugin): Plugin = {
val pluginWithAbsoluteJavascriptEntrypoint = plugin.copy()
val jsEntrypoint = plugin.manifest.content.javascriptEntrypointUrl
if (jsEntrypoint.startsWith("http://") || jsEntrypoint.startsWith("https://")) {
pluginWithAbsoluteJavascriptEntrypoint
} else {
val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
pluginWithAbsoluteJavascriptEntrypoint.manifest.content.setJavascriptEntrypointUrl(absoluteJavascriptEntrypoint)
pluginWithAbsoluteJavascriptEntrypoint
}
}
def replaceRelativeJavascriptEntrypoint(plugin: Plugin): Plugin = {
val pluginWithAbsoluteJavascriptEntrypoint = plugin.copy(
manifest = plugin.manifest.copy(
content = plugin.manifest.content.copy()
)
)
val jsEntrypoint = plugin.manifest.content.javascriptEntrypointUrl
if (jsEntrypoint.startsWith("http://") || jsEntrypoint.startsWith("https://")) {
pluginWithAbsoluteJavascriptEntrypoint
} else {
val baseUrl = plugin.manifest.url.substring(0, plugin.manifest.url.lastIndexOf('/') + 1)
val absoluteJavascriptEntrypoint = baseUrl + jsEntrypoint
val updatedContent = pluginWithAbsoluteJavascriptEntrypoint.manifest.content.copy(
javascriptEntrypointUrl = absoluteJavascriptEntrypoint
)
val updatedManifest = pluginWithAbsoluteJavascriptEntrypoint.manifest.copy(
content = updatedContent
)
pluginWithAbsoluteJavascriptEntrypoint.copy(
manifest = updatedManifest
)
}
}

@sonarqubecloud

Copy link
Copy Markdown

@gustavotrott gustavotrott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Plugins.scala (1)

64-75: LGTM! Consider using java.net.URL for robust URL handling.

The implementation of replaceRelativeJavascriptEntrypoint correctly handles both absolute and relative JavaScript entry points while maintaining immutability. However, manually manipulating URLs with string operations might not handle all edge cases.

Consider using java.net.URL for more robust URL handling:

import java.net.URL

def replaceRelativeJavascriptEntrypoint(plugin: Plugin): Plugin = {
  val jsEntrypoint = plugin.manifest.content.javascriptEntrypointUrl
  if (jsEntrypoint.startsWith("http://") || jsEntrypoint.startsWith("https://")) {
    plugin
  } else {
    val manifestUrl = new URL(plugin.manifest.url)
    val absoluteJavascriptEntrypoint = new URL(manifestUrl, jsEntrypoint).toString
    val newPluginManifestContent = plugin.manifest.content.copy(javascriptEntrypointUrl = absoluteJavascriptEntrypoint)
    val newPluginManifest = plugin.manifest.copy(content = newPluginManifestContent)
    plugin.copy(manifest = newPluginManifest)
  }
}

This approach will handle more complex URL scenarios correctly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a033164 and e81dda8.

📒 Files selected for processing (1)
  • akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Plugins.scala (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/Plugins.scala (1)

82-83: LGTM! Ensures consistent absolute URLs for JavaScript entry points.

The changes in createPluginModelFromJson correctly apply the replaceRelativeJavascriptEntrypoint method to each plugin object. This ensures that all plugins processed from JSON have their JavaScript entry points set to absolute URLs, which aligns with the PR objectives.

@antobinary antobinary added this to the Release 3.0 milestone Oct 21, 2024
@antobinary
antobinary merged commit a9e0e87 into bigbluebutton:v3.0.x-release Oct 21, 2024
@github-actions

Copy link
Copy Markdown

Automated tests Summary

🚨 Test workflow has failed


Click here to check the action test reports

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.

3 participants