Code Monkey home page Code Monkey logo

Comments (8)

teamupdivision avatar teamupdivision commented on May 28, 2024

Hello @japc-74,

Thanks for using Creative Tim products.
We're back at the office starting Monday 3rd of Jan and we'll be able to help you then.

All the best

from ct-argon-dashboard-pro-laravel.

teamupdivision avatar teamupdivision commented on May 28, 2024

Hi @japc-74,

Thank you for reporting this and for using our products.

Would you be able to share with us the archive of the files created by you or a video/screenshot with the policy files, please? We think this will help a lot in investigating further.

Best,
UPDIVISION Team

from ct-argon-dashboard-pro-laravel.

japc-74 avatar japc-74 commented on May 28, 2024

Hello guys, thanks for your reply, this is the files created, besides the view.

ClientesPolicy

`<?php

namespace App\Policies;

use App\User;
use App\Models\Clientes;
use Illuminate\Auth\Access\HandlesAuthorization;

class ClientePolicy
{
use HandlesAuthorization;

/**
 * Determine whether the user can see the roles.
 *
 * @param  \App\User  $user
 * @return boolean
 */
public function viewAny(User $user)
{
    return $user->isAdmin();
}

/**
 * Determine whether the user can create roles.
 *
 * @param  \App\User  $user
 * @return boolean
 */
public function create(User $user)
{
    return $user->isAdmin();
}

/**
 * Determine whether the user can update the role.
 *
 * @param  \App\User  $user
 * @param  \App\Role  $role
 * @return boolean
 */
public function update(User $user, Clientes $cliente)
{
    if (env('IS_DEMO')){
        return $user->isAdmin() && !in_array($cliente->id, [1, 2, 3]);
    }
    return $user->isAdmin();
}

}
`

CreateClientesRequest

`<?php

namespace App\Http\Requests;

use App\Models\Clientes;
use Illuminate\Validation\Rule;
use Illuminate\Foundation\Http\FormRequest;

class CreateClientesRequest extends FormRequest
{

/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    
    return auth()->check();
    //return true;
}

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return Clientes::$rules;
}

}
`

ClientesRepository

`<?php

namespace App\Repositories;

use App\Models\Clientes;
use App\Repositories\BaseRepository;

/**

  • Class ClientesRepository
  • @Package App\Repositories
  • @Version December 13, 2021, 1:24 pm UTC
    */

class ClientesRepository extends BaseRepository
{
/**
* @var array
*/
protected $fieldSearchable = [
'clte_nom',
'clte_cob',
'clte_imp',
'clte_vigente'
];

/**
 * Return searchable fields
 *
 * @return array
 */
public function getFieldsSearchable()
{
    return $this->fieldSearchable;
}

/**
 * Configure the Model
 **/
public function model()
{
    return Clientes::class;
}

}
`

from ct-argon-dashboard-pro-laravel.

teamupdivision avatar teamupdivision commented on May 28, 2024

Hi @japc-74,

Thank you for the details provided.

It should be fine what you already have, but you can check also:

  1. In your controller, you should have this function that will authorize resources:
    public function __construct()
    {
    $this->authorizeResource(Tag::class);
    }

  2. Check your UserPolicy.php, there will be two functions: manageUsers and manageItems, if you use this, maybe you can take a look here to be sure that will satisfy your requirements.

  3. Also, could you give us some information about your controllers and what's your functions that display edit/update pages, please?

Please let us know.

Thank you,
UPDIVISION Team

from ct-argon-dashboard-pro-laravel.

japc-74 avatar japc-74 commented on May 28, 2024

Hello

In my controller I have this:

`

public function __construct(ClientesRepository $clientesRepo)
{
    $this->authorizeResource(Clientes::class);
    $this->clientesRepository = $clientesRepo;
}

public function index(Clientes $model)
{
    $this->authorize('manage-users', User::class);

    return view('clientes.index', ['clientes' => $model->all()]);
}

public function store(CreateClientesRequest $request, Clientes $model)
{
    
    $model->create($request->all());

    return redirect()->route('clientes.index')->withStatus(__('Cliente creado exitosamente.'));
}

public function edit(Clientes $cliente)
{
    return view('clientes.edit', compact('cliente'));
}

public function update(UpdateClientesRequest $request, Clientes $cliente)
{
    $cliente->update($request->all());

    return redirect()->route('clientes.index')->withStatus(__('Cliente actualizado exitosamente.'));
}

`

In my Policy I have this:

`

namespace App\Policies;

use App\User;
use App\Models\Clientes;
use Illuminate\Auth\Access\HandlesAuthorization;

class ClientePolicy
{
use HandlesAuthorization;

/**
 * Determine whether the user can see the roles.
 *
 * @param  \App\User  $user
 * @return boolean
 */
public function viewAny(User $user)
{
    return $user->isAdmin();
}

/**
 * Determine whether the user can create roles.
 *
 * @param  \App\User  $user
 * @return boolean
 */
public function create(User $user)
{
    return $user->isAdmin();
}

/**
 * Determine whether the user can update the role.
 *
 * @param  \App\User  $user
 * @param  \App\Role  $role
 * @return boolean
 */
public function update(User $user, Clientes $cliente)
{
    if (env('IS_DEMO')){
        return $user->isAdmin() && !in_array($cliente->id, [1, 2, 3]);
    }
    return $user->isAdmin();
}

}

`

from ct-argon-dashboard-pro-laravel.

teamupdivision avatar teamupdivision commented on May 28, 2024

Hi @japc-74,

Thank you for sharing these details. We're not sure if we understood correctly, but we believe the logic example from Tag Management may be helpful to be checked in this case. You may check the flow for Policy, Controller, Model, Request. Please let us know if this helped.

Best,
UPDIVISION Team

from ct-argon-dashboard-pro-laravel.

japc-74 avatar japc-74 commented on May 28, 2024

Hello, I appreciate your response, but unfortunately it doesn't works.
I have Policy, Controller, Model, Request and Route configured exactly as Tag, or User and I'm still getting 403 forbidden for edit and view.

Please may you share additional information to extend the functionality to other controllers views and models?

This is the guard info for tags and obviously works
Captura de Pantalla 2022-02-11 a la(s) 01 21 09

This is the info for clientes and comes empty
Captura de Pantalla 2022-02-11 a la(s) 01 21 46

from ct-argon-dashboard-pro-laravel.

teamupdivision avatar teamupdivision commented on May 28, 2024

Hi @japc-74,

Thank you for the additional details. We would probably need to analyze this in detail as it is a new custom feature. Unfortunately, at the moment we are not able to figure out a quick solution to give you an idea. 



If you need help with any of your projects, we're happy to get in touch. We do custom development for start-ups and companies across the globe (you can check out our portfolio here https://updivision.com/portfolio and some happy clients over here https://updivision.com/testimonials). Don`t hesitate to drop us a line at [email protected] or by using our contact form (https://updivision.com/contact).

All the best,
UPDIVISON Team

from ct-argon-dashboard-pro-laravel.

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.