From 4055f04f8d0a51c076e66b1bcc33415909ed69ce Mon Sep 17 00:00:00 2001 From: Bryan Holladay Date: Tue, 11 Nov 2014 16:48:00 +0000 Subject: [PATCH] SAK-28037 Shopping Period Bulk Add Update and Delete git-svn-id: https://source.sakaiproject.org/svn/delegatedaccess/trunk@315333 66ffb92e-73f9-0310-93c1-f5514f145a0a --- .../delegatedaccess/logic/ProjectLogic.java | 15 ++++++ .../logic/ProjectLogicImpl.java | 21 +++++++++ .../DelegatedAccessApplication.properties | 1 + .../tool/pages/ShoppingEditBulkPage.java | 46 +++++++++++++++---- .../tool/pages/ShoppingEditPage.java | 8 +--- 5 files changed, 76 insertions(+), 15 deletions(-) diff --git a/delegatedaccess/api/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogic.java b/delegatedaccess/api/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogic.java index 550e21968206..a1062467b801 100644 --- a/delegatedaccess/api/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogic.java +++ b/delegatedaccess/api/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogic.java @@ -378,4 +378,19 @@ public interface ProjectLogic { public void removeAllPermsForUser(String userId); public Map> getHierarchySearchOptions(Map hierarchySearchMap); + + /** + * filters out any node id that the user doesn't have permission to modify shopping period settings + * @param nodeIds + * @return + */ + public Set filterShoppingPeriodEditNodes(Set nodeIds); + + /** + * filters out any node id that the user doesn't have permission to modify shopping period settings + * @param nodeIds + * @param userId + * @return + */ + public Set filterShoppingPeriodEditNodes(Set nodeIds, String userId); } diff --git a/delegatedaccess/impl/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogicImpl.java b/delegatedaccess/impl/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogicImpl.java index a042f3ab2bc0..52ea0b431033 100644 --- a/delegatedaccess/impl/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogicImpl.java +++ b/delegatedaccess/impl/src/java/org/sakaiproject/delegatedaccess/logic/ProjectLogicImpl.java @@ -2749,4 +2749,25 @@ public Map> getHierarchySearchOptions(Map hi return results; } } + + @Override + public Set filterShoppingPeriodEditNodes(Set nodeIds) { + return filterShoppingPeriodEditNodes(nodeIds, sakaiProxy.getCurrentUserId()); + } + + @Override + public Set filterShoppingPeriodEditNodes(Set nodeIds, String userId) { + Set returnNodes = new HashSet(); + Set nodes = hierarchyService.getNodesForUserPerm(userId, DelegatedAccessConstants.NODE_PERM_SHOPPING_ADMIN); + for(String nodeId : nodeIds){ + for(HierarchyNode node : nodes){ + if(nodeId.equals(node.id) || node.childNodeIds.contains(nodeId)){ + returnNodes.add(nodeId); + break; + } + } + } + + return returnNodes; + } } diff --git a/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/DelegatedAccessApplication.properties b/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/DelegatedAccessApplication.properties index 38d2ed6968a4..2ca1087433bc 100644 --- a/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/DelegatedAccessApplication.properties +++ b/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/DelegatedAccessApplication.properties @@ -181,6 +181,7 @@ siteIdsInfo=(one ID per line) sitesToBeDeleted=Sites to be deleted noSitesInInput=No sites to add. sitesNotFound=The following sites were not found in the hierarchy: {0} +sitesNoAccess=You do not have permission to modify the following sites: {0} siteId=Site ID siteTitle=Title addUpdateShoppingSettings=Add or Update Shopping Period Settings diff --git a/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditBulkPage.java b/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditBulkPage.java index a0ef8029a8b5..80a0c915c3f0 100644 --- a/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditBulkPage.java +++ b/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditBulkPage.java @@ -8,10 +8,12 @@ import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import org.apache.log4j.Logger; import org.apache.wicket.AttributeModifier; @@ -612,21 +614,39 @@ private List getValidSitesFromInput(List } //filter out any sites that do not have nodes Map> nodes = projectLogic.getNodesBySiteRef(lookupSiteRefs.toArray(new String[lookupSiteRefs.size()]), DelegatedAccessConstants.HIERARCHY_ID); + Set shoppingEditableNodes = new HashSet(); + //get list of node ids to check whether the user can modify the settings + for(Entry> entry : nodes.entrySet()){ + shoppingEditableNodes.addAll(entry.getValue()); + } + if(!sakaiProxy.isSuperUser()){ + //Admin users can always edit any site, so only filter for non admins + shoppingEditableNodes = projectLogic.filterShoppingPeriodEditNodes(shoppingEditableNodes); + } String notFound = ""; + String noAccess = ""; for(String siteId : lookupSiteIds){ siteId = siteId.trim(); //check that this site id doesn't already exist: boolean exist = nodes.containsKey("/site/" + siteId) && nodes.get("/site/" + siteId) != null && nodes.get("/site/" + siteId).size() > 0; if(exist){ - Site site = sakaiProxy.getSiteById(siteId); - if(site != null){ - returnList.add(new DecoratedSiteModel(site.getId(), site.getTitle(), nodes.get("/site/" + siteId).get(0))); - anyAdded = true; + boolean hasAccess = shoppingEditableNodes.contains(nodes.get("/site/" + siteId).get(0)); + if(hasAccess){ + Site site = sakaiProxy.getSiteById(siteId); + if(site != null){ + returnList.add(new DecoratedSiteModel(site.getId(), site.getTitle(), nodes.get("/site/" + siteId).get(0))); + anyAdded = true; + }else{ + if(!"".equals(notFound)){ + notFound += ", "; + } + notFound += siteId; + } }else{ - if(!"".equals(notFound)){ - notFound += ", "; + if(!"".equals(noAccess)){ + noAccess += ", "; } - notFound += siteId; + noAccess += siteId; } }else{ if(!"".equals(notFound)){ @@ -635,8 +655,18 @@ private List getValidSitesFromInput(List notFound += siteId; } } + String errorMessageStr = ""; if(!"".equals(notFound)){ - errorMessage.setObject(new StringResourceModel("sitesNotFound", null, new String[]{notFound}).getObject()); + errorMessageStr += new StringResourceModel("sitesNotFound", null, new String[]{notFound}).getObject(); + } + if(!"".equals(noAccess)){ + if(!"".equals(errorMessageStr)){ + errorMessageStr += " "; + } + errorMessageStr += new StringResourceModel("sitesNoAccess", null, new String[]{noAccess}).getObject(); + } + if(!"".equals(errorMessageStr)){ + errorMessage.setObject(errorMessageStr); } }else{ errorMessage.setObject(new ResourceModel("noSitesInInput").getObject()); diff --git a/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditPage.java b/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditPage.java index c1ba05850227..f30000d60aec 100644 --- a/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditPage.java +++ b/delegatedaccess/tool/src/java/org/sakaiproject/delegatedaccess/tool/pages/ShoppingEditPage.java @@ -92,13 +92,7 @@ public ShoppingEditPage(){ @Override public void onClick() { setResponsePage(new ShoppingEditBulkPage()); - } - - @Override - public boolean isVisible() { - return sakaiProxy.isSuperUser(); - } - + } }); //FORM: