forked from dantofema/segmenter
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
22,285 additions
and
21,454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Spatie\Permission\Models\Permission; | ||
|
||
class FilterController extends Controller | ||
{ | ||
public function listarFiltros(){ | ||
$filtros = Permission::where('guard_name', 'filters')->get(); | ||
return view('filters', compact('filtros')); | ||
} | ||
|
||
public function renombrarFiltro(Request $request, Permission $filter){ | ||
$filtro = Permission::where('id', $filter->id)->where('guard_name', 'filters')->first(); | ||
if($filtro) { | ||
if ($request->newName) { | ||
$nuevo = Permission::where('name', $request->newName)->where('guard_name', 'filters')->first(); | ||
if($nuevo) { | ||
return redirect()->back()->with('error_rename','Ya existe el filtro!')->with('id_error', $filter->id); | ||
} else { | ||
$filtro->name = $request->newName; | ||
$filtro->save(); | ||
return redirect()->route('admin.listarFiltros')->with('info','Filtro actualizado!'); | ||
} | ||
} else { | ||
return redirect()->back()->with('error_rename','El nombre del filtro no puede estar vacío.')->with('id_error', $filter->id); | ||
} | ||
} | ||
} | ||
|
||
public function crearFiltro(Request $request){ | ||
if($request->newFilterName){ | ||
$filtro = Permission::where('name', $request->newFilterName)->where('guard_name', 'filters')->first(); | ||
if($filtro) { | ||
return redirect()->back()->with('error_create','Ya existe el filtro!')->with('id', $filtro->id); | ||
} else { | ||
Permission::create(['name' => $request->newFilterName, 'guard_name' => 'filters']); | ||
return redirect()->route('admin.listarFiltros')->with('info','Filtro creado!'); | ||
} | ||
} else { | ||
return redirect()->back()->with('error_create','El nombre del filtro no puede estar vacío.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Spatie\Permission\Models\Role; | ||
use Spatie\Permission\Models\Permission; | ||
|
||
class RoleController extends Controller | ||
{ | ||
public function listarRoles(){ | ||
$roles = Role::all(); | ||
$permisos = Permission::where('guard_name', 'web')->get(); | ||
$filtros = Permission::where('guard_name', 'filters')->get(); | ||
return view('roles', compact('roles','permisos','filtros')); | ||
} | ||
|
||
public function editarRol(Request $request, Role $role){ | ||
$rol = Role::find($role)->first(); | ||
if($rol) { | ||
if($request->newName){ | ||
$nuevo = Role::where('name', $request->newName)->first(); | ||
if($nuevo) { | ||
return redirect()->back()->with('error_rename','Ya existe el rol!')->with('id_error', $role->id); | ||
} else { | ||
$rol->name = $request->newName; | ||
$rol->save(); | ||
} | ||
} | ||
if($request->role_type == "permisos"){ | ||
if($request->permisos){ | ||
// actualizo el guard antes de hacer la sincronizacion | ||
$rol->setAttribute('guard_name', 'web'); | ||
$rol->save(); | ||
$rol->syncPermissions($request->permisos); | ||
return redirect()->route('admin.listarRoles')->with('info','Rol actualizado!'); | ||
} else { | ||
return redirect()->back()->with('error_authorization_edit','Debe asignar al menos un permiso/filtro')->with('id_error', $role->id); | ||
} | ||
} elseif($request->role_type == "filtros") { | ||
if($request->filtros){ | ||
// tomo los modelos ya que si a syncPermissions() le mando una lista de ids intentara sincronizar usando el guard default (web) | ||
$filtros = Permission::find($request->filtros); | ||
// actualizo el guard antes de hacer la sincronizacion | ||
$rol->setAttribute('guard_name', 'filters'); | ||
$rol->save(); | ||
$rol->syncPermissions($request->filtros); | ||
return redirect()->route('admin.listarRoles')->with('info','Rol actualizado!'); | ||
} else { | ||
return redirect()->back()->with('error_authorization_edit','Debe asignar al menos un permiso/filtro')->with('id_error', $role->id); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public function crearRol(Request $request){ | ||
if($request->newRoleName){ | ||
$rol = Role::where('name', $request->newRoleName)->first(); | ||
if($rol) { | ||
return redirect()->back()->with('error_create','Ya existe el rol!')->with('id', $rol->id); | ||
} else { | ||
if($request->role_type == "permisos"){ | ||
if($request->permisos){ | ||
$nuevoRol = Role::create(['guard_name' => 'web','name' => $request->newRoleName]); | ||
$nuevoRol->syncPermissions($request->permisos); | ||
return redirect()->route('admin.listarRoles')->with('info','Rol creado!'); | ||
} else { | ||
return redirect()->back()->with('error_authorizations_new','Debe asignar al menos un permiso/filtro'); | ||
} | ||
} elseif($request->role_type == "filtros") { | ||
$nuevoRol = Role::create(['guard_name' => 'filters','name' => $request->newRoleName]); | ||
// tomo los modelos ya que si a syncPermissions() le mando una lista de ids intentara sincronizar usando el guard default (web) | ||
$filtros = Permission::find($request->filtros); | ||
$nuevoRol->syncPermissions($request->filtros); | ||
return redirect()->route('admin.listarRoles')->with('info','Rol creado!'); | ||
} else { | ||
return redirect()->back()->with('error_authorizations_new','Debe asignar al menos un permiso/filtro'); | ||
} | ||
} | ||
} else { | ||
return redirect()->back()->with('error_create','El nombre del rol no puede estar vacío.'); | ||
} | ||
|
||
} | ||
|
||
public function detallesRol(Request $request, $roleId) { | ||
$rol = Role::find($roleId); | ||
$autorizaciones = $rol->permissions()->pluck('name'); | ||
return response()->json([ | ||
'rol' => $rol, | ||
'autorizaciones' => $autorizaciones, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.