use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class XWikiHibernateRecycleBinStoreTest method getAllDeletedDocuments.
@Test
public void getAllDeletedDocuments() throws Exception {
XWikiDocument document = mock(XWikiDocument.class);
when(document.getFullName()).thenReturn("Space.Page");
when(document.getLanguage()).thenReturn("ro");
List<XWikiDeletedDocument> deletedVersions = Arrays.asList(mock(XWikiDeletedDocument.class, "v1"), mock(XWikiDeletedDocument.class, "v2"));
Criteria criteria = mock(Criteria.class);
when(criteria.list()).thenReturn(deletedVersions);
when(session.createCriteria(XWikiDeletedDocument.class)).thenReturn(criteria);
assertArrayEquals(deletedVersions.toArray(new XWikiDeletedDocument[2]), mocker.getComponentUnderTest().getAllDeletedDocuments(document, xcontext, true));
// Too bad the restrictions don't implement equals..
verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("fullName=Space.Page"))));
verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("language=ro"))));
verify(criteria).addOrder(argThat(new HasToString<Order>(equalTo("date desc"))));
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteAction method action.
@Override
public boolean action(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
// If the provided DeletedDocument ID is invalid, for any reason, redirect to view mode to see the document does
// not exist screen.
XWikiDeletedDocument deletedDocument = getDeletedDocument(context);
if (deletedDocument == null) {
sendRedirect(response, doc.getURL(VIEW_ACTION, context));
return false;
}
// confirm=true.
if (TRUE.equals(request.getParameter(SHOW_BATCH_PARAMETER)) && !TRUE.equals(request.getParameter(CONFIRM_PARAMETER))) {
return true;
}
// CSRF prevention
if (!csrfTokenCheck(context)) {
return false;
}
// If the current user is not allowed to restore, render the "accessdenied" template.
DeletedDocument deletedDocumentAPI = new DeletedDocument(deletedDocument, context);
if (!deletedDocumentAPI.canUndelete()) {
return true;
}
boolean redirected = false;
if (deletedDocument != null) {
redirected = restoreDocument(deletedDocument, context);
}
// Redirect to the undeleted document. Make sure to redirect to the proper translation.
if (!redirected) {
String queryString = getRedirectQueryString(context, deletedDocument.getLocale());
sendRedirect(response, doc.getURL(VIEW_ACTION, queryString, context));
redirected = true;
}
return !redirected;
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteAction method render.
@Override
public String render(XWikiContext context) throws XWikiException {
String result = null;
XWikiRequest request = context.getRequest();
// If showBatch=true and user confirmation is required, display the "restore" UI.
if (TRUE.equals(request.getParameter(SHOW_BATCH_PARAMETER)) && !TRUE.equals(request.getParameter(CONFIRM_PARAMETER))) {
result = "restore";
}
// If the current user is not allowed to restore, display the "accessdenied" template.
XWikiDeletedDocument deletedDocument = getDeletedDocument(context);
if (deletedDocument != null) {
// Note: Checking for null because when the document is actually restored, it may no longer be in the
// recycle bin by the time render() gets called.
DeletedDocument deletedDocumentAPI = new DeletedDocument(deletedDocument, context);
if (!deletedDocumentAPI.canUndelete()) {
return "accessdenied";
}
}
return result;
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class XWikiHibernateRecycleBinStore method createXWikiDeletedDocument.
private XWikiDeletedDocument createXWikiDeletedDocument(XWikiDocument doc, String deleter, Date date, XWikiRecycleBinContentStoreInterface contentStore, String batchId) throws XWikiException {
XWikiDeletedDocument trashdoc;
String storeType = null;
XWikiDeletedDocumentContent deletedDocumentContent = null;
if (contentStore != null) {
storeType = contentStore.getHint();
} else {
deletedDocumentContent = new XWikiHibernateDeletedDocumentContent(doc);
}
trashdoc = new XWikiDeletedDocument(doc.getFullName(), doc.getLocale(), storeType, deleter, date, deletedDocumentContent, batchId);
return trashdoc;
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class XWikiHibernateRecycleBinStore method getAllDeletedDocuments.
@Override
public XWikiDeletedDocument[] getAllDeletedDocuments(String batchId, boolean withContent, XWikiContext context, boolean bTransaction) throws XWikiException {
XWikiDeletedDocument[] deletedDocuments = executeRead(context, new DeletedDocumentsBatchHibernateCallback(batchId));
// Resolve deleted document content if needed
if (withContent) {
for (int i = 0; i < deletedDocuments.length; ++i) {
XWikiDeletedDocument deletedDocument = deletedDocuments[i];
deletedDocuments[i] = resolveDeletedDocumentContent(deletedDocument, bTransaction);
}
}
return deletedDocuments;
}
Aggregations