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

fix: upstream sync #109

Merged
merged 22 commits into from
Feb 25, 2024
Merged

fix: upstream sync #109

merged 22 commits into from
Feb 25, 2024

Conversation

SergeWilfried
Copy link
Owner

@SergeWilfried SergeWilfried commented Feb 25, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a DeleteAccountDialog component for users to delete their account with support for two-factor authentication.
    • Added functionality to cancel pending documents and transfer ownership upon user deletion.
    • Implemented a service account retrieval function for deleted user accounts.
    • Enhanced theme customization options with new configurations for 'field-card'.
    • Updated button styles to include a focus-visible ring effect for the destructive variant.
  • Refactor
    • Improved readability of the forwardPorts array in the development container configuration.
    • Updated import statements across various modules for better consistency and performance.
  • Bug Fixes
    • Fixed styling inconsistencies in document flow components and added new styles for better alignment with the design system.
  • Chores
    • Created a new user account for deleted accounts in the database with predefined attributes.

ephraimduncan and others added 22 commits January 20, 2024 19:07
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
	- Added two-factor authentication form handling in profile settings.
- Introduced account deletion functionality, including Stripe customer
data removal.
- Updated UI components and styles for improved user interaction, such
as enhanced visual feedback for destructive actions.
- **Refactor**
- Improved code quality by updating import statements for type-only
imports.
- **Chores**
- Restructured the `forwardPorts` array in dev container configuration
for clarity.
- Removed a trailing comma in the `vscode` extensions list to adhere to
JSON format rules.
- **Documentation**
- Added comments to clarify the handling of undefined values in
two-factor authentication verification.
- **Database**
- Implemented a SQL migration script for creating a default deleted user
in the system.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@SergeWilfried SergeWilfried self-assigned this Feb 25, 2024
Copy link

coderabbitai bot commented Feb 25, 2024

Walkthrough

Walkthrough

The recent updates focus on enhancing user experience and code readability across the project. Key changes include the addition of a new DeleteAccountDialog component for account deletion, improved two-factor authentication handling, and updates to styling and theme configurations. Additionally, backend adjustments were made for user deletion processes and document ownership management. The codebase also saw improvements in import statements for better clarity and maintenance.

Changes

Files Summary
.devcontainer/devcontainer.json, packages/trpc/react/index.tsx, packages/lib/server-only/2fa/validate-2fa.ts, packages/lib/server-only/2fa/verify-2fa-token.ts Improved code readability by restructuring arrays and modifying import statements.
apps/web/src/app/.../settings/profile/delete-account-dialog.tsx, apps/web/src/app/.../settings/profile/page.tsx, apps/web/src/components/forms/profile.tsx, packages/lib/server-only/user/delete-user.ts, packages/trpc/server/profile-router/router.ts Introduced and integrated DeleteAccountDialog for account deletion, including two-factor authentication handling and backend deletion processes.
packages/lib/server-only/user/service-accounts/deleted-account.ts, packages/prisma/migrations/20240205120648_create_delete_account/migration.sql Managed service account retrieval and database updates for deleted user accounts.
packages/tailwind-config/index.cjs, packages/ui/primitives/..., packages/ui/styles/theme.css Updated styling and theme configurations for UI components.

Poem

