Skip to content

Commit

Permalink
SAK-28037 Shopping Period Bulk Add Update and Delete
Browse files Browse the repository at this point in the history
git-svn-id: https://source.sakaiproject.org/svn/delegatedaccess/trunk@315333 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
Bryan Holladay committed Nov 11, 2014
1 parent 428e087 commit 4055f04
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,19 @@ public interface ProjectLogic {
public void removeAllPermsForUser(String userId);

public Map<String, Set<String>> getHierarchySearchOptions(Map<String, String> hierarchySearchMap);

/**
* filters out any node id that the user doesn't have permission to modify shopping period settings
* @param nodeIds
* @return
*/
public Set<String> filterShoppingPeriodEditNodes(Set<String> 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<String> filterShoppingPeriodEditNodes(Set<String> nodeIds, String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2749,4 +2749,25 @@ public Map<String, Set<String>> getHierarchySearchOptions(Map<String, String> hi
return results;
}
}

@Override
public Set<String> filterShoppingPeriodEditNodes(Set<String> nodeIds) {
return filterShoppingPeriodEditNodes(nodeIds, sakaiProxy.getCurrentUserId());
}

@Override
public Set<String> filterShoppingPeriodEditNodes(Set<String> nodeIds, String userId) {
Set<String> returnNodes = new HashSet<String>();
Set<HierarchyNode> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -612,21 +614,39 @@ private List<DecoratedSiteModel> getValidSitesFromInput(List<DecoratedSiteModel>
}
//filter out any sites that do not have nodes
Map<String, List<String>> nodes = projectLogic.getNodesBySiteRef(lookupSiteRefs.toArray(new String[lookupSiteRefs.size()]), DelegatedAccessConstants.HIERARCHY_ID);
Set<String> shoppingEditableNodes = new HashSet<String>();
//get list of node ids to check whether the user can modify the settings
for(Entry<String, List<String>> 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)){
Expand All @@ -635,8 +655,18 @@ private List<DecoratedSiteModel> getValidSitesFromInput(List<DecoratedSiteModel>
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ public ShoppingEditPage(){
@Override
public void onClick() {
setResponsePage(new ShoppingEditBulkPage());
}

@Override
public boolean isVisible() {
return sakaiProxy.isSuperUser();
}

}
});

//FORM:
Expand Down

0 comments on commit 4055f04

Please sign in to comment.