Skip to content

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
Ajustar pacote ACL novo padrão
  • Loading branch information
Nandovga committed Jan 30, 2024
1 parent 7800263 commit c1f5658
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 223 deletions.
2 changes: 1 addition & 1 deletion src/Acl/Model/Perfil.php → src/Acl/Model/PerfilModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Perfil extends Model
class PerfilModel extends Model
{
use HasFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PerfilPermissoes extends Model
class PerfilPermissoesModel extends Model
{
use HasFactory;

Expand Down
14 changes: 14 additions & 0 deletions src/Acl/Model/PermissoesGrupoModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Orangecode\Acl\Model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PermissoesGrupoModel extends Model
{
use HasFactory;

/** @var string */
public $table = 'acl_permissoes_grupo';
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Permissoes extends Model
class PermissoesModel extends Model
{
use HasFactory;

Expand Down
14 changes: 14 additions & 0 deletions src/Acl/Model/PermissoesModuloModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Orangecode\Acl\Model;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PermissoesModuloModel extends Model
{
use HasFactory;

/** @var string */
public $table = 'acl_permissoes_Modulo';
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class PermissoesUsuario extends Model
class PermissoesUsuarioModel extends Model
{
use HasFactory;

Expand Down
27 changes: 21 additions & 6 deletions src/Acl/Repository/PerfilAclRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@

namespace Orangecode\Acl\Repository;

use Orangecode\Acl\Model\Perfil;
use Illuminate\Database\Eloquent\Collection;
use Orangecode\Acl\Model\PerfilModel;
use Orangecode\Repository\Repository;
use Orangecode\Repository\RepositoryDataBase;

/**
* Repository - Perfil Acl
*/
class PerfilAclRepository implements Repository
{
use RepositoryDataBase;

/** @var Perfil */
private Perfil $model;
private PerfilModel $model;

public function __construct(PerfilModel $perfil)
{
$this->model = $perfil;
}

/**
* @param Perfil $perfil
* Realiza a pesquisa - Perfil Acl
*/
public function __construct(Perfil $perfil)
public function findAll(int $filial): Collection
{
$this->model = $perfil;
return $this->model::where('id_filial', $filial)
->get()
->map(function ($item) {
$data = $item;
$data->id_acl_perfil = $item->id;
$data->label = $item->nome;
return $data;
});
}
}
41 changes: 35 additions & 6 deletions src/Acl/Repository/PerfilPermissoesAclRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,51 @@

namespace Orangecode\Acl\Repository;

use Orangecode\Acl\Model\PerfilPermissoes;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;
use Orangecode\Acl\Model\PerfilPermissoesModel;
use Orangecode\Acl\Model\PermissoesModel;
use Orangecode\Repository\Repository;
use Orangecode\Repository\RepositoryDataBase;

/**
* Repository - Perfil Permissões Acl
*/
class PerfilPermissoesAclRepository implements Repository
{
use RepositoryDataBase;

/** @var PerfilPermissoes */
private PerfilPermissoes $model;
private PerfilPermissoesModel $model;

private PermissoesModel $modelPermissoes;

public function __construct(
PerfilPermissoesModel $perfil,
PermissoesModel $modelPermissoes
) {
$this->model = $perfil;
$this->modelPermissoes = $modelPermissoes;
}

/**
* @param PerfilPermissoes $perfil
* Realiza a pesquisa das permissões por perfil - Perfil Pemissões Acl
*/
public function __construct(PerfilPermissoes $perfil)
public function findAll(int $perfil, int $grupo): Collection
{
$this->model = $perfil;
$perfilPermissoes = DB::table('acl_perfil_permissoes')
->where('id_perfil', $perfil)
->get();
return $this->modelPermissoes::where('id_permissoes_grupo', $grupo)
->where('ativo', 'S')
->orderBy('id')
->get()
->map(function ($item) use ($perfilPermissoes) {
$data = $item;
$data->active = !is_bool($perfilPermissoes->search(function ($value) use ($item) {
return $item->id == $value->id_permissoes;
}));
$data->label = $item->id . ' -> ' . $item->nome;
return $data;
});
}
}
90 changes: 84 additions & 6 deletions src/Acl/Repository/PermissoesAclRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,100 @@

namespace Orangecode\Acl\Repository;

use Orangecode\Acl\Model\Permissoes;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;
use Orangecode\Acl\Model\PermissoesGrupoModel;
use Orangecode\Acl\Model\PermissoesModel;
use Orangecode\Acl\Model\PermissoesModuloModel;
use Orangecode\Repository\Repository;
use Orangecode\Repository\RepositoryDataBase;

/**
* Repository - Permissões Acl
*/
class PermissoesAclRepository implements Repository
{
use RepositoryDataBase;

/** @var Permissoes */
private Permissoes $model;
private PermissoesModel $model;

private PermissoesGrupoModel $permissoesGrupo;

private PermissoesModuloModel $permissoesModulo;

public function __construct(
PermissoesModel $permissoes,
PermissoesGrupoModel $permissoesGrupo,
PermissoesModuloModel $permissoesModulo
) {
$this->model = $permissoes;
$this->permissoesModulo = $permissoesModulo;
$this->permissoesGrupo = $permissoesGrupo;
}

/**
* Realiza a pesquisa - Permissões Acl
*/
public function findAll(int $grupo = null): Collection
{
return $this->model::select('*')
->where('ativo', 'S')
->when(!empty($grupo) ? $grupo : false, function ($query, $grupo) {
$query->where('id_permissoes_grupo', $grupo);
})
->get();
}

/**
* Realiza a pesquisa dos módulos - Permissões Acl
*/
public function findModulo(): Collection
{
return $this->permissoesModulo::all()
->map(function ($item) {
$data = $item;
$data->name = $item->nome;
return $data;
});
}

/**
* Realiza a pesquisa do grupo de permissões - Permissões Acl
*/
public function findGrupo(int $modulo = null): Collection
{
return $this->permissoesGrupo::select('*')
->when(!empty($modulo) ? $modulo : false, function ($query, $modulo) {
$query->where('id_permissoes_modulo', $modulo);
})
->get()
->map(function ($item) {
$data = $item;
$data->name = $item->nome;
return $data;
});
}

/**
* @param Permissoes $perfil
* Realiza a pesquisa permissões por usuário - Permissões Acl
*/
public function __construct(Permissoes $perfil)
public function findAllUser(?int $grupo = null, ?int $user = null): Collection
{
$this->model = $perfil;
$permissoes = DB::table('usuario_filial_acl_perfil')
->select(['acl_perfil_permissoes.id_permissoes'])
->join('acl_perfil', 'acl_perfil.id', '=', 'usuario_filial_acl_perfil.id_acl_perfil')
->join('acl_perfil_permissoes', 'acl_perfil_permissoes.id_perfil', '=', 'acl_perfil.id')
->where('usuario_filial_acl_perfil.id_usuario_filial', '=', $user)
->get()
->groupBy('id_permissoes')
->keys()
->all();
return $this->model::select('*')
->where('ativo', 'S')
->whereNotIn('id', $permissoes)
->when(!empty($grupo) ? $grupo : false, function ($query, $grupo) {
$query->where('id_permissoes_grupo', $grupo);
})
->get();
}
}
51 changes: 45 additions & 6 deletions src/Acl/Repository/PermissoesUsuarioAclRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,61 @@

namespace Orangecode\Acl\Repository;

use Orangecode\Acl\Model\PermissoesUsuario;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;
use Orangecode\Acl\Model\PermissoesModel;
use Orangecode\Acl\Model\PermissoesUsuarioModel;
use Orangecode\Repository\Repository;
use Orangecode\Repository\RepositoryDataBase;

/**
* Repository - Permissões Usuário Acl
*/
class PermissoesUsuarioAclRepository implements Repository
{
use RepositoryDataBase;

/** @var PermissoesUsuario */
private PermissoesUsuario $model;
private PermissoesUsuarioModel $model;

private PermissoesModel $permissoes;

public function __construct(
PermissoesUsuarioModel $model,
PermissoesModel $permissoes
) {
$this->model = $model;
$this->permissoes = $permissoes;
}

/**
* @param PermissoesUsuario $perfil
* Realiza a pesquisa das permissões por usuário - Permissões Usuário Acl
*/
public function __construct(PermissoesUsuario $perfil)
public function findAll(?int $grupo, ?int $user): Collection
{
$this->model = $perfil;
$permissoesUser = $this->model::select('*')
->where('id_usuario_filial', '=', $user)
->get();
$permissoes = DB::table('usuario_filial_acl_perfil')
->select(['acl_perfil_permissoes.id_permissoes'])
->join('acl_perfil', 'acl_perfil.id', '=', 'usuario_filial_acl_perfil.id_acl_perfil')
->join('acl_perfil_permissoes', 'acl_perfil_permissoes.id_perfil', '=', 'acl_perfil.id')
->where('usuario_filial_acl_perfil.id_usuario_filial', '=', $user)
->get()
->groupBy('id_permissoes')
->keys()
->all();
return $this->permissoes::where('id_permissoes_grupo', $grupo)
->whereNotIn('id', $permissoes)
->where('ativo', 'S')
->orderBy('id')
->get()
->map(function ($item) use ($permissoesUser) {
$data = $item;
$data->active = !is_bool($permissoesUser->search(function ($value) use ($item) {
return $item->id == $value->id_permissoes;
}));
$data->label = $item->id . ' -> ' . $item->nome;
return $data;
});
}
}
31 changes: 7 additions & 24 deletions src/Acl/Service/PerfilAclService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,19 @@
namespace Orangecode\Acl\Service;

use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Orangecode\Service\ServiceBase;
use Orangecode\Service\Response\ServiceResponse;
use Orangecode\Acl\Repository\PerfilAclRepository;

/**
* Service - Perfil Acl
*
* @method findAll(int $filial)
*/
class PerfilAclService extends ServiceBase
{
/**
* @param PerfilAclRepository $repository
* @param ServiceResponse $response
*/
public function __construct(PerfilAclRepository $repository, ServiceResponse $response)
{
parent::__construct($repository, $response);
}

/**
* Realiza a pesquisa do perfil por filial
* @param int $filial
* @return Collection
*/
public function findFilial(int $filial): Collection
public function __construct(PerfilAclRepository $repository)
{
return $this->getModel()::where('id_filial', $filial)
->get()
->map(function ($item) {
$data = $item;
$data->label = $item->nome;
return $data;
});
parent::__construct($repository);
}

/**
Expand Down
Loading

0 comments on commit c1f5658

Please sign in to comment.