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 @@