Find Modules according to Permissions

Asked

Viewed 204 times

2

I designed a function that lists all modules and sub-modules within the system. But I need it to be different, I need that in this same listing, only come the modules and submodules that the customer has access to, rather than checking whether he has permission or not. I’ll expose how I did:

Function for Listing Modules:

public function getModulosCategoria(){
    $sql = "SELECT * FROM modulos WHERE idModuloBase = '0'";
    $consulta = $this->db->query($sql)->result();   

        foreach($consulta as &$valor){
            $sql_model = "SELECT * FROM modulos WHERE idModuloBase = '{$valor->idModulo}'";
            $valor->subModulo = $this->db->query($sql_model)->result();     
        }

    return $consulta;
}

In the listing I do the following check:

foreach($modulo->subModulo as $submodulo){
    $permissao = "a".ucfirst($submodulo->pasta);
    if($this->permission->checkPermission($this->session->userdata('permissao'),$permissao)){
         Exibe o Link para o Modulo...

So far it’s working 100%, but I need to do it differently. I want you to list all the modules, just look for the allowed modules.

Table of Modules inserir a descrição da imagem aqui

Permissions Table: inserir a descrição da imagem aqui

Return field permissions within table permissions:

a:12:{i:0;s:9:"aCedentes";i:1;s:9:"eCedentes";i:2;s:9:"dCedentes";i:3;s:9:"vCedentes";i:4;s:9:"aUsuarios";i:5;s:9:"eUsuarios";i:6;s:9:"dUsuarios";i:7;s:9:"vUsuarios";i:8;s:13:"aFornecedores";i:9;s:13:"eFornecedores";i:10;s:13:"dFornecedores";i:11;s:13:"vFornecedores";}

Set the modules of each client: inserir a descrição da imagem aqui

1 answer

0

You need to change your query to fetch the modules by relating to the table permissions. Then return the list of modules with access to a certain user for example.

But I don’t see a link between the table modules and the table permissions.

I couldn’t see your json either.

  • I have the impression that you should use the comments instead of using the "answer" option for this.

  • Exactly, because the permission is recorded separately... I write inside the permission table, as if I create several types of permissions, and then only select which permission the client has... But I managed to settle the matter differently.

  • I would, but I still can’t comment on the question, I can’t say why but tell me I need 50 points.

  • Ue, if you decided to put your answer and mark your answer as right. Someone may have the same doubt. Sorry for the lack of accents.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.