Only fetch bookmarks when the license allows to use them (#8616)

* Only fetch bookmarks when the license allows to use them

* Fix tests

* Clarify condition

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Daniel Espino García 2025-02-28 10:25:32 +01:00 committed by GitHub
parent 5429dac612
commit 1ee03c73e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -1,6 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {SYSTEM_IDENTIFIERS} from '@constants/database';
import DatabaseManager from '@database/manager';
import NetworkManager from '@managers/network_manager';
@ -54,6 +55,7 @@ describe('channel bookmarks', () => {
configsToDelete: [],
prepareRecordsOnly: false,
});
await operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'true'}}], prepareRecordsOnly: false});
bookmarkSpy = jest.spyOn(operator, 'handleChannelBookmark');
});
@ -155,4 +157,13 @@ describe('channel bookmarks', () => {
expect(result).toBeDefined();
expect(result.bookmarks).toBeDefined();
});
it('should not fetch bookmarks if license is not licensed', async () => {
await operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.LICENSE, value: {IsLicensed: 'false'}}], prepareRecordsOnly: false});
const result = await fetchChannelBookmarks(serverUrl, channelId);
expect(result).toBeDefined();
expect(result.bookmarks).toBeDefined();
expect(result.bookmarks?.length).toBe(0);
expect(mockClient.getChannelBookmarksForChannel).not.toHaveBeenCalled();
});
});

View file

@ -5,7 +5,7 @@ import DatabaseManager from '@database/manager';
import NetworkManager from '@managers/network_manager';
import websocketManager from '@managers/websocket_manager';
import {getBookmarksSince, getChannelBookmarkById} from '@queries/servers/channel_bookmark';
import {getConfigValue} from '@queries/servers/system';
import {getConfigValue, getLicense} from '@queries/servers/system';
import {getFullErrorMessage} from '@utils/errors';
import {logError} from '@utils/log';
@ -17,7 +17,9 @@ export async function fetchChannelBookmarks(serverUrl: string, channelId: string
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
const bookmarksEnabled = (await getConfigValue(database, 'FeatureFlagChannelBookmarks')) === 'true';
if (!bookmarksEnabled) {
const isLicensed = (await getLicense(database))?.IsLicensed === 'true';
if (!bookmarksEnabled || !isLicensed) {
return {bookmarks: []};
}