snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s

This commit is contained in:
upstream-mirror
2026-09-16 00:29:55 +05:00
commit 240db4e2a7
15309 changed files with 2173406 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {expect, test} from '@mattermost/playwright-lib';
import {setupContentFlagging, createPost} from './../support';
/**
* @objective Verify that a deletion report summary is posted to the reviewer's content review thread after removing a flagged post
* @testcase
* 1. Create two users and set one as reviewer
* 2. Setup content flagging
* 3. Create a post, flag it, and remove it via reviewer
* 4. Login as the reviewer and navigate to the content review DM
* 5. Verify the deletion report summary table is posted in the reviewer's thread
*/
test('Reviewer receives a deletion report summary after removing a flagged post', async ({pw}) => {
const {adminClient, team, user: reviewerUser} = await pw.initSetup();
// # Create author user
const authorUser = await pw.random.user('author');
const {id: authorUserID} = await adminClient.createUser(authorUser, '', '');
await adminClient.addToTeam(team.id, authorUserID);
const {client: authorUserClient} = await pw.makeClient(authorUser);
await setupContentFlagging(adminClient, [reviewerUser.id]);
const message = `Sensitive 2 post by @${authorUser.username} to be removed`;
const {post} = await createPost(adminClient, authorUserClient, team, authorUser, message);
const expectedFileName = `deletion_report_${post.id}.md`;
// # Flag the post
await adminClient.flagPost(post.id, 'Classification mismatch', 'This message contains sensitive data');
// # Login as reviewer and navigate to content review DM
const {channelsPage, contentReviewPage} = await pw.testBrowser.login(reviewerUser);
await channelsPage.goto(team.name, '@content-review');
await channelsPage.toBeVisible();
const flaggedPost = await channelsPage.centerView.getLastPost();
await flaggedPost.toContainText(message);
// # Remove the post via the UI. The remove flow still routes through the
// skip-confirm step (destructive action), unlike the keep flow which now
// bypasses it.
await contentReviewPage.setReportCardByPostID(post.id);
await contentReviewPage.openViewDetails();
await contentReviewPage.waitForRHSVisible();
await contentReviewPage.openViewDetails();
await contentReviewPage.clickRemoveMessage();
await contentReviewPage.enterConfirmationComment('Removing: data spillage confirmed');
await contentReviewPage.confirmRemoveWithoutReport();
await channelsPage.goto(team.name, '@content-review');
await channelsPage.toBeVisible();
// * Verify the removed stub is in the content-review thread
const removedPost = await channelsPage.centerView.getPostByText(
'Content deleted as part of Content Flagging review process',
);
await removedPost.toBeVisible();
// # Open the thread — the deletion report is posted as a reply, not on the
// view-details property card.
await expect(removedPost.threadFooter.container).toBeVisible();
await removedPost.threadFooter.reply();
await channelsPage.sidebarRight.toBeVisible();
// * Verify the async deletion-report file is in the thread before table headers
await channelsPage.sidebarRight.toContainText(expectedFileName);
// * Verify the summary table headers are present (rendered as markdown table)
await channelsPage.sidebarRight.toContainText('Step');
await channelsPage.sidebarRight.toContainText('Status');
await channelsPage.sidebarRight.toContainText('Detail');
await channelsPage.sidebarRight.toContainText('File attachments');
await channelsPage.sidebarRight.toContainText('File attachment records');
await channelsPage.sidebarRight.toContainText('Edit history');
await channelsPage.sidebarRight.toContainText('Priority metadata');
await channelsPage.sidebarRight.toContainText('Persistent notifications');
await channelsPage.sidebarRight.toContainText('Acknowledgements');
await channelsPage.sidebarRight.toContainText('Reminders');
await channelsPage.sidebarRight.toContainText('Thread, replies, and reactions');
await channelsPage.sidebarRight.toContainText('Post record');
});

View File

@@ -0,0 +1,49 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {expect, test} from '@mattermost/playwright-lib';
import {createPost, verifyAuthorNotification, setupContentFlagging} from './../support';
/**
* @objective Verify that when the author deletes a flagged message before review,
* the flag status is updated to "Removed" and the report reflects the deletion.
*/
// TODO: Fix defect https://mattermost.atlassian.net/browse/MM-66342
test.skip('should not be able to restore flagged messages when author deletes message', async ({pw}) => {
const {adminClient, team, user: reviewerUser} = await pw.initSetup();
// Create second user and add to team
const reporterUser = await pw.random.user('second');
const {id: reporterUserID} = await adminClient.createUser(reporterUser, '', '');
await adminClient.addToTeam(team.id, reporterUserID);
// Create third user and add to team
const postFromThirdUser = await pw.random.user('third');
const {id: postFromThirdUserID} = await adminClient.createUser(postFromThirdUser, '', '');
await adminClient.addToTeam(team.id, postFromThirdUserID);
const {client: thirdUserClient} = await pw.makeClient(postFromThirdUser);
const {client: reporterUserClient} = await pw.makeClient(reporterUser);
await setupContentFlagging(adminClient, [reviewerUser.id], true, false);
const message = `Post by @${reviewerUser.username}, is flagged once`;
const {post} = await createPost(adminClient, thirdUserClient, team, postFromThirdUser, message);
await reporterUserClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
// delete the post as the author
await thirdUserClient.deletePost(post.id);
// verify the flag status is updated to "Removed"
const flagReport = await adminClient.getFlaggedPost(post.id);
// Verify the delete_at timestamp is set (indicating deletion)
expect(flagReport.delete_at).not.toBe(0);
const {channelsPage, contentReviewPage} = await pw.testBrowser.login(reviewerUser);
await channelsPage.goto(team.name, 'town-square');
await channelsPage.toBeVisible();
await verifyAuthorNotification(post.id, channelsPage, contentReviewPage, team.name, message, 'Removed');
});

