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: show guided tour on first connection #1404

Conversation

nas-tabchiche
Copy link
Contributor

@nas-tabchiche nas-tabchiche commented Jan 22, 2025

  • Add accessible domains to User type
  • Display guided tour on first time connection

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced user profile with additional attributes including user groups, roles, permissions, and domain access.
    • Added first-time connection tracking for improved user onboarding experience.
  • Backend Updates

    • Implemented retrieval of accessible domains for authenticated users.
  • Frontend Updates

    • Updated sidebar component to manage first-time connection state.
    • Streamlined guided tour logic by removing translation steps and adjusting display conditions.

Copy link

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request introduces enhancements to user management and access control across multiple frontend and backend files. The changes focus on expanding user metadata, implementing accessible domain retrieval, and refining the first-time user connection experience. The modifications include updating the user interface type definitions, adding new store management for first-time connections, and modifying the sidebar component to handle guided tour logic based on accessible domains.

Changes

File Change Summary
backend/iam/views.py - Added Folder model import
- Implemented accessible_domains retrieval in CurrentUserView
frontend/src/lib/components/SideBar/SideBar.svelte - Replaced firstTime with firstTimeConnection
- Removed wrapStepWithTranslation function
- Updated guided tour trigger logic
frontend/src/lib/utils/stores.ts - Added firstTimeConnection persistent store
- Reorganized Driver import
frontend/src/lib/utils/types.ts - Extended User interface with new properties:
- user_groups
- roles
- permissions
- is_third_party
- is_admin
- accessible_domains

Sequence Diagram

sequenceDiagram
    participant User
    participant Backend
    participant Frontend
    participant Store

    User->>Backend: Login Request
    Backend->>Backend: Retrieve User Details
    Backend->>Frontend: Return User Data with Accessible Domains
    Frontend->>Store: Update firstTimeConnection
    Frontend->>Frontend: Determine Guided Tour Visibility
Loading

Poem

🐰 A Rabbit's Ode to Access Control 🔐

Domains dance, permissions sing,
First connections take their wing,
User types now rich and bright,
Guided tours now shine just right!

Code hops forward with glee! 🚀


🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@nas-tabchiche nas-tabchiche changed the title CA 818 suggest loading dummy data and or guided tour if there are no accessible domains feat: show guided tour to admin on first connection Jan 22, 2025
@nas-tabchiche nas-tabchiche changed the title feat: show guided tour to admin on first connection feat: show guided tour on first connection Jan 22, 2025
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.

Actionable comments posted: 2

🧹 Nitpick comments (3)
frontend/src/lib/utils/stores.ts (1)

5-5: LGTM! Consider documenting the store's purpose.

The implementation of the persisted store for tracking first-time connection is correct. Consider adding a brief comment explaining its purpose and persistence behavior.

 import type { Driver } from 'driver.js';

+// Persisted store to track and remember if this is user's first time connecting
 export const firstTimeConnection = persisted('firstTimeConnection', true);

Also applies to: 19-19

frontend/src/lib/utils/types.ts (1)

12-17: Consider using more specific types instead of Record<string, any>.

While the additions to the User interface are good, using Record<string, any> for user_groups, roles, and permissions is too permissive and could lead to type-safety issues.

Consider defining specific interfaces for these properties:

interface UserGroup {
  id: string;
  name: string;
  // add other relevant fields
}

interface Role {
  id: string;
  name: string;
  // add other relevant fields
}

interface Permission {
  id: string;
  name: string;
  // add other relevant fields
}

export interface User {
  // ...existing fields
  user_groups: UserGroup[];
  roles: Role[];
  permissions: Permission[];
  // ...other fields
}
backend/iam/views.py (1)

73-75: Consider caching the accessible domains query.

The get_accessible_folders query might be expensive. Consider caching the result, especially if it's accessed frequently.

from django.core.cache import cache

# In get method
cache_key = f'user_{request.user.id}_accessible_domains'
accessible_domains = cache.get(cache_key)
if accessible_domains is None:
    accessible_domains = RoleAssignment.get_accessible_folders(
        Folder.get_root_folder(), request.user, Folder.ContentType.DOMAIN
    )
    cache.set(cache_key, accessible_domains, timeout=3600)  # Cache for 1 hour
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d0a017 and 96c71d1.

📒 Files selected for processing (4)
  • backend/iam/views.py (3 hunks)
  • frontend/src/lib/components/SideBar/SideBar.svelte (2 hunks)
  • frontend/src/lib/utils/stores.ts (2 hunks)
  • frontend/src/lib/utils/types.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: build (3.12)
  • GitHub Check: Analyze (python)
  • GitHub Check: test (3.12)
  • GitHub Check: ruff (3.12)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
frontend/src/lib/components/SideBar/SideBar.svelte (1)

192-195: Consider edge cases in tour trigger logic.

Setting $firstTimeConnection to false immediately after triggering the tour might cause issues if the user closes or interrupts the tour before completion.

Consider tracking tour completion instead:

 if ($firstTimeConnection) {
   triggerVisit();
-  $firstTimeConnection = false; // This will prevent the tour from showing up again on page reload
+  // Listen for tour completion before setting firstTimeConnection to false
+  $driverInstance?.onDestroyStarted(() => {
+    if ($driverInstance?.isLastStep()) {
+      $firstTimeConnection = false;
+    }
+  });
 }

Comment on lines 17 to 18
const user = $page.data?.user;
$firstTimeConnection = $firstTimeConnection && user.accessible_domains.length === 0;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use reactive statement for store value updates.

Direct mutation of store values outside of reactive statements can lead to reactivity issues.

-$firstTimeConnection = $firstTimeConnection && user.accessible_domains.length === 0;
+$: $firstTimeConnection = $firstTimeConnection && user.accessible_domains.length === 0;
📝 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
const user = $page.data?.user;
$firstTimeConnection = $firstTimeConnection && user.accessible_domains.length === 0;
const user = $page.data?.user;
$: $firstTimeConnection = $firstTimeConnection && user.accessible_domains.length === 0;

@@ -82,6 +85,7 @@ def get(self, request) -> Response:
"permissions": request.user.permissions,
"is_third_party": request.user.is_third_party,
"is_admin": request.user.is_admin(),
"accessible_domains": [str(f) for f in accessible_domains],
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for string conversion.

The list comprehension for converting folders to strings might fail if any folder object is invalid.

-"accessible_domains": [str(f) for f in accessible_domains],
+"accessible_domains": [str(f) for f in accessible_domains if f is not None],
📝 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
"accessible_domains": [str(f) for f in accessible_domains],
"accessible_domains": [str(f) for f in accessible_domains if f is not None],

Copy link
Collaborator

@eric-intuitem eric-intuitem left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
frontend/src/lib/components/SideBar/SideBar.svelte (2)

181-188: Add error handling for driver initialization.

The driver initialization should be wrapped in a try-catch block to handle potential runtime errors gracefully.

 function triggerVisit() {
-    const translatedSteps = steps;
-    const driverObj = driver({
-        showProgress: true,
-        steps: translatedSteps
-    });
-    $driverInstance = driverObj;
-    driverObj.drive();
+    try {
+        const translatedSteps = steps;
+        const driverObj = driver({
+            showProgress: true,
+            steps: translatedSteps
+        });
+        $driverInstance = driverObj;
+        driverObj.drive();
+    } catch (error) {
+        console.error('Failed to initialize guided tour:', error);
+        // Consider showing a user-friendly error message
+    }
 }

201-203: Add null check for user properties and optimize reactive dependencies.

The reactive statement assumes user and user.is_admin are always defined. Also, consider moving this statement before the firstTimeConnection update to optimize reactivity chain.

-$: displayGuidedTour = $firstTimeConnection && user.is_admin;
+$: displayGuidedTour = $firstTimeConnection && user?.is_admin === true;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96c71d1 and 8ad0983.

📒 Files selected for processing (1)
  • frontend/src/lib/components/SideBar/SideBar.svelte (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: build (3.12)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
frontend/src/lib/components/SideBar/SideBar.svelte (4)

8-15: LGTM! Clean import organization and prop typing.

The imports are well-organized and the open prop is properly typed as a boolean.


190-195: LGTM! Clean mount logic implementation.

The mount logic correctly checks the display condition before triggering the tour and properly updates the store afterward.


199-199: Use reactive statement for store value updates.

Direct mutation of store values outside of reactive statements can lead to reactivity issues.

-$: $firstTimeConnection = $firstTimeConnection && user.accessible_domains.length === 0;
+$: $firstTimeConnection = $firstTimeConnection && user?.accessible_domains?.length === 0;

17-17: Add null check for user data access.

The optional chaining on data is good, but accessing properties on potentially undefined user later in the code could cause runtime errors.

Copy link
Collaborator

@Mohamed-Hacene Mohamed-Hacene left a comment

Choose a reason for hiding this comment

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

0k

@Mohamed-Hacene Mohamed-Hacene merged commit 6b0fb66 into main Jan 24, 2025
21 checks passed
@Mohamed-Hacene Mohamed-Hacene deleted the CA-818-suggest-loading-dummy-data-and-or-guided-tour-if-there-are-no-accessible-domains branch January 24, 2025 14:32
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants