KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Unauthorized when click second level in Dashboard DrillDown #3470

Open Daniel Cordeiro opened this topic on on Feb 11 - 5 comments

Daniel Cordeiro commented on Feb 11

Hello,

I created a Drilldown in my dashboard. But, when I click in one month, the graph shows me the sentence;

{"panels":{"Page":["
\n
\n
\n
\n
\n
401<\/h1>\n
Unauthorized<\/h4>\n

This is restricted area, please contact admin for access granting.<\/p>\n <\/div>\n <\/div>\n <\/div>\n <\/div>\n<\/div>",null]},"scripts":[]}

This is my code:

class DrillDownDemo extends DrillDown
{
  protected function levels()
    {
        return [
            Level::create()
                ->title("Meses")
                ->widget(
                    KWidget::create()
                    ->use(\koolreport\widgets\google\ColumnChart::class)
                    ->dataSource(function($params, $scope){
                      return AutoMaker::table("pedidos ped")
                              ->selectRaw("extract(month from ped.data_resposta) as mes")
                              ->count("ped.identificacao")->alias("total")
                              ->where("extract(year from ped.data_resposta)",date('Y') ) 
                              ->where('ped.fk_cliente', 3455) 
                              ->groupBy("mes")->run();
                    })->columns([
                        "mes"=>["type"=>"string"],
                        "total"=>["type"=>"number"]
                    ])
                ),
            //Segundo Nivel
            Level::create()
                ->title(function($params){
                    return "Mes ".$params["mes"];
                })
                ->widget(
                    KWidget::create()
                    ->use(\koolreport\widgets\google\ColumnChart::class)
                    ->dataSource(function($params, $scope) {
                      return AutoMaker::table("pedidos ped")
                        ->selectRaw("extract(day from ped.data_resposta) as dia")
                        ->count("ped.identificacao")->alias("total")
                        ->where('ped.fk_cliente', 3455)
                        ->where("extract(year from ped.data_resposta)",date('Y'))
                        ->where("extract(mont from ped.data_resposta)",$params["mes"])
                        ->groupBy("dia")->run();
                    })
                    ->columns([
                        "dia"=>[
                            "type"=>"string"                          
                        ],
                        "total"=>[
                            "type"=>"number",
                        ]
                    ])
                ),
];
}

I don't use any permissions nether roles in my page.
Sebastian Morales commented on Mar 3

Sorry for the delay. Pls check these docs to see if your Dashboard uses the following permission:

Dashboard permission

Dashboard Admin panel permission

Pablo Tavares commented 2 days ago

These links don't lead anywhere, please explain how to resolve this authorization error as quickly as possible.

Tell me which file I should edit so that it works afterwards.

DRILLDOWN SCREEN

<?php

namespace App\Dashboard\TCU;

use Database\AutoMaker;
use \koolreport\dashboard\widgets\drilldown\DrillDown;
use \koolreport\dashboard\widgets\drilldown\Level;
use \koolreport\dashboard\widgets\KWidget;

class DrillDownDemo extends DrillDown
{
    protected function levels()
    {
        return [

            // NIVEL 1 - MESES
            Level::create()
                ->title("Meses")
                ->widget(
                    KWidget::create()
                        ->use(\koolreport\widgets\google\ColumnChart::class)
                        ->dataSource(function($params,$scope){

                            return AutoMaker::table("tb_pedidos ped")
                                ->selectRaw("extract(month from ped.data_resposta) as mes")
                                ->count("ped.identificacao")->alias("total")
                                ->whereRaw("extract(year from ped.data_resposta)=2025")
                                ->where('ped.fk_cliente',4804734)
                                ->whereIn('ped.status',['C','P'])
                                ->groupBy("mes")
                                ->orderBy("mes")
                                ->run();
                        })
                        ->columns([
                            "mes"=>[
                                "type"=>"number"
                            ],
                            "total"=>[
                                "type"=>"number"
                            ]
                        ])
                ),

            // NIVEL 2 - DIAS
            Level::create()
                ->title(function($params){
                    return "Mês ".$params["mes"];
                })
                ->widget(
                    KWidget::create()
                        ->use(\koolreport\widgets\google\ColumnChart::class)
                        ->dataSource(function($params,$scope){

                            return AutoMaker::table("tb_pedidos ped")
                                ->selectRaw("extract(day from ped.data_resposta) as dia")
                                ->count("ped.identificacao")->alias("total")
                                ->whereRaw("extract(year from ped.data_resposta)=2025")
                                ->whereRaw("extract(month from ped.data_resposta)=".$params["mes"])
                                ->where('ped.fk_cliente',4804734)
                                ->whereIn('ped.status',['C','P'])
                                ->groupBy("dia")
                                ->orderBy("dia")
                                ->run();
                        })
                        ->columns([
                            "dia"=>[
                                "type"=>"number"
                            ],
                            "total"=>[
                                "type"=>"number"
                            ]
                        ])
                )
        ];
    }
}

ARCHIVE APP

<?php
//App.php
// use \koolreport\dashboard\amazing\Theme;
// use koolreport\amazing\dashboard\Amazing;
namespace App;
use \koolreport\dashboard\languages\PTBR;   //Portuguese Brazil

use \koolreport\dashboard\Application;
use \koolreport\appstack\dashboard\AppStack;
use \koolreport\dashboard\User;
use \koolreport\dashboard\pages\Login;
use App\Dashboard\Gerencial\GerencialBoard;
use App\Dashboard\Financeiro\FinanceiroBoard;
use App\Dashboard\Performance\PerformanceBoard;
use App\Dashboard\Produtos\ProdutosBoard;
use App\Dashboard\Categorias\CategoriasBoard;
use App\Dashboard\SLA\SLABoard;
use App\Dashboard\PDM\PDMBoard;
use App\Dashboard\TCU\TCUBoard;
use App\Dashboard\Contrato\ContratoBoard;
use App\Dashboard\Compras\ComprasBoard;
use \koolreport\dashboard\ExportHandler;
// use \koolreport\dashboard\export\ChromeHeadlessio;
use \koolreport\dashboard\export\CSVEngine;
// use \koolreport\dashboard\export\LocalExport;
use Database\AutoMaker;
use Database\AutoMakerPdm;

class App extends Application
{
    protected function onCreated()
    {
        $this->language(PTBR::create())
            ->csrf(\koolreport\dashboard\security\CSRF::create())
            ->theme(
                AppStack::create()
                    ->colorScheme("dark") //"default", "colored", "dark", "light"
                    ->sidebarBehavior("sticky") //"sticky","fixed","compact"
                    ->layout("fluid") //"fluid" or "boxed"
            )
            ->debugMode(true)
            ->user(
                $this->user()
            );

        $this->language(PTBR::create());
    }

    protected function sidebar()
    {
        return [
            "Gerencial" => GerencialBoard::create()->icon("fa fa-chart-line")
                ->params([
                    "Year" => date('Y')
                ]),
            "Saving" => PerformanceBoard::create()->icon("fa fa-piggy-bank"),
            "SLA" => SLABoard::create()->icon("fa fa-stopwatch"),
            // "Fornecedores" => FinanceiroBoard::create(),
            "Produtos" => ProdutosBoard::create()->icon("fa fa-boxes"),
            // "Associadas" => FinanceiroBoard::create(),
            "PDM" => PDMBoard::create()->icon("fa fa-project-diagram"),
            "Compras" => ComprasBoard::create()->icon("fa fa-shopping-cart"),
            "Contrato" => ContratoBoard::create()->icon("fa fa-file-contract"),
            "Categorias" => CategoriasBoard::create()->icon("fa fa-cubes"),
            "TCU" => TCUBoard::create()->icon("fa fa-gavel")
                        ->enabled(function($request){
                            return $request->user()->hasRole("user");
                        }),
        ];
    }

    protected function login()
    {
        // commented code
    }
  
    protected function allowAccess($request)
    {
        $user = $request->user();
        $route = $request->route();
        $action = $request->action();
        $params = $request->params();

        //Allow true to allow access and false otherwise
        return true;
    }
    protected function export()
    {
        return ExportHandler::create()
            ->storage(dirname(__DIR__) . "/storage/exports")
            ->csvEngine(
                CSVEngine::create()
                    ->defaultConfig([
                        "BOM" => false,
                        "buffer" => 100,
                    ])
                    ->delimiter(",")
                    ->rawData(true)
            );
        // ->pdfEngine(
        // LocalExport::create()
        // ChromeHeadlessio::create()->token("ecd9cda54738e4b67f73e71853db89d57fd9c1b808a3374e66c2eceb3fd1f59f")
        // );
    }
}

ARCHIVE BOARD

<?php

namespace App\Dashboard\TCU;

// use AssociadasSelect;
use \koolreport\dashboard\Dashboard;

use \koolreport\dashboard\containers\Row;
use \koolreport\dashboard\languages\PTBR;
use \koolreport\dashboard\containers\Panel;
use \koolreport\dashboard\containers\Html;
use App\Dashboard\TCU;
// use \koolreport\dashboard\inputs\Button;
// use \koolreport\dashboard\Client;
// use App\Field\AnoSelect;
// use ComprasAnoCard;
// use SavingAnoCard;

class TCUBoard extends Dashboard
{
    protected function onCreate()
    {
        $this->title("TCU")
            ->hidden(false)
            ->icon("fa fa-home")
            ->badge(["NEW", "danger"])
            ->updateEffect("fade")
            ->language(PTBR::create())
            ->pdfExportable(true);    //Allow exporting 

        $params = $this->params();
    }

    protected function content()
    {
        return [
            // Row::create()
            Panel::create()->header("<b>DrillDown</b>")->sub([
                DrillDownDemo::create()
            ]),
            // ->sub([            
            //     DrillDownDemo::create()                
            // ]),    
        ];       
    }
}
Sebastian Morales commented 1 day ago

Would you pls let us know your Dashboard version, which could be found in the json file .../koolreport/dashboard/composer.json?

Pablo Tavares commented 1 day ago

{
    "name": "koolreport/dashboard",
    "version":"4.8.3",
    "description": "A sleek php framework to construct modern dashboard and admin panel",
    "keywords": ["PHP","report","dashboard","framework","admin panel"],
    "homepage": "https://www.koolreport.com",
    "type": "library",
    "license": "https://www.koolreport.com/license",
    "require": {
        "koolreport/pro":">=6.0"
    }
}

Sebastian Morales commented 7 hours ago

I think this is a csrf token validation when sending request. Pls add the csrf token value to your Drilldown widget like this:

class DrillDownDemo extends DrillDown
{
    protected function onInit()
    {
        $this->settings([
            "global" => [
                "_token" => $this->app()->csrf()->token(),
                ...
            ],
            ...

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
bug
help needed

DrillDown