View File

@@ -0,0 +1,77 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {test} from '@mattermost/playwright-lib';
import {createPost, verifyAuthorNotification, setupContentFlagging} from './../support';
/** @objective Verify Post message is updated for the reviewer, if author updates the post before reviewer's action
* @testcase
* 1. Setup Content Flagging with reviewers
* 2. Create a post by User A
* 3. Flag the post by User B
* 4. Edit the post by User A before reviewer's action
* 5. Login as Reviewer and verify the updated message in Content Review page
*/
test("Verify Post message is updated for the reviewer, if author updates the post before reviewer's action ", async ({
pw,
}) => {
const {adminClient, team, user, userClient, adminUser} = await pw.initSetup();
// Create second user and add to team
const secondUser = await pw.random.user('reviewer');
const {id: secondUserID} = await adminClient.createUser(secondUser, '', '');
await adminClient.addToTeam(team.id, secondUserID);
// Promote to system_admin so SystemAdminsAsReviewers:true (the test-suite default)
// keeps them as a reviewer even if a concurrent initSetup() resets CommonReviewerIds:[].
await adminClient.updateUserRoles(secondUserID, 'system_user system_admin');
// Setup content flagging with explicit reviewer list and HideFlaggedContent=false.
// The default test config sets EnableContentFlagging=true and SystemAdminsAsReviewers=true,
// so concurrent initSetup() resets from other workers cannot silently disable this test.
await setupContentFlagging(adminClient, [adminUser.id, secondUserID], true, false);
const message = `Post by @${user.username}, is flagged once`;
const {post} = await createPost(adminClient, userClient, team, user, message);
await adminClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
let updatedMessage = `${message} - Edited during review`;
await userClient.updatePost({
id: post.id,
create_at: post.create_at,
update_at: Date.now(),
edit_at: 0,
delete_at: 0,
is_pinned: false,
user_id: post.user_id,
channel_id: post.channel_id,
root_id: '',
original_id: '',
message: updatedMessage,
type: '',
props: {},
hashtags: '',
file_ids: [],
pending_post_id: '',
remote_id: '',
reply_count: 0,
last_reply_at: 0,
participants: null,
metadata: post.metadata,
});
const {channelsPage: secondChannelsPage, contentReviewPage: secondContentReviewPage} =
await pw.testBrowser.login(secondUser);
// The edited post will have Edited indicator automatically added by the system
updatedMessage = `${updatedMessage} Edited`;
await verifyAuthorNotification(
post.id,
secondChannelsPage,
secondContentReviewPage,
team.name,
updatedMessage,
'Pending',
);
});

View File

