Git Product home page Git Product logo

Comments (10)

cja-github avatar cja-github commented on May 23, 2024 2

Thank you very much.

from laravel-database-schedule.

JohnRoux avatar JohnRoux commented on May 23, 2024 1

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 👍

from laravel-database-schedule.

cja-github avatar cja-github commented on May 23, 2024 1

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.

from laravel-database-schedule.

robersonfaria avatar robersonfaria commented on May 23, 2024 1

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.

from laravel-database-schedule.

robersonfaria avatar robersonfaria commented on May 23, 2024 1

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.

from laravel-database-schedule.

cja-github avatar cja-github commented on May 23, 2024

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

from laravel-database-schedule.

robersonfaria avatar robersonfaria commented on May 23, 2024

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.

from laravel-database-schedule.

cja-github avatar cja-github commented on May 23, 2024

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?

from laravel-database-schedule.

JohnRoux avatar JohnRoux commented on May 23, 2024

from laravel-database-schedule.

cja-github avatar cja-github commented on May 23, 2024

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...

from laravel-database-schedule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.