forked from Ivasoft/mattermost-mobile
removed TOS from Server DB schema (#6117)
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
@@ -32,7 +32,6 @@ export const MM_TABLES = {
|
||||
TEAM_CHANNEL_HISTORY: 'TeamChannelHistory',
|
||||
TEAM_MEMBERSHIP: 'TeamMembership',
|
||||
TEAM_SEARCH_HISTORY: 'TeamSearchHistory',
|
||||
TERMS_OF_SERVICE: 'TermsOfService',
|
||||
THREAD: 'Thread',
|
||||
THREADS_IN_TEAM: 'ThreadsInTeam',
|
||||
THREAD_PARTICIPANT: 'ThreadParticipant',
|
||||
|
||||
@@ -15,7 +15,7 @@ import {CategoryModel, CategoryChannelModel, ChannelModel, ChannelInfoModel, Cha
|
||||
MyChannelModel, MyChannelSettingsModel, MyTeamModel,
|
||||
PostModel, PostsInChannelModel, PostsInThreadModel, PreferenceModel, ReactionModel, RoleModel,
|
||||
SystemModel, TeamModel, TeamChannelHistoryModel, TeamMembershipModel, TeamSearchHistoryModel,
|
||||
TermsOfServiceModel, ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
} from '@database/models/server';
|
||||
import AppDataOperator from '@database/operator/app_data_operator';
|
||||
import ServerDataOperator from '@database/operator/server_data_operator';
|
||||
@@ -51,7 +51,7 @@ class DatabaseManager {
|
||||
MyChannelModel, MyChannelSettingsModel, MyTeamModel,
|
||||
PostModel, PostsInChannelModel, PostsInThreadModel, PreferenceModel, ReactionModel, RoleModel,
|
||||
SystemModel, TeamModel, TeamChannelHistoryModel, TeamMembershipModel, TeamSearchHistoryModel,
|
||||
TermsOfServiceModel, ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
];
|
||||
this.databaseDirectory = '';
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import {CategoryModel, CategoryChannelModel, ChannelModel, ChannelInfoModel, Cha
|
||||
MyChannelModel, MyChannelSettingsModel, MyTeamModel,
|
||||
PostModel, PostsInChannelModel, PostsInThreadModel, PreferenceModel, ReactionModel, RoleModel,
|
||||
SystemModel, TeamModel, TeamChannelHistoryModel, TeamMembershipModel, TeamSearchHistoryModel,
|
||||
TermsOfServiceModel, ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
} from '@database/models/server';
|
||||
import AppDataOperator from '@database/operator/app_data_operator';
|
||||
import ServerDataOperator from '@database/operator/server_data_operator';
|
||||
@@ -46,7 +46,7 @@ class DatabaseManager {
|
||||
MyChannelModel, MyChannelSettingsModel, MyTeamModel,
|
||||
PostModel, PostsInChannelModel, PostsInThreadModel, PreferenceModel, ReactionModel, RoleModel,
|
||||
SystemModel, TeamModel, TeamChannelHistoryModel, TeamMembershipModel, TeamSearchHistoryModel,
|
||||
TermsOfServiceModel, ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
ThreadModel, ThreadParticipantModel, ThreadInTeamModel, UserModel,
|
||||
];
|
||||
|
||||
this.databaseDirectory = Platform.OS === 'ios' ? getIOSAppGroupDetails().appGroupDatabase : `${FileSystem.documentDirectory}databases/`;
|
||||
|
||||
@@ -23,7 +23,6 @@ export {default as TeamChannelHistoryModel} from './team_channel_history';
|
||||
export {default as TeamMembershipModel} from './team_membership';
|
||||
export {default as TeamModel} from './team';
|
||||
export {default as TeamSearchHistoryModel} from './team_search_history';
|
||||
export {default as TermsOfServiceModel} from './terms_of_service';
|
||||
export {default as ThreadModel} from './thread';
|
||||
export {default as ThreadInTeamModel} from './thread_in_team';
|
||||
export {default as ThreadParticipantModel} from './thread_participant';
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Model} from '@nozbe/watermelondb';
|
||||
import {field} from '@nozbe/watermelondb/decorators';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
import type TermsOfServiceModelInterface from '@typings/database/models/servers/terms_of_service';
|
||||
|
||||
const {TERMS_OF_SERVICE} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
* The model for Terms of Service
|
||||
*/
|
||||
export default class TermsOfServiceModel extends Model implements TermsOfServiceModelInterface {
|
||||
/** table (name) : TermsOfService */
|
||||
static table = TERMS_OF_SERVICE;
|
||||
|
||||
/** accepted_at : the date the term has been accepted */
|
||||
@field('accepted_at') acceptedAt!: number;
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import type TeamModel from '@typings/database/models/servers/team';
|
||||
import type TeamChannelHistoryModel from '@typings/database/models/servers/team_channel_history';
|
||||
import type TeamMembershipModel from '@typings/database/models/servers/team_membership';
|
||||
import type TeamSearchHistoryModel from '@typings/database/models/servers/team_search_history';
|
||||
import type TermsOfServiceModel from '@typings/database/models/servers/terms_of_service';
|
||||
import type ThreadModel from '@typings/database/models/servers/thread';
|
||||
import type UserModel from '@typings/database/models/servers/user';
|
||||
|
||||
@@ -48,10 +47,6 @@ export const isRecordSystemEqualToRaw = (record: SystemModel, raw: IdValue) => {
|
||||
return raw.id === record.id;
|
||||
};
|
||||
|
||||
export const isRecordTermsOfServiceEqualToRaw = (record: TermsOfServiceModel, raw: TermsOfService) => {
|
||||
return raw.id === record.id;
|
||||
};
|
||||
|
||||
export const isRecordDraftEqualToRaw = (record: DraftModel, raw: Draft) => {
|
||||
return raw.channel_id === record.channelId && raw.root_id === record.rootId;
|
||||
};
|
||||
|
||||
@@ -7,13 +7,11 @@ import {
|
||||
isRecordCustomEmojiEqualToRaw,
|
||||
isRecordRoleEqualToRaw,
|
||||
isRecordSystemEqualToRaw,
|
||||
isRecordTermsOfServiceEqualToRaw,
|
||||
} from '@database/operator/server_data_operator/comparators';
|
||||
import {
|
||||
transformCustomEmojiRecord,
|
||||
transformRoleRecord,
|
||||
transformSystemRecord,
|
||||
transformTermsOfServiceRecord,
|
||||
} from '@database/operator/server_data_operator/transformers/general';
|
||||
|
||||
import type ServerDataOperator from '..';
|
||||
@@ -107,36 +105,6 @@ describe('*** DataOperator: Base Handlers tests ***', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('=> HandleTermsOfService: should write to the TERMS_OF_SERVICE table', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const spyOnHandleRecords = jest.spyOn(operator, 'handleRecords');
|
||||
|
||||
const termOfService: TermsOfService[] = [
|
||||
{
|
||||
id: 'tos-1',
|
||||
accepted_at: 1,
|
||||
create_at: 1613667352029,
|
||||
user_id: 'user1613667352029',
|
||||
text: '',
|
||||
},
|
||||
];
|
||||
|
||||
await operator.handleTermOfService({
|
||||
termOfService,
|
||||
prepareRecordsOnly: false,
|
||||
});
|
||||
|
||||
expect(spyOnHandleRecords).toHaveBeenCalledWith({
|
||||
findMatchingRecordBy: isRecordTermsOfServiceEqualToRaw,
|
||||
fieldName: 'id',
|
||||
transformer: transformTermsOfServiceRecord,
|
||||
createOrUpdateRawValues: termOfService,
|
||||
tableName: 'TermsOfService',
|
||||
prepareRecordsOnly: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('=> No table name: should not call execute if tableName is invalid', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
|
||||
@@ -8,24 +8,21 @@ import {
|
||||
isRecordCustomEmojiEqualToRaw,
|
||||
isRecordRoleEqualToRaw,
|
||||
isRecordSystemEqualToRaw,
|
||||
isRecordTermsOfServiceEqualToRaw,
|
||||
} from '@database/operator/server_data_operator/comparators';
|
||||
import {
|
||||
transformCustomEmojiRecord,
|
||||
transformRoleRecord,
|
||||
transformSystemRecord,
|
||||
transformTermsOfServiceRecord,
|
||||
} from '@database/operator/server_data_operator/transformers/general';
|
||||
import {getUniqueRawsBy} from '@database/operator/utils/general';
|
||||
|
||||
import type {Model} from '@nozbe/watermelondb';
|
||||
import type {HandleCustomEmojiArgs, HandleRoleArgs, HandleSystemArgs, HandleTOSArgs, OperationArgs} from '@typings/database/database';
|
||||
import type {HandleCustomEmojiArgs, HandleRoleArgs, HandleSystemArgs, OperationArgs} from '@typings/database/database';
|
||||
import type CustomEmojiModel from '@typings/database/models/servers/custom_emoji';
|
||||
import type RoleModel from '@typings/database/models/servers/role';
|
||||
import type SystemModel from '@typings/database/models/servers/system';
|
||||
import type TermsOfServiceModel from '@typings/database/models/servers/terms_of_service';
|
||||
|
||||
const {SERVER: {CUSTOM_EMOJI, ROLE, SYSTEM, TERMS_OF_SERVICE}} = MM_TABLES;
|
||||
const {SERVER: {CUSTOM_EMOJI, ROLE, SYSTEM}} = MM_TABLES;
|
||||
|
||||
export default class ServerDataOperatorBase extends BaseDataOperator {
|
||||
handleRole = ({roles, prepareRecordsOnly = true}: HandleRoleArgs) => {
|
||||
@@ -79,23 +76,6 @@ export default class ServerDataOperatorBase extends BaseDataOperator {
|
||||
}) as Promise<SystemModel[]>;
|
||||
};
|
||||
|
||||
handleTermOfService = ({termOfService, prepareRecordsOnly = true}: HandleTOSArgs) => {
|
||||
if (!termOfService.length) {
|
||||
throw new DataOperatorException(
|
||||
'An empty "values" array has been passed to the handleTermOfService',
|
||||
);
|
||||
}
|
||||
|
||||
return this.handleRecords({
|
||||
fieldName: 'id',
|
||||
findMatchingRecordBy: isRecordTermsOfServiceEqualToRaw,
|
||||
transformer: transformTermsOfServiceRecord,
|
||||
prepareRecordsOnly,
|
||||
createOrUpdateRawValues: getUniqueRawsBy({raws: termOfService, key: 'id'}),
|
||||
tableName: TERMS_OF_SERVICE,
|
||||
}) as Promise<TermsOfServiceModel[]>;
|
||||
};
|
||||
|
||||
/**
|
||||
* execute: Handles the Create/Update operations on an table.
|
||||
* @param {OperationArgs} execute
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
transformCustomEmojiRecord,
|
||||
transformRoleRecord,
|
||||
transformSystemRecord,
|
||||
transformTermsOfServiceRecord,
|
||||
} from '@database/operator/server_data_operator/transformers/general';
|
||||
import {createTestConnection} from '@database/operator/utils/create_test_connection';
|
||||
import {OperationType} from '@typings/database/enums';
|
||||
@@ -56,33 +55,6 @@ describe('*** System Prepare Records Test ***', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('*** TOS Prepare Records Test ***', () => {
|
||||
it('=> transformTermsOfServiceRecord: should return an array of type TermsOfService', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
const database = await createTestConnection({databaseName: 'isolated_prepare_records', setActive: true});
|
||||
expect(database).toBeTruthy();
|
||||
|
||||
const preparedRecords = await transformTermsOfServiceRecord({
|
||||
action: OperationType.CREATE,
|
||||
database: database!,
|
||||
value: {
|
||||
record: undefined,
|
||||
raw: {
|
||||
id: 'tos-1',
|
||||
accepted_at: 1,
|
||||
create_at: 1613667352029,
|
||||
user_id: 'user1613667352029',
|
||||
text: '',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(preparedRecords).toBeTruthy();
|
||||
expect(preparedRecords!.collection.modelClass.name).toBe('TermsOfServiceModel');
|
||||
});
|
||||
});
|
||||
|
||||
describe('*** CustomEmoj Prepare Records Test ***', () => {
|
||||
it('=> transformCustomEmojiRecord: should return an array of type CustomEmoji', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
@@ -9,13 +9,11 @@ import type {TransformerArgs} from '@typings/database/database';
|
||||
import type CustomEmojiModel from '@typings/database/models/servers/custom_emoji';
|
||||
import type RoleModel from '@typings/database/models/servers/role';
|
||||
import type SystemModel from '@typings/database/models/servers/system';
|
||||
import type TermsOfServiceModel from '@typings/database/models/servers/terms_of_service';
|
||||
|
||||
const {
|
||||
CUSTOM_EMOJI,
|
||||
ROLE,
|
||||
SYSTEM,
|
||||
TERMS_OF_SERVICE,
|
||||
} = MM_TABLES.SERVER;
|
||||
|
||||
/**
|
||||
@@ -97,30 +95,3 @@ export const transformSystemRecord = ({action, database, value}: TransformerArgs
|
||||
fieldsMapper,
|
||||
}) as Promise<SystemModel>;
|
||||
};
|
||||
|
||||
/**
|
||||
* transformTermsOfServiceRecord: Prepares a record of the SERVER database 'TermsOfService' table for update or create actions.
|
||||
* @param {TransformerArgs} operator
|
||||
* @param {Database} operator.database
|
||||
* @param {RecordPair} operator.value
|
||||
* @returns {Promise<TermsOfServiceModel>}
|
||||
*/
|
||||
export const transformTermsOfServiceRecord = ({action, database, value}: TransformerArgs): Promise<TermsOfServiceModel> => {
|
||||
const raw = value.raw as TermsOfService;
|
||||
const record = value.record as TermsOfServiceModel;
|
||||
const isCreateAction = action === OperationType.CREATE;
|
||||
|
||||
// If isCreateAction is true, we will use the id (API response) from the RAW, else we shall use the existing record id from the database
|
||||
const fieldsMapper = (tos: TermsOfServiceModel) => {
|
||||
tos._raw.id = isCreateAction ? (raw?.id ?? tos.id) : record.id;
|
||||
tos.acceptedAt = raw?.accepted_at;
|
||||
};
|
||||
|
||||
return prepareBaseRecord({
|
||||
action,
|
||||
database,
|
||||
tableName: TERMS_OF_SERVICE,
|
||||
value,
|
||||
fieldsMapper,
|
||||
}) as Promise<TermsOfServiceModel>;
|
||||
};
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
TeamMembershipSchema,
|
||||
TeamSchema,
|
||||
TeamSearchHistorySchema,
|
||||
TermsOfServiceSchema,
|
||||
ThreadSchema,
|
||||
ThreadInTeamSchema,
|
||||
ThreadParticipantSchema,
|
||||
@@ -58,7 +57,6 @@ export const serverSchema: AppSchema = appSchema({
|
||||
TeamMembershipSchema,
|
||||
TeamSchema,
|
||||
TeamSearchHistorySchema,
|
||||
TermsOfServiceSchema,
|
||||
ThreadSchema,
|
||||
ThreadInTeamSchema,
|
||||
ThreadParticipantSchema,
|
||||
|
||||
@@ -23,7 +23,6 @@ export {default as TeamChannelHistorySchema} from './team_channel_history';
|
||||
export {default as TeamMembershipSchema} from './team_membership';
|
||||
export {default as TeamSchema} from './team';
|
||||
export {default as TeamSearchHistorySchema} from './team_search_history';
|
||||
export {default as TermsOfServiceSchema} from './terms_of_service';
|
||||
export {default as ThreadSchema} from './thread';
|
||||
export {default as ThreadParticipantSchema} from './thread_participant';
|
||||
export {default as ThreadInTeamSchema} from './thread_in_team';
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {tableSchema} from '@nozbe/watermelondb';
|
||||
|
||||
import {MM_TABLES} from '@constants/database';
|
||||
|
||||
const {TERMS_OF_SERVICE} = MM_TABLES.SERVER;
|
||||
|
||||
export default tableSchema({
|
||||
name: TERMS_OF_SERVICE,
|
||||
columns: [
|
||||
{name: 'accepted_at', type: 'number'},
|
||||
],
|
||||
});
|
||||
@@ -30,7 +30,6 @@ const {
|
||||
TEAM_CHANNEL_HISTORY,
|
||||
TEAM_MEMBERSHIP,
|
||||
TEAM_SEARCH_HISTORY,
|
||||
TERMS_OF_SERVICE,
|
||||
THREAD,
|
||||
THREAD_PARTICIPANT,
|
||||
THREADS_IN_TEAM,
|
||||
@@ -427,14 +426,6 @@ describe('*** Test schema for SERVER database ***', () => {
|
||||
{name: 'term', type: 'string'},
|
||||
],
|
||||
},
|
||||
[TERMS_OF_SERVICE]: {
|
||||
name: TERMS_OF_SERVICE,
|
||||
unsafeSql: undefined,
|
||||
columns: {
|
||||
accepted_at: {name: 'accepted_at', type: 'number'},
|
||||
},
|
||||
columnArray: [{name: 'accepted_at', type: 'number'}],
|
||||
},
|
||||
[THREAD]: {
|
||||
name: THREAD,
|
||||
unsafeSql: undefined,
|
||||
|
||||
Reference in New Issue
Block a user