From f938403cea5ef6bbe64513a0a4055712e8a62ed4 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 22 Feb 2016 15:18:34 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Byl=20omezen=20v=C3=BDb=C4=9Br=20st=C5=99ed?= =?UTF-8?q?isek=20u=20nov=C3=A9ho=20po=C5=BEadavku,=20aby=20bylo=20zamezen?= =?UTF-8?q?o=20schvalov=C3=A1n=C3=AD=20sob=C4=9B=20sam=C3=A9mu.=20closes?= =?UTF-8?q?=20#266?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/info/bukova/isspst/SessionData.java | 9 +++ .../isspst/security/LoginSuccessHandler.java | 19 +++-- .../services/orders/OrderServiceImpl.java | 5 ++ .../RequirementBaseServiceImpl.java | 10 ++- .../services/workgroups/WorkgroupService.java | 5 +- .../workgroups/WorkgroupServiceImpl.java | 70 +++++++++++++++++-- .../info/bukova/isspst/ui/ListViewModel.java | 1 + .../orders/requirements/RequirementForm.java | 17 +++-- .../ui/requirement/TripRequirementForm.java | 10 ++- .../trips/requirements/requirementsForm.zul | 3 +- 10 files changed, 123 insertions(+), 26 deletions(-) diff --git a/src/main/java/info/bukova/isspst/SessionData.java b/src/main/java/info/bukova/isspst/SessionData.java index 9743550b..139acb6c 100644 --- a/src/main/java/info/bukova/isspst/SessionData.java +++ b/src/main/java/info/bukova/isspst/SessionData.java @@ -17,6 +17,7 @@ public class SessionData implements Serializable { private static final long serialVersionUID = -764426911263559759L; private List userCentres; + private List userOnlyCentres; private List userWorkgroups; private User currentUser; private Map> workgroupRoles; @@ -75,4 +76,12 @@ public class SessionData implements Serializable { public Object getProperty(String key) { return properties.get(key); } + + public List getUserOnlyCentres() { + return userOnlyCentres; + } + + public void setUserOnlyCentres(List userOnlyCentres) { + this.userOnlyCentres = userOnlyCentres; + } } diff --git a/src/main/java/info/bukova/isspst/security/LoginSuccessHandler.java b/src/main/java/info/bukova/isspst/security/LoginSuccessHandler.java index 2d16b541..4e47ef5e 100644 --- a/src/main/java/info/bukova/isspst/security/LoginSuccessHandler.java +++ b/src/main/java/info/bukova/isspst/security/LoginSuccessHandler.java @@ -7,16 +7,6 @@ import info.bukova.isspst.data.UserSettingsData; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -24,6 +14,14 @@ import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler implements AuthenticationSuccessHandler { @Autowired @@ -45,6 +43,7 @@ public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessH logger.info("User " + u.getUsername() + " logged in"); sessionData.setUserCentres(workgroupService.getUserCentres((User) auth.getPrincipal())); + sessionData.setUserOnlyCentres(workgroupService.getUserCentres((User) auth.getPrincipal(), true)); sessionData.setUserWorkgroups(workgroupService.getUserWorkgroups((User) auth.getPrincipal())); workgroupService.loadParents(u); sessionData.setCurrentUser(u); diff --git a/src/main/java/info/bukova/isspst/services/orders/OrderServiceImpl.java b/src/main/java/info/bukova/isspst/services/orders/OrderServiceImpl.java index 27ecdc55..25fd9bcc 100644 --- a/src/main/java/info/bukova/isspst/services/orders/OrderServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/orders/OrderServiceImpl.java @@ -10,6 +10,7 @@ import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.settings.GlobalSettingsService; +import info.bukova.isspst.services.settings.SeasonService; import org.hibernate.Hibernate; import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; @@ -28,6 +29,9 @@ public class OrderServiceImpl extends AbstractOwnedService implements @Autowired private RequirementItemDao requirementItemDao; + @Autowired + private SeasonService seasonService; + @Override @PreAuthorize("hasPermission(this, 'PERM_ADD')") public Order createOrder(List items) { @@ -45,6 +49,7 @@ public class OrderServiceImpl extends AbstractOwnedService implements } order.setTotal(total); + order.setSeason(seasonService.getActive()); return order; } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java index 2245b5be..b5d5a157 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -94,7 +94,11 @@ public abstract class RequirementBaseServiceImpl exte Workgroup reqWorkgroup = null; for (Workgroup w : workgroupService.getUserWorkgroups(getLoggedInUser())) { if (workgroupService.getMembers(entity.getCentre()).contains(w)) { - reqWorkgroup = w; + for (Role r : workgroupService.getUserWorkgroupRoles(w, getLoggedInUser())) { + if (r.getAuthority().equals(Constants.ROLE_USER)) { + reqWorkgroup = w; + } + } } } @@ -105,7 +109,9 @@ public abstract class RequirementBaseServiceImpl exte if (!canAdd(entity)) { throw new AddRequirementException(); } - + + entity.setSeason(seasonService.getActive()); + this.addWorkflow(entity); entity.setNumser(this.getNumberSerie()); diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java index ec1b33bb..c4ea4cf2 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupService.java @@ -1,7 +1,5 @@ package info.bukova.isspst.services.workgroups; -import java.util.List; - import info.bukova.isspst.data.JobMapping; import info.bukova.isspst.data.Member; import info.bukova.isspst.data.Role; @@ -9,6 +7,8 @@ import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.Service; +import java.util.List; + public interface WorkgroupService extends Service { public void addMember(Workgroup workgroup, Member member, Role role); @@ -17,6 +17,7 @@ public interface WorkgroupService extends Service { public List getCentres(); public boolean isMember(Workgroup workgroup, Member member); public List getUserCentres(User user); + public List getUserCentres(User user, boolean userOnly); public List getUserWorkgroups(User user); public List getUserWorkgroupRoles(Workgroup workgroup, User user); public List getMembers(Workgroup workgroup); diff --git a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java index 9b2c3a1d..8a68e6ab 100644 --- a/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/workgroups/WorkgroupServiceImpl.java @@ -8,15 +8,14 @@ import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; - -import java.util.ArrayList; -import java.util.List; - import org.hibernate.LazyInitializationException; import org.hibernate.Query; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + public class WorkgroupServiceImpl extends AbstractOwnedService implements WorkgroupService { @Override @@ -125,7 +124,7 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem @Override @Transactional public List getUserCentres(User user) { - if (user.equals(getLoggedInUser()) && sessionData.getUserCentres() != null) { + /*if (user.equals(getLoggedInUser()) && sessionData.getUserCentres() != null) { return sessionData.getUserCentres(); } @@ -150,6 +149,67 @@ public class WorkgroupServiceImpl extends AbstractOwnedService implem } } } + return centres;*/ + return getUserCentres(user, false); + } + + @Override + @Transactional + public List getUserCentres(User user, boolean userOnly) { + if (!userOnly && user.equals(getLoggedInUser()) && sessionData.getUserCentres() != null) { + return sessionData.getUserCentres(); + } + + if (userOnly && user.equals(getLoggedInUser()) && sessionData.getUserOnlyCentres() != null) { + return sessionData.getUserOnlyCentres(); + } + + List parents; + + if (userOnly) { + parents = filterUserOnly(user, getParents(user)); + } else { + parents = getParents(user); + } + + if (parents == null) { + return null; + } + + List centres = new ArrayList(); + for (Workgroup w : parents) { + if (w.isCentre()) { + centres.add(w); + } + } + + for (Workgroup w : getUserWorkgroups(user)) { + loadParents(w); + for (Workgroup centre : w.getParents()) { + if (!centres.contains(centre)) { + centres.add(centre); + } + } + } + return centres; + } + + private List filterUserOnly(User user, List wgList) { + List centres = new ArrayList(); + + for (Workgroup wg : wgList) { + List roles = getUserWorkgroupRoles(wg, user); + if (roles == null) { + continue; + } + + for (Role r : roles) { + if (r.getAuthority().equals(Constants.ROLE_USER)) { + centres.add(wg); + } + } + } + return centres; } diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index c722523f..ab00cce5 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -290,6 +290,7 @@ public class ListViewModel extends DocumentViewModel public void reload() { dataBean = null; dataList.clear(); + setHqlFilter(); loadFromDbSync(); } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index c3e96ec9..8d3e6cf4 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -12,10 +12,6 @@ import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.FormViewModel; import info.bukova.isspst.validators.RequirementFormValidator; - -import java.math.BigDecimal; -import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.zkoss.bind.BindUtils; @@ -29,6 +25,10 @@ import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; import org.zkoss.zul.impl.InputElement; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + public class RequirementForm extends FormViewModel { private final static Logger log = LoggerFactory.getLogger(RequirementForm.class.getName()); @@ -112,7 +112,14 @@ public class RequirementForm extends FormViewModel this.setRequirementFormValidator(new RequirementFormValidator()); this.setSyncItems(this.getDataBean().getItems()); requirementService.loadType(getDataBean()); - this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); + + if (isEditRec()) { + List current = new ArrayList(); + current.add(getDataBean().getCentre()); + this.centres = current; + } else { + this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent(), true)); + } } public List getSyncItems() diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java index 70b35615..4a0ca31c 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java @@ -24,6 +24,7 @@ import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Window; +import java.util.ArrayList; import java.util.List; public class TripRequirementForm extends FormWithUpload { @@ -73,7 +74,14 @@ public class TripRequirementForm extends FormWithUpload { @Init(superclass = true) public void init() { tripRequirementService.loadType(getDataBean()); - centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); + if (isEditRec()) { + List current = new ArrayList(); + current.add(getDataBean().getCentre()); + this.centres = current; + } else { + this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent(), true)); + } + users = userService.getUsersForCombo(); passengers = getDataBean().getPassengers(); validator = new TripRequirementFormValidator(); diff --git a/src/main/webapp/main/trips/requirements/requirementsForm.zul b/src/main/webapp/main/trips/requirements/requirementsForm.zul index bd446031..9c8599a5 100644 --- a/src/main/webapp/main/trips/requirements/requirementsForm.zul +++ b/src/main/webapp/main/trips/requirements/requirementsForm.zul @@ -63,7 +63,8 @@ + selectedItem="@bind(fx.centre)" + disabled="@load(vm.editRec)"> From b276746bac665a764983f2e0592e00ff86efb124 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 22 Feb 2016 21:24:45 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Zm=C4=9Bn=C4=9Bn=20popisek=20pole=20"Zpr?= =?UTF-8?q?=C3=A1va=20o=20v=C3=BDsledku=20pracovn=C3=AD=20cesty"=20closes?= =?UTF-8?q?=20#260?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/webapp/WEB-INF/locales/zk-label.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 1a920bb8..d0f131bd 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -421,7 +421,7 @@ Passenger = Pasažér ChooseThePasseger = Vyberte pasažéra TransportMode = Způsob dopravy ForeignPersons = Cizí osoby -TripBillResultMessageText = Zpráva z pracovní cesty +TripBillResultMessageText = Stručná zpráva z pracovní cesty, přínosy a podněty k dalšímu využití ErrFillTripBillResultMessageText = Vyplňte zprávu z pracovní cesty. ErrFillTripBillResultTimes = Zadejte časy odjezdu a příjezdu.