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

feat: Allow disable IAM registration #7910

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

jackylamhk
Copy link
Contributor

@jackylamhk jackylamhk commented May 17, 2024

Motivation and context

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Conditional registration functionality based on the IAM_REGISTRATION_ENABLED setting.
  • Configuration

    • Added IAM_REGISTRATION_ENABLED environment variable to control registration feature.
    • Updated docker-compose and Helm chart configurations to include IAM_REGISTRATION_ENABLED setting.

Copy link
Contributor

coderabbitai bot commented May 17, 2024

Warning

Rate Limit Exceeded

@jackylamhk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 45 minutes and 15 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 4abe4ae and 9cf452f.

Walkthrough

These changes introduce a new feature that conditionally enables user registration in the CVAT application based on the IAM_REGISTRATION_ENABLED setting. This setting is configurable via environment variables and is integrated into various configuration files, including docker-compose.yml and Helm chart templates.

Changes

File Change Summary
cvat/apps/iam/urls.py, cvat/settings/base.py Conditionally add the registration path in URLs and append 'dj_rest_auth.registration' to INSTALLED_APPS.
docker-compose.yml, helm-chart/values.yaml Added IAM_REGISTRATION_ENABLED with a value of 'true' to control registration functionality.
helm-chart/templates/.../deployment.yml Added IAM_REGISTRATION_ENABLED sourced from $localValues.envs.IAM_REGISTRATION_ENABLED.

In code we trust, with toggles and might,
New settings arise, to shine in the light.
Conditional paths, like doors open wide,
For users to join, with joy and with pride.
A rabbit's delight, in features so grand,
Hopping through code, with a helping hand.
🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
Contributor

@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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 59e31b3 and 723c426.
Files selected for processing (5)
  • cvat/apps/iam/urls.py (2 hunks)
  • cvat/settings/base.py (1 hunks)
  • docker-compose.yml (1 hunks)
  • helm-chart/templates/cvat_backend/server/deployment.yml (1 hunks)
  • helm-chart/values.yaml (1 hunks)
Files skipped from review due to trivial changes (2)
  • docker-compose.yml
  • helm-chart/values.yaml
Additional Context Used
Ruff (4)
cvat/settings/base.py (4)

34-34: Module level import not at top of file


36-36: Module level import not at top of file


80-80: keys.secret_key.SECRET_KEY imported but unused


723-723: Module level import not at top of file

Additional comments not posted (3)
cvat/apps/iam/urls.py (1)

39-42: Conditional inclusion of registration URL looks correct.

Verification successful

The IAM_REGISTRATION_ENABLED setting is correctly defined in cvat/settings/base.py and used in cvat/apps/iam/urls.py to conditionally include the registration URL. This confirms that the setting is correctly propagated and affects the URL patterns as expected.

  • cvat/settings/base.py: IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', False))
  • cvat/settings/base.py: if IAM_REGISTRATION_ENABLED:
  • cvat/apps/iam/urls.py: if settings.IAM_REGISTRATION_ENABLED:
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly propagated and affects the URL patterns as expected.

# Test: Check if the setting is correctly read from the environment and affects the urlpatterns.
rg --type python $'IAM_REGISTRATION_ENABLED' --files-with-matches | xargs cat | grep 'urlpatterns'

Length of output: 126



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly propagated and affects the URL patterns as expected.

# Test: Check if the setting is correctly read from the environment and affects the urlpatterns.
rg --type py IAM_REGISTRATION_ENABLED --files-with-matches | xargs cat | grep 'urlpatterns'

Length of output: 233



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly propagated and affects the URL patterns as expected.

# Test: Locate the specific usage of `IAM_REGISTRATION_ENABLED` in the codebase to ensure it correctly affects the URL patterns.
rg --type py 'IAM_REGISTRATION_ENABLED' | rg 'urlpatterns'

Length of output: 56



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly propagated and affects the URL patterns as expected.

# Test: Locate all occurrences of `IAM_REGISTRATION_ENABLED` in the codebase to manually verify its impact on URL patterns.
rg --type py 'IAM_REGISTRATION_ENABLED'

Length of output: 257

helm-chart/templates/cvat_backend/server/deployment.yml (1)

61-62: Correct addition of IAM_REGISTRATION_ENABLED environment variable in Helm chart.

Verification successful

---

# Verification of `IAM_REGISTRATION_ENABLED` Environment Variable in Helm Chart

The `IAM_REGISTRATION_ENABLED` environment variable is correctly set in the Helm chart template.

- Location: `helm-chart/templates/cvat_backend/server/deployment.yml`



</details>

<details>
<summary>Scripts Executed</summary>

The following scripts were executed for the analysis:



---

Script:
```shell
#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` environment variable is correctly set in the deployment and affects the application behavior.

# Test: Check if the environment variable is set and propagated to the application.
kubectl get deployment cvat-backend-server -o jsonpath='{.spec.template.spec.containers[?(@.name=="cvat-backend")].env[?(@.name=="IAM_REGISTRATION_ENABLED")]}'

Length of output: 236



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` environment variable is correctly set in the Helm chart templates.

# Search for the `IAM_REGISTRATION_ENABLED` environment variable in the Helm chart templates.
ast-grep --lang yaml --pattern $'- name: IAM_REGISTRATION_ENABLED\n  value: $_' helm-chart/templates/

Length of output: 210



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` environment variable is correctly set in the Helm chart templates.

# Search for the `IAM_REGISTRATION_ENABLED` environment variable in the Helm chart templates.
rg 'name: IAM_REGISTRATION_ENABLED' helm-chart/templates/

Length of output: 158

cvat/settings/base.py (1)

238-241: Conditional inclusion of 'dj_rest_auth.registration' in INSTALLED_APPS is implemented correctly.

Verification successful

The verification confirms that the IAM_REGISTRATION_ENABLED setting correctly affects the inclusion of dj_rest_auth.registration in INSTALLED_APPS.

  • cvat/settings/base.py:
    • 'dj_rest_auth.registration' is conditionally appended to INSTALLED_APPS.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly affecting the Django settings.

# Test: Check if the setting is correctly affecting the `INSTALLED_APPS`.
rg --type python $'INSTALLED_APPS' --files-with-matches | xargs cat | grep 'dj_rest_auth.registration'

Length of output: 130



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly affecting the Django settings.

# Test: Check if the setting is correctly affecting the `INSTALLED_APPS`.
rg 'INSTALLED_APPS' --type py | xargs grep 'dj_rest_auth.registration'

Length of output: 924



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly affecting the Django settings.

# Test: Check if the setting is correctly affecting the `INSTALLED_APPS`.
rg 'INSTALLED_APPS' --type py | xargs -I {} grep 'dj_rest_auth.registration' {}

Length of output: 613



Script:

#!/bin/bash
# Description: Verify that the `IAM_REGISTRATION_ENABLED` setting is correctly affecting the Django settings.

# Test: Check if the setting is correctly affecting the `INSTALLED_APPS`.
rg 'INSTALLED_APPS' --type py -l | xargs grep 'dj_rest_auth.registration'

Length of output: 203

@jackylamhk jackylamhk force-pushed the feat/allow-disable-registration branch from 723c426 to 4abe4ae Compare May 17, 2024 22:58
@jackylamhk jackylamhk requested a review from nmanovic as a code owner May 17, 2024 23:00
Copy link
Contributor

