Overview
The Report Management module handles Power BI report configuration, embedding, access control, and token management. It provides interfaces for administrators to add reports and for all users to view their assigned reports. Controller:ReportController (app/Http/Controllers/ReportController.php:16)Model:
Report (app/Models/Report.php:11)Trait:
PowerBITrait (app/Traits/PowerBITrait.php)Vue Components:
resources/js/Pages/Report/Index.vueresources/js/Pages/Report/View.vueresources/js/Pages/Report/Import.vue
Key Features
Report Configuration
Configure Power BI report IDs, group IDs, and access levels
Token Management
Automatic generation and refresh of embed tokens
Import from Power BI
Import reports directly from Power BI workspace
User Assignment
Control which users can access each report
Filter Integration
Apply user-specific filters to reports
Embedded Viewing
Seamlessly embed reports using Power BI JavaScript SDK
Data Model
TheReport model represents Power BI report configurations:
Relationships
Created By (HasOne):Filter Array Accessor
The model includes a computed attribute that formats filters for Power BI:Permissions
Report management routes require specific permissions (routes/web.php:105-161):report.create: Create and edit reportsreport.edit: Edit existing reportsreport.destroy: Delete reportsimport-report: Import reports from Power BI
super-admin role can access all reports.
API Endpoints
List Reports
- Super admins see all reports
- Other users see only assigned reports
reports: Collection of accessible reports
View Report
groupId: Power BI workspace/group IDreportId: Power BI report ID
- Super admins can view any report
- Other users can only view assigned reports
- Returns 403 error if user doesn’t have access
- Check if report has valid embed token
- If token is null or expired, request new token from Power BI
- Cache token in database with expiration date
- Add user access token and embed URL to report object
- Redirects to report index
- Displays danger banner with error message
Create Report
- Create new report record
- Set
user_idto authenticated user - Save to database
- Return updated reports list
Update Report
Delete Report
- Delete report record
- Cascade removes user assignments and filters
- Return remaining reports
Power BI Import
The system includes functionality to import reports directly from Power BI workspace.Import Interface
import-report
Implementation: ImportReportController.php
Get Available Reports
- Authenticate with Power BI using service principal or user credentials
- Query workspace for available reports
- Return report metadata (name, ID, group ID, dataset ID)
import-report
Import Report
import-report
Token Management
Reports use two types of tokens:User Access Token
Obtained viagetUserAccessToken() method from PowerBITrait:
- Used to authenticate API requests to Power BI
- Generated using Azure AD authentication
- Typically valid for 1 hour
- Automatically refreshed when expired
Report Embed Token
Generated viagetReportAccessToken($userToken, $report) method:
- Used to embed reports in the application
- Scoped to specific report and user
- Cached in database (
reports.tokenfield) - Expiration stored in
reports.expiration_date - Automatically refreshed when expired
Token Refresh Logic
Token caching significantly reduces API calls to Power BI and improves page load performance.
Access Levels
Reports support different access levels:- View: Read-only access to report
- Edit: Can modify report visuals and filters (within Power BI)
- Create: Can create new pages and content
Access level is set at the report configuration level, not per user. All users assigned to a report inherit the same access level.
User Assignment
Reports are assigned to users through theuser_reports pivot table:
Pivot Table Columns
user_id: Foreign key to usersreport_id: Foreign key to reportsshow: Boolean flag for dashboard visibility (default: false)
Report Filtering
User-specific filters can be applied to reports:Filter Configuration
Filters are configured via the Report Filters module and assigned through the user management interface.Filter Application
When a report loads, thefilter_array accessor generates a JSON structure:
Filter Operators
Supported operators:In: Value is in listNotIn: Value is not in listEquals: Value equalsNotEquals: Value does not equalContains: String containsNotContains: String does not containGreaterThan: Numeric greater thanLessThan: Numeric less than
Embed URL Structure
Reports are embedded using the following URL pattern:Report Viewer Component
The frontend uses Power BI JavaScript SDK to embed reports:Error Handling
Token Generation Failure
If Power BI API fails to generate embed token:Report Not Found
If report doesn’t exist or user doesn’t have access:Best Practices
Descriptive Names
Use clear report names that reflect content (e.g., “Monthly Sales Dashboard”, “Inventory Levels Report”).
Access Control
Only assign reports to users who need them. Use filters to restrict data visibility.
Regular Cleanup
Remove unused reports and revoke access from users who no longer need it.
Monitor Performance
Large reports with many filters can impact load times. Optimize Power BI datasets.
Usage Workflow
Import or Create
Import report from Power BI using import interface, or manually create report configuration.
Related Modules
Dashboard
Displays embedded reports for users
Users
Assign reports to users
Report Filters
Configure data filters for reports