Skip to content

gql-server: Introduce an endpoint /api/rest/userMetadata - #21258

Merged
gustavotrott merged 1 commit into
bigbluebutton:v3.0.x-releasefrom
gustavotrott:gql-endpoint-userMetadata
Sep 25, 2024
Merged

gustavotrott merged 1 commit into
bigbluebutton:v3.0.x-releasefrom
gustavotrott:gql-endpoint-userMetadata

Conversation

@gustavotrott

@gustavotrott gustavotrott commented Sep 25, 2024 •

Copy link
Copy Markdown
Contributor

This pull request introduces a new GET endpoint /api/rest/userMetadata, enabling clients to fetch userdata properties such as bbb_custom_style and bbb_custom_style_url before initiating a GraphQL connection.

Provided by Hasura, this endpoint includes all standard validations akin to GraphQL queries.

Additionally, it grants the bbb_client_not_in_meeting role (users that haven't join) permission to access user_metadata.

Query used internally:

query getUserMetadata {
    user_metadata {
      parameter
      value
    }
}

Example of response:

{
  "data": {
    "user_metadata": [
      {
        "parameter": "bbb_client_title",
        "value": "test"
      }
    ]
  }
}

Summary by CodeRabbit

  • New Features

    • Introduced a new role bbb_client_not_in_meeting for enhanced user access control.
    • Added a userMetadata query to retrieve user-specific metadata.
    • Created a new REST endpoint for accessing user metadata via a GET request.
  • Improvements

    • Enhanced API functionality with a dedicated endpoint for user metadata access.

These updates provide more granular control and improved access to user data in various scenarios.

…he client to fetch userdata info before creating a graphql connection.

It is necessary to fetch props bbb_custom_style and bbb_custom_style_url.
@gustavotrott gustavotrott added this to the Release 3.0 milestone Sep 25, 2024
@coderabbitai

coderabbitai Bot commented Sep 25, 2024 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce a new role bbb_client_not_in_meeting to manage user permissions in the public_v_user_metadata.yaml file, allowing access to specific user metadata. A new GraphQL query userMetadata is added to retrieve user-specific metadata, and a corresponding REST endpoint is defined for it. Additionally, the Nginx configuration is updated to handle requests to the new endpoint with appropriate authorization checks.

Changes

Files Change Summary
bbb-graphql-server/metadata/databases/...yaml Added role bbb_client_not_in_meeting to manage access permissions for user metadata based on meeting and user IDs.
bbb-graphql-server/metadata/query_collections.yaml Introduced new query userMetadata to retrieve parameter and value fields from user metadata.
bbb-graphql-server/metadata/rest_endpoints.yaml Defined new REST endpoint userMetadata for GET requests, linking it to the userMetadata query in the allowed queries collection.
build/packages-template/bbb-graphql-middleware/...nginx Added Nginx location block for /api/rest/userMetadata, implementing authorization checks and setting up proxy settings for backend service communication.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Nginx
    participant Backend

    Client->>Nginx: GET /api/rest/userMetadata
    Nginx->>Nginx: Check authorization
    Nginx->>Backend: Proxy request to userMetadata query
    Backend-->>Nginx: Return user metadata
    Nginx-->>Client: Return user metadata response
Loading

Poem

🐇 In the meadow, changes bloom,
New roles and queries clear the gloom.
Metadata dances in the light,
With endpoints ready, all feels right.
A hop, a skip, we celebrate,
Access granted, oh, how great! 🌼


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.

@sonarqubecloud

Copy link
Copy Markdown

@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)
bbb-graphql-server/metadata/rest_endpoints.yaml (1)

10-10: Consider adding a descriptive comment for the new endpoint.

The comment field for the new userMetadata endpoint is currently empty. Adding a brief description of the endpoint's purpose and usage would improve documentation and maintainability.

Consider adding a comment like:

- comment: "Retrieves specific user metadata properties (bbb_custom_style and bbb_custom_style_url) for clients not in a meeting"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6f5482d and 439f048.

📒 Files selected for processing (4)
  • bbb-graphql-server/metadata/databases/BigBlueButton/tables/public_v_user_metadata.yaml (1 hunks)
  • bbb-graphql-server/metadata/query_collections.yaml (1 hunks)
  • bbb-graphql-server/metadata/rest_endpoints.yaml (1 hunks)
  • build/packages-template/bbb-graphql-middleware/graphql.nginx (1 hunks)
🔇 Additional comments not posted (4)
bbb-graphql-server/metadata/rest_endpoints.yaml (1)

11-18: LGTM! The new endpoint is well-structured and aligns with PR objectives.

The userMetadata endpoint is correctly defined and consistent with the existing clientSettings endpoint structure. It properly specifies the GET method and uses the "allowed-queries" collection, which suggests appropriate access restrictions.

To ensure the corresponding GraphQL query exists and is correctly implemented, please run the following script:

This script will help verify that the GraphQL query exists and includes the expected fields (bbb_custom_style and bbb_custom_style_url) as mentioned in the PR objectives.

bbb-graphql-server/metadata/query_collections.yaml (1)

11-18: LGTM! Consider adding parameter filters.

The addition of the userMetadata query aligns well with the PR objectives. It correctly retrieves the parameter and value fields from the user_metadata entity, which is suitable for key-value pair data.

However, consider the following suggestions:

  1. The PR mentions specifically retrieving bbb_custom_style and bbb_custom_style_url. You might want to add a filter to the query to retrieve only these specific parameters, enhancing security by limiting data exposure.

  2. Ensure that standard validations mentioned in the PR description are indeed applied to this query, particularly considering it doesn't currently have any filters.

To verify the application of standard validations, please run the following script:

This script will help ensure that appropriate validations are in place for the user_metadata table.

bbb-graphql-server/metadata/databases/BigBlueButton/tables/public_v_user_metadata.yaml (1)

21-32: Approve with suggestions for clarification and documentation.

The new role bbb_client_not_in_meeting is structurally sound and maintains consistent security measures with the existing bbb_client role. The use of X-Hasura-MeetingId and X-Hasura-UserId in the filter conditions ensures proper authorization.

However, I have a few suggestions:

  1. The permissions for bbb_client_not_in_meeting are identical to bbb_client. Could you clarify the necessity for a separate role? If there are distinctions in how these roles are used, it might be beneficial to document this.

  2. The role name suggests it's for clients not in a meeting, but the permissions are the same as for clients in a meeting. Could you explain the reasoning behind this naming convention and how it relates to the actual use case?

  3. Consider adding a comment to explain the purpose and usage of this new role. This would help future maintainers understand the rationale behind its addition.

To ensure there are no unintended duplications or inconsistencies, let's verify the uniqueness of roles and their configurations:

This script will help us verify the uniqueness of roles across YAML files and identify any potential duplications or inconsistencies in role configurations.

✅ Verification successful

Approval confirmed: New role bbb_client_not_in_meeting does not introduce naming conflicts.

The verification process has confirmed that the new role bbb_client_not_in_meeting does not introduce any naming conflicts with existing roles in the system. This supports the approval of the change from a role uniqueness perspective.

However, I would like to reiterate the suggestions from the initial review:

  1. While the role name is unique, its permissions are identical to the existing bbb_client role. Consider documenting the specific use case or scenario that necessitates this separate role to aid future maintenance and understanding.

  2. The role name suggests it's for clients not in a meeting, but the permissions are the same as for clients in a meeting. It would be beneficial to clarify the reasoning behind this naming convention and how it relates to the actual use case.

  3. Adding a comment in the YAML file to explain the purpose and usage of this new role would greatly help future maintainers understand the rationale behind its addition.

These suggestions aim to improve the overall clarity and maintainability of the role structure in your system.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for unique roles and their configurations in YAML files

# Test: List all roles and their configurations
echo "Roles and their configurations:"
fd -e yaml | xargs yq '.select_permissions[] | {"role": .role, "columns": .permission.columns, "filter": .permission.filter}'

# Test: Check for duplicate role names
echo -e "\nDuplicate role names (if any):"
fd -e yaml | xargs yq '.select_permissions[].role' | sort | uniq -d

Length of output: 421


Script:

#!/bin/bash
# Description: Check for unique roles and their configurations in YAML files without using yq

# List all YAML files
yaml_files=$(fd -e yaml)

# Extract roles and their configurations
echo "Roles and their configurations:"
for file in $yaml_files; do
  echo "File: $file"
  awk '/role:/ {role=$2} /columns:/ {cols=""} /- parameter/ {cols=cols " parameter"} /- value/ {cols=cols " value"} /filter:/ {filt=""} /_and:/ {filt="_and"} /meetingId:/ {filt=filt " meetingId=_eq"} /userId:/ {filt=filt " userId=_eq"} END {print "  Role: " role ", Columns:" cols ", Filter:" filt}' "$file"
done

# Check for duplicate role names
echo -e "\nDuplicate role names (if any):"
for file in $yaml_files; do
  awk '/role:/ {print $2}' "$file"
done | sort | uniq -d

Length of output: 71752


Script:

#!/bin/bash
# Description: Accurately extract roles and their configurations from YAML files and identify duplicates

# List all YAML files
yaml_files=$(fd -e yaml)

# Initialize temporary files to store roles and configurations
echo "Roles and their configurations:" > roles_configurations.txt

