use of com.xpn.xwiki.api.DeletedDocument 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.api.DeletedDocument 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.api.DeletedDocument 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.api.DeletedDocument 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;
}
Aggregations