🐰💻
In the code where changes bloom,
A rabbit hopped, dispelling gloom.
With each line neat and functionality new,
It crafted a world, bright and true.
Through ports and dialogs, themes so bright,
It danced in the moonlight, coding by night. 🌙✨

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between eb97e12 and 6ea6dda.
Files selected for processing (16)
  • .devcontainer/devcontainer.json (2 hunks)
  • apps/web/src/app/(dashboard)/settings/profile/delete-account-dialog.tsx (1 hunks)
  • apps/web/src/app/(dashboard)/settings/profile/page.tsx (2 hunks)
  • apps/web/src/components/forms/profile.tsx (3 hunks)
  • packages/lib/server-only/2fa/validate-2fa.ts (1 hunks)
  • packages/lib/server-only/2fa/verify-2fa-token.ts (1 hunks)
  • packages/lib/server-only/user/delete-user.ts (2 hunks)
  • packages/lib/server-only/user/service-accounts/deleted-account.ts (1 hunks)
  • packages/prisma/migrations/20240205120648_create_delete_account/migration.sql (1 hunks)
  • packages/tailwind-config/index.cjs (1 hunks)
  • packages/trpc/react/index.tsx (1 hunks)
  • packages/trpc/server/profile-router/router.ts (2 hunks)
  • packages/ui/primitives/button.tsx (1 hunks)
  • packages/ui/primitives/document-flow/add-fields.tsx (2 hunks)
  • packages/ui/primitives/document-flow/field-item.tsx (1 hunks)
  • packages/ui/styles/theme.css (1 hunks)
Additional comments: 9
packages/prisma/migrations/20240205120648_create_delete_account/migration.sql (1)
  • 1-30: The migration script is well-structured and follows best practices for conditional data insertion. It ensures that the service account is created only if it does not already exist, which is crucial for idempotency in migrations.
apps/web/src/app/(dashboard)/settings/profile/page.tsx (1)
  • 18-26: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [8-23]

The integration of the DeleteAccountDialog component into the profile settings page is correctly implemented. The component is imported and used with appropriate props, enhancing the page's functionality.

packages/lib/server-only/2fa/verify-2fa-token.ts (1)
  • 4-4: The use of import type for importing the User type is a best practice in TypeScript, optimizing the bundle size by ensuring that type imports do not result in any runtime JavaScript code.
packages/lib/server-only/2fa/validate-2fa.ts (1)
  • 1-1: The change to use import type for the User type is consistent with TypeScript best practices, ensuring that type imports do not contribute to the runtime JavaScript code.
apps/web/src/components/forms/profile.tsx (2)
  • 32-36: The introduction of ZTwoFactorAuthTokenSchema and TTwoFactorAuthTokenSchema for two-factor authentication token validation is a good practice for ensuring the correctness and security of user inputs. It's important to validate the format of the token received from the user to prevent potential security vulnerabilities.
  • 58-62: Adding support for two-factor authentication (hasTwoFactorAuthentication) and account deletion functionality (deleteAccount) within the ProfileForm component enhances the application's security and user control over their data. However, ensure that the backend properly handles the two-factor authentication process and securely deletes user data to prevent any data leaks or unauthorized access.
Verification successful

The executed scripts have provided extensive details on the implementation of two-factor authentication and account deletion features within the backend. From the output, we can observe the following:

  1. Two-Factor Authentication (2FA):

    • The backend has a dedicated router for two-factor authentication (twoFactorAuthenticationRouter) as seen in packages/trpc/server/router.ts.
    • There are schemas defined for setting up, enabling, and disabling two-factor authentication in packages/trpc/server/two-factor-authentication-router/schema.ts.
    • The actual implementation for setting up, enabling, and disabling 2FA, as well as viewing recovery codes, is found in packages/trpc/server/two-factor-authentication-router/router.ts. This includes authenticated procedures, indicating that user authentication is required to perform these actions.
    • The User model in the Prisma schema (packages/prisma/schema.prisma) includes fields related to two-factor authentication, such as twoFactorSecret, twoFactorEnabled, and twoFactorBackupCodes, indicating that the user's 2FA settings are stored in the database.
  2. Account Deletion:

    • The account deletion functionality is implemented as an authenticated procedure within the profile-router (packages/trpc/server/profile-router/router.ts), indicating that user authentication is required to delete an account.
    • The frontend component DeleteAccountDialog in apps/web/src/app/(dashboard)/settings/profile/delete-account-dialog.tsx interacts with the deleteAccount mutation from the backend, providing a UI for users to delete their accounts.

These findings confirm that the backend properly handles the two-factor authentication process and securely deletes user data, with appropriate authentication checks in place to prevent unauthorized access. The implementation details suggest that the application adheres to security best practices for these features.

