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