Search in sources :

Example 11 with XWikiDeletedDocument

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"))));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) HasToString(org.hamcrest.object.HasToString) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) Criteria(org.hibernate.Criteria) Test(org.junit.Test)

Example 12 with XWikiDeletedDocument

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) DeletedDocument(com.xpn.xwiki.api.DeletedDocument) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument)

Example 13 with XWikiDeletedDocument

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;
}
Also used : XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) DeletedDocument(com.xpn.xwiki.api.DeletedDocument) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument)

Example 14 with XWikiDeletedDocument

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;
}
Also used : XWikiHibernateDeletedDocumentContent(com.xpn.xwiki.internal.store.hibernate.XWikiHibernateDeletedDocumentContent) XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument) XWikiDeletedDocumentContent(com.xpn.xwiki.doc.XWikiDeletedDocumentContent)

Example 15 with XWikiDeletedDocument

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;
}
Also used : XWikiDeletedDocument(com.xpn.xwiki.doc.XWikiDeletedDocument)

Aggregations

XWikiDeletedDocument (com.xpn.xwiki.doc.XWikiDeletedDocument)24 Test (org.junit.Test)13 XWikiContext (com.xpn.xwiki.XWikiContext)10 DocumentReference (org.xwiki.model.reference.DocumentReference)8 XWiki (com.xpn.xwiki.XWiki)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 XWikiException (com.xpn.xwiki.XWikiException)5 CSRFToken (org.xwiki.csrf.CSRFToken)5 DeletedDocument (com.xpn.xwiki.api.DeletedDocument)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 XWikiRecycleBinStoreInterface (com.xpn.xwiki.store.XWikiRecycleBinStoreInterface)4 XWikiRightService (com.xpn.xwiki.user.api.XWikiRightService)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)2 XWikiDeletedDocumentContent (com.xpn.xwiki.doc.XWikiDeletedDocumentContent)1 XWikiHibernateDeletedDocumentContent (com.xpn.xwiki.internal.store.hibernate.XWikiHibernateDeletedDocumentContent)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Map (java.util.Map)1 HasToString (org.hamcrest.object.HasToString)1