Giter Site home page Giter Site logo

Comments (5)

robclancy avatar robclancy commented on May 23, 2024

I'm not sure I would call it a bug but that could be improved. I'm confused by the syntax you show though since it's not blade or PHP.

from presenter.

n3storm avatar n3storm commented on May 23, 2024

Sorry I did not make myself clear enough cause Twig is an all time classic:

The syntax is Twig https://twig.symfony.com/, using https://github.com/rcrowe/TwigBridge, which Readme states that supports "can" as a function (though I am not using that) and found no issue regards "can" checking.

The following is pseudocode:

Do not work:

if myuser.can('update', mymodel)
    do whatever...
endif

can('update', mymodel)
    do whatever...
endcan

Do work after exposing protected object:

if myuser.can('update', mymodel.object)
    do whatever...
endif

can('update', mymodel.object)
    do whatever...
endcan

Haven't checked with Blade but my bet is it will not work either.

IMHO: decorating the model disables the container ability to resolve dependencies to be injected. I am not a dependency expert.

from presenter.

robclancy avatar robclancy commented on May 23, 2024

Laravel maps models to policies. So that is what is failing saying it doesn't find a policy so it will just return false. I think we can simply add can to the presenter instance that retries on the object directly. And also add any other permission based methods.

from presenter.

n3storm avatar n3storm commented on May 23, 2024

Are you saying if I add a can() method to my presenter make this work?

https://laravel.com/docs/10.x/authorization#via-the-user-model

Something like this?

public function can($action)
{
    return \Auth::user()->can($action, $this->object);
}

Then in my views:

myobject.can('update')

Though it may work, it looks wrong cause it shoud be read as myobject.canbe('updated')

I don't think you mean that :D

from presenter.

robclancy avatar robclancy commented on May 23, 2024
public function can($abilities, $arguments = [])
{
    if (method_exists($this->object, 'can')) {
        return $this->object->can($abilities, $arguments);
    }
}

This is a quick and dirty way to do it. I would do it similar I think but checking the interface instead of method and maybe implement the interface in the presenter.

https://github.com/laravel/framework/blob/10.x/src/Illuminate/Contracts/Auth/Access/Authorizable.php

If it still doesn't work then you can implement that interface as well since there could be checks for it somewhere.

from presenter.

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.