@@ -0,0 +1,534 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {expect, test} from '@mattermost/playwright-lib';
// NOTE: No global afterAll disabling content flagging here. A global afterAll
// that writes shared server config races with reviewer-* tests running in a
// parallel worker on the same shard. Each test that needs content flagging
// disabled sets it explicitly at the start (see the "feature is disabled" test
// below). Tests that need it enabled do the same via patchConfig/setupContentFlagging.
// Constants for repeated strings
const FLAG_REASON_CLASSIFICATION_MISMATCH: string = 'Classification mismatch';
// Sent by every patchConfig below: the reason list is server-wide and replaced as a whole, so a
// test cannot rely on the one another test left behind.
const FLAG_REASONS: string[] = ['Spam', FLAG_REASON_CLASSIFICATION_MISMATCH, 'Harassment', 'Hate Speech', 'Other'];
const FLAG_COMMENT: string = 'This message contains misclassified data';
const systemMessageForUser = (username: string): string =>
`The message from @${username} has been quarantined for review. You will be notified once it is reviewed by a Reviewer.`;
// Helper to login and navigate to channel
async function loginAndNavigate(pw: any, user: any, teamName?: string, channelName?: string): Promise<any> {
const {channelsPage} = await pw.testBrowser.login(user);
if (teamName && channelName) {
await channelsPage.goto(teamName, channelName);
} else {
await channelsPage.goto();
}
await channelsPage.toBeVisible();
return channelsPage;
}
// Helper to post a message and get post info
async function postMessage(channelsPage: any, message: string): Promise<{post: any; postId: any}> {
await channelsPage.postMessage(message);
const post = await channelsPage.getLastPost();
const postId = await channelsPage.centerView.getLastPostID();
return {post, postId};
}
// Helper to flag a post
async function flagPostFlow(
post: any,
channelsPage: any,
message: string,
reason: string = FLAG_REASON_CLASSIFICATION_MISMATCH,
comment: string = FLAG_COMMENT,
): Promise<void> {
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItem.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.toContainPostText(message);
await channelsPage.centerView.flagPostConfirmationDialog.selectFlagReason(reason);
await channelsPage.centerView.flagPostConfirmationDialog.fillFlagComment(comment);
await channelsPage.centerView.flagPostConfirmationDialog.submitButton.click();
await channelsPage.centerView.flagPostConfirmationDialog.notToBeVisible();
}
// Helper to open the dot menu for a given post
async function openPostDotMenu(post: any, channelsPage: any): Promise<void> {
await post.hover();
await post.postMenu.toBeVisible();
await post.postMenu.dotMenuButton.click();
await channelsPage.postDotMenu.toBeVisible();
}
/**
* @objective: Test the basic flow of flagging a message and verify flagged message is hidden
*
* @testcase
* 1. Login as a user
* 2. Post a message
* 3. Flag the message
* 4. Verify the message is hidden and a system message is shown
*/
test('Verify flagged message is hidden by default', async ({pw}) => {
const {user, adminClient} = await pw.initSetup();
// Explicitly set HideFlaggedContent: true — a parallel worker may have set it
// to false (e.g. author-deletes-message-before-review.spec.ts). Without an
// explicit value this test would fail intermittently under PW_WORKERS=2.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
HideFlaggedContent: true,
Reasons: FLAG_REASONS,
},
},
});
const channelsPage = await loginAndNavigate(pw, user);
const message = 'This is a test message to be flagged';
const {post, postId} = await postMessage(channelsPage, message);
// Re-apply guard: concurrent initSetup() may reset EnableContentFlagging: false.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {HideFlaggedContent: true, Reasons: FLAG_REASONS},
},
});
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === true;
});
// Cancel flagging the message
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItem.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.toContainPostText(message);
await channelsPage.centerView.flagPostConfirmationDialog.cancelButton.click();
await channelsPage.centerView.flagPostConfirmationDialog.notToBeVisible();
// Flag the message
await flagPostFlow(post, channelsPage, message, FLAG_REASON_CLASSIFICATION_MISMATCH);
// Verify the message is flagged
const flaggedPost = await channelsPage.centerView.getPostById(postId);
await flaggedPost.toContainText('(message deleted)');
const systemMessage = await channelsPage.getLastPost();
await expect(systemMessage.body).toContainText(systemMessageForUser(user.username));
});
/**
* @objective: Verify Post is not hidden after flagging if HideFlaggedContent is false
*
* @testcase
* 1. Login as a user
* 2. Post a message
* 3. Flag the message
* 4. Verify the message is not hidden
*/
test('Verify Post is not hidden after flagging if HideFlaggedContent is false', async ({pw}) => {
const {user, adminClient} = await pw.initSetup();
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
HideFlaggedContent: false,
Reasons: FLAG_REASONS,
},
},
});
const channelsPage = await loginAndNavigate(pw, user);
const message = 'This is a test message to be flagged';
const {post, postId} = await postMessage(channelsPage, message);
await post.toBeVisible();
// Re-apply guard: concurrent initSetup() may reset EnableContentFlagging: false.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {HideFlaggedContent: false, Reasons: FLAG_REASONS},
},
});
// Cancel flagging the message
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItem.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.toContainPostText(message);
await channelsPage.centerView.flagPostConfirmationDialog.cancelButton.click();
await channelsPage.centerView.flagPostConfirmationDialog.notToBeVisible();
// Flag the message
await flagPostFlow(post, channelsPage, message);
// Verify the message is flagged
const originaltext = await channelsPage.centerView.getPostById(postId);
await expect(originaltext.body).toContainText(message);
const systemMessage = await channelsPage.getLastPost();
await expect(systemMessage.body).toContainText(systemMessageForUser(user.username));
});
/**
* @objective: Test that another user cannot flag an already flagged message
*
* @testcase
* 1. Login as a user
* 2. Post a message
* 3. Flag the message
* 4. Login as another user
* 5. Attempt to flag the already flagged message
* 6. Verify that the message cannot be flagged again
*/
test('Verify user cannot flag already flagged message', async ({pw}) => {
const {user, adminClient, team} = await pw.initSetup();
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
HideFlaggedContent: false,
Reasons: FLAG_REASONS,
},
NotificationSettings: {
EventTargetMapping: {
assigned: ['reviewers'],
dismissed: ['reporter', 'author', 'reviewers'],
flagged: ['reviewers'],
removed: ['author', 'reporter', 'reviewers'],
},
},
},
});
const secondUser = await pw.random.user('mentioned');
const {id: secondUserID} = await adminClient.createUser(secondUser, '', '');
await adminClient.addToTeam(team.id, secondUserID);
const channels = await adminClient.getMyChannels(team.id);
const townSquare = channels.find((channel) => channel.name === 'town-square');
if (!townSquare) {
throw new Error('Town Square channel not found');
}
const message = `Post by @${user.username}, is flagged once`;
const postToBeflagged = await adminClient.createPost({
channel_id: townSquare.id,
message,
user_id: user.id,
});
await adminClient.flagPost(postToBeflagged.id, FLAG_REASON_CLASSIFICATION_MISMATCH, FLAG_COMMENT);
// Login as the second user
const channelsPage = await loginAndNavigate(pw, secondUser, team.name, 'town-square');
// Town Square may show join/system posts above the target — select by post id.
const post = await channelsPage.centerView.getPostById(postToBeflagged.id);
// Re-apply guard immediately before dot-menu: login takes 3-5 s during which a
// concurrent initSetup() can reset EnableContentFlagging to false.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {HideFlaggedContent: false, Reasons: FLAG_REASONS},
},
});
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === true;
});
// Try to flag already flagged post
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItem.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.selectFlagReason(FLAG_REASON_CLASSIFICATION_MISMATCH);
await channelsPage.centerView.flagPostConfirmationDialog.fillFlagComment(FLAG_COMMENT);
await channelsPage.centerView.flagPostConfirmationDialog.submitButton.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.cannotFlagAlreadyFlaggedPostToBeVisible();
});
/**
* @objective: Test that user cannot flag a message that was previously retained.
*
* @testcase
* 1. Login as a user
* 2. Post a message
* 3. Flag the message
* 4. Retain the message as a reviewer
* 5. Attempt to flag the retained message again
* 6. Verify that the message cannot be flagged again
*/
test('Verify user cannot flag a message that was previously retained', async ({pw}) => {
const {user, adminClient, team} = await pw.initSetup();
const secondUser = await pw.random.user('mentioned-');
const {id: secondUserID, username: secondUsername} = await adminClient.createUser(secondUser, '', '');
await adminClient.addToTeam(team.id, secondUserID);
const channels = await adminClient.getMyChannels(team.id);
const townSquare = channels.find((channel) => channel.name === 'town-square');
if (!townSquare) {
throw new Error('Town Square channel not found');
}
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
HideFlaggedContent: false,
Reasons: FLAG_REASONS,
},
NotificationSettings: {
EventTargetMapping: {
assigned: ['reviewers'],
dismissed: ['reporter', 'author', 'reviewers'],
flagged: ['reviewers'],
removed: ['author', 'reporter', 'reviewers'],
},
},
ReviewerSettings: {
CommonReviewers: true,
SystemAdminsAsReviewers: true,
TeamAdminsAsReviewers: true,
CommonReviewerIds: [user.id, secondUserID],
},
},
});
const message = `Post by @${secondUsername}, is flagged once`;
const postToBeflagged = await adminClient.createPost({
channel_id: townSquare.id,
message,
user_id: secondUserID,
});
await adminClient.flagPost(postToBeflagged.id, FLAG_REASON_CLASSIFICATION_MISMATCH, FLAG_COMMENT);
await adminClient.keepFlaggedPost(postToBeflagged.id, 'Retaining this post after review');
// Re-apply guard before UI interaction: a concurrent initSetup() may have reset
// EnableContentFlagging or reviewer settings between the initial patchConfig and here.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {HideFlaggedContent: false, Reasons: FLAG_REASONS},
NotificationSettings: {
EventTargetMapping: {
assigned: ['reviewers'],
dismissed: ['reporter', 'author', 'reviewers'],
flagged: ['reviewers'],
removed: ['author', 'reporter', 'reviewers'],
},
},
ReviewerSettings: {
CommonReviewers: true,
SystemAdminsAsReviewers: true,
TeamAdminsAsReviewers: true,
CommonReviewerIds: [user.id, secondUserID],
},
},
});
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === true;
});
// Login as the second user
const channelsPage = await loginAndNavigate(pw, secondUser, team.name, 'town-square');
const post = await channelsPage.centerView.getPostById(postToBeflagged.id);
// Try to flag previously retained post
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItem.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.toContainPostText(message);
await channelsPage.centerView.flagPostConfirmationDialog.selectFlagReason(FLAG_REASON_CLASSIFICATION_MISMATCH);
await channelsPage.centerView.flagPostConfirmationDialog.fillFlagComment(FLAG_COMMENT);
await channelsPage.centerView.flagPostConfirmationDialog.submitButton.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.cannotFlagPreviouslyRetainedPostToBeVisible();
});
/**
* @objective: Test that flag message option is not available when Content Flagging feature is disabled
* * @testcase
* 1. Login as a user
* 2. Post a message
* 3. Verify that flag message option is not available in the post menu
*/
test('Verify the Quarantine for Review option is not available when feature is disabled', async ({pw}) => {
const {user, adminClient} = await pw.initSetup();
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: false,
},
});
const channelsPage = await loginAndNavigate(pw, user);
const message = 'This is a test message to be flagged';
const {post} = await postMessage(channelsPage, message);
// Re-apply guard: parallel tests often turn flagging back on; the menu item only hides when false.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: false,
},
});
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === false;
});
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItemNotToBeVisible();
});
/**
* @objective: Verify Flagging reason dropdown options
* * @testcase
* 1. Login as a user
* 2. Post a message
* 3. Open flag message dialog
* 4. Verify the flagging reason dropdown options
*/
test('Verify Flagging reason dropdown', async ({pw}) => {
const {user, adminClient, team} = await pw.initSetup();
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
Reasons: FLAG_REASONS,
},
},
});
const channelsPage = await loginAndNavigate(pw, user, team.name, 'town-square');
const message = 'This is a test message to be flagged';
const {post} = await postMessage(channelsPage, message);
// Re-apply guard: concurrent initSetup() may reset EnableContentFlagging: false.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
Reasons: FLAG_REASONS,
},
},
});
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItem.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.toContainPostText(message);
await channelsPage.centerView.flagPostConfirmationDialog.selectFlagReason(FLAG_REASON_CLASSIFICATION_MISMATCH);
});
/**
* @objective: Verify Comments are required for Flagging
* * @testcase
* 1. Login as a user
* 2. Post a message
* 3. Open flag message dialog
* 4. Verify that comments are required for flagging
*/
test('Verify Comments are required for Flagging', async ({pw}) => {
const {user, adminClient, team} = await pw.initSetup();
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
Reasons: FLAG_REASONS,
ReporterCommentRequired: true,
},
},
});
const channelsPage = await loginAndNavigate(pw, user, team.name, 'town-square');
const message = 'This is a test message to be flagged';
const {post} = await postMessage(channelsPage, message);
// Re-apply guard: concurrent initSetup() may reset EnableContentFlagging: false.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
AdditionalSettings: {
Reasons: FLAG_REASONS,
ReporterCommentRequired: true,
},
},
});
await openPostDotMenu(post, channelsPage);
await channelsPage.postDotMenu.flagMessageMenuItem.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.toContainPostText(message);
await channelsPage.centerView.flagPostConfirmationDialog.selectFlagReason(FLAG_REASON_CLASSIFICATION_MISMATCH);
await channelsPage.centerView.flagPostConfirmationDialog.submitButton.click();
await channelsPage.centerView.flagPostConfirmationDialog.toBeVisible();
await channelsPage.centerView.flagPostConfirmationDialog.requireCommentsForFlaggingPost();
});
/**
* @objective: Verify message is removed from channel if the reviewer removed the message
*
* @testcase
* 1. Login as a user
* 2. Post a message
* 3. Flag the message
* 4. Login as a reviewer and remove the message
* 5. Verify the message is removed from the channel
*/
test('Verify message is removed from channel if the reviewer removed the message', async ({pw}) => {
const {user, adminClient, team} = await pw.initSetup();
// Only set the fields this test actually needs. Omitting ReviewerSettings.CommonReviewerIds
// prevents racing with reviewer-* tests that set their own reviewer list — a patchConfig
// that includes CommonReviewerIds replaces the array for ALL concurrent tests on the same
// server, causing reviewer-actions.spec.ts to lose its notification recipients.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
ReviewerSettings: {
SystemAdminsAsReviewers: true,
},
AdditionalSettings: {
HideFlaggedContent: false,
Reasons: FLAG_REASONS,
},
},
});
const channels = await adminClient.getMyChannels(team.id);
const townSquare = channels.find((channel) => channel.name === 'town-square');
if (!townSquare) {
throw new Error('Town Square channel not found');
}
const message = `Post by @${user.username}, is flagged once`;
const postToBeflagged = await adminClient.createPost({
channel_id: townSquare.id,
message,
user_id: user.id,
});
await adminClient.flagPost(postToBeflagged.id, FLAG_REASON_CLASSIFICATION_MISMATCH, FLAG_COMMENT);
// Re-apply guard: concurrent initSetup() may reset EnableContentFlagging: false or
// SystemAdminsAsReviewers: false between the initial patchConfig and the remove call.
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: true,
ReviewerSettings: {
SystemAdminsAsReviewers: true,
},
AdditionalSettings: {
HideFlaggedContent: false,
Reasons: FLAG_REASONS,
},
},
});
await adminClient.removeFlaggedPost(postToBeflagged.id, 'Removing this post after review');
// Login as the user
const channelsPage = await loginAndNavigate(pw, user, team.name, 'town-square');
const lastPostId = await channelsPage.centerView.getLastPostID();
expect(lastPostId).not.toBe(postToBeflagged.id);
});

