From 9d4b521de79896d60f18636c0a5511187b48137a Mon Sep 17 00:00:00 2001
From: Charles Severance
Date: Tue, 18 Jul 2017 13:52:08 -0400
Subject: [PATCH] SAK-30656 - Add delete tool checkboxes to delete deployment
screen (#4617)
---
.../org/sakaiproject/lti/api/LTIService.java | 2 +
.../org/sakaiproject/util/foorm/Foorm.java | 4 +
.../util/foorm/TestFoormJUnit.java | 30 ++++++-
.../sakaiproject/lti/impl/BaseLTIService.java | 78 +++++++++++++++++--
.../sakaiproject/lti/impl/DBLTIService.java | 27 +++++--
.../src/bundle/ltitool.properties | 2 +
.../sakaiproject/blti/tool/LTIAdminTool.java | 72 +++++++++--------
.../src/webapp/vm/lti_deploy_delete.vm | 17 ++++
8 files changed, 183 insertions(+), 49 deletions(-)
diff --git a/basiclti/basiclti-api/src/java/org/sakaiproject/lti/api/LTIService.java b/basiclti/basiclti-api/src/java/org/sakaiproject/lti/api/LTIService.java
index bd8dbed7fd29..81dc819518f1 100644
--- a/basiclti/basiclti-api/src/java/org/sakaiproject/lti/api/LTIService.java
+++ b/basiclti/basiclti-api/src/java/org/sakaiproject/lti/api/LTIService.java
@@ -323,6 +323,8 @@ public interface LTIService {
boolean deleteTool(Long key, String siteId);
+ public List deleteToolAndContents(Long key, String siteId);
+
boolean deleteToolDao(Long key, String siteId, boolean isAdminRole, boolean isMaintainRole);
Map getTool(Long key, String siteId);
diff --git a/basiclti/basiclti-common/src/java/org/sakaiproject/util/foorm/Foorm.java b/basiclti/basiclti-common/src/java/org/sakaiproject/util/foorm/Foorm.java
index 745e7b8d4d44..f17e17edad6d 100644
--- a/basiclti/basiclti-common/src/java/org/sakaiproject/util/foorm/Foorm.java
+++ b/basiclti/basiclti-common/src/java/org/sakaiproject/util/foorm/Foorm.java
@@ -1460,6 +1460,10 @@ public String searchCheck(String search, String tableName, String[] fieldinfo) {
if (search == null) {
return null;
}
+ //check if is a direct search
+ if (StringUtils.isNotEmpty(search) && search.matches("(\\w+\\.)?\\w+\\s*=.+")) {
+ return search;
+ }
StringBuilder sb = new StringBuilder();
List tokens = getSearchTokens(search);
List separators = getSearchSeparators(search);
diff --git a/basiclti/basiclti-common/src/test/org/sakaiproject/util/foorm/TestFoormJUnit.java b/basiclti/basiclti-common/src/test/org/sakaiproject/util/foorm/TestFoormJUnit.java
index 5a884b1d3820..edca85c3f5b5 100644
--- a/basiclti/basiclti-common/src/test/org/sakaiproject/util/foorm/TestFoormJUnit.java
+++ b/basiclti/basiclti-common/src/test/org/sakaiproject/util/foorm/TestFoormJUnit.java
@@ -117,8 +117,34 @@ public void testBasicFormExtraction() {
@Test
public void testSearchCheckSql() {
Foorm foorm = new Foorm();
- // There was a problem with a NPE being thrown when there weren't any colons in the search
- assertEquals(null, foorm.searchCheck("COLUMN = 'value'", "table", new String[]{}));
+ // SAK-32704 - Want to review all this can perhaps adjust how the decision is made
+ // about which search approach is in use
+ String whereStyle = "COLUMN = 'value'";
+ assertEquals(whereStyle, foorm.searchCheck(whereStyle, "table", new String[]{}));
+ whereStyle = "COLUMN='value'";
+ assertEquals(whereStyle, foorm.searchCheck(whereStyle, "table", new String[]{}));
+ whereStyle = "COLUMN='value' OR OTHER=42";
+ assertEquals(whereStyle,foorm.searchCheck(whereStyle, "table", new String[]{}));
+ whereStyle = "COLUMN='value' OR ( OTHER=42 and zap=21)";
+ assertEquals(whereStyle, foorm.searchCheck(whereStyle, "table", new String[]{}));
+
+ // Workaround for the Null ones below - not pretty but works
+ whereStyle = "1=1 and (table.COLUMN LIKE '%zap%' OR ( othertable.OTHER=42 and zap=21))";
+ assertEquals(whereStyle, foorm.searchCheck(whereStyle, "table", new String[]{}));
+
+ // At some point we might want these to pass
+ whereStyle = "(1=1) and (table.COLUMN LIKE '%zap%' OR ( othertable.OTHER=42 and zap=21))";
+ assertNull(foorm.searchCheck(whereStyle, "table", new String[]{}));
+ whereStyle = "table.COLUMN LIKE '%zap%' OR ( othertable.OTHER=42 and zap=21)";
+ assertNull(foorm.searchCheck(whereStyle, "table", new String[]{}));
+
+ // A parenthesis first should be OK
+ whereStyle = "(COLUMN='value') OR ( OTHER=42 and zap=21)";
+ assertNull(foorm.searchCheck(whereStyle, "table", new String[]{}));
+ whereStyle = "( COLUMN = 'value' ) OR ( OTHER=42 and zap=21)";
+ assertNull(foorm.searchCheck(whereStyle, "table", new String[]{}));
+ whereStyle = " ( COLUMN = 'value' ) OR ( OTHER=42 and zap=21)";
+ assertNull(foorm.searchCheck(whereStyle, "table", new String[]{}));
}
@Test
diff --git a/basiclti/basiclti-impl/src/java/org/sakaiproject/lti/impl/BaseLTIService.java b/basiclti/basiclti-impl/src/java/org/sakaiproject/lti/impl/BaseLTIService.java
index efa969060867..0503fb1ae722 100644
--- a/basiclti/basiclti-impl/src/java/org/sakaiproject/lti/impl/BaseLTIService.java
+++ b/basiclti/basiclti-impl/src/java/org/sakaiproject/lti/impl/BaseLTIService.java
@@ -445,6 +445,73 @@ public boolean deleteTool(Long key, String siteId) {
return deleteToolDao(key, siteId, isAdmin(siteId), isMaintain(siteId));
}
+ /** Delete a tool and delete the content items and site links assocated with the tool
+ *
+ * This is called by a maintain user in a regualr site and deletes a tool, its content
+ * item, and pages with it on the page.
+ *
+ * For the admin user in the !admin site - it deletes a tool and then removes the
+ * placements + pages from all the sites that have the tool - might take a second or two.
+ *
+ * @return A list of strings that are error messages
+ */
+ @Override
+ public List deleteToolAndContents(Long key, String siteId) {
+
+ List retval = new ArrayList ();
+ String errstr;
+
+ List