From 3c42c1be3520835ea9f381a4bd2d123739ef3f4e Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 18 Jul 2014 23:55:45 +0200 Subject: [PATCH] =?UTF-8?q?Pokud=20je=20role=20pou=C5=BEit=C3=A1=20ve=20st?= =?UTF-8?q?=C5=99edisku=20nebo=20komisi,=20nebo=20pokud=20je=20v=20procesu?= =?UTF-8?q?=20schv=C3=A1len=C3=AD,=20nelze=20od=C5=A1krtnout=20checkbox=20?= =?UTF-8?q?"Funkce=20ve=20st=C5=99edisku/komisi".=20Kde=20je=20pou=C5=BEit?= =?UTF-8?q?o=20se=20objev=C3=AD=20v=20popup=20okn=C4=9B=20po=20najet=C3=AD?= =?UTF-8?q?=20my=C5=A1i=20na=20checkbox.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../isspst/services/users/RoleService.java | 5 +++ .../services/users/RoleServiceImpl.java | 37 ++++++++++++++++++ .../isspst/ui/users/PermissionForm.java | 39 +++++++++++++++++++ .../WEB-INF/locales/zk-label.properties | 2 + .../webapp/admin/permissions/permForm.zul | 23 +++++++++-- 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/src/main/java/info/bukova/isspst/services/users/RoleService.java b/src/main/java/info/bukova/isspst/services/users/RoleService.java index ea5d1d65..9b9349f8 100644 --- a/src/main/java/info/bukova/isspst/services/users/RoleService.java +++ b/src/main/java/info/bukova/isspst/services/users/RoleService.java @@ -4,6 +4,7 @@ import java.util.List; import info.bukova.isspst.data.Permission; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.Service; public interface RoleService extends Service { @@ -13,5 +14,9 @@ public interface RoleService extends Service { public List getCentreRoles(); public List getRolesWithPermission(Permission perm, boolean centre); public List getRolesWithPermission(String authority, boolean centre); + public boolean canChangeCenter(Role role); + public boolean canChangeWorkgroup(Role role); + public boolean isInWorkflow(Role role); + public List getRoleUsage(Role role); } diff --git a/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java index 944f93fe..01fcae2c 100644 --- a/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/RoleServiceImpl.java @@ -2,6 +2,7 @@ package info.bukova.isspst.services.users; import info.bukova.isspst.data.Permission; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractService; import java.util.HashSet; @@ -56,4 +57,40 @@ public class RoleServiceImpl extends AbstractService implements RoleServic return getRolesWithPermission(p, centre); } + @Override + @Transactional + public boolean canChangeWorkgroup(Role role) { + Query q = dao.getQuery("select count(w) from Workgroup w join w.members m where w.centre = false and m.role = :role"); + q.setParameter("role", role); + long i = (Long)q.uniqueResult(); + return i == 0; + } + + @Override + @Transactional + public boolean canChangeCenter(Role role) { + Query q = dao.getQuery("select count(w) from Workgroup w join w.members m where w.centre = true and m.role = :role"); + q.setParameter("role", role); + long i = (Long)q.uniqueResult(); + return i == 0; + } + + @SuppressWarnings("unchecked") + @Override + @Transactional + public List getRoleUsage(Role role) { + Query q = dao.getQuery("select distinct w from Workgroup w join w.members m where m.role = :role"); + q.setParameter("role", role); + return q.list(); + } + + @Override + @Transactional + public boolean isInWorkflow(Role role) { + Query q = dao.getQuery("select count(*) from Workflow where role = :role"); + q.setParameter("role", role); + long i = (Long)q.uniqueResult(); + return i != 0; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java b/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java index ee5f4c0d..b5082dbe 100644 --- a/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java +++ b/src/main/java/info/bukova/isspst/ui/users/PermissionForm.java @@ -2,10 +2,14 @@ package info.bukova.isspst.ui.users; import info.bukova.isspst.Constants; import info.bukova.isspst.Module; +import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.Role; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.users.PermissionService; +import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.ui.FormViewModel; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -16,11 +20,30 @@ public class PermissionForm extends FormViewModel { @WireVariable private PermissionService permissionService; + @WireVariable + private RoleService roleService; private RolePermissions rolePerms; + private boolean canChangeWorkgroup; + private boolean canChangeCentre; + private boolean inWorkflow; + private List usage; @Init(superclass = true) public void init() { rolePerms = new RolePermissions(getDataBean(), permissionService.getAll()); + canChangeWorkgroup = roleService.canChangeWorkgroup(getDataBean()); + canChangeCentre = roleService.canChangeCenter(getDataBean()); + inWorkflow = roleService.isInWorkflow(getDataBean()); + List wgList = roleService.getRoleUsage(getDataBean()); + usage = new ArrayList(); + + for (Workgroup w : wgList) { + usage.add(w.toString()); + } + + if (inWorkflow) { + usage.add(StringUtils.localize("Workflow")); + } } public List getModules() { @@ -31,4 +54,20 @@ public class PermissionForm extends FormViewModel { return rolePerms; } + public boolean isCanChangeWorkgroup() { + return canChangeWorkgroup; + } + + public boolean isCanChangeCentre() { + return canChangeCentre; + } + + public boolean isInWorkflow() { + return inWorkflow; + } + + public List getUsage() { + return usage; + } + } diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 182b7ccf..82410706 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -64,6 +64,8 @@ RightsGridRole=Role RightsGridModules=Práva modulů WorkgroupFunction=Funkce v komisích CentreFunction=Funkce ve střediscích +PermissionFormUsedIn=Použito v: + AgendaSuppliers=Dodavatelé SuppliersFormTitle=Dodavatel diff --git a/src/main/webapp/admin/permissions/permForm.zul b/src/main/webapp/admin/permissions/permForm.zul index da5fa53c..784d4d2d 100644 --- a/src/main/webapp/admin/permissions/permForm.zul +++ b/src/main/webapp/admin/permissions/permForm.zul @@ -5,9 +5,26 @@