View File

@@ -0,0 +1,90 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {expect, test} from '@mattermost/playwright-lib';
import {createPost} from './../support';
async function setupContentFlagging(adminClient: any, userIds: string[], enable = true) {
await adminClient.patchConfig({
ContentFlaggingSettings: {
EnableContentFlagging: enable,
ReviewerSettings: {
CommonReviewers: true,
SystemAdminsAsReviewers: true,
TeamAdminsAsReviewers: true,
CommonReviewerIds: userIds,
},
NotificationSettings: {
EventTargetMapping: {
assigned: ['reviewers', 'author'],
dismissed: ['reporter', 'author', 'reviewers'],
flagged: ['reviewers', 'author'],
removed: ['author', 'reporter', 'reviewers'],
},
},
AdditionalSettings: {
HideFlaggedContent: true,
},
},
});
return adminClient;
}
async function verifyAuthorNotification(channelsPage: any, teamName: string, expectedMessage: string) {
await channelsPage.goto(teamName, '@content-review');
await channelsPage.toBeVisible();
const lastPostId = await channelsPage.centerView.getLastPostID();
const post = await channelsPage.centerView.getPostById(lastPostId);
await expect(post.body).toContainText(expectedMessage);
}
/**
* @objective Verify Author is notified if the post is flagged in a channel
*/
test('Verify Author is notified if the post is flagged in a channel', async ({pw}) => {
const {adminClient, team, user, userClient} = await pw.initSetup();
await setupContentFlagging(adminClient, [user.id]);
const message = `Post by @${user.username}, is flagged once`;
const {post, townSquare} = await createPost(adminClient, userClient, team, user, message);
await adminClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
const {channelsPage} = await pw.testBrowser.login(user);
const expected = `Your post having ID ${post.id} in the channel ${townSquare.display_name} has been quarantined for review.`;
await verifyAuthorNotification(channelsPage, team.name, expected);
});
/**
* @objective Verify Author is notified if flagged post is Retained by the reviewer
*/
test('Verify Author is notified if flagged post is Retained in a channel', async ({pw}) => {
const {adminClient, team, user, userClient} = await pw.initSetup();
await setupContentFlagging(adminClient, [user.id]);
const message = `Post by @${user.username}, is flagged once`;
const {post, townSquare} = await createPost(adminClient, userClient, team, user, message);
await adminClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
await adminClient.keepFlaggedPost(post.id, 'Retaining this post after review');
const {channelsPage} = await pw.testBrowser.login(user);
const expected = `Your post having ID ${post.id} in the channel ${townSquare.display_name} which was quarantined for review has been restored by a reviewer.`;
await verifyAuthorNotification(channelsPage, team.name, expected);
});
/**
* @objective Verify Author is notified if flagged post is Removed by the reviewer
*/
test('Verify Author is notified if flagged post is Removed from a channel', async ({pw}) => {
const {adminClient, team, user, userClient} = await pw.initSetup();
await setupContentFlagging(adminClient, [user.id]);
const message = `Post by @${user.username}, is flagged once`;
const {post, townSquare} = await createPost(adminClient, userClient, team, user, message);
await adminClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
await adminClient.removeFlaggedPost(post.id, 'Removing this post after review');
const {channelsPage} = await pw.testBrowser.login(user);
const expected = `Your post having ID ${post.id} in the channel ${townSquare.display_name} which was quarantined for review has been permanently removed by a reviewer.`;
await verifyAuthorNotification(channelsPage, team.name, expected);
});

