From 07170becfce3ff6b0d9ad3545602e5ec6801316e Mon Sep 17 00:00:00 2001 From: Oana-Lavinia Florean Date: Tue, 13 Feb 2024 18:19:35 +0200 Subject: [PATCH] XWIKI-21884: Uploading files during page creation step will mark XWikiGuest as creator * set the page creator --- .../internal/resources/BaseAttachmentsResource.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/BaseAttachmentsResource.java b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/BaseAttachmentsResource.java index 00eedec191bc..ac4e808318c1 100644 --- a/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/BaseAttachmentsResource.java +++ b/xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/BaseAttachmentsResource.java @@ -56,6 +56,7 @@ import org.xwiki.rest.internal.Utils; import org.xwiki.rest.model.jaxb.Attachment; import org.xwiki.rest.model.jaxb.Attachments; +import org.xwiki.user.UserReferenceResolver; import com.xpn.xwiki.XWiki; import com.xpn.xwiki.XWikiContext; @@ -127,6 +128,10 @@ public boolean isAlreadyExisting() @Named("context") private Provider componentManagerProvider; + @Inject + @Named("document") + private UserReferenceResolver documentReferenceUserReferenceResolver; + /** * @param scope where to retrieve the attachments from; it should be a reference to a wiki, space or document * @param filters the filters used to restrict the set of attachments (you can filter by space name, document @@ -411,7 +416,11 @@ protected XWikiAttachment createOrUpdateAttachment(AttachmentReference attachmen String.format("Failed to instantiate a [%s] component.", AttachmentValidator.class.getName()), e); } - // Set the document author. + // Set the document creator / author. + if (document.isNew()) { + document.getAuthors() + .setCreator(this.documentReferenceUserReferenceResolver.resolve(xcontext.getUserReference())); + } document.setAuthorReference(xcontext.getUserReference()); // Calculate and store the attachment media type.