-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix cross-device sync for attach logs preference (MM-67856) #9667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import {map} from 'rxjs/operators'; | |
| import {Preferences} from '@constants'; | ||
| import {withServerUrl} from '@context/server'; | ||
| import {observeIsBoREnabled, observeIsPostPriorityEnabled} from '@queries/servers/post'; | ||
| import {queryPreferencesByCategoryAndName} from '@queries/servers/preference'; | ||
| import {observePreferenceAsBool} from '@queries/servers/preference'; | ||
| import {observeCanUploadFiles} from '@queries/servers/security'; | ||
| import {observeConfigBooleanValue, observeMaxFileCount} from '@queries/servers/system'; | ||
|
|
||
|
|
@@ -26,20 +26,16 @@ const enhanced = withObservables([], ({database, serverUrl}: EnhancedProps) => { | |
| const canUploadFiles = observeCanUploadFiles(database); | ||
| const maxFileCount = observeMaxFileCount(database); | ||
| const allowDownloadLogs = observeConfigBooleanValue(database, 'AllowDownloadLogs', true); | ||
| const attachLogsPref = queryPreferencesByCategoryAndName( | ||
| database, | ||
| Preferences.CATEGORIES.ADVANCED_SETTINGS, | ||
| Preferences.ATTACH_APP_LOGS, | ||
| ).observe(); | ||
| const attachLogsEnabled = observePreferenceAsBool(database, Preferences.CATEGORIES.ADVANCED_SETTINGS, Preferences.ATTACH_APP_LOGS); | ||
|
|
||
|
Comment on lines
26
to
30
|
||
| return { | ||
| canUploadFiles, | ||
| isAgentsEnabled: observeIsAgentsEnabled(serverUrl), | ||
| isPostPriorityEnabled: observeIsPostPriorityEnabled(database), | ||
| isBoREnabled: observeIsBoREnabled(database), | ||
| maxFileCount, | ||
| showAttachLogs: combineLatest([allowDownloadLogs, attachLogsPref]).pipe( | ||
| map(([allowed, prefs]) => allowed && prefs?.[0]?.value === 'true'), | ||
| showAttachLogs: combineLatest([allowDownloadLogs, attachLogsEnabled]).pipe( | ||
| map(([allowed, enabled]) => allowed && enabled), | ||
| ), | ||
| }; | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| // See LICENSE.txt for license information. | ||
|
|
||
| import {Database, Model, Q} from '@nozbe/watermelondb'; | ||
| import {of as of$, type Observable} from 'rxjs'; | ||
| import {map, switchMap} from 'rxjs/operators'; | ||
|
|
||
| import {Preferences} from '@constants'; | ||
| import {MM_TABLES} from '@constants/database'; | ||
|
|
@@ -118,3 +120,12 @@ export const queryEmojiPreferences = (database: Database, name: string) => { | |
| export const queryAdvanceSettingsPreferences = (database: Database, name?: string, value?: string) => { | ||
| return queryPreferencesByCategoryAndName(database, ADVANCED_SETTINGS, name, value); | ||
| }; | ||
|
|
||
| export const observePreferenceAsBool = (database: Database, category: string, name: string, defaultValue = false): Observable<boolean> => { | ||
| return queryPreferencesByCategoryAndName(database, category, name). | ||
| observe(). | ||
| pipe( | ||
| switchMap((prefs) => (prefs.length ? prefs[0].observe() : of$(undefined))), | ||
| map((pref) => (pref ? pref.value === 'true' : defaultValue)), | ||
| ); | ||
|
Comment on lines
+124
to
+130
|
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // See LICENSE.txt for license information. | ||
|
|
||
| import {Database} from '@nozbe/watermelondb'; | ||
| import {act} from '@testing-library/react-native'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait for observable propagation before asserting the updated value. The assertion on Line 207 can race async emission from the DB observable chain and intermittently flake. 💡 Suggested fix-import {act} from '@testing-library/react-native';
+import {act, waitFor} from '@testing-library/react-native';
@@
- // * Should react to the value change
- expect(getByTestId('attachLogsEnabled')).toHaveTextContent('false');
+ // * Should react to the value change
+ await waitFor(() => {
+ expect(getByTestId('attachLogsEnabled')).toHaveTextContent('false');
+ });Also applies to: 206-207 🤖 Prompt for AI Agents |
||
| import React, {type ComponentProps} from 'react'; | ||
| import {View, Text} from 'react-native'; | ||
|
|
||
|
|
@@ -171,4 +172,38 @@ describe('screens/report_a_problem/index', () => { | |
| expect(getByTestId('attachLogsEnabled')).toHaveTextContent('false'); | ||
| expect(getByTestId('currentUserId')).toHaveTextContent('user2'); | ||
| }); | ||
|
|
||
| it('should react to attachLogsEnabled preference value changes', async () => { | ||
| await operator.handlePreferences({ | ||
| preferences: [{ | ||
| user_id: 'user1', | ||
| category: 'advanced_settings', | ||
| name: 'attach_app_logs', | ||
| value: 'true', | ||
| }], | ||
| prepareRecordsOnly: false, | ||
| }); | ||
|
|
||
| const Component = enhanced; | ||
| const {getByTestId} = renderWithEverything(<Component componentId={'ReportProblem'}/>, {database}); | ||
|
|
||
| // * Initially true | ||
| expect(getByTestId('attachLogsEnabled')).toHaveTextContent('true'); | ||
|
|
||
| // # Update the existing preference value from 'true' to 'false' | ||
| await act(async () => { | ||
| await operator.handlePreferences({ | ||
| preferences: [{ | ||
| user_id: 'user1', | ||
| category: 'advanced_settings', | ||
| name: 'attach_app_logs', | ||
| value: 'false', | ||
| }], | ||
| prepareRecordsOnly: false, | ||
| }); | ||
| }); | ||
|
|
||
| // * Should react to the value change | ||
| expect(getByTestId('attachLogsEnabled')).toHaveTextContent('false'); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||||||
| // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||||||||||||||||
| // See LICENSE.txt for license information. | ||||||||||||||||
|
|
||||||||||||||||
| import {SettingsScreen} from '@support/ui/screen'; | ||||||||||||||||
| import {timeouts} from '@support/utils'; | ||||||||||||||||
|
|
||||||||||||||||
| class ReportProblemScreen { | ||||||||||||||||
| testID = { | ||||||||||||||||
| reportProblemScreen: 'report_problem.screen', | ||||||||||||||||
| backButton: 'screen.back.button', | ||||||||||||||||
| enableLogAttachmentsToggleOff: 'report_problem.enable_log_attachments.toggled.false.button', | ||||||||||||||||
| enableLogAttachmentsToggleOn: 'report_problem.enable_log_attachments.toggled.true.button', | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| reportProblemScreen = element(by.id(this.testID.reportProblemScreen)); | ||||||||||||||||
| backButton = element(by.id(this.testID.backButton)); | ||||||||||||||||
| enableLogAttachmentsToggleOff = element(by.id(this.testID.enableLogAttachmentsToggleOff)); | ||||||||||||||||
| enableLogAttachmentsToggleOn = element(by.id(this.testID.enableLogAttachmentsToggleOn)); | ||||||||||||||||
|
|
||||||||||||||||
| toBeVisible = async () => { | ||||||||||||||||
| await waitFor(this.reportProblemScreen).toExist().withTimeout(timeouts.TEN_SEC); | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+20
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a visibility matcher in
💡 Suggested fix toBeVisible = async () => {
- await waitFor(this.reportProblemScreen).toExist().withTimeout(timeouts.TEN_SEC);
+ await waitFor(this.reportProblemScreen).toBeVisible().withTimeout(timeouts.TEN_SEC);
return this.reportProblemScreen;
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| return this.reportProblemScreen; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| open = async () => { | ||||||||||||||||
| await SettingsScreen.reportProblemOption.tap(); | ||||||||||||||||
|
|
||||||||||||||||
| return this.toBeVisible(); | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| back = async () => { | ||||||||||||||||
| await this.backButton.tap(); | ||||||||||||||||
| await waitFor(this.reportProblemScreen).not.toBeVisible().withTimeout(timeouts.TEN_SEC); | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| enableAttachLogs = async () => { | ||||||||||||||||
| await waitFor(this.enableLogAttachmentsToggleOff).toExist().withTimeout(timeouts.FOUR_SEC); | ||||||||||||||||
| await this.enableLogAttachmentsToggleOff.tap(); | ||||||||||||||||
| await waitFor(this.enableLogAttachmentsToggleOn).toExist().withTimeout(timeouts.FOUR_SEC); | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| disableAttachLogs = async () => { | ||||||||||||||||
| await waitFor(this.enableLogAttachmentsToggleOn).toExist().withTimeout(timeouts.FOUR_SEC); | ||||||||||||||||
| await this.enableLogAttachmentsToggleOn.tap(); | ||||||||||||||||
| await waitFor(this.enableLogAttachmentsToggleOff).toExist().withTimeout(timeouts.FOUR_SEC); | ||||||||||||||||
| }; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const reportProblemScreen = new ReportProblemScreen(); | ||||||||||||||||
| export default reportProblemScreen; | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
logDebugstatements log preference values received over WebSocket. Preference values can be large (e.g., theme JSON) and may contain sensitive/user-specific data; logging them can bloat logs and impact performance in production. Consider logging only category/name (and maybe value length), or gating value logging behind a debug/dev flag.