View File

@@ -0,0 +1,94 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {expect, test} from '@mattermost/playwright-lib';
import {setupContentFlagging, createPost, verifyReporterNotification} from './../support';
/**
* @objective Verify Reporter is notified if the flagged post is Retained by the reviewer
*/
test('Verify Reporter is notified if flagged post is Retained in a channel', async ({pw}) => {
const {adminClient, team, user: reviewerUser, userClient: reviewerUserClient} = await pw.initSetup();
// Create second user and add to team
const reporterUser = await pw.random.user('second');
const {id: reporterUserID} = await adminClient.createUser(reporterUser, '', '');
await adminClient.addToTeam(team.id, reporterUserID);
// Create third user and add to team
const postFromThirdUser = await pw.random.user('third');
const {id: postFromThirdUserID} = await adminClient.createUser(postFromThirdUser, '', '');
await adminClient.addToTeam(team.id, postFromThirdUserID);
const {client: thirdUserClient} = await pw.makeClient(postFromThirdUser);
const {client: reporterUserClient} = await pw.makeClient(reporterUser);
await setupContentFlagging(adminClient, [reviewerUser.id]);
await expect
.poll(
async () => {
const cfg = await adminClient.getAdminContentFlaggingConfig();
return cfg.ReviewerSettings?.CommonReviewerIds?.includes(reviewerUser.id) ?? false;
},
{timeout: 30_000, intervals: [500, 1500, 3000]},
)
.toBe(true);
const message = `Post by @${reviewerUser.username}, is flagged once`;
const {post, townSquare} = await createPost(adminClient, thirdUserClient, team, postFromThirdUser, message);
await reporterUserClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
await reviewerUserClient.keepFlaggedPost(post.id, 'Retaining this post after review');
const {channelsPage} = await pw.testBrowser.login(reporterUser);
await channelsPage.goto(team.name, 'town-square');
await channelsPage.toBeVisible();
const expected = `The post having ID ${post.id} in the channel ${townSquare.display_name} which you quarantined for review has been restored by a reviewer.`;
await verifyReporterNotification(channelsPage, team.name, expected);
});
/**
* @objective Verify Reporter is notified if flagged post is Removed from a channel
*/
test('Verify Reporter is notified if flagged post is Removed from a channel', async ({pw}) => {
const {adminClient, team, user: reviewerUser, userClient: reviewerUserClient} = await pw.initSetup();
// Create second user and add to team
const reporterUser = await pw.random.user('second');
const {id: reporterUserID} = await adminClient.createUser(reporterUser, '', '');
await adminClient.addToTeam(team.id, reporterUserID);
// Create third user and add to team
const postFromThirdUser = await pw.random.user('third');
const {id: postFromThirdUserID} = await adminClient.createUser(postFromThirdUser, '', '');
await adminClient.addToTeam(team.id, postFromThirdUserID);
const {client: thirdUserClient} = await pw.makeClient(postFromThirdUser);
const {client: reporterUserClient} = await pw.makeClient(reporterUser);
await setupContentFlagging(adminClient, [reviewerUser.id]);
await expect
.poll(
async () => {
const cfg = await adminClient.getAdminContentFlaggingConfig();
return cfg.ReviewerSettings?.CommonReviewerIds?.includes(reviewerUser.id) ?? false;
},
{timeout: 30_000, intervals: [500, 1500, 3000]},
)
.toBe(true);
const message = `Post by @${reviewerUser.username}, is flagged once`;
const {post, townSquare} = await createPost(adminClient, thirdUserClient, team, postFromThirdUser, message);
await reporterUserClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
await reviewerUserClient.removeFlaggedPost(post.id, 'Retaining this post after review');
const {channelsPage} = await pw.testBrowser.login(reporterUser);
await channelsPage.goto(team.name, 'town-square');
await channelsPage.toBeVisible();
const expected = `The post having ID ${post.id} in the channel ${townSquare.display_name} which you quarantined for review has been permanently removed by a reviewer.`;
await verifyReporterNotification(channelsPage, team.name, expected);
});

