rabol / filament-logviewer

Logviewer for Filament admin
MIT License
9 stars 5 forks source link

Issue with custom policy not being used in Laravel Log Viewer #6

Closed mohammedBamatraf closed 1 year ago

mohammedBamatraf commented 1 year ago

I downloaded the log viewer library in Laravel and followed the installation instructions. However, I'm encountering an error when trying to use my custom policy. The error message states: "Rabol\FilamentLogviewer\Policies\LogFilePolicy::delete(): Argument #1 ($user) must be of type App\Models\User, App\Models\Admin given, called in C:\github\backend-rakeb\vendor\laravel\framework\src\Illuminate\Auth\Access\Gate.php on ...".

Steps to Reproduce:

  1. Install the log viewer library following the provided instructions.
  2. Open the configuration file located at config/filament-logviewer.php.
  3. In the configuration file, ensure that the policy_class key is set to the correct namespace and class name of your custom policy, which is App\Policies\LogFilePolicy::class.
  4. Save the configuration file.

Expected Behavior: I expected the log viewer library to use my custom policy, App\Policies\LogFilePolicy, for authorization checks.

Actual Behavior: Instead of using my custom policy, the log viewer library is trying to use Rabol\FilamentLogviewer\Policies\LogFilePolicy and encountering a type error when calling the delete method.

Custom Policy Contents:


<?php

namespace App\Policies;

use App\Models\Admin;
use Illuminate\Auth\Access\HandlesAuthorization;

class LogFilePolicy
{
    use HandlesAuthorization;

    public function view(Admin $Admin)
    {
        return true;
    }

    public function viewAny(Admin $Admin)
    {
        return true;
    }

    public function create(Admin $Admin)
    {
        return true;
    }

    public function update(Admin $Admin)
    {
        return true;
    }

    public function delete(Admin $Admin)
    {
        return true;
    }

    public function deleteAny(Admin $Admin)
    {
        return true;
    }
}

Contents of config/filament-logviewer.php:
<?php
// config for Rabol/FilamentLogviewer

use App\Policies\LogFilePolicy;

return [
    'navigation_group' => 'System',
    'model_class' => \Rabol\FilamentLogviewer\Models\LogFile::class,
    'policy_class' => LogFilePolicy::class,
];
mohammedBamatraf commented 1 year ago

Note to: @rabol , @curder , @onexer

mohammedBamatraf commented 1 year ago

@rabol , @curder , @onexer , any Update

rabol commented 1 year ago

Not really sure how to fix this as you can see the code is registreing the policy that is in the config:

https://github.com/rabol/filament-logviewer/blob/7b32b80392eb2cd29f28e68af2e002d0419a4da2/src/FilamentLogviewerServiceProvider.php#L57

mohammedBamatraf commented 1 year ago

i found the problem thank you