Skip to content

Conversation

@nikhilsinhaparseable
Copy link
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Oct 20, 2025

allow admins to get, update and delete dashboards and filters

Summary by CodeRabbit

  • New Features
    • Administrators can now view, update, add to, and delete dashboards and filters across the system.
    • Admins are recognized via session-based permission checks, granting broader access than regular users.

allow admins to get, update and delete dashboards and filters
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Walkthrough

The changes introduce admin-aware authorization across handlers and data layers. A new is_admin(req) util extracts admin status from session permissions; handlers compute and propagate is_admin to data-layer methods. Dashboard and filter methods now accept is_admin and permit admin access in ownership checks.

Changes

Cohort / File(s) Summary
Handler layer admin propagation
src/handlers/http/users/dashboards.rs, src/handlers/http/users/filters.rs
Handlers call is_admin(req) and pass the resulting is_admin boolean to downstream data-layer calls; is_admin errors are mapped into handler-specific error variants.
Data layer — dashboards
src/users/dashboards.rs
Added is_admin: bool parameter to get_dashboard_by_user, delete_dashboard, and ensure_dashboard_ownership; ownership checks updated to allow access when is_admin is true.
Data layer — filters
src/users/filters.rs
get_filter signature updated to accept is_admin: bool; selection logic now returns a filter if the user matches OR is_admin is true.
Utilities
src/utils/mod.rs
New public is_admin(req: &HttpRequest) -> Result<bool, anyhow::Error> that extracts session info and computes admin status from permissions.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Handler as Handler Layer
    participant Utils as Utils (is_admin)
    participant Data as Data Layer
    participant DB as Database

    Client->>Handler: Request (GET/UPDATE/DELETE)
    Handler->>Utils: is_admin(req)
    Utils->>DB: extract session -> fetch permissions
    DB-->>Utils: permissions
    Utils-->>Handler: Result<bool>

    alt is_admin OK
        Handler->>Data: call method with is_admin
        Data->>DB: verify ownership OR allow if is_admin
        DB-->>Data: item / not found / error
        Data-->>Handler: result
        Handler-->>Client: response
    else is_admin Err
        Handler->>Handler: map error to Custom error
        Handler-->>Client: error response
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • update dashboard implementation #1348 — Extends dashboard/filter handlers and data-layer methods to thread is_admin and perform admin-aware checks (touches same functions/signatures).
  • dashboard changes #1362 — Modifies dashboard ownership/authorization paths including ensure_dashboard_ownership and related dashboard functions.

Suggested labels

for next release

Poem

🐰 I hopped through code with a curious twitch,

Passed an admin flag with a nimble switch,
Owners still hold, but admins may see,
Permissions now bloom — a new key for me! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description is severely incomplete compared to the repository's template requirements. The provided description is a single sentence ("allow admins to get, update and delete dashboards and filters") that lacks the structured sections specified in the template, including: a detailed description of the PR goal, explanation of possible solutions and rationale, detailed key changes made, and the testing/documentation checklist items. While the description is not entirely off-topic and does relate to the PR objective, it fails to meet the minimum expected documentation standards by missing nearly all required template sections. The author should expand the PR description to follow the template structure by: adding a comprehensive Description section explaining the goal, rationale for the chosen approach, and detailed key changes; including a "Fixes #XXXX" reference if applicable; and completing the checklist items indicating whether testing was performed, comments were added, and documentation was updated. This will provide reviewers with the necessary context and ensure proper documentation of the changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "add admin authorizations to dashboards and filters" directly reflects the core changes in the changeset. The raw summary confirms that the primary modifications involve introducing admin checks via is_admin(req) and propagating this parameter through dashboard and filter operation methods to allow admins to access, update, and delete resources in addition to the original owner. The title is concise, specific, and clearly communicates the main objective of the changes without unnecessary noise or vagueness.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab18e39 and ad97ff9.

📒 Files selected for processing (1)
  • src/utils/mod.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: coverage
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

🧹 Nitpick comments (1)
src/utils/mod.rs (1)

159-159: Avoid unnecessary String allocation in permission check.

The current check allocates a new String for comparison. Consider using a string literal instead.

Apply this diff:

-    Ok(permissions.contains(&String::from("admin")))
+    Ok(permissions.contains(&"admin".to_string()) || permissions.iter().any(|p| p == "admin"))

Or even simpler, if the collection supports it:

-    Ok(permissions.contains(&String::from("admin")))
+    Ok(permissions.iter().any(|p| p == "admin"))
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f6da2e and ab18e39.

📒 Files selected for processing (5)
  • src/handlers/http/users/dashboards.rs (4 hunks)
  • src/handlers/http/users/filters.rs (4 hunks)
  • src/users/dashboards.rs (4 hunks)
  • src/users/filters.rs (1 hunks)
  • src/utils/mod.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-01T10:27:56.858Z
