r1013 - in xwiki/trunk/src: main/java/com/xpn/xwiki/doc main/java/com/xpn/xwiki/user/impl/xwiki main/web/templates test/java/com/xpn/xwiki/plugin/charts/tests test/java/com/xpn/xwiki/test test/java/com/xpn/xwiki/test/plugin/query
Ludovic Dubost
ludovic at users.forge.objectweb.org
Wed Mar 29 23:25:58 CEST 2006
Author: ludovic
Date: 2006-03-29 23:25:57 +0200 (Wed, 29 Mar 2006)
New Revision: 1013
Modified:
xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java
xwiki/trunk/src/main/web/templates/editactions.vm
xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ObjectsTest.java
xwiki/trunk/src/test/java/com/xpn/xwiki/test/HibernateCustomMappingTest.java
xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java
Log:
Fix big bug in XWikiRightsServiceImpl which would bypass some rights objects
Fix tests in hibernate custom mapping that would fail on unix
Fix tests in Queryplugin that would fail because dates in the database strip milliseconds
Made sure dates in memory would be the same as one in the database
Fix javascript that would fail in inline mode
Added missing fields in document toXML
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-03-29 10:50:57 UTC (rev 1012)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-03-29 21:25:57 UTC (rev 1013)
@@ -199,7 +199,11 @@
this.name = name.substring(i1 + 1);
}
this.updateDate = new Date();
+ updateDate.setTime((updateDate.getTime()/1000) * 1000);
+ this.contentUpdateDate = new Date();
+ contentUpdateDate.setTime((contentUpdateDate.getTime()/1000) * 1000);
this.creationDate = new Date();
+ creationDate.setTime((creationDate.getTime()/1000) * 1000);
this.parent = "";
this.content = "\n";
this.format = "";
@@ -389,6 +393,8 @@
if ((date != null) && (!date.equals(this.updateDate))) {
setMetaDataDirty(true);
}
+ // Make sure we drop milliseconds for consistency with the database
+ date.setTime((date.getTime()/1000) * 1000);
this.updateDate = date;
}
@@ -403,6 +409,9 @@
if ((date != null) && (!creationDate.equals(this.creationDate))) {
setMetaDataDirty(true);
}
+
+ // Make sure we drop milliseconds for consistency with the database
+ date.setTime((date.getTime()/1000) * 1000);
this.creationDate = date;
}
@@ -417,6 +426,9 @@
if ((date != null) && (!date.equals(this.contentUpdateDate))) {
setMetaDataDirty(true);
}
+
+ // Make sure we drop milliseconds for consistency with the database
+ date.setTime((date.getTime()/1000) * 1000);
this.contentUpdateDate = date;
}
@@ -826,7 +838,10 @@
}
public String getTemplate() {
- return template;
+ if (template==null)
+ return "";
+ else
+ return template;
}
public void setTemplate(String template) {
@@ -1261,6 +1276,9 @@
if (!getVersion().equals(doc.getVersion()))
return false;
+ if (!getTemplate().equals(doc.getTemplate()))
+ return false;
+
try {
if (!getArchive().equals(doc.getArchive()))
return false;
@@ -1394,6 +1412,10 @@
el.addText(getAuthor());
docel.add(el);
+ el = new DOMElement("contentAuthor");
+ el.addText(getContentAuthor());
+ docel.add(el);
+
long d = getCreationDate().getTime();
el = new DOMElement("creationDate");
el.addText("" + d);
@@ -1404,10 +1426,19 @@
el.addText("" + d);
docel.add(el);
+ d = getContentUpdateDate().getTime();
+ el = new DOMElement("contentUpdateDate");
+ el.addText("" + d);
+ docel.add(el);
+
el = new DOMElement("version");
el.addText(getVersion());
docel.add(el);
+ el = new DOMElement("template");
+ el.addText(getTemplate());
+ docel.add(el);
+
List alist = getAttachmentList();
for (int ai = 0; ai < alist.size(); ai++) {
XWikiAttachment attach = (XWikiAttachment) alist.get(ai);
Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java
===================================================================
--- xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java 2006-03-29 10:50:57 UTC (rev 1012)
+++ xwiki/trunk/src/main/java/com/xpn/xwiki/user/impl/xwiki/XWikiRightServiceImpl.java 2006-03-29 21:25:57 UTC (rev 1013)
@@ -251,28 +251,47 @@
Vector vobj = doc.getObjects(className);
if (vobj != null) {
+ if (log.isDebugEnabled())
+ log.debug("Checking objects " + vobj.size());
for (int i = 0; i < vobj.size(); i++) {
+ if (log.isDebugEnabled())
+ log.debug("Checking object " + i);
+
BaseObject bobj = (BaseObject) vobj.get(i);
- if (bobj == null)
+
+ if (bobj == null) {
+ if (log.isDebugEnabled())
+ log.debug("Bypass object " + i);
continue;
+ }
String users = bobj.getStringValue(fieldName);
String levels = bobj.getStringValue("levels");
boolean allowdeny = (bobj.getIntValue("allow") == 1);
if (allowdeny == allow) {
+ if (log.isDebugEnabled())
+ log.debug("Checking match: " + accessLevel + " in " + levels);
+
String[] levelsarray = StringUtils.split(levels, " ,|");
if (ArrayUtils.contains(levelsarray, accessLevel)) {
if (log.isDebugEnabled())
log.debug("Found a right for " + allow);
found = true;
+
+ if (log.isDebugEnabled())
+ log.debug("Checking match: " + name + " in " + users);
+
String[] userarray = StringUtils.split(users, " ,|");
- for (int ii = 0; i < userarray.length; i++) {
+ for (int ii = 0; ii < userarray.length; ii++) {
String value = userarray[ii];
if (value.indexOf("XWiki.") == -1)
userarray[ii] = "XWiki." + value;
}
+ if (log.isDebugEnabled())
+ log.debug("Checking match: " + name + " in " + StringUtils.join(userarray, ","));
+
// In the case where the document database and the user database is the same
// then we allow the usage of the short name, otherwise the fully qualified name is requested
if (context.getDatabase().equals(userdatabase)) {
@@ -296,7 +315,13 @@
log.debug("Found matching right in " + users + " for " + name);
return true;
}
+
+ if (log.isDebugEnabled())
+ log.debug("Failed match: " + name + " in " + users);
}
+ } else {
+ if (log.isDebugEnabled())
+ log.debug("Bypass object because wrong allow/deny" + i);
}
}
}
Modified: xwiki/trunk/src/main/web/templates/editactions.vm
===================================================================
--- xwiki/trunk/src/main/web/templates/editactions.vm 2006-03-29 10:50:57 UTC (rev 1012)
+++ xwiki/trunk/src/main/web/templates/editactions.vm 2006-03-29 21:25:57 UTC (rev 1013)
@@ -1,9 +1,11 @@
<script type="text/javascript">
function checkDocumentContent() {
- var content = document.forms.edit.content.value;
- if (content == null || content == "") {
+ if (document.forms.edit.content) {
+ var content = document.forms.edit.content.value;
+ if (content == null || content == "") {
alert("$msg.get('wikicontentcannotbeempty')");
return false ;
+ }
}
return true;
}
Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ObjectsTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ObjectsTest.java 2006-03-29 10:50:57 UTC (rev 1012)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/plugin/charts/tests/ObjectsTest.java 2006-03-29 21:25:57 UTC (rev 1013)
@@ -77,7 +77,7 @@
XWikiDocument doc2 = TestHelper.createDocument("XWikiTest.Doc2", "", context);
XWikiDocument doc3 = TestHelper.createDocument("XWikiTest.Doc3", "", context);
- list = xwiki.getStore().searchDocumentsNames("doc.fullName LIKE 'XWikiTest.%'", context);
+ list = xwiki.getStore().searchDocumentsNames("doc.fullName like 'XWikiTest.%'", context);
Assert.assertEquals(3, list.size());
Assert.assertTrue(list.contains(doc1));
Assert.assertTrue(list.contains(doc2));
Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/test/HibernateCustomMappingTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/HibernateCustomMappingTest.java 2006-03-29 10:50:57 UTC (rev 1012)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/HibernateCustomMappingTest.java 2006-03-29 21:25:57 UTC (rev 1013)
@@ -1,25 +1,25 @@
-/*
- * Copyright 2006, XpertNet SARL, and individual contributors as indicated
- * by the contributors.txt.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- *
- * @author ludovic
- * @author sdumitriu
- */
+/*
+ * Copyright 2006, XpertNet SARL, and individual contributors as indicated
+ * by the contributors.txt.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+ * @author ludovic
+ * @author sdumitriu
+ */
package com.xpn.xwiki.test;
@@ -134,7 +134,7 @@
XWikiHibernateStore hibstore = getXWiki().getHibernateStore();
try {
hibstore.beginTransaction(getXWikiContext());
- runSQL(hibstore, "delete from xwikicustom_test_hcmclass", getXWikiContext());
+ runSQL(hibstore, "delete from xwikicustom_Test_HCMClass", getXWikiContext());
} finally {
hibstore.endTransaction(getXWikiContext(), true);
}
@@ -204,9 +204,9 @@
try {
getXWiki().getHibernateStore().beginTransaction(getXWikiContext());
- Object result = runSQLuniqueResult(getXWiki().getHibernateStore(),"select count(*) from xwikicustom_test_hcmclass", getXWikiContext());
+ Object result = runSQLuniqueResult(getXWiki().getHibernateStore(),"select count(*) from xwikicustom_Test_HCMClass", getXWikiContext());
assertEquals("Table does not exist", 0, ((Number)result).intValue());
- List list = runSQLwithReturn(getXWiki().getHibernateStore(),"select xwo_first_name, xwo_last_name, xwo_comment, xwo_age, xwo_password from xwikicustom_test_hcmclass", getXWikiContext());
+ List list = runSQLwithReturn(getXWiki().getHibernateStore(),"select xwo_first_name, xwo_last_name, xwo_comment, xwo_age, xwo_password from xwikicustom_Test_HCMClass", getXWikiContext());
assertNotNull("Table items incorrect does not exist", list);
} finally {
getXWiki().getHibernateStore().endTransaction(getXWikiContext(), false);
@@ -258,9 +258,9 @@
try {
getXWiki().getHibernateStore().beginTransaction(getXWikiContext());
- Object result = runSQLuniqueResult(getXWiki().getHibernateStore(),"select count(*) from xwikicustom_test_hcmclass", getXWikiContext());
+ Object result = runSQLuniqueResult(getXWiki().getHibernateStore(),"select count(*) from xwikicustom_Test_HCMClass", getXWikiContext());
assertEquals("Table does not exist", 1, ((Number)result).intValue());
- List list = runSQLwithReturn(getXWiki().getHibernateStore(),"select xwo_first_name, xwo_last_name, xwo_comment, xwo_age, xwo_password from xwikicustom_test_hcmclass", getXWikiContext());
+ List list = runSQLwithReturn(getXWiki().getHibernateStore(),"select xwo_first_name, xwo_last_name, xwo_comment, xwo_age, xwo_password from xwikicustom_Test_HCMClass", getXWikiContext());
assertNotNull("Table items incorrect does not exist", list);
assertEquals("Result size incorrect", 1, list.size());
Map item = (Map)list.get(0);
@@ -331,7 +331,7 @@
try {
getXWiki().getHibernateStore().beginTransaction(getXWikiContext());
// We should have nothing in the custom mapped table
- List list = runSQLwithReturn(getXWiki().getHibernateStore(),"select xwo_first_name, xwo_last_name, xwo_comment, xwo_age, xwo_password from xwikicustom_test_hcmclass", getXWikiContext());
+ List list = runSQLwithReturn(getXWiki().getHibernateStore(),"select xwo_first_name, xwo_last_name, xwo_comment, xwo_age, xwo_password from xwikicustom_Test_HCMClass", getXWikiContext());
assertNotNull("Table items incorrect does not exist", list);
assertEquals("Result size incorrect", 0, list.size());
} finally {
Modified: xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java
===================================================================
--- xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java 2006-03-29 10:50:57 UTC (rev 1012)
+++ xwiki/trunk/src/test/java/com/xpn/xwiki/test/plugin/query/QueryPluginTest.java 2006-03-29 21:25:57 UTC (rev 1013)
@@ -71,7 +71,12 @@
}
} else {
if (exp==obj) continue; // XXX: bugs with proxy objects?
- assertEquals("Objects #"+i+" not equals", obj, exp);
+ if (exp instanceof XWikiDocument)
+ assertEquals("Objects #"+i+" not equals",
+ ((XWikiDocument)obj).toFullXML(context),
+ ((XWikiDocument)exp).toFullXML(context));
+ else
+ assertEquals("Objects #"+i+" not equals", obj, exp);
}
}
}
@@ -113,7 +118,8 @@
doc1.setContent("no content");
doc1.setAuthor("Artem Melentev");
doc1.setParent("Main.WebHome");
- hibstore.saveXWikiDoc(doc1, getXWikiContext());
+ xwiki.saveDocument(doc1, getXWikiContext());
+ doc1 = xwiki.getDocument(doc1.getFullName(), getXWikiContext());
testSearchXP1("//*/*", doc1);
checkEquals(qf.getDocs("*/*", null, null).list(), new Object[]{doc1});
@@ -129,13 +135,18 @@
checkEquals(qf.getChildDocs("Main/WebHome", null, null).list(), new Object[]{doc1});
testSearchXP("//Main/*[@parent!='Main.WebHome']", NOTHING);
checkEquals(qf.getDocs("Main/*[@parent!='Main.WebHome']", null, null).list(), NOTHING);
-
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {}
+
XWikiDocument doc2 = new XWikiDocument("Main", "WebHome2");
doc2.setContent("no content");
doc2.setAuthor("Someone");
doc2.setParent("Main.WebHome");
- hibstore.saveXWikiDoc(doc2, getXWikiContext());
-
+ xwiki.saveDocument(doc2, getXWikiContext());
+ doc2 = xwiki.getDocument(doc2.getFullName(), getXWikiContext());
+
testSearchXP("//*/*", new Object[]{doc1, doc2});
checkEquals(qf.getDocs("*/*", null, null).list(), new Object[]{doc1, doc2});
testSearchXP("//*/* order by @creationDate descending", new Object[]{doc2, doc1});
@@ -153,22 +164,32 @@
//testSearchXP("//*", new Object[]{"Main"});
testSearchXP("//Main/*[jcr:like(@name, '%2')]", new Object[]{doc2});
checkEquals(qf.getDocs("Main/*[jcr:like(@name, '%2')]", null, null).list(), new Object[]{doc2});
-
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {}
+
XWikiDocument doc3 = new XWikiDocument("Main", "WebHome3");
doc3.setContent("no content");
doc3.setAuthor("Artem Melentev");
doc3.setParent("Main.WebHome2");
- hibstore.saveXWikiDoc(doc3, getXWikiContext());
-
+ xwiki.saveDocument(doc3, getXWikiContext());
+ doc3 = xwiki.getDocument(doc3.getFullName(), getXWikiContext());
+
testSearchXP("//*/*[@parent='Main.WebHome2']", new Object[]{doc3});
checkEquals(qf.getChildDocs("Main/WebHome2", null, null).list(), new Object[]{doc3});
-
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {}
+
XWikiDocument doc4 = new XWikiDocument("Test", "WebHome4");
doc4.setContent("no content");
doc4.setAuthor("Someone");
doc4.setParent("Main.WebHome2");
- hibstore.saveXWikiDoc(doc4, getXWikiContext());
-
+ xwiki.saveDocument(doc4, getXWikiContext());
+ doc4 = xwiki.getDocument(doc4.getFullName(), getXWikiContext());
+
testSearchXP("//*/*[@parent='Main.WebHome2']", new Object[]{doc3, doc4});
checkEquals(qf.getChildDocs("Main/WebHome2", null, null).list(), new Object[]{doc3, doc4});
testSearchXP("//*/*[@author='Someone']", new Object[]{doc2, doc4});
@@ -184,12 +205,18 @@
checkEquals(qf.getDocs("*/*[@author!='Someone' and not(jcr:like(@name, '%3'))]", null, null).list(), new Object[]{doc1});
testSearchXP("//*/*[@author='Someone' or @author='Artem Melentev']", new Object[]{doc1,doc2,doc3,doc4});
checkEquals(qf.getDocs("*/*[@author='Someone' or @author='Artem Melentev']", null, null).list(), new Object[]{doc1,doc2,doc3,doc4});
-
+
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {}
+
XWikiDocument doc5 = new XWikiDocument("Test", "WebHome5");
doc5.setContent("is content");
doc5.setAuthor("Someone");
doc5.setParent("Main.WebHome2");
- hibstore.saveXWikiDoc(doc5, getXWikiContext());
+ xwiki.saveDocument(doc5, getXWikiContext());
+ doc5 = xwiki.getDocument(doc5.getFullName(), getXWikiContext());
+
testSearchXP("//*/*[@parent='Main.WebHome2']", new Object[]{doc3,doc4,doc5});
checkEquals(qf.getChildDocs("Main.WebHome2", null, null).list(), new Object[]{doc3,doc4,doc5});
testSearchXP("//*/*[@parent='Main.WebHome2']/@name", new Object[]{doc3.getName(),doc4.getName(),doc5.getName()});
More information about the Xwiki-notifications
mailing list