@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: 3

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 723c426 and 4abe4ae.
Files selected for processing (5)
  • cvat/apps/iam/urls.py (2 hunks)
  • cvat/settings/base.py (1 hunks)
  • docker-compose.yml (1 hunks)
  • helm-chart/templates/cvat_backend/server/deployment.yml (1 hunks)
  • helm-chart/values.yaml (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • cvat/apps/iam/urls.py
  • docker-compose.yml
  • helm-chart/templates/cvat_backend/server/deployment.yml
  • helm-chart/values.yaml
Additional Context Used
Ruff (4)
cvat/settings/base.py (4)

34-34: Module level import not at top of file


36-36: Module level import not at top of file


80-80: keys.secret_key.SECRET_KEY imported but unused


723-723: Module level import not at top of file

Comment on lines 238 to 241
IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', False))
if IAM_REGISTRATION_ENABLED:
INSTALLED_APPS.append('dj_rest_auth.registration')

Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure the conditional inclusion of 'dj_rest_auth.registration' is tested under different environments.

  • No tests were found that cover the conditional inclusion of 'dj_rest_auth.registration' or the IAM_REGISTRATION_ENABLED setting.
  • Recommend adding tests to verify that 'dj_rest_auth.registration' is included in INSTALLED_APPS only when IAM_REGISTRATION_ENABLED is true.
Analysis chain

Ensure the conditional inclusion of 'dj_rest_auth.registration' is tested under different environments.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the conditional inclusion of 'dj_rest_auth.registration' in INSTALLED_APPS.

# Test: Search for the usage of 'dj_rest_auth.registration' in the codebase. Expect: Only occurances when IAM_REGISTRATION_ENABLED is true.
rg --type python $'dj_rest_auth.registration'

Length of output: 75



Script:

#!/bin/bash
# Description: Verify the conditional inclusion of 'dj_rest_auth.registration' in INSTALLED_APPS.

# Test: Search for the usage of 'dj_rest_auth.registration' in the codebase. Expect: Only occurrences when IAM_REGISTRATION_ENABLED is true.
rg 'dj_rest_auth.registration'

Length of output: 340



Script:

#!/bin/bash
# Description: Verify the existence of tests for the conditional inclusion of 'dj_rest_auth.registration' and related functionality.

# Test: Search for tests related to 'dj_rest_auth.registration' and `IAM_REGISTRATION_ENABLED`.
rg 'dj_rest_auth.registration' --glob '*test*.py'
rg 'IAM_REGISTRATION_ENABLED' --glob '*test*.py'

Length of output: 98



Script:

#!/bin/bash
# Description: Verify the existence of tests for the INSTALLED_APPS configuration and IAM functionality.

# Test: Search for tests related to INSTALLED_APPS configuration.
rg 'INSTALLED_APPS' --glob '*test*.py'

# Test: Search for tests related to IAM functionality.
rg 'IAM' --glob '*test*.py'

Length of output: 121


Consider adding a default value for IAM_REGISTRATION_ENABLED in the environment configuration to ensure consistency across different deployment environments.

- IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', False))
+ IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', 'False'))

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.

Suggested change
IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', False))
if IAM_REGISTRATION_ENABLED:
INSTALLED_APPS.append('dj_rest_auth.registration')
IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', 'False'))
if IAM_REGISTRATION_ENABLED:
INSTALLED_APPS.append('dj_rest_auth.registration')

Refactor the handling of IAM_REGISTRATION_ENABLED to ensure it is robust against different types of input values.

- IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', False))
+ IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', 'False').strip().lower() in ['true', '1', 't', 'y', 'yes'])

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.

Suggested change
IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', False))
if IAM_REGISTRATION_ENABLED:
INSTALLED_APPS.append('dj_rest_auth.registration')
IAM_REGISTRATION_ENABLED = to_bool(os.getenv('IAM_REGISTRATION_ENABLED', 'False').strip().lower() in ['true', '1', 't', 'y', 'yes'])
if IAM_REGISTRATION_ENABLED:
INSTALLED_APPS.append('dj_rest_auth.registration')

@jackylamhk jackylamhk force-pushed the feat/allow-disable-registration branch from d5f4a00 to 9cf452f Compare May 17, 2024 23:06
@nmanovic nmanovic removed their request for review May 20, 2024 07:37
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.

None yet

1 participant