Learnt from: nikhilsinhaparseable
PR: parseablehq/parseable#1305
File: src/handlers/http/users/dashboards.rs:0-0
Timestamp: 2025-05-01T10:27:56.858Z
Learning: The `add_tile()` function in `src/handlers/http/users/dashboards.rs` should use `get_dashboard_by_user(dashboard_id, &user_id)` instead of `get_dashboard(dashboard_id)` to ensure proper authorization checks when modifying a dashboard.

Applied to files:

  • src/users/dashboards.rs
  • src/handlers/http/users/dashboards.rs
🧬 Code graph analysis (5)
src/utils/mod.rs (3)
src/utils/actix.rs (2)
  • req (31-31)
  • extract_session_key_from_req (51-71)
src/rbac/user.rs (3)
  • userid (80-85)
  • userid (239-241)
  • from (201-211)
src/rbac/map.rs (2)
  • from (294-302)
  • from (346-354)
src/users/filters.rs (1)
src/utils/mod.rs (1)
  • is_admin (149-160)
src/handlers/http/users/filters.rs (2)
src/utils/actix.rs (2)
  • extract_session_key_from_req (51-71)
  • req (31-31)
src/utils/mod.rs (3)
  • get_hash (70-75)
  • get_user_from_request (60-68)
  • is_admin (149-160)
src/users/dashboards.rs (1)
src/utils/mod.rs (1)
  • is_admin (149-160)
src/handlers/http/users/dashboards.rs (2)
src/utils/mod.rs (3)
  • get_hash (70-75)
  • get_user_from_request (60-68)
  • is_admin (149-160)
src/users/dashboards.rs (1)
  • validate_dashboard_id (167-170)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Build Default aarch64-unknown-linux-gnu
  • GitHub Check: Build Kafka x86_64-unknown-linux-gnu
  • GitHub Check: Build Default x86_64-pc-windows-msvc
  • GitHub Check: Build Default x86_64-apple-darwin
  • GitHub Check: Build Kafka aarch64-apple-darwin
  • GitHub Check: Build Default aarch64-apple-darwin
  • GitHub Check: Build Default x86_64-unknown-linux-gnu
  • GitHub Check: Quest Smoke and Load Tests for Standalone deployments
  • GitHub Check: Quest Smoke and Load Tests for Distributed deployments
  • GitHub Check: coverage
🔇 Additional comments (10)
src/handlers/http/users/filters.rs (3)

43-60: Admin authorization integrated correctly.

The handler now properly computes admin status and passes it to get_filter, allowing admins to access any filter while maintaining owner-based access for non-admin users. The error handling is appropriate.


79-106: Admin bypass correctly implemented for filter updates.

The update handler properly checks admin status before authorizing filter modifications. The implementation allows admins to update any filter while preserving ownership checks for regular users.


108-127: Deletion authorization enhanced with admin support.

The delete handler correctly incorporates admin checking, allowing administrators to remove any filter while maintaining the existing authorization model for regular users.

src/users/filters.rs (1)

135-150: Admin-aware filter retrieval implemented correctly.

The updated get_filter() method signature and logic properly incorporate admin authorization. The condition f.user_id == Some(user_id.to_string()) || is_admin correctly allows admins to bypass ownership checks while maintaining user-based filtering for regular users.

src/handlers/http/users/dashboards.rs (3)

100-187: Admin authorization correctly integrated into dashboard updates.

The update_dashboard handler now computes admin status and passes it to get_dashboard_by_user, properly allowing administrators to update any dashboard. The error handling maintains clear messaging for authorization failures.


189-203: Dashboard deletion now supports admin authorization.

The delete handler correctly computes admin status and delegates authorization to the data layer via delete_dashboard. This maintains the separation of concerns while enabling admin access.


205-236: Admin authorization added while maintaining proper authorization checks.

The add_tile handler now computes admin status and correctly uses get_dashboard_by_user with the is_admin flag for authorization. This aligns with previous guidance to use get_dashboard_by_user instead of get_dashboard for proper authorization checks when modifying dashboards.

Based on learnings.

src/users/dashboards.rs (3)

294-316: Dashboard deletion method properly updated with admin support.

The delete_dashboard method signature correctly accepts the is_admin parameter and threads it through to ensure_dashboard_ownership, maintaining the authorization model while enabling admin access.


335-352: Admin-aware dashboard retrieval correctly implemented.

The get_dashboard_by_user method now accepts is_admin and correctly implements the bypass logic: d.author == Some(user_id.to_string()) || is_admin. This allows administrators to access any dashboard while maintaining owner-based access for regular users, consistent with the filter implementation.


410-423: Ownership verification updated to respect admin privileges.

The ensure_dashboard_ownership helper correctly delegates to get_dashboard_by_user with the is_admin flag, maintaining its role as an authorization validator while incorporating admin bypass logic.

@nitisht nitisht merged commit c9fa7c7 into parseablehq:main Oct 21, 2025
13 checks 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.

2 participants