Skip to content

Commit

Permalink
XWIKI-21884: Uploading files during page creation step will mark XWik…
Browse files Browse the repository at this point in the history
…iGuest as creator

* set the page creator
  • Loading branch information
oanalavinia committed Feb 13, 2024
1 parent 103650d commit 07170be
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -127,6 +128,10 @@ public boolean isAlreadyExisting()
@Named("context")
private Provider<ComponentManager> componentManagerProvider;

@Inject
@Named("document")
private UserReferenceResolver<DocumentReference> 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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 07170be

Please sign in to comment.