View File

@@ -0,0 +1,100 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {test} from '@mattermost/playwright-lib';
import {setupContentFlagging, createPost, verifyAuthorNotification} from './../support';
/** @objective Verify Removed Flagged posts show appropriate status and do not show the post message
* @testcase
* 1. Create three users and add them as reviewers to a team
* 2. Setup content flagging with the three users as reviewers
* 3. Create a post and flag it
* 4. As Reviewer 1, walk through the multi-step removal flow (form → report generated → remove permanently)
* 5. As Reviewer 2, verify the flagged post status is 'Removed' and the message has been replaced
*/
test('Verify Removed Flagged posts show appropriate status and do not show the post message', async ({pw}) => {
const {adminClient, team, user, userClient, adminUser} = await pw.initSetup();
// Create second user and add to team
const secondUser = await pw.random.user('reviewer');
const {id: secondUserID} = await adminClient.createUser(secondUser, '', '');
await adminClient.addToTeam(team.id, secondUserID);
// Make system_admin so SystemAdminsAsReviewers: true covers them even if
// CommonReviewerIds is reset to [] by a concurrent initSetup() call.
await adminClient.updateUserRoles(secondUserID, 'system_user system_admin');
// Create third user and add to team
const thirdUser = await pw.random.user('reviewer');
const {id: thirdUserID} = await adminClient.createUser(thirdUser, '', '');
await adminClient.addToTeam(team.id, thirdUserID);
await adminClient.updateUserRoles(thirdUserID, 'system_user system_admin');
// Setup content flagging *after* roles are set
await setupContentFlagging(adminClient, [adminUser.id, secondUserID, thirdUserID]);
const message = `Post by @${user.username}, is flagged once`;
const {post} = await createPost(adminClient, userClient, team, user, message);
// Re-apply guard: concurrent initSetup() may reset EnableContentFlagging: false
// between the initial setupContentFlagging call and the flagPost call.
// pw.waitUntil confirms the config is actually true before proceeding — this
// closes the race window to < 100 ms (time between final poll and flagPost).
await setupContentFlagging(adminClient, [adminUser.id, secondUserID, thirdUserID]);
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === true;
});
await adminClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
// Re-apply guard: concurrent initSetup() may have reset config between flagPost and login
await setupContentFlagging(adminClient, [adminUser.id, secondUserID, thirdUserID]);
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === true;
});
const {channelsPage: secondChannelsPage, contentReviewPage: secondContentReviewPage} =
await pw.testBrowser.login(secondUser);
await verifyAuthorNotification(post.id, secondChannelsPage, secondContentReviewPage, team.name, message, 'Pending');
const commentRemove = 'Removing this message as it violates the guidelines.';
const contentModerationMessage = 'Content deleted as part of Content Flagging review process';
await secondContentReviewPage.setReportCardByPostID(post.id);
await secondContentReviewPage.openViewDetails();
await secondContentReviewPage.waitForRHSVisible();
await secondContentReviewPage.openViewDetails();
await setupContentFlagging(adminClient, [adminUser.id, secondUserID, thirdUserID]);
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === true;
});
await secondContentReviewPage.clickRemoveMessage();
await secondContentReviewPage.enterConfirmationComment(commentRemove);
// New multi-step flow: Continue → wait for report to generate → Remove permanently
await secondContentReviewPage.submitFormAndWaitForReport();
await secondContentReviewPage.confirmRemovePermanently();
await setupContentFlagging(adminClient, [adminUser.id, secondUserID, thirdUserID]);
// After the remove action succeeds, the reviewer's own view of the flagged
// post should be replaced with the moderation placeholder rather than the
// original message that is now cleared from the redux store (MM-69043).
// The placeholder appears both in the RHS detail view and in the report
// card shown in the @content-review center channel — assert each scope
// separately so a regression in either location is caught.
await secondContentReviewPage.verifyFlaggedPostMessageInRHS(contentModerationMessage);
await secondContentReviewPage.verifyFlaggedPostMessageInCenter(post.id, contentModerationMessage);
const {channelsPage: channelsPageThird, contentReviewPage: contentReviewPageThird} =
await pw.testBrowser.login(thirdUser);
await verifyAuthorNotification(
post.id,
channelsPageThird,
contentReviewPageThird,
team.name,
contentModerationMessage,
'Removed',
);
});

