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

Update Readme to help out new folk #8

Closed
JohnRoux opened this issue Mar 29, 2021 · 10 comments
Closed

Update Readme to help out new folk #8

JohnRoux opened this issue Mar 29, 2021 · 10 comments

Comments

@JohnRoux
Copy link

Hey,

It would be great if you could add an example of how to modify the gate in the Dashboard Authorization section

It's a crucial part of the install and not all users will be familiar with extending vendor Service Providers 👍

@cja-github
Copy link

I need to know how to do this. I cannot use this package if its webpage will be public.

@robersonfaria
Copy link
Owner

Hi, I've been very busy for the past few weeks, I will try to improve the documentation now.
But basically the package requires that you have a Gate called "viewDatabaseSchedule" defined in some Service Provider, in it you can do the validation that you find most convenient to your business rule.

I don't recommend leaving the cron configuration in public mode, but if you wish you can simply return true to your gate.
Example:

Gate::define('viewDatabaseSchedule', function ($user) {
     return true;
});

I will add a little more documentation.

Thank you for your interest.

@cja-github
Copy link

cja-github commented Apr 12, 2021

Thank you for your reply.

I see you provide a gate in called viewDatabaseSchedule in vendor/robersonfaria/laravel-database-schedule/src/DatabaseScheduleApplicationServiceProvider.php.

If I add another gate with the same name then will the gate I add override your gate? Or will they conflict with each other in some way?

@JohnRoux
Copy link
Author

JohnRoux commented Apr 12, 2021

As long as you register your gate after this one, yours will override.

So if you put it in your App Service Provider*, you're good 👍

@cja-github
Copy link

cja-github commented Apr 12, 2021

Thank you. I've just tried this, returning false in the gate definition, and I can still access the webpage (/schedule).

This is the contents of app/Providers/AppServiceProvider.php:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Gate::define('viewDatabaseSchedule', function ($user) {
            return false;//$user->hasRole('Administrator');
        });
    }
}

And now I think about it, the default gate provided by the package should have denied access before I added my overriding gate above, but it let me access the webpage. The default gate is:

        Gate::define('viewDatabaseSchedule', function ($user) {
            return in_array($user->email, [
                //
            ]);
        });

So either I'm doing something wrong (likely) or the access control doesn't work.

@JohnRoux
Copy link
Author

JohnRoux commented Apr 12, 2021 via email

@cja-github
Copy link

cja-github commented Apr 12, 2021

Do you mean that if I change APP_ENV in .env to production then the gate should work?

I just did that then ran php artisan cache:clear and was still able to load the webpage.

Hopefully I did the wrong thing...

@robersonfaria
Copy link
Owner

I have improved the documentation a little, but after that I saw that the @cja-github question has not yet been answered, I am doing some more tests and I will update again, give me a few minutes to do so.

@robersonfaria
Copy link
Owner

I added a configuration to make the route public and left the gate by default false, so it is mandatory to inform a gate if the route is not public.
I also updated the documentation to explain this situation.
If you have any suggestions for improving the documentation or implementing the access restriction, please send a pull request, I will be happy to review and approve.

Thank you for your contribution @cja-github @JohnRoux

I will close this issue, but if they still find any problem they can reopen.

@cja-github
Copy link

Thank you very much.

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

3 participants