Refactor user registration and update handling; modify UserController for putUser endpoint and enhance application properties
This commit is contained in:
parent
e5d5c63763
commit
f882fd173b
|
|
@ -24,8 +24,8 @@ public class SecurityConfig {
|
|||
http.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/css/**", "/js/**", "/images/**").permitAll() // Permitir acceso a CSS, JS e imágenes
|
||||
.requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
.requestMatchers("/user/**").hasAnyRole("USER", "ADMIN")
|
||||
.requestMatchers("/management", "/user_management","/user_list","/departamento_list","/userPage","/putUser").hasRole("ADMIN")
|
||||
.requestMatchers("/user/**","/departamento_list").hasAnyRole("USER", "ADMIN")
|
||||
.requestMatchers("/management", "/user_management","/user_list","/userPage","/putUser").hasRole("ADMIN")
|
||||
.requestMatchers("/", "/login").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,11 +3,9 @@ package com.ieslamar.GestionInventario.controllers;
|
|||
import com.ieslamar.GestionInventario.dto.BotonDTO;
|
||||
import com.ieslamar.GestionInventario.dto.BotonManager;
|
||||
import com.ieslamar.GestionInventario.entities.*;
|
||||
import com.ieslamar.GestionInventario.repos.GenericEntityService;
|
||||
import com.ieslamar.GestionInventario.services.CategoriaService;
|
||||
import com.ieslamar.GestionInventario.services.DepartamentoService;
|
||||
import com.ieslamar.GestionInventario.services.UserService;
|
||||
import jakarta.persistence.Entity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
|
@ -18,8 +16,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
|
@ -124,7 +120,6 @@ public class UserController {
|
|||
return updateUser(id,nombre,password,role,mail,iddepartamento);
|
||||
|
||||
}
|
||||
|
||||
private String updateUser(Long id,String nombre,String password,String role,String mail, Integer iddepartamento){
|
||||
logger.info(" entra en updateUser jjknnjn");
|
||||
Departamento departamento = null;
|
||||
|
|
@ -168,6 +163,7 @@ public class UserController {
|
|||
userService.deleteUser(user); // Llama al servicio para eliminar el usuario
|
||||
return "redirect:/user_list"; // Redirige a la página de gestión de usuarios
|
||||
}
|
||||
|
||||
@GetMapping("/user_list")
|
||||
public String userList(Model model) {
|
||||
return buildUserList(model, userService.getAllUsers());
|
||||
|
|
@ -196,15 +192,15 @@ public class UserController {
|
|||
|
||||
return "list";
|
||||
}
|
||||
@GetMapping("/edit_user/{id}")
|
||||
public String editUser(@PathVariable Long id, Model model) {
|
||||
User user = userService.getUserById(id);
|
||||
if (user != null) {
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("departamentos", departamentoService.getAllDepartamentos());
|
||||
}
|
||||
return "userPage"; // Redirige a la página de registro
|
||||
}
|
||||
// @GetMapping("/edit_user/{id}")
|
||||
// public String editUser(@PathVariable Long id, Model model) {
|
||||
// User user = userService.getUserById(id);
|
||||
// if (user != null) {
|
||||
// model.addAttribute("user", user);
|
||||
// model.addAttribute("departamentos", departamentoService.getAllDepartamentos());
|
||||
// }
|
||||
// return "userPage"; // Redirige a la página de registro
|
||||
// }
|
||||
|
||||
|
||||
//DEPARTAMENTOS--------------------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||
public class BotonManager {
|
||||
private final BotonDTO gestionUsuarios = new BotonDTO("Gestión de usuarios", "/user_list", true, null);
|
||||
private final BotonDTO gestionProductos = new BotonDTO("Gestión de Productos", "/user_management", true, null);
|
||||
private final BotonDTO gestionDepartamentos = new BotonDTO("Gestión de Departamentos", "/departamento_list", true, null);
|
||||
private final BotonDTO gestionDepartamentos = new BotonDTO("Gestión de Departamentos", "/departamento_list", false, null);
|
||||
private final BotonDTO gestionCategorias = new BotonDTO("Gestión de Categorías", "/user_management", true, null);
|
||||
private final BotonDTO gestionUbicaciones = new BotonDTO("Gestión de Ubicaciones", "/user_management", true, null);
|
||||
private final BotonDTO gestionInventario = new BotonDTO("Gestión de Inventario", "/inventario", true, null);
|
||||
|
|
|
|||
|
|
@ -2,13 +2,12 @@ package com.ieslamar.GestionInventario.services;
|
|||
|
||||
import com.ieslamar.GestionInventario.entities.Categoria;
|
||||
import com.ieslamar.GestionInventario.repos.CategoriaRepository;
|
||||
import com.ieslamar.GestionInventario.repos.GenericEntityService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CategoriaService implements GenericEntityService<Categoria> {
|
||||
public class CategoriaService {
|
||||
private final CategoriaRepository categoriaRepository;
|
||||
|
||||
public CategoriaService(CategoriaRepository categoriaRepository) {
|
||||
|
|
@ -26,22 +25,4 @@ public class CategoriaService implements GenericEntityService<Categoria> {
|
|||
categoria.setNombre(nombre);
|
||||
categoriaRepository.save(categoria);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Categoria> findAll() {
|
||||
return categoriaRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHeaders() {
|
||||
return List.of("ID","Nombre");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getRowValues(Categoria categoria) {
|
||||
return List.of(
|
||||
categoria.getId(),
|
||||
categoria.getNombre()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ package com.ieslamar.GestionInventario.services;
|
|||
import com.ieslamar.GestionInventario.entities.Departamento;
|
||||
import com.ieslamar.GestionInventario.entities.User;
|
||||
import com.ieslamar.GestionInventario.repos.DepartamentoRepository;
|
||||
import com.ieslamar.GestionInventario.repos.GenericEntityService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DepartamentoService implements GenericEntityService<Departamento> {
|
||||
public class DepartamentoService {
|
||||
private final DepartamentoRepository departamentoRepository;
|
||||
|
||||
public DepartamentoService(DepartamentoRepository departamentoRepository) {
|
||||
|
|
@ -27,21 +26,5 @@ public class DepartamentoService implements GenericEntityService<Departamento> {
|
|||
departamentoRepository.save(departamento);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List findAll() {
|
||||
return departamentoRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getHeaders() {
|
||||
return List.of("ID", "Nombre");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getRowValues(Departamento departamento) {
|
||||
return List.of(
|
||||
departamento.getId(),
|
||||
departamento.getNombre()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,12 +62,14 @@ table {
|
|||
}
|
||||
|
||||
.celda-acciones {
|
||||
display: flex ;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
justify-content: space-evenly;
|
||||
}
|
||||
|
||||
.celda-acciones a {
|
||||
width: fit-content;
|
||||
}
|
||||
.celda-acciones button {
|
||||
background-color: rgba(255, 255, 255, 0.3);
|
||||
border: none;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="es" xmlns:th="http://www.thymeleaf.org">
|
||||
<html lang="es" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
|
||||
<head>
|
||||
<title th:text="${title}">Página Genérica</title>
|
||||
<link rel="stylesheet" th:href="@{/css/table_style.css}">
|
||||
|
|
@ -27,13 +27,13 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th th:each="header : ${headers}" th:text="${header}"></th>
|
||||
<th>Acciones</th>
|
||||
<th sec:authorize="hasRole('ADMIN')">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="item : ${items}">
|
||||
<td th:each="value : ${item.values}" th:text="${value}"></td>
|
||||
<td>
|
||||
<td sec:authorize="hasRole('ADMIN')">
|
||||
<div class="celda-acciones">
|
||||
<a th:href="@{/userPage(id=${item.id})}">
|
||||
<button type="button" th:title="Editar">✏️</button>
|
||||
|
|
|
|||
Loading…
Reference in New Issue