From 10344bc0cc9e60b217a8388cd1e18c42735808c3 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 28 Mar 2021 01:03:55 +0100 Subject: [PATCH] Arreglos de la rama develop --- .../configuration/SecurityConfiguration.java | 11 ++++---- .../cheapy/web/FoodOfferController.java | 27 ++++++------------- .../cheapy/web/NuOfferController.java | 19 +++---------- .../cheapy/web/SpeedOfferController.java | 23 +++------------- .../cheapy/web/TimeOfferController.java | 21 +++++---------- .../WEB-INF/jsp/foodOffers/foodOffersShow.jsp | 7 ++--- 6 files changed, 30 insertions(+), 78 deletions(-) diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 83b783305..9435b1b30 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -36,20 +36,21 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/", "/oups").permitAll() .antMatchers("/users/new").permitAll() - .antMatchers("/nuOffers/**").hasAnyAuthority("admin","cliente") - .antMatchers("/timeOffers/**").hasAnyAuthority("admin","client") + .antMatchers("/offers/nu/**").hasAnyAuthority("admin","cliente") + .antMatchers("/offers/time/**").hasAnyAuthority("admin","cliente") .antMatchers("/login/**").anonymous() .antMatchers("/logout").permitAll() .antMatchers("/usuarios/new").permitAll() .antMatchers("/admin/**").hasAnyAuthority("admin") - .antMatchers("/speedOffers/**").hasAnyAuthority("admin", "client") - .antMatchers("/foodOffers/**").hasAnyAuthority("admin", "client") + .antMatchers("/offers/speed/**").hasAnyAuthority("admin", "cliente") + .antMatchers("/offers/food/**").hasAnyAuthority("admin", "cliente") .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") .antMatchers("/clients/new").permitAll() - .antMatchers("/offers/**").hasAnyAuthority("admin", "cliente") + .antMatchers("/offers").permitAll() + .and().formLogin() diff --git a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java index aeaeb378d..c11296573 100644 --- a/src/main/java/org/springframework/cheapy/web/FoodOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/FoodOfferController.java @@ -29,7 +29,7 @@ public class FoodOfferController { this.clientService = clientService; } - private boolean checkIdentity(final int foodOfferId) { + /*private boolean checkIdentity(final int foodOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); @@ -38,7 +38,7 @@ public class FoodOfferController { res = true; } return res; - } + }*/ @GetMapping("/foodOffers/new") public String initCreationForm(Map model) { @@ -56,7 +56,7 @@ public class FoodOfferController { foodOffer.setClient(client); foodOffer.setStatus(StatusOffer.hidden); this.foodOfferService.saveFoodOffer(foodOffer); - return "redirect:/foodOffers/" + foodOffer.getId(); + return "redirect:/offers/food/" + foodOffer.getId(); } } @@ -80,18 +80,17 @@ public class FoodOfferController { FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); model.put("foodOffer", foodOffer); - + + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + + return "foodOffers/foodOffersShow"; } @GetMapping(value = "/offers/food/{foodOfferId}/edit") public String updateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { - - if (!this.checkIdentity(foodOfferId)) { - return "error"; - } - + FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); model.addAttribute("foodOffer", foodOffer); return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; @@ -101,10 +100,6 @@ public class FoodOfferController { public String updateFoodOffer(@Valid final FoodOffer foodOfferEdit, final BindingResult result, final ModelMap model) { - if (!this.checkIdentity(foodOfferEdit.getId())) { - return "error"; - } - if (result.hasErrors()) { model.addAttribute("foodOffer", foodOfferEdit); return FoodOfferController.VIEWS_FOOD_OFFER_CREATE_OR_UPDATE_FORM; @@ -118,9 +113,6 @@ public class FoodOfferController { @GetMapping(value = "/offers/food/{foodOfferId}/disable") public String disableFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { - if (!this.checkIdentity(foodOfferId)) { - return "error"; - } FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); model.put("foodOffer", foodOffer); @@ -130,9 +122,6 @@ public class FoodOfferController { @PostMapping(value = "/offers/food/{foodOfferId}/disable") public String disableFoodOfferForm(@PathVariable("foodOfferId") final int foodOfferId, final ModelMap model) { - if (!this.checkIdentity(foodOfferId)) { - return "error"; - } FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java index 8c53a9a31..730eb5635 100644 --- a/src/main/java/org/springframework/cheapy/web/NuOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -1,6 +1,7 @@ package org.springframework.cheapy.web; import java.security.Principal; +import java.time.format.DateTimeFormatter; import java.util.Map; import javax.validation.Valid; @@ -32,7 +33,7 @@ public class NuOfferController { } - private boolean checkIdentity(final int nuOfferId) { + /*private boolean checkIdentity(final int nuOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); @@ -41,7 +42,7 @@ public class NuOfferController { res = true; } return res; - } + }*/ @GetMapping("/nuOffers/new") public String initCreationForm(Map model) { @@ -87,6 +88,7 @@ public class NuOfferController { public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map model) { NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); model.put("nuOffer", nuOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "nuOffers/nuOffersShow"; } @@ -94,9 +96,6 @@ public class NuOfferController { @GetMapping(value = "/offers/nu/{nuOfferId}/edit") public String updateNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final ModelMap model) { - if (!this.checkIdentity(nuOfferId)) { - return "error"; - } NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); model.addAttribute("nuOffer", nuOffer); @@ -106,10 +105,6 @@ public class NuOfferController { @PostMapping(value = "/offers/nu/{nuOfferId}/edit") public String updateNuOffer(@Valid final NuOffer nuOfferEdit, final BindingResult result, final ModelMap model) { - if (!this.checkIdentity(nuOfferEdit.getId())) { - return "error"; - } - if (result.hasErrors()) { model.addAttribute("nuOffer", nuOfferEdit); return NuOfferController.VIEWS_NU_OFFER_CREATE_OR_UPDATE_FORM; @@ -124,9 +119,6 @@ public class NuOfferController { public String disableNuOffer(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { - if (!this.checkIdentity(nuOfferId)) { - return "error"; - } NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); model.put("nuOffer", nuOffer); @@ -137,9 +129,6 @@ public class NuOfferController { public String disableNuOfferForm(@PathVariable("nuOfferId") final int nuOfferId, final Principal principal, final ModelMap model) { - if (!this.checkIdentity(nuOfferId)) { - return "error"; - } NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); nuOffer.setStatus(StatusOffer.inactive); diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java index 050dfc779..aa9236f82 100644 --- a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -1,5 +1,6 @@ package org.springframework.cheapy.web; +import java.time.format.DateTimeFormatter; import java.util.Map; import javax.validation.Valid; @@ -29,7 +30,7 @@ public class SpeedOfferController { this.clientService = clientService; } - private boolean checkIdentity(final int speedOfferId) { + /*private boolean checkIdentity(final int speedOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); @@ -38,7 +39,7 @@ public class SpeedOfferController { res = true; } return res; - } + }*/ @GetMapping("/speedOffers/new") public String initCreationForm(Map model) { @@ -79,8 +80,6 @@ public class SpeedOfferController { SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); model.put("speedOffer", speedOffer); - - //Se aƱade formateador de fecha al modelo model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); return "speedOffers/speedOffersShow"; } @@ -88,10 +87,6 @@ public class SpeedOfferController { @GetMapping(value = "/offers/speed/{speedOfferId}/edit") public String updateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { - if (!this.checkIdentity(speedOfferId)) { - return "error"; - } - SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); model.addAttribute("speedOffer", speedOffer); return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; @@ -100,10 +95,6 @@ public class SpeedOfferController { @PostMapping(value = "/offers/speed/{speedOfferId}/edit") public String updateSpeedOffer(@Valid final SpeedOffer speedOfferEdit, final BindingResult result, final ModelMap model) { - if (!this.checkIdentity(speedOfferEdit.getId())) { - return "error"; - } - if (result.hasErrors()) { model.addAttribute("speedOffer", speedOfferEdit); return SpeedOfferController.VIEWS_SPEED_OFFER_CREATE_OR_UPDATE_FORM; @@ -117,10 +108,7 @@ public class SpeedOfferController { @GetMapping(value = "/offers/speed/{speedOfferId}/disable") public String disableSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { - - if (!this.checkIdentity(speedOfferId)) { - return "error"; - } + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); model.put("speedOffer", speedOffer); @@ -130,9 +118,6 @@ public class SpeedOfferController { @PostMapping(value = "/offers/speed/{speedOfferId}/disable") public String disableSpeedOfferForm(@PathVariable("speedOfferId") final int speedOfferId, final ModelMap model) { - if (!this.checkIdentity(speedOfferId)) { - return "error"; - } SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); diff --git a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java index 430b5d9c2..c6d0f0430 100644 --- a/src/main/java/org/springframework/cheapy/web/TimeOfferController.java +++ b/src/main/java/org/springframework/cheapy/web/TimeOfferController.java @@ -1,6 +1,7 @@ package org.springframework.cheapy.web; +import java.time.format.DateTimeFormatter; import java.util.Map; import javax.validation.Valid; @@ -31,7 +32,7 @@ public class TimeOfferController { } - private boolean checkIdentity(final int timeOfferId) { + /*private boolean checkIdentity(final int timeOfferId) { boolean res = false; Client client = this.clientService.getCurrentClient(); TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); @@ -41,7 +42,7 @@ public class TimeOfferController { } return res; } - +*/ @GetMapping("/timeOffers/new") public String initCreationForm(Map model) { TimeOffer timeOffer = new TimeOffer(); @@ -89,6 +90,8 @@ public class TimeOfferController { model.put("timeOffer", timeOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "timeOffers/timeOffersShow"; } @@ -96,9 +99,6 @@ public class TimeOfferController { @GetMapping(value = "/offers/time/{timeOfferId}/edit") public String updateTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { - if (!this.checkIdentity(timeOfferId)) { - return "error"; - } TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); model.addAttribute("timeOffer", timeOffer); @@ -108,9 +108,6 @@ public class TimeOfferController { @PostMapping(value = "/offers/time/{timeOfferId}/edit") public String updateTimeOffer(@Valid final TimeOffer timeOfferEdit, final BindingResult result, final ModelMap model) { - if (!this.checkIdentity(timeOfferEdit.getId())) { - return "error"; - } if (result.hasErrors()) { model.addAttribute("timeOffer", timeOfferEdit); @@ -125,10 +122,7 @@ public class TimeOfferController { @GetMapping(value = "/offers/time/{timeOfferId}/disable") public String disableTimeOffer(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { - - if (!this.checkIdentity(timeOfferId)) { - return "error"; - } + TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); model.put("timeOffer", timeOffer); @@ -138,9 +132,6 @@ public class TimeOfferController { @PostMapping(value = "/offers/time/{timeOfferId}/disable") public String disableTimeOfferForm(@PathVariable("timeOfferId") final int timeOfferId, final ModelMap model) { - if (!this.checkIdentity(timeOfferId)) { - return "error"; - } TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); diff --git a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp index 91ed28bfc..44b10a7f0 100644 --- a/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp +++ b/src/main/webapp/WEB-INF/jsp/foodOffers/foodOffersShow.jsp @@ -31,10 +31,7 @@ - - - - + @@ -57,5 +54,5 @@ Desactivar oferta - +