Skip to content
Permalink
Browse files Browse the repository at this point in the history
XWIKI-18430: Wrong handling of template documents
* improve retro compatibility with future 12.10.x versions
  • Loading branch information
tmortagne committed Mar 15, 2021
1 parent 76d2e6e commit b35ef0e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
Expand Up @@ -32,7 +32,6 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.csrf.CSRFToken;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.DocumentReferenceResolver;
import org.xwiki.model.reference.EntityReferenceSerializer;
import org.xwiki.model.reference.SpaceReference;
import org.xwiki.security.authorization.ContextualAuthorizationManager;
Expand Down Expand Up @@ -97,11 +96,6 @@ public class CreateAction extends XWikiAction
*/
private static final String LOCAL_SERIALIZER_HINT = "local";

/**
* Current entity reference resolver hint.
*/
private static final String CURRENT_MIXED_RESOLVER_HINT = "currentmixed";

/**
* The action to perform when creating a new page from a template.
*
Expand Down Expand Up @@ -277,14 +271,6 @@ private void doCreate(XWikiContext context, XWikiDocument newDocument, boolean i
}
}

/**
* @return the resolver uses to resolve references received in request parameters
*/
private DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
{
return Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, CURRENT_MIXED_RESOLVER_HINT);
}

/**
* Initialize and save the new document before editing it. Follow the steps done by the Save action.
*
Expand Down Expand Up @@ -312,7 +298,7 @@ private void initAndSaveDocument(XWikiContext context, XWikiDocument newDocument

// Set the parent field.
if (!StringUtils.isEmpty(parent)) {
DocumentReference parentReference = this.currentmixedReferenceResolver.resolve(parent);
DocumentReference parentReference = getCurrentMixedDocumentReferenceResolver().resolve(parent);
newDocument.setParentReference(parentReference);
}

Expand Down
Expand Up @@ -153,13 +153,6 @@ public abstract class XWikiAction implements LegacyAction
@Inject
protected Execution execution;

@Inject
protected ContextualAuthorizationManager autorization;

@Inject
@Named("currentmixed")
protected DocumentReferenceResolver<String> currentmixedReferenceResolver;

/**
* Indicate if the action allow asynchronous display (among which the XWiki initialization).
*/
Expand All @@ -170,6 +163,13 @@ public abstract class XWikiAction implements LegacyAction
*/
protected boolean handleRedirectObject = false;

@Inject
@Named("currentmixed")
private DocumentReferenceResolver<String> currentmixedReferenceResolver;

@Inject
private ContextualAuthorizationManager autorization;

private ContextualLocalizationManager localization;

private JobProgressManager progress;
Expand Down Expand Up @@ -201,6 +201,24 @@ protected ContextualLocalizationManager getLocalization()
return this.localization;
}

/**
* @since 12.10.6
* @since 13.2RC1
*/
protected DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
{
return this.currentmixedReferenceResolver;
}

/**
* @since 12.10.6
* @since 13.2RC1
*/
protected ContextualAuthorizationManager getContextualAuthorizationManager()
{
return this.autorization;
}

protected String localizePlainOrKey(String key, Object... parameters)
{
return StringUtils.defaultString(getLocalization().getTranslationPlain(key, parameters), key);
Expand Down Expand Up @@ -1158,10 +1176,10 @@ protected void setContentLength(XWikiResponse response, long length)
protected DocumentReference resolveTemplate(String template)
{
if (StringUtils.isNotBlank(template)) {
DocumentReference templateReference = this.currentmixedReferenceResolver.resolve(template);
DocumentReference templateReference = getCurrentMixedDocumentReferenceResolver().resolve(template);

// Make sure the current user have access to the template document before copying it
if (this.autorization.hasAccess(Right.VIEW, templateReference)) {
if (getContextualAuthorizationManager().hasAccess(Right.VIEW, templateReference)) {
return templateReference;
}
}
Expand Down

0 comments on commit b35ef0e

Please sign in to comment.