# Extract roles, columns, and filters using grep and sed
for file in $yaml_files; do
  echo "File: $file" >> roles_configurations.txt
  # Extract role
  role=$(grep -E '^\s*role:\s*\S+' "$file" | sed -e 's/^\s*role:\s*//')
  # Extract columns
  columns=$(grep -A2 'columns:' "$file" | grep -E '^\s*-\s*\S+' | awk '{print $2}' | paste -sd ", " -)
  # Extract filters
  filters=$(grep -A4 'filter:' "$file" | grep -E '^\s*-|\s*_and:' | sed -e 's/^\s*- //;s/^\s*_and://')
  echo "  Role: $role, Columns: $columns, Filter: $filters" >> roles_configurations.txt
done

# Display the roles and their configurations
cat roles_configurations.txt

# Check for duplicate role names
echo -e "\nDuplicate role names (if any):" >> roles_configurations.txt
grep -E '^\s*role:\s*\S+' $yaml_files | sed -e 's/^\s*role:\s*//' | sort | uniq -d >> roles_configurations.txt

# Display duplicates
cat roles_configurations.txt

Length of output: 98195


Script:

#!/bin/bash
# Description: Extract all non-empty role names from YAML files and identify duplicates

# List all YAML files
yaml_files=$(fd -e yaml)

# Extract role names, remove empty entries, sort them, and count duplicates
echo "Extracting role names and identifying duplicates..."
grep -hE '^\s*role:\s*\S+' $yaml_files | sed -e 's/^\s*role:\s*//' | grep -v '^$' | sort | uniq -c | awk '$1 > 1 {print "Duplicate Role \"" $2 "\" found " $1 " times."}'

# If no duplicates are found, indicate as such
if ! grep -hE '^\s*role:\s*\S+' $yaml_files | sed -e 's/^\s*role:\s*//' | grep -v '^$' | sort | uniq -c | awk '$1 > 1 {exit 1}'; then
  echo "No duplicate roles found."
fi

Length of output: 20778


Script:

#!/bin/bash
# Description: Extract all non-empty role names from YAML files and identify duplicates

# List all YAML files
yaml_files=$(fd -e yaml)

# Extract role names, remove empty entries, sort them, and count duplicates
echo "Extracting role names and identifying duplicates..."
duplicates=$(grep -hE '^\s*role:\s*\S+' $yaml_files | sed -e 's/^\s*role:\s*//' | grep -v '^$' | sort | uniq -c | awk '$1 > 1 {print "Duplicate Role \"" $2 "\" found " $1 " times."}')

# Check if duplicates are found
if [ -n "$duplicates" ]; then
  echo "$duplicates"
else
  echo "No duplicate roles found."
fi

Length of output: 13974

build/packages-template/bbb-graphql-middleware/graphql.nginx (1)

30-39: LGTM! The new endpoint is well-implemented.

The new location block for /api/rest/userMetadata is correctly implemented with proper authorization checks and proxy settings. It aligns well with the existing configuration style and the PR objectives.

Consider caching for performance optimization.

Unlike the /api/rest/clientSettings endpoint, this new endpoint doesn't include caching directives. If the user metadata is not expected to change frequently, consider adding caching to improve performance.

If caching is appropriate, you could add the following directives:

proxy_cache user_metadata_cache;
proxy_cache_key "$uri|$meeting_id";
proxy_cache_use_stale updating;
proxy_cache_valid 15m;  # Adjust the cache duration as needed
proxy_cache_lock on;
add_header X-Cached $upstream_cache_status;

Verify the role-based access control.

The PR objectives mention granting the bbb_client_not_in_meeting role permission to access user metadata. Ensure that this role-based access control is implemented in the backend (Hasura) or in the checkGraphqlAuthorization endpoint.

To verify the role-based access control, you can run the following script:

✅ Verification successful

Role-based access control confirmed.

The bbb_client_not_in_meeting role is correctly defined in multiple configuration files, ensuring proper permission settings as per the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the presence of the 'bbb_client_not_in_meeting' role in the Hasura configuration

# Test: Search for the 'bbb_client_not_in_meeting' role in Hasura configuration files
rg --type yaml 'bbb_client_not_in_meeting' -g 'metadata/databases/*/tables/*.yaml'

Length of output: 231


Script:

#!/bin/bash
# Description: Check for the presence of the 'bbb_client_not_in_meeting' role in all YAML configuration files

# Test: Search for the 'bbb_client_not_in_meeting' role across the entire codebase in YAML files
rg --type yaml 'bbb_client_not_in_meeting'

Length of output: 872

@gustavotrott

Copy link
Copy Markdown
Contributor Author

@JoVictorNunes will review it while he implements his task that relies on this PR.

@github-actions

Copy link
Copy Markdown

Automated tests Summary

✅ All the CI tests have 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.

1 participant