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

Upgraded workflows-service TypeScript version #2148

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

Omri-Levy
Copy link
Contributor

@Omri-Levy Omri-Levy commented Mar 2, 2024

User description

Description

  1. Upgraded workflows-service TypeScript version to latest
  2. Commented out nest-access-control code since it does not work with TypeScript version 5 and up

Type

enhancement, bug_fix


Description

  • Commented out all usages of nest-access-control across various files, effectively disabling ACL checks.
  • Upgraded TypeScript version from ^4.9.3 to ^5.3.3.
  • This change affects multiple controllers and interceptors, indicating a shift away from using nest-access-control for access control logic.
  • Tests and configuration files have been updated to reflect the removal of ACL-related logic.

Changes walkthrough

Relevant files
Enhancement
acl-validate-request.interceptor.ts
Comment Out ACL Request Validation Interceptor                     

services/workflows-service/src/common/access-control/interceptors/acl-validate-request.interceptor.ts

  • Commented out the entire AclValidateRequestInterceptor class.
+42/-42 
acl-filter-response.interceptor.ts
Comment Out ACL Response Filter Interceptor                           

services/workflows-service/src/common/access-control/interceptors/acl-filter-response.interceptor.ts

  • Commented out the entire AclFilterResponseInterceptor class.
  • Added an import statement for Permission from "accesscontrol".
  • +37/-36 
    workflow.controller.external.ts
    Disable ACL in External Workflow Controller                           

    services/workflows-service/src/workflow/workflow.controller.external.ts

    • Commented out import and usage of nestAccessControl.
    +4/-5     
    workflow.controller.internal.ts
    Disable ACL in Internal Workflow Controller                           

    services/workflows-service/src/workflow/workflow.controller.internal.ts

    • Commented out import and usage of nestAccessControl.
    +8/-8     
    Tests
    workflow.controller.external.unit.test.ts
    Disable ACL in External Workflow Controller Unit Tests     

    services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts

  • Commented out imports and usage of ACL related interceptors and
    guards.
  • Added AclFilterResponseInterceptor import statement.
  • +8/-8     
    nest-app-helper.ts
    Disable ACL in Test Helper                                                             

    services/workflows-service/src/test/helpers/nest-app-helper.ts

  • Commented out overrides for ACL related guards and interceptors in
    test helper.
  • +9/-9     
    Configuration changes
    acl.module.ts
    Disable ACL Module Setup                                                                 

    services/workflows-service/src/common/access-control/acl.module.ts

    • Commented out the entire ACL module setup.
    +9/-9     
    Dependencies
    package.json
    Remove ACL Dependency and Upgrade TypeScript                         

    services/workflows-service/package.json

  • Removed nest-access-control dependency.
  • Upgraded TypeScript version to ^5.3.3.
  • +1/-2     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    changeset-bot bot commented Mar 2, 2024

    ⚠️ No Changeset found

    Latest commit: 066bfbd

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    @github-actions github-actions bot added enhancement New feature or request bug_fix labels Mar 2, 2024
    Copy link
    Contributor

    github-actions bot commented Mar 2, 2024

    PR Description updated to latest commit (7f0d3ed)

    Copy link
    Contributor

    github-actions bot commented Mar 2, 2024

    PR Review

    ⏱️ Estimated effort to review [1-5]

    4, because the PR involves significant changes across multiple files, including the removal of access control logic and an upgrade of TypeScript version. Reviewing these changes requires a thorough understanding of the project's architecture, security implications, and potential impact on existing functionality.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Removing nest-access-control and related access control logic could introduce security vulnerabilities if not properly replaced or if the removal was unintended.

    The upgrade of TypeScript version might introduce compatibility issues with existing code or dependencies.

    🔒 Security concerns

    Yes, because the removal of access control logic (nest-access-control) across various files could potentially expose sensitive endpoints or data if not adequately replaced or managed.

    Code feedback:
    relevant fileservices/workflows-service/src/common/access-control/interceptors/acl-validate-request.interceptor.ts
    suggestion      

    Consider implementing custom access control logic or integrating another library to replace the commented-out nest-access-control functionality to ensure the application's endpoints remain secure. [important]

    relevant line// import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';

    relevant fileservices/workflows-service/src/common/access-control/acl.module.ts
    suggestion      

    If access control logic is being replaced or removed, ensure that the new implementation is correctly integrated into the ACL module or consider removing the module if it's no longer needed. [important]

    relevant line// import { AccessControlModule, RolesBuilder } from 'nest-access-control';

    relevant fileservices/workflows-service/package.json
    suggestion      

    Ensure all dependencies are compatible with the upgraded TypeScript version ^5.3.3 to prevent potential build or runtime errors. [important]

    relevant line"typescript": "^5.3.3"

    relevant fileservices/workflows-service/src/workflow/workflow.controller.external.unit.test.ts
    suggestion      

    Update unit tests to reflect the removal of nest-access-control and ensure that custom access control logic (if implemented) is adequately tested. [medium]

    relevant line// import { ACGuard } from 'nest-access-control';


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
    When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    

    With a configuration file, use the following template:

    [pr_reviewer]
    some_config1=...
    some_config2=...
    
    Utilizing extra instructions

    The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

    Examples for extra instructions:

    [pr_reviewer] # /review #
    extra_instructions="""
    In the 'possible issues' section, emphasize the following:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    How to enable\disable automation
    • When you first install PR-Agent app, the default mode for the review tool is:
    pr_commands = ["/review", ...]
    

    meaning the review tool will run automatically on every PR, with the default configuration.
    Edit this field to enable/disable the tool, or to change the used configurations

    Auto-labels

    The review tool can auto-generate two specific types of labels for a PR:

    • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
    • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
    Extra sub-tools

    The review tool provides a collection of possible feedbacks about a PR.
    It is recommended to review the possible options, and choose the ones relevant for your use case.
    Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
    require_score_review, require_soc2_ticket, and more.

    Auto-approve PRs

    By invoking:

    /review auto_approve
    

    The tool will automatically approve the PR, and add a comment with the approval.

    To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:

    [pr_reviewer]
    enable_auto_approval = true
    

    (this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)

    You can also enable auto-approval only if the PR meets certain requirements, such as that the estimated_review_effort is equal or below a certain threshold, by adjusting the flag:

    [pr_reviewer]
    maximal_review_effort = 5
    
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the review usage page for a comprehensive guide on using this tool.

    Copy link
    Contributor

    github-actions bot commented Mar 2, 2024

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Security
    Re-enable the 'nest-access-control' import to ensure role-based access control is enforced.

    Uncomment and resolve the dependency on 'nest-access-control'. It's essential for
    enforcing role-based access control in your controllers.

    services/workflows-service/src/business/business.controller.external.ts [8]

    -// import * as nestAccessControl from 'nest-access-control';
    +import * as nestAccessControl from 'nest-access-control';
     
    Re-enable the AccessControlModule setup for role-based access control.

    Uncomment the AccessControlModule setup to ensure role-based access control is properly
    configured throughout the application.

    services/workflows-service/src/common/access-control/acl.module.ts [2-15]

    -// import { AccessControlModule, RolesBuilder } from 'nest-access-control';
    -// import grants from '../../grants.json';
    -//
    -// const rolesBuilder = new RolesBuilder(grants);
    -//
    -// @Module({
    -// imports: [AccessControlModule.forRoles(rolesBuilder)],
    -// providers: [
    -//   {
    -//     provide: RolesBuilder,
    -//     useValue: rolesBuilder,
    -//   },
    -// ],
    -// exports: [RolesBuilder], // Export RolesBuilder
    -// })
    +import { AccessControlModule, RolesBuilder } from 'nest-access-control';
    +import grants from '../../grants.json';
     
    +const rolesBuilder = new RolesBuilder(grants);
    +
    +@Module({
    +  imports: [AccessControlModule.forRoles(rolesBuilder)],
    +  providers: [
    +    {
    +      provide: RolesBuilder,
    +      useValue: rolesBuilder,
    +    },
    +  ],
    +  exports: [RolesBuilder], // Export RolesBuilder
    +})
    +
    Re-enable the AclFilterResponseInterceptor to ensure response data is filtered based on permissions.

    Uncomment the AclFilterResponseInterceptor to filter response data based on user
    permissions.

    services/workflows-service/src/common/access-control/interceptors/acl-filter-response.interceptor.ts [1-37]

    -// import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
    -// ...
    -// export class AclFilterResponseInterceptor implements NestInterceptor {
    -// ...
    -// }
    +import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
    +...
    +export class AclFilterResponseInterceptor implements NestInterceptor {
    +...
    +}
     
    Re-enable the AclValidateRequestInterceptor to validate requests based on roles and permissions.

    Uncomment the AclValidateRequestInterceptor to validate requests against user roles and
    permissions.

    services/workflows-service/src/common/access-control/interceptors/acl-validate-request.interceptor.ts [1-42]

    -// import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
    -// ...
    -// export class AclValidateRequestInterceptor implements NestInterceptor {
    -// ...
    -// }
    +import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
    +...
    +export class AclValidateRequestInterceptor implements NestInterceptor {
    +...
    +}
     
    Ensure secure access control mechanisms are in place.

    If the roles and access control are being refactored or temporarily disabled, ensure to
    address any security implications or provide an alternative mechanism for access control.

    services/workflows-service/src/workflow/workflow.controller.external.ts [45-46]

    -// @nestAccessControl.InjectRolesBuilder()
    -// protected readonly rolesBuilder: nestAccessControl.RolesBuilder,
    +// Example of alternative or updated access control mechanism
    +// This is a placeholder for the actual implementation
     
    Ensure tests maintain security integrity.

    If the access control guards are being refactored or temporarily disabled for testing,
    make sure to mock or implement alternative security checks to maintain the integrity of
    the tests.

    services/workflows-service/src/workflow/workflow.controller.external.unit.test.ts [87-88]

    -// .overrideGuard(ACGuard)
    -// .useValue(acGuard)
    +// Example of mocking or alternative security checks
    +// This is a placeholder for the actual implementation
     
    Maintainability
    Ensure ACGuard and interceptors are included in test setups for access control testing.

    Uncomment the overrides for ACGuard and interceptors in the test setup to ensure access
    control is tested.

    services/workflows-service/src/test/helpers/nest-app-helper.ts [77-82]

    -// .overrideGuard(ACGuard)
    -// .useValue(acGuard)
    -// .overrideInterceptor(AclFilterResponseInterceptor)
    -// .useValue(aclFilterResponseInterceptor)
    -// .overrideInterceptor(AclValidateRequestInterceptor)
    -// .useValue(aclValidateRequestInterceptor)
    +.overrideGuard(ACGuard)
    +.useValue(acGuard)
    +.overrideInterceptor(AclFilterResponseInterceptor)
    +.useValue(aclFilterResponseInterceptor)
    +.overrideInterceptor(AclValidateRequestInterceptor)
    +.useValue(aclValidateRequestInterceptor)
     
    Remove unused or commented-out imports.

    Consider removing the commented-out import of nest-access-control if it is no longer
    needed in the project. This helps in keeping the codebase clean and maintainable.

    services/workflows-service/src/workflow/workflow.controller.external.ts [9]

    -// import * as nestAccessControl from 'nest-access-control';
     
    +
    Replace or remove deprecated access control references.

    If the nest-access-control package is being phased out, ensure that all references,
    including decorators like @nestAccessControl.UseRoles, are replaced or removed to avoid
    runtime errors.

    services/workflows-service/src/workflow/workflow.controller.internal.ts [306-310]

    -// @nestAccessControl.UseRoles({
    -//   resource: 'Workflow',
    -//   action: 'delete',
    -//   possession: 'own',
    -// })
    +// Example of alternative or updated access control decorator
    +// This is a placeholder for the actual implementation
     
    Possible issue
    Verify intentional removal of dependencies to avoid breaking changes.

    Ensure that the removal of nest-access-control from the dependencies is intentional and
    that all its usages have been refactored or replaced within the project to avoid breaking
    changes.

    services/workflows-service/package.json [89-91]

     "nestjs-cls": "^3.5.0",
     "nestjs-prisma": "0.20.0",
     "nestjs-zod": "^3.0.0",
    +// Ensure all dependencies are correctly managed
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    @Omri-Levy
    Copy link
    Contributor Author

    @alonp99 let me know if we can delete the lines and files related to nest-access-control.

    @Omri-Levy Omri-Levy merged commit 4f5fbe8 into dev Mar 4, 2024
    9 checks passed
    @Omri-Levy Omri-Levy deleted the omri-levy/feat/workflows-service-ts-version branch March 4, 2024 17:13
    chesterkmr pushed a commit that referenced this pull request Mar 11, 2024
    * refactor(workflows-service): commented out nest-access-control and upgraded typescript to latest
    
    * fix(*): fixed failing tests
    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