View File

@@ -0,0 +1,76 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {test} from '@mattermost/playwright-lib';
import {createPost, verifyFlaggedPostCardDetails, verifyRHSFlaggedPostDetails} from './../support';
/**
* @objective Verify a reviewer from other team can receive a review request for a flagged post
* @testcase
* 1. Create two teams and users
* 2. Setup content flagging with reviewers from both teams
* 3. Create a post in team A and flag it
* 4. Verify that a reviewer from team B receives a review request in Content Review channel
* 5. Verify the flagged post details in the reviewer's Content Review DM and RHS
*/
test('Verify reviewer from another team can receive a review request for a flagged post', async ({pw}) => {
const reasonToFlag = 'Classification mismatch';
const flagPostReviewStatus = 'Pending';
const flagPostComment = 'This message is inappropriate';
const {adminClient, team, user, userClient, adminUser} = await pw.initSetup();
const secondTeam = await userClient.createTeam(await pw.random.team('team', 'Team', 'O', true));
const secondUser = await pw.random.user('mentioned');
const {id: secondUserID} = await adminClient.createUser(secondUser, '', '');
await adminClient.addToTeam(team.id, secondUserID);
await adminClient.addToTeam(secondTeam.id, secondUserID);
await adminClient.updateUserRoles(secondUserID, 'system_user system_admin');
// Configure content flagging
await adminClient.saveContentFlaggingConfig({
EnableContentFlagging: true,
NotificationSettings: {
EventTargetMapping: {
assigned: ['reviewers', 'author'],
dismissed: ['reporter', 'author', 'reviewers'],
flagged: ['reviewers', 'author'],
removed: ['author', 'reporter', 'reviewers'],
},
},
ReviewerSettings: {
CommonReviewers: true,
CommonReviewerIds: [user.id, adminUser.id, secondUserID],
TeamReviewersSetting: {},
SystemAdminsAsReviewers: true,
TeamAdminsAsReviewers: true,
},
AdditionalSettings: {
Reasons: ['Classification mismatch', 'Need-to-know violation', 'Unauthorized disclosure', 'Other'],
ReporterCommentRequired: true,
ReviewerCommentRequired: true,
HideFlaggedContent: true,
},
});
// Create and flag post
const message = `Post by @${user.username}, is flagged once`;
const {post, townSquare} = await createPost(adminClient, userClient, team, user, message);
await adminClient.flagPost(post.id, reasonToFlag, flagPostComment);
// Reviewer logs in and verifies flagged post in content review
const {channelsPage, contentReviewPage} = await pw.testBrowser.login(secondUser);
await verifyFlaggedPostCardDetails(post.id, channelsPage, contentReviewPage, secondTeam, message);
await verifyRHSFlaggedPostDetails(
post.id,
contentReviewPage,
user.username,
adminUser.username,
message,
reasonToFlag,
flagPostReviewStatus,
townSquare.display_name,
);
});

View File