Given the evidence from the script outputs, the review comment regarding the addition of two-factor authentication and account deletion functionality enhancing the application's security and user control over their data is verified. The backend implementations for these features have been confirmed to securely handle user data and require proper authentication checks.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the backend implementation for two-factor authentication and account deletion
# Ensure secure handling of user data and proper authentication checks
echo "Manual verification required for backend implementations of two-factor authentication and account deletion."

Length of output: 224



Script:

#!/bin/bash
# Search for backend implementation of two-factor authentication
rg "twoFactor|2FA|authenticate|verification" --ignore-case

# Search for backend implementation of account deletion
rg "deleteAccount|removeUser|accountDeletion" --ignore-case

Length of output: 57717

packages/trpc/server/profile-router/router.ts (1)
  • 160-176: The addition of the deleteAccount method to the profileRouter is a significant enhancement for user control over their data. It's important to ensure that this method properly authenticates the user before proceeding with account deletion and handles any potential errors gracefully to provide a smooth user experience. Additionally, consider logging this action for audit purposes.
packages/ui/primitives/document-flow/add-fields.tsx (2)
  • 326-328: The updates to the CSS classes and styles for the Card component, including new classes related to borders and opacity, enhance the visual consistency and user interaction experience. It's important to ensure that these changes are consistently applied across all instances of the Card component to maintain a uniform appearance throughout the application.
  • 339-339: The modification of class names for the CardContent component for consistency is a good practice for maintainability and readability of the code. Ensure that these class name changes are reflected wherever the CardContent component is used to avoid styling inconsistencies.

Comment on lines +3 to +16
export const deletedAccountServiceAccount = async () => {
const serviceAccount = await prisma.user.findFirst({
where: {
email: '[email protected]',
},
});

if (!serviceAccount) {
throw new Error(
'Deleted account service account not found, have you ran the appropriate migrations?',
);
}

return serviceAccount;
Copy link

Choose a reason for hiding this comment

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

Consider externalizing the email address '[email protected]' to an environment variable for easier configuration and to avoid hardcoding values in the codebase. Additionally, enhancing the error message to include steps for running migrations could improve developer experience.

-      email: '[email protected]',
+      email: process.env.DELETED_ACCOUNT_SERVICE_EMAIL,

And for the error message:

-      'Deleted account service account not found, have you ran the appropriate migrations?',
+      'Deleted account service account not found. Please ensure you have run the appropriate migrations and that the DELETED_ACCOUNT_SERVICE_EMAIL environment variable is correctly set.',

@@ -1,5 +1,6 @@
import { TRPCError } from '@trpc/server';

import { deleteUser } from '@documenso/lib/server-only/user/delete-user';
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The deleteUser function implementation primarily focuses on transferring documents associated with the user to a service account and then deleting the user record. However, there are a few considerations for ensuring comprehensive data deletion:

  • The presence of a TODO comment suggests that the functionality to send out cancellations for all pending documents is not yet implemented, indicating the function might not fully address all aspects of user data.
  • The function does not explicitly mention handling other user-related data (e.g., sessions, preferences), which might be necessary for a thorough account deletion process.

Given these observations, it's recommended to review the deleteUser function further to ensure it comprehensively handles all aspects of user data deletion, including the completion of the noted TODO and consideration of other user-related data.

Analysis chain

The import of deleteUser from @documenso/lib/server-only/user/delete-user is crucial for enabling account deletion functionality. It's important to ensure that the deleteUser function properly handles all aspects of user data deletion, including associated documents and any other related data, to maintain data integrity and privacy.


Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the implementation of deleteUser function to ensure comprehensive data deletion
echo "Manual verification required for the deleteUser function implementation."

Length of output: 154



Script:

#!/bin/bash
# Attempt to locate and display the contents of the deleteUser function implementation
fd "delete-user\.(js|ts)" --exec cat {}

Length of output: 1014

@SergeWilfried SergeWilfried merged commit b81c620 into SergeWilfried:main Feb 25, 2024
5 of 9 checks passed
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.

4 participants