mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-13 06:30:29 +00:00
* MM-68219 - Add redacted files placeholder and related functionality * add feature flag control and e2e tests * adjust placeholder design, polish code, fix permalink preview issue * polish code and add missing test * use import path with right path * gate post refetch behind the feature flag, refetch the open thread and avoid observeCount * restore filesInfo for the permalink files prop added upstream * fix stale redaction on background servers, consume the flag on every fetch path and share the viewport emitter * replace the in-memory redaction flag with a persisted per-post epoch so ABAC file decisions survive restarts and stale posts stay hidden * raise the redaction epoch on every resync, capture the epoch counter, only invalidate channels on role changes, and store the newer epoch when a re-verified post is otherwise unchanged * store superseded responses unverified instead of dropping them, keep the since-fetch when re-verifying, verify permalink embeds against the linked channel, and capture the websocket epoch on arrival * nvalidate file decisions when a user attribute field changes or all its values are cleared * batch channel invalidations, close file viewers only when affected, reset the epoch on unstamped redaction changes, and only re-verify the newest page's attachment posts * re-check older channel posts a page at a time instead of one request per post * skip the unstamped epoch lookup for posts with no files, redacted count or permalink * keep the attribute-view retry after later invalidations, retry linked posts unless refused for the current epoch, and stop older payloads from rolling back edits via the redaction check * MM-70905 - disable and grey out the attachment button when an ABAC pe… (#10195) * MM-70905 - disable and grey out the attachment button when an ABAC permission policy denies uploads in the channel * only back off render permission fetches when the server request fails, and log other errors without retrying * remove the disableServer helper and have removeServer do both steps * split defaultAllowed into allowWhenUnenforced and allowWhenNotEvaluated, and treat render permissions as unenforced on servers without the decisions API * MM-69627: Add playbook task requirements support on mobile (#10035) * MM-69627: Add playbook task requirements support on mobile Allow filling required task fields when checking off checklist items during a run, gated by the same Playbooks beta setting used on web. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Address PR review feedback for task requirements Propagate settings write failures, harden fill-requirements save/title handling, and add missing unit coverage. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Fix TypeScript errors in new unit tests Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Use defineMessages for fill requirements titles Keep i18n extraction able to find the header titles after moving them to the route. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Address review feedback for task requirements Update checklist items locally when saving requirement values instead of refetching the run, add missing query/navigation tests, and apply small callback/reduce cleanups from review. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Fix task requirements review follow-ups Propagate local checklist write failures, clear a stale task-requirements flag when playbooks is unsupported, and cap fill values at the desktop/ server max length. Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69627: Move requirement field into its own component Keep one component per file on the fill-requirements screen. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> * MM-69122: Add file element support to interactive dialogs (#9898) * Implement Interactive Dialog - file upload * update demo plugin version for e2etests * fix and add e2etests * review fixes * Fix version bump checkout when a tag shares the branch name (#10229) * Fix Android crashes caused by animated custom emoji (#10030) * Route GIF decoding through Glide - Keep APNG4Android for APNG, animated WebP, and animated AVIF support. - Prepend Glide's GIF decoders to avoid APNG4Android's native GIF overflow. * Clear Expo image resources with Glide targets - Detach drawables when Glide clears their custom target. - Prevent recycled GIF frame resources from remaining attached to Expo image views. * Preserve foreground image during GIF target recycling --------- Co-authored-by: Asaad Mahmood <asaadmahmood@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Scott Bishel <scott.bishel@mattermost.com> Co-authored-by: Nuno Simões <nuno.simoes@mattermost.com> Co-authored-by: MangelSpec <74370284+MangelSpec@users.noreply.github.com> * detox - fix clobbering of feature flags that cause failures in other suites. Also small fix of a incorrectly set test-id --------- Co-authored-by: Asaad Mahmood <asaadmahmood@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Scott Bishel <scott.bishel@mattermost.com> Co-authored-by: Nuno Simões <nuno.simoes@mattermost.com> Co-authored-by: MangelSpec <74370284+MangelSpec@users.noreply.github.com> Co-authored-by: Nate Schlossberg <nate.schlossberg@mattermost.com>
325 lines
12 KiB
TypeScript
325 lines
12 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {RedactionInvalidationReason} from '@actions/local/redaction';
|
|
import {fetchRolesIfNeeded} from '@actions/remote/role';
|
|
import {invalidateRedactionForCurrentUser} from '@actions/websocket/access_control';
|
|
import DatabaseManager from '@database/manager';
|
|
import {getRoleById} from '@queries/servers/role';
|
|
import {getCurrentUserId} from '@queries/servers/system';
|
|
import {getCurrentUser} from '@queries/servers/user';
|
|
import TestHelper from '@test/test_helper';
|
|
|
|
import {handleRoleUpdatedEvent, handleUserRoleUpdatedEvent, handleTeamMemberRoleUpdatedEvent} from './roles';
|
|
|
|
import type ServerDataOperator from '@database/operator/server_data_operator';
|
|
|
|
jest.mock('@actions/remote/role');
|
|
jest.mock('@actions/websocket/access_control');
|
|
jest.mock('@database/manager');
|
|
jest.mock('@queries/servers/role');
|
|
jest.mock('@queries/servers/system');
|
|
jest.mock('@queries/servers/user');
|
|
|
|
describe('WebSocket Roles Actions', () => {
|
|
const serverUrl = 'baseHandler.test.com';
|
|
const currentUserId = 'current-user-id';
|
|
const roleId = 'role-id';
|
|
const teamId = 'team-id';
|
|
|
|
let operator: ServerDataOperator;
|
|
let batchRecords: jest.SpyInstance;
|
|
let handleRole: jest.SpyInstance;
|
|
let handleMyTeam: jest.SpyInstance;
|
|
let handleTeamMemberships: jest.SpyInstance;
|
|
|
|
beforeEach(async () => {
|
|
jest.clearAllMocks();
|
|
|
|
await DatabaseManager.init([serverUrl]);
|
|
operator = DatabaseManager.serverDatabases[serverUrl]!.operator;
|
|
|
|
batchRecords = jest.spyOn(operator, 'batchRecords').mockResolvedValue();
|
|
handleRole = jest.spyOn(operator, 'handleRole').mockResolvedValue([TestHelper.fakeRoleModel({id: 'role1'})]);
|
|
handleMyTeam = jest.spyOn(operator, 'handleMyTeam').mockResolvedValue([]);
|
|
handleTeamMemberships = jest.spyOn(operator, 'handleTeamMemberships').mockResolvedValue([]);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await DatabaseManager.destroyServerDatabase(serverUrl);
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
describe('handleRoleUpdatedEvent', () => {
|
|
it('should handle missing operator', async () => {
|
|
DatabaseManager.serverDatabases = {};
|
|
const msg = {
|
|
data: {
|
|
role: JSON.stringify({id: roleId}),
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle missing role in database', async () => {
|
|
jest.mocked(getRoleById).mockResolvedValue(undefined);
|
|
const msg = {
|
|
data: {
|
|
role: JSON.stringify({id: roleId}),
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should update existing role', async () => {
|
|
const mockRole = {
|
|
id: roleId,
|
|
name: 'test_role',
|
|
permissions: ['permission1'],
|
|
};
|
|
jest.mocked(getRoleById).mockResolvedValue(TestHelper.fakeRoleModel({id: roleId}));
|
|
const msg = {
|
|
data: {
|
|
role: JSON.stringify(mockRole),
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleRoleUpdatedEvent(serverUrl, msg);
|
|
|
|
expect(handleRole).toHaveBeenCalledWith({
|
|
roles: [mockRole],
|
|
prepareRecordsOnly: false,
|
|
});
|
|
});
|
|
|
|
it('should handle invalid JSON in role data', async () => {
|
|
jest.mocked(getRoleById).mockResolvedValue(TestHelper.fakeRoleModel({id: roleId}));
|
|
const msg = {
|
|
data: {
|
|
role: 'invalid json',
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('handleUserRoleUpdatedEvent', () => {
|
|
it('should handle missing operator', async () => {
|
|
DatabaseManager.serverDatabases = {};
|
|
const msg = {
|
|
data: {
|
|
user_id: currentUserId,
|
|
roles: 'role1 role2',
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleUserRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle different user', async () => {
|
|
jest.mocked(getCurrentUserId).mockResolvedValue('different-user');
|
|
const msg = {
|
|
data: {
|
|
user_id: currentUserId,
|
|
roles: 'role1 role2',
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleUserRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should update roles and user', async () => {
|
|
jest.mocked(getCurrentUserId).mockResolvedValue(currentUserId);
|
|
jest.mocked(getCurrentUser).mockResolvedValue(TestHelper.fakeUserModel({
|
|
prepareUpdate: jest.fn(),
|
|
}));
|
|
jest.mocked(fetchRolesIfNeeded).mockResolvedValue({
|
|
roles: [TestHelper.fakeRole({id: 'role1'})],
|
|
});
|
|
|
|
const msg = {
|
|
data: {
|
|
user_id: currentUserId,
|
|
roles: 'role1 role2',
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleUserRoleUpdatedEvent(serverUrl, msg);
|
|
|
|
expect(handleRole).toHaveBeenCalled();
|
|
expect(batchRecords).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should invalidate file decisions only when the role set actually changes', async () => {
|
|
// The ABAC subject carries the resolved system role; the same roles in another order are not a change.
|
|
jest.mocked(getCurrentUserId).mockResolvedValue(currentUserId);
|
|
jest.mocked(getCurrentUser).mockResolvedValue(TestHelper.fakeUserModel({roles: 'role1 role2', prepareUpdate: jest.fn()}));
|
|
jest.mocked(fetchRolesIfNeeded).mockResolvedValue({roles: []});
|
|
|
|
await handleUserRoleUpdatedEvent(serverUrl, {data: {user_id: currentUserId, roles: 'role2 role1'}} as WebSocketMessage);
|
|
expect(invalidateRedactionForCurrentUser).not.toHaveBeenCalled();
|
|
|
|
await handleUserRoleUpdatedEvent(serverUrl, {data: {user_id: currentUserId, roles: 'role1'}} as WebSocketMessage);
|
|
expect(invalidateRedactionForCurrentUser).toHaveBeenCalledWith(serverUrl, RedactionInvalidationReason.UserRoles);
|
|
});
|
|
|
|
it('should handle missing current user', async () => {
|
|
jest.mocked(getCurrentUserId).mockResolvedValue(currentUserId);
|
|
jest.mocked(getCurrentUser).mockResolvedValue(undefined);
|
|
jest.mocked(fetchRolesIfNeeded).mockResolvedValue({
|
|
roles: [TestHelper.fakeRole({id: 'role1'})],
|
|
});
|
|
|
|
const msg = {
|
|
data: {
|
|
user_id: currentUserId,
|
|
roles: 'role1',
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleUserRoleUpdatedEvent(serverUrl, msg);
|
|
|
|
expect(handleRole).toHaveBeenCalled();
|
|
expect(batchRecords).toHaveBeenCalledWith(expect.arrayContaining([]), 'handleUserRoleUpdatedEvent');
|
|
});
|
|
|
|
it('should handle no new roles from fetchRolesIfNeeded', async () => {
|
|
jest.mocked(getCurrentUserId).mockResolvedValue(currentUserId);
|
|
jest.mocked(getCurrentUser).mockResolvedValue(TestHelper.fakeUserModel({
|
|
prepareUpdate: jest.fn(),
|
|
}));
|
|
jest.mocked(fetchRolesIfNeeded).mockResolvedValue({
|
|
roles: [],
|
|
});
|
|
|
|
const msg = {
|
|
data: {
|
|
user_id: currentUserId,
|
|
roles: 'role1',
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleUserRoleUpdatedEvent(serverUrl, msg);
|
|
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
expect(batchRecords).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('handleTeamMemberRoleUpdatedEvent', () => {
|
|
it('should handle missing operator', async () => {
|
|
DatabaseManager.serverDatabases = {};
|
|
const msg = {
|
|
data: {
|
|
member: JSON.stringify({
|
|
user_id: currentUserId,
|
|
team_id: teamId,
|
|
roles: 'role1',
|
|
delete_at: 0,
|
|
}),
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleTeamMemberRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle deleted member', async () => {
|
|
const msg = {
|
|
data: {
|
|
member: JSON.stringify({
|
|
user_id: currentUserId,
|
|
team_id: teamId,
|
|
roles: 'role1',
|
|
delete_at: 1234,
|
|
}),
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleTeamMemberRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle different user', async () => {
|
|
jest.mocked(getCurrentUserId).mockResolvedValue('different-user');
|
|
const msg = {
|
|
data: {
|
|
member: JSON.stringify({
|
|
user_id: currentUserId,
|
|
team_id: teamId,
|
|
roles: 'role1',
|
|
delete_at: 0,
|
|
}),
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleTeamMemberRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should update roles, myTeam and teamMembership', async () => {
|
|
jest.mocked(getCurrentUserId).mockResolvedValue(currentUserId);
|
|
jest.mocked(fetchRolesIfNeeded).mockResolvedValue({
|
|
roles: [TestHelper.fakeRole({id: 'role1'})],
|
|
});
|
|
|
|
const msg = {
|
|
data: {
|
|
member: JSON.stringify({
|
|
user_id: currentUserId,
|
|
team_id: teamId,
|
|
roles: 'role1',
|
|
delete_at: 0,
|
|
}),
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleTeamMemberRoleUpdatedEvent(serverUrl, msg);
|
|
|
|
expect(handleRole).toHaveBeenCalled();
|
|
expect(handleMyTeam).toHaveBeenCalled();
|
|
expect(handleTeamMemberships).toHaveBeenCalled();
|
|
expect(batchRecords).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle invalid JSON in member data', async () => {
|
|
const msg = {
|
|
data: {
|
|
member: 'invalid json',
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleTeamMemberRoleUpdatedEvent(serverUrl, msg);
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
expect(handleMyTeam).not.toHaveBeenCalled();
|
|
expect(handleTeamMemberships).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle no new roles from fetchRolesIfNeeded', async () => {
|
|
jest.mocked(getCurrentUserId).mockResolvedValue(currentUserId);
|
|
jest.mocked(fetchRolesIfNeeded).mockResolvedValue({
|
|
roles: [],
|
|
});
|
|
|
|
const msg = {
|
|
data: {
|
|
member: JSON.stringify({
|
|
user_id: currentUserId,
|
|
team_id: teamId,
|
|
roles: 'role1',
|
|
delete_at: 0,
|
|
}),
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleTeamMemberRoleUpdatedEvent(serverUrl, msg);
|
|
|
|
expect(handleRole).not.toHaveBeenCalled();
|
|
expect(handleMyTeam).toHaveBeenCalled();
|
|
expect(handleTeamMemberships).toHaveBeenCalled();
|
|
expect(batchRecords).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|