@@ -0,0 +1,56 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {test} from '@mattermost/playwright-lib';
import {setupContentFlagging, createPost, verifyAuthorNotification} from './../support';
/** @objective Verify that multiple reviewers receive the same flag notification
* @testcase
* 1. Create three users and add them as reviewers to a team
* 2. Setup content flagging with the three users as reviewers
* 3. Create a post and flag it
* 4. Verify that all three reviewers receive a review request in their Content Review channel
* 5. Verify the flagged post details in each reviewer's Content Review DM and RHS
*
*/
test('Verify multiple reviewers receive same flagged post', async ({pw}) => {
const {adminClient, team, user, userClient, adminUser} = await pw.initSetup();
// Create second user and add to team
const secondUser = await pw.random.user('reviewer');
const {id: secondUserID} = await adminClient.createUser(secondUser, '', '');
await adminClient.addToTeam(team.id, secondUserID);
await adminClient.updateUserRoles(secondUserID, 'system_user system_admin');
// Create third user and add to team
const thirdUser = await pw.random.user('reviewer');
const {id: thirdUserID} = await adminClient.createUser(thirdUser, '', '');
await adminClient.addToTeam(team.id, thirdUserID);
await adminClient.updateUserRoles(thirdUserID, 'system_user system_admin');
// Setup content flagging *after* roles are set
await setupContentFlagging(adminClient, [adminUser.id, secondUserID, thirdUserID]);
const message = `Post by @${user.username}, is flagged once`;
const {post} = await createPost(adminClient, userClient, team, user, message);
// Re-apply guard: concurrent initSetup() may reset EnableContentFlagging: false
// between the initial setupContentFlagging call and the flagPost call.
// pw.waitUntil confirms the config is actually true before proceeding — closes
// the race window to < 100 ms (time between final poll and flagPost).
await setupContentFlagging(adminClient, [adminUser.id, secondUserID, thirdUserID]);
await pw.waitUntil(async () => {
const cfg = await adminClient.getConfig();
return cfg.ContentFlaggingSettings?.EnableContentFlagging === true;
});
await adminClient.flagPost(post.id, 'Classification mismatch', 'This message is inappropriate');
const {channelsPage: secondChannelsPage, contentReviewPage: secondContentReviewPage} =
await pw.testBrowser.login(secondUser);
await verifyAuthorNotification(post.id, secondChannelsPage, secondContentReviewPage, team.name, message, 'Pending');
const {channelsPage: channelsPageThird, contentReviewPage: contentReviewPageThird} =
await pw.testBrowser.login(thirdUser);
await verifyAuthorNotification(post.id, channelsPageThird, contentReviewPageThird, team.name, message, 'Pending');
});

View File

@@ -0,0 +1,129 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {expect} from '@mattermost/playwright-lib';
export async function setupContentFlagging(
adminClient: any,
userIds: string[],
enable = true,
hideFlaggedContent = true,
) {
// Configure content flagging
await adminClient.saveContentFlaggingConfig({
EnableContentFlagging: enable,
NotificationSettings: {
EventTargetMapping: {
assigned: ['reviewers', 'author'],
dismissed: ['reporter', 'author', 'reviewers'],
flagged: ['reviewers', 'author'],
removed: ['author', 'reporter', 'reviewers'],
},
},
ReviewerSettings: {
CommonReviewers: true,
CommonReviewerIds: userIds,
TeamReviewersSetting: {},
SystemAdminsAsReviewers: true,
TeamAdminsAsReviewers: true,
},
AdditionalSettings: {
Reasons: ['Classification mismatch', 'Need-to-know violation', 'Unauthorized disclosure', 'Other'],
ReporterCommentRequired: true,
ReviewerCommentRequired: true,
HideFlaggedContent: hideFlaggedContent,
},
});
return adminClient;
}
export async function createPost(adminClient: any, userClient: any, team: any, user: any, message: string) {
const channels = await adminClient.getMyChannels(team.id);
const townSquare = channels.find((ch: any) => ch.name === 'town-square');
if (!townSquare) {
throw new Error('Town Square channel not found');
}
const post = await userClient.createPost({
channel_id: townSquare.id,
message,
user_id: user.id,
});
return {post, message, townSquare};
}
export async function verifyAuthorNotification(
postID: string,
channelsPage: any,
contentReviewPage: any,
teamName: string,
expectedMessage: string,
postStatus: string,
) {
await channelsPage.goto(teamName, '@content-review');
await channelsPage.toBeVisible();
await contentReviewPage.setReportCardByPostID(postID);
await contentReviewPage.waitForPageLoaded();
await contentReviewPage.verifyFlaggedPostStatus(postStatus);
await contentReviewPage.verifyFlaggedPostReason('Classification mismatch');
await contentReviewPage.verifyFlaggedPostMessage(expectedMessage);
}
/**
* Verify flagged post details inside the RHS view
*/
export async function verifyRHSFlaggedPostDetails(
postID: string,
contentReviewPage: any,
postedByUsername: string,
flaggedByUsername: string,
postMessageFlagged: string,
reasonToFlag: string,
flagPostReviewStatus: string,
postFlaggedInChannel: string,
) {
await contentReviewPage.setReportCardByPostID(postID);
await contentReviewPage.openViewDetails();
await contentReviewPage.waitForRHSVisible();
await contentReviewPage.expectSelectProperty('Status', flagPostReviewStatus);
await contentReviewPage.expectSelectProperty('Reason', reasonToFlag);
await contentReviewPage.expectMessageContains(postMessageFlagged);
await contentReviewPage.expectUser('Quarantined by', flaggedByUsername);
await contentReviewPage.expectUser('Posted by', postedByUsername);
await contentReviewPage.expectChannel(postFlaggedInChannel);
}
/**
* Verify flagged post card details in the Content Review DM
*/
export async function verifyFlaggedPostCardDetails(
postID: string,
channelsPage: any,
contentReviewPage: any,
team: any,
expectedMessage: string,
) {
await channelsPage.goto(team.name, '@content-review');
await channelsPage.toBeVisible();
await contentReviewPage.setReportCardByPostID(postID);
await contentReviewPage.waitForPageLoaded();
await contentReviewPage.verifyFlaggedPostStatus('Pending');
await contentReviewPage.verifyFlaggedPostReason('Classification mismatch');
await contentReviewPage.verifyFlaggedPostMessage(expectedMessage);
}
export async function verifyReporterNotification(channelsPage: any, teamName: string, expectedMessage: string) {
await channelsPage.goto(teamName, '@content-review');
await channelsPage.toBeVisible();
const lastPostId = await channelsPage.centerView.getLastPostID();
const post = await channelsPage.centerView.getPostById(lastPostId);
await expect(post.body).toContainText(expectedMessage);
}