KoolReport's Forum

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

Using Permit class with pages #3297

Closed Eugene opened this topic on on May 22 - 5 comments

Eugene commented on May 22

Hi,

in your example you use Permit class in App.php

But if I use pages the function sidebar() is located in the page file and I get an error Call to undefined method koolreport\dashboard\Permit::hasSpecialReportAccess()

I tried to move permision() function to my MemberPage.php but it has not helped.

MemberPage.php


use Utils\AppPermit;

class MemberPage extends Main
{
    protected function onCreated()
    {
        $this->loginRequired(true); // Do need login to access

    }

    protected function permision()
    {
        return AppPermit::create();
    }

    protected function sidebar()
    {
        return [
            'Special Reports' => Section::create()->enabledWhen('hasSpecialReportAccess')->sub([
                'Wine Report' => WineReportBoard::create()->enabledWhen('hasSpecialReportAccess')->icon('fas fa-glass')

                ]),
        ];
...

AppPermit.php

class AppPermit extends \koolreport\dashboard\Permit
{
    protected function beAdmin($request, $sender)
    {
        return $request->user()->hasRole('admin');
    }

    protected function hasSpecialReportAccess($request, $sender)
    {
        return $request->user()->hasRole('special-report');
    }
}

So, how to use Permit class with Pages? Or what am I doing wrong?

KoolReport commented on May 22

Hi Eugene,

The permission() method is available in App only, when you assign the the custom Permit with your own functions.

Please move the permission() to your App file, it will work.

Let us know if you need further assistance.

Eugene commented on May 22

Well so I keep the permission method in App but use enabledWhen in my MemberPage class?

No it does not work: Call to undefined method koolreport\dashboard\Permit::hasSpecialReportAccess()

KoolReport commented on May 22

What I mean is you move the permission() method to Application level:

class App extends Application
{
    protected function permission()
    {
         return AppPermit::create();
    }
}

and in the MemberPage, you can use enabledWhen() like you do now.

Eugene commented on May 22

I have found the reason of the issue

you have a typo in your example here https://www.koolreport.com/docs/dashboard/permission/

permiSion()

KoolReport commented on May 22

Oh, our bad, I have fixed the documentation. Thank you very much for letting us know and sorry for your time taken.

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
help needed

Dashboard