Skip to content
Snippets Groups Projects
Commit b596117a authored by Manuel Leduc's avatar Manuel Leduc
Browse files

XWIKI-20114: Mention in comments wrongly attributed to the last document content editor (#1909)

parent 6b644bad
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,7 @@ public void consume(DocumentReference documentReference, String version) throws
XWikiDocument doc = this.documentRevisionProvider.getRevision(documentReference, version);
if (doc != null) {
String authorReference =
this.userReferenceSerializer.serialize(doc.getAuthors().getEffectiveMetadataAuthor());
this.userReferenceSerializer.serialize(doc.getAuthors().getOriginalMetadataAuthor());
List<MentionNotificationParameters> mentionNotificationParameters;
if (doc.getPreviousVersion() == null) {
// CREATE
......
......@@ -59,7 +59,9 @@
@ComponentTest
class DefaultMentionsDataConsumerTest
{
private static final String AUTHOR_REFERENCE = "xwiki:XWiki.Author";
private static final String EFFECTIVE_METADATA_AUTHOR_REFERENCE = "xwiki:XWiki.EffectiveAuthor";
private static final String ORIGINAL_METADATA_AUTHOR_REFERENCE = "xwiki:XWiki.OriginalAuthor";
private static final DocumentReference DOCUMENT_REFERENCE = new DocumentReference("xwiki", "XWiki", "Doc");
......@@ -84,14 +86,23 @@ class DefaultMentionsDataConsumerTest
@Mock
private XWikiDocument doc;
@Mock
private UserReference effectiveMetadataAuthorReference;
@Mock
private UserReference originalMetadataAuthorReference;
@BeforeEach
void setUp()
{
DocumentAuthors documentAuthors = mock(DocumentAuthors.class);
when(this.doc.getAuthors()).thenReturn(documentAuthors);
UserReference userReference = mock(UserReference.class);
when(documentAuthors.getEffectiveMetadataAuthor()).thenReturn(userReference);
when(this.userReferenceSerializer.serialize(userReference)).thenReturn(AUTHOR_REFERENCE);
when(documentAuthors.getEffectiveMetadataAuthor()).thenReturn(effectiveMetadataAuthorReference);
when(documentAuthors.getOriginalMetadataAuthor()).thenReturn(originalMetadataAuthorReference);
when(this.userReferenceSerializer.serialize(effectiveMetadataAuthorReference))
.thenReturn(EFFECTIVE_METADATA_AUTHOR_REFERENCE);
when(this.userReferenceSerializer.serialize(originalMetadataAuthorReference))
.thenReturn(ORIGINAL_METADATA_AUTHOR_REFERENCE);
when(this.doc.getVersion()).thenReturn("1.1");
}
......@@ -111,13 +122,15 @@ void consumeCreatedDocumentNoMentions() throws Exception
when(this.documentRevisionProvider.getRevision(DOCUMENT_REFERENCE, "1.1")).thenReturn(this.doc);
when(this.doc.getPreviousVersion()).thenReturn(null);
when(this.doc.getDocumentReferenceWithLocale()).thenReturn(DOCUMENT_REFERENCE);
when(this.createdDocumentMentionsAnalyzer.analyze(this.doc, DOCUMENT_REFERENCE, "1.1", AUTHOR_REFERENCE))
when(this.createdDocumentMentionsAnalyzer.analyze(this.doc, DOCUMENT_REFERENCE, "1.1",
ORIGINAL_METADATA_AUTHOR_REFERENCE))
.thenReturn(emptyList());
this.dataConsumer.consume(DOCUMENT_REFERENCE, "1.1");
verifyNoInteractions(this.updatedDocumentMentionsAnalyzer);
verify(this.createdDocumentMentionsAnalyzer).analyze(this.doc, DOCUMENT_REFERENCE, "1.1", AUTHOR_REFERENCE);
verify(this.createdDocumentMentionsAnalyzer).analyze(this.doc, DOCUMENT_REFERENCE, "1.1",
ORIGINAL_METADATA_AUTHOR_REFERENCE);
verifyNoInteractions(this.observationManager);
}
......@@ -128,21 +141,22 @@ void consumeCreatedDocumentNewMentions() throws Exception
when(this.doc.getPreviousVersion()).thenReturn(null);
when(this.doc.getDocumentReferenceWithLocale()).thenReturn(DOCUMENT_REFERENCE);
MentionNotificationParameters mentionNotificationParameters =
new MentionNotificationParameters(AUTHOR_REFERENCE, DOCUMENT_REFERENCE, MentionLocation.DOCUMENT,
"1.1")
new MentionNotificationParameters(ORIGINAL_METADATA_AUTHOR_REFERENCE, DOCUMENT_REFERENCE,
MentionLocation.DOCUMENT, "1.1")
.addNewMention("user",
new MentionNotificationParameter("xwiki:XWiki.U1", "anchor1", DisplayStyle.FIRST_NAME));
when(this.createdDocumentMentionsAnalyzer.analyze(this.doc, DOCUMENT_REFERENCE, "1.1", AUTHOR_REFERENCE))
.thenReturn(singletonList(
mentionNotificationParameters));
when(this.createdDocumentMentionsAnalyzer.analyze(this.doc, DOCUMENT_REFERENCE, "1.1",
ORIGINAL_METADATA_AUTHOR_REFERENCE))
.thenReturn(singletonList(mentionNotificationParameters));
this.dataConsumer.consume(DOCUMENT_REFERENCE, "1.1");
verifyNoInteractions(this.updatedDocumentMentionsAnalyzer);
verify(this.createdDocumentMentionsAnalyzer)
.analyze(this.doc, DOCUMENT_REFERENCE, "1.1", AUTHOR_REFERENCE);
.analyze(this.doc, DOCUMENT_REFERENCE, "1.1", ORIGINAL_METADATA_AUTHOR_REFERENCE);
verify(this.observationManager)
.notify(isA(NewMentionsEvent.class), eq(AUTHOR_REFERENCE), eq(mentionNotificationParameters));
.notify(isA(NewMentionsEvent.class), eq(ORIGINAL_METADATA_AUTHOR_REFERENCE),
eq(mentionNotificationParameters));
}
@Test
......@@ -155,14 +169,15 @@ void consumeUpdatedDocumentNoMentions() throws Exception
when(this.doc.getPreviousVersion()).thenReturn("1.0");
when(this.doc.getDocumentReferenceWithLocale()).thenReturn(DOCUMENT_REFERENCE);
when(
this.updatedDocumentMentionsAnalyzer.analyze(oldDoc, this.doc, DOCUMENT_REFERENCE, "1.1", AUTHOR_REFERENCE))
this.updatedDocumentMentionsAnalyzer.analyze(oldDoc, this.doc, DOCUMENT_REFERENCE, "1.1",
ORIGINAL_METADATA_AUTHOR_REFERENCE))
.thenReturn(emptyList());
this.dataConsumer.consume(DOCUMENT_REFERENCE, "1.1");
verifyNoInteractions(this.createdDocumentMentionsAnalyzer);
verify(this.updatedDocumentMentionsAnalyzer).analyze(oldDoc, this.doc, DOCUMENT_REFERENCE, "1.1",
AUTHOR_REFERENCE);
ORIGINAL_METADATA_AUTHOR_REFERENCE);
verifyNoInteractions(this.observationManager);
}
......@@ -175,20 +190,22 @@ void consumeUpdatedDocumentNewMentions() throws Exception
when(this.doc.getPreviousVersion()).thenReturn("1.0");
when(this.doc.getDocumentReferenceWithLocale()).thenReturn(DOCUMENT_REFERENCE);
MentionNotificationParameters mentionNotificationParameters =
new MentionNotificationParameters(AUTHOR_REFERENCE, DOCUMENT_REFERENCE, MentionLocation.DOCUMENT,
"1.1")
new MentionNotificationParameters(ORIGINAL_METADATA_AUTHOR_REFERENCE, DOCUMENT_REFERENCE,
MentionLocation.DOCUMENT, "1.1")
.addNewMention("user",
new MentionNotificationParameter("xwiki:XWiki.U1", "anchor1", DisplayStyle.FIRST_NAME));
when(
this.updatedDocumentMentionsAnalyzer.analyze(oldDoc, this.doc, DOCUMENT_REFERENCE, "1.1", AUTHOR_REFERENCE))
this.updatedDocumentMentionsAnalyzer.analyze(oldDoc, this.doc, DOCUMENT_REFERENCE, "1.1",
ORIGINAL_METADATA_AUTHOR_REFERENCE))
.thenReturn(singletonList(mentionNotificationParameters));
this.dataConsumer.consume(DOCUMENT_REFERENCE, "1.1");
verifyNoInteractions(this.createdDocumentMentionsAnalyzer);
verify(this.updatedDocumentMentionsAnalyzer)
.analyze(oldDoc, this.doc, DOCUMENT_REFERENCE, "1.1", AUTHOR_REFERENCE);
.analyze(oldDoc, this.doc, DOCUMENT_REFERENCE, "1.1", ORIGINAL_METADATA_AUTHOR_REFERENCE);
verify(this.observationManager)
.notify(isA(NewMentionsEvent.class), eq(AUTHOR_REFERENCE), eq(mentionNotificationParameters));
.notify(isA(NewMentionsEvent.class), eq(ORIGINAL_METADATA_AUTHOR_REFERENCE),
eq(mentionNotificationParameters));
}
}
......@@ -60,10 +60,12 @@ class MentionsIT
{
private static final String U1_USERNAME = "U1";
private static final String USERS_PWD = "password";
private static final String U2_USERNAME = "U2";
private static final String U3_USERNAME = "U3";
private static final String USERS_PWD = "password";
/**
* A duplicate of {@link Runnable} which allows to throw checked {@link Exception}.
* @see Runnable
......@@ -150,11 +152,17 @@ void comment(TestUtils setup, TestReference reference) throws Exception
// create the users.
setup.createUser(U1_USERNAME, USERS_PWD, null);
setup.createUser(U2_USERNAME, USERS_PWD, null);
setup.createUser(U3_USERNAME, USERS_PWD, null);
});
runAsUser(setup, U1_USERNAME, USERS_PWD, () -> {
setup.deletePage(reference);
setup.createPage(reference, "", pageName);
});
// We comment with a user distinct from the one who created the page (U1) to make sure that the emitter of
// the mention is correct.
runAsUser(setup, U3_USERNAME, USERS_PWD, () -> {
Map<String, Object> properties = new HashMap<>();
properties.put("author", "xwiki:XWiki.U1");
properties.put("date", "17/08/2020 14:55:18");
......@@ -184,7 +192,7 @@ void comment(TestUtils setup, TestReference reference) throws Exception
mentionNotificationPage.openGroup(0);
assertEquals("mentioned you on a comment on page Mention Comment Test Page",
mentionNotificationPage.getText(0, 0));
assertEquals("U1", mentionNotificationPage.getEmitter(0, 0));
assertEquals("U3", mentionNotificationPage.getEmitter(0, 0));
assertTrue(mentionNotificationPage.hasSummary(0, 0));
assertEquals("@U2 XYZ", mentionNotificationPage.getSummary(0, 0));
tray.clearAllNotifications();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment