Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twill 3 custom roles & permissions are not working #2716

Open
shamith-smp-dgt opened this issue Jan 27, 2025 · 0 comments
Open

Twill 3 custom roles & permissions are not working #2716

shamith-smp-dgt opened this issue Jan 27, 2025 · 0 comments

Comments

@shamith-smp-dgt
Copy link

Description

Hello, I'm trying to create new roles and add permissions to them. i want to make some modules only accessible by some of the new roles I've created. I followed the twill documentation and I still get Forbidden yellow screen error when i try to access a certain module as the new user role i created.

It looks like the code in AuthServiceProvider is not redefining twill's default permissions. how do i fix this?

Steps to reproduce

here is my code,

Models/Enums/UserRole.php

class UserRole extends Enum
{
    const VIEWONLY = 'View Only';
    const PUBLISHER = 'Publisher';
    const ADMIN = 'Admin';

    const VIEWER = 'Viewer';
    const EDITOR = 'Editor';
}

Providers/AppServiceProvider.php

public function register(): void
    {        \A17\Twill\Facades\TwillPermissions::setRoleEnum(\App\Models\Enums\UserRole::class);
    }

Providers/AuthServiceProvider.php

    public function boot(): void
    {
        Gate::define('list', function ($user) {
            return in_array($user->role_value, [
                UserRole::VIEWONLY,
                UserRole::VIEWER,
                UserRole::EDITOR,
                UserRole::ADMIN
            ]);
        });
    }

Expected result

When i logged in as a VIEWER and visit a module, I should be able to see it.

Actual result

But a I get a Forbidden yellow screen error.

Versions

Twill version: 3.4
Laravel version: 11.9
PHP version: 8.2
Database engine: MySQL

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

No branches or pull requests

1 participant