use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class DeletedDocumentRevisionProvider method getRevision.
private XWikiDocument getRevision(String revision) throws XWikiException {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDeletedDocument deletedDocument = xcontext.getWiki().getDeletedDocument(Long.valueOf(revision), xcontext);
return deletedDocument != null ? deletedDocument.restoreDocument(xcontext) : null;
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class DefaultModelBridge method canRestoreDeletedDocument.
@Override
public boolean canRestoreDeletedDocument(long deletedDocumentId, DocumentReference userReference) {
boolean result = false;
XWikiContext context = this.xcontextProvider.get();
XWiki xwiki = context.getWiki();
// Remember the context user.
DocumentReference currentUserReference = context.getUserReference();
try {
XWikiDeletedDocument deletedDocument = xwiki.getRecycleBinStore().getDeletedDocument(deletedDocumentId, context, true);
// Reuse the DeletedDocument API to check rights.
DeletedDocument deletedDocumentApi = new DeletedDocument(deletedDocument, context);
// Note: DeletedDocument API works with the current context user.
context.setUserReference(userReference);
result = deletedDocumentApi.canUndelete();
} catch (Exception e) {
logger.error("Failed to check restore rights on deleted document [{}] for user [{}]", deletedDocumentId, userReference, e);
} finally {
// Restore the context user;
context.setUserReference(currentUserReference);
}
return result;
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class DefaultModelBridge method getDeletedDocumentIds.
@Override
public List<Long> getDeletedDocumentIds(String batchId) {
XWikiContext context = this.xcontextProvider.get();
XWiki xwiki = context.getWiki();
List<Long> result = new ArrayList<>();
try {
XWikiDeletedDocument[] deletedDocuments = xwiki.getRecycleBinStore().getAllDeletedDocuments(batchId, false, context, true);
for (XWikiDeletedDocument deletedDocument : deletedDocuments) {
result.add(deletedDocument.getId());
}
} catch (Exception e) {
logger.error("Failed to get deleted document IDs for batch [{}]", batchId);
}
return result;
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method canRestoreDeletedDocument.
@Test
public void canRestoreDeletedDocument() throws Exception {
long deletedDocumentId = 42;
String deletedDocumentFullName = "Space.DeletedDocument";
DocumentReference userReferenceToCheck = new DocumentReference("wiki", "Space", "User");
DocumentReference currentUserReference = new DocumentReference("wiki", "Space", "CurrentUser");
when(xcontext.getUserReference()).thenReturn(currentUserReference);
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getFullName()).thenReturn(deletedDocumentFullName);
XWikiRecycleBinStoreInterface recycleBin = mock(XWikiRecycleBinStoreInterface.class);
when(recycleBin.getDeletedDocument(deletedDocumentId, xcontext, true)).thenReturn(deletedDocument);
when(xwiki.getRecycleBinStore()).thenReturn(recycleBin);
XWikiRightService rightService = mock(XWikiRightService.class);
when(xwiki.getRightService()).thenReturn(rightService);
when(rightService.hasAccessLevel(any(), any(), any(), any())).thenReturn(true);
assertTrue(mocker.getComponentUnderTest().canRestoreDeletedDocument(deletedDocumentId, userReferenceToCheck));
// Verify that the rights were checked with the specified user as context user.
verify(xcontext).setUserReference(userReferenceToCheck);
// Verify that the context user was restored. Note: We don`t know the order here, but maybe we don`t care that
// much.
verify(xcontext).setUserReference(currentUserReference);
}
use of com.xpn.xwiki.doc.XWikiDeletedDocument in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method restoreDeletedDocumentNoRights.
@Test
public void restoreDeletedDocumentNoRights() throws Exception {
long deletedDocumentId = 42;
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
String deletedDocumentFullName = "space.page";
XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class);
when(deletedDocument.getDocumentReference()).thenReturn(documentReference);
when(deletedDocument.getId()).thenReturn(deletedDocumentId);
when(deletedDocument.getFullName()).thenReturn(deletedDocumentFullName);
when(xwiki.getDeletedDocument(deletedDocumentId, xcontext)).thenReturn(deletedDocument);
when(xwiki.exists(documentReference, xcontext)).thenReturn(false);
XWikiRecycleBinStoreInterface recycleBin = mock(XWikiRecycleBinStoreInterface.class);
when(recycleBin.getDeletedDocument(deletedDocumentId, xcontext, true)).thenReturn(deletedDocument);
when(xwiki.getRecycleBinStore()).thenReturn(recycleBin);
// No rights.
XWikiRightService rightService = mock(XWikiRightService.class);
when(xwiki.getRightService()).thenReturn(rightService);
when(rightService.hasAccessLevel(any(), any(), any(), any())).thenReturn(false);
assertFalse(mocker.getComponentUnderTest().restoreDeletedDocument(deletedDocumentId, true));
verify(mocker.getMockedLogger()).error("You are not allowed to restore document [{}] with ID [{}]", documentReference, deletedDocumentId);
verify(xwiki, never()).restoreFromRecycleBin(any(), any(), any());
}
Aggregations