use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class DocumentEventConverter method unserializeDeletdDocument.
private XWikiDocument unserializeDeletdDocument(Serializable remoteData, XWikiContext xcontext) throws XWikiException {
Map<String, Serializable> remoteDataMap = (Map<String, Serializable>) remoteData;
DocumentReference docReference = (DocumentReference) remoteDataMap.get(DOC_NAME);
XWikiDocument doc = new XWikiDocument(docReference);
XWikiDocument origDoc = new XWikiDocument(docReference);
// We have to get deleted document from the trash (hoping it is in the trash...)
XWiki xwiki = xcontext.getWiki();
XWikiRecycleBinStoreInterface store = xwiki.getRecycleBinStore();
XWikiDeletedDocument[] deletedDocuments = store.getAllDeletedDocuments(origDoc, xcontext, true);
if (deletedDocuments != null && deletedDocuments.length > 0) {
long index = deletedDocuments[0].getId();
origDoc = store.restoreFromRecycleBin(index, xcontext, true);
}
doc.setOriginalDocument(origDoc);
return doc;
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class DeleteAction method deleteFromRecycleBin.
private void deleteFromRecycleBin(long index, XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
XWikiDeletedDocument dd = xwiki.getRecycleBinStore().getDeletedDocument(index, context, true);
// don't try to delete it and instead redirect to the view page.
if (dd != null) {
DeletedDocument ddapi = new DeletedDocument(dd, context);
if (!ddapi.canDelete()) {
throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, "You are not allowed to delete a document from the trash " + "immediately after it has been deleted from the wiki");
}
if (!dd.getFullName().equals(doc.getFullName())) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION, "The specified trash entry does not match the current document");
}
xwiki.getRecycleBinStore().deleteFromRecycleBin(index, context, true);
}
sendRedirect(response, Utils.getRedirect("view", context));
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteActionTest method missingCSRFToken.
@Test
public void missingCSRFToken() throws Exception {
// Valid Deleted document ID.
long id = 13;
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
// Invalid CSRF token.
CSRFToken csrfToken = mocker.getInstance(CSRFToken.class);
when(csrfToken.isTokenValid(null)).thenReturn(false);
assertFalse(undeleteAction.action(context));
// Verify that the resubmission URL was retrieved to be used in the redirect.
verify(csrfToken).getResubmissionURL();
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteActionTest method restoreSingleDocument.
/**
* Launches a RestoreJob with the current deleted document ID.
*/
@Test
public void restoreSingleDocument() throws Exception {
CSRFToken csrfToken = mocker.getInstance(CSRFToken.class);
when(csrfToken.isTokenValid(null)).thenReturn(true);
long id = 13;
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getLocale()).thenReturn(Locale.ROOT);
when(deletedDocument.getId()).thenReturn(id);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
when(rightsService.hasAccessLevel(any(), any(), any(), any())).thenReturn(true);
assertFalse(undeleteAction.action(context));
verify(refactoringScriptService).createRestoreRequest(Arrays.asList(id));
verify(jobExecutor).execute(RefactoringJobs.RESTORE, jobRequest);
verify(job).join();
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class UndeleteActionTest method notAllowedToRestoreBatch.
/**
* When trying to restore, rights are checked on the current deleted document, regardless if single or batch
* restore.
*/
@Test
public void notAllowedToRestoreBatch() throws Exception {
CSRFToken csrfToken = mocker.getInstance(CSRFToken.class);
when(csrfToken.isTokenValid(null)).thenReturn(true);
long id = 13;
String batchId = "abc123";
when(request.getParameter("id")).thenReturn(String.valueOf(id));
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getLocale()).thenReturn(Locale.ROOT);
when(deletedDocument.getId()).thenReturn(id);
when(deletedDocument.getBatchId()).thenReturn(batchId);
when(xwiki.getDeletedDocument(anyLong(), any(XWikiContext.class))).thenReturn(deletedDocument);
// Go through the screen showing the option to include the batch and displaying its contents.
when(request.getParameter("showBatch")).thenReturn("true");
// Option to include the entire batch when restoring is enabled.
when(request.getParameter("includeBatch")).thenReturn("true");
// Confirmation button pressed.
when(request.getParameter("confirm")).thenReturn("true");
// No rights to restore the page when checking from the Action. The job will check individual rights.
when(rightsService.hasAccessLevel(any(), any(), any(), any())).thenReturn(false);
assertTrue(undeleteAction.action(context));
// Render the "accessdenied" template.
assertEquals("accessdenied", undeleteAction.render(context));
// Just make sure we don`t go any further.
verify(refactoringScriptService, never()).createRestoreRequest(batchId);
}
Aggregations