diff --git a/app/api/server/v1/users.js b/app/api/server/v1/users.js index bf5c0c67d29..9dad4a9811f 100644 --- a/app/api/server/v1/users.js +++ b/app/api/server/v1/users.js @@ -49,13 +49,13 @@ API.v1.addRoute( sendWelcomeEmail: Match.Maybe(Boolean), verified: Match.Maybe(Boolean), customFields: Match.Maybe(Object), - origin: Match.Maybe(String), }); // New change made by pull request #5152 if (typeof this.bodyParams.joinDefaultChannels === 'undefined') { this.bodyParams.joinDefaultChannels = true; } + if (this.bodyParams.customFields) { validateCustomFields(this.bodyParams.customFields); } @@ -72,10 +72,6 @@ API.v1.addRoute( }); } - if (this.bodyParams.origin) { - Users.update({ _id: newUserId }, { $set: { origin: this.bodyParams.origin } }); - } - const { fields } = this.parseJsonQuery(); return API.v1.success({ user: Users.findOneById(newUserId, { fields }) }); diff --git a/app/importer-csv/server/importer.js b/app/importer-csv/server/importer.js index 687a9e48d97..ce92a08c235 100644 --- a/app/importer-csv/server/importer.js +++ b/app/importer-csv/server/importer.js @@ -2,7 +2,6 @@ import { Random } from 'meteor/random'; import { Base, ProgressStep, ImporterWebsocket } from '../../importer/server'; import { Users } from '../../models/server'; -import { USER_ORIGIN } from '../../../definition/IUser'; export class CsvImporter extends Base { constructor(info, importRecord) { @@ -117,7 +116,6 @@ export class CsvImporter extends Base { emails: [email], username, name, - origin: USER_ORIGIN.CSV_IMPORT, }); } diff --git a/app/importer-hipchat-enterprise/server/importer.js b/app/importer-hipchat-enterprise/server/importer.js index fdad1dff9b0..c2c05c34032 100644 --- a/app/importer-hipchat-enterprise/server/importer.js +++ b/app/importer-hipchat-enterprise/server/importer.js @@ -5,7 +5,6 @@ import fs from 'fs'; import { Meteor } from 'meteor/meteor'; import { Base, ProgressStep } from '../../importer/server'; -import { USER_ORIGIN } from '../../../definition/IUser'; export class HipChatEnterpriseImporter extends Base { constructor(info, importRecord) { @@ -43,7 +42,6 @@ export class HipChatEnterpriseImporter extends Base { bio: u.User.title || undefined, deleted: u.User.is_deleted, type: 'user', - origin: USER_ORIGIN.HIPTEXT_IMPORT, }; count++; diff --git a/app/importer-slack-users/server/importer.js b/app/importer-slack-users/server/importer.js index aa21b1b941c..08c2992c766 100644 --- a/app/importer-slack-users/server/importer.js +++ b/app/importer-slack-users/server/importer.js @@ -5,7 +5,6 @@ import { Random } from 'meteor/random'; import { RawImports, Base, ProgressStep, Selection, SelectionUser } from '../../importer/server'; import { RocketChatFile } from '../../file'; import { Users } from '../../models'; -import { USER_ORIGIN } from '../../../definition/IUser'; export class SlackUsersImporter extends Base { constructor(info, importRecord) { @@ -132,7 +131,7 @@ export class SlackUsersImporter extends Base { // since we have an existing user, let's try a few things userId = existantUser._id; u.rocketId = existantUser._id; - Users.update({ _id: u.rocketId }, { $addToSet: { importIds: u.user_id }, $set: { origin: USER_ORIGIN.SLACK_USER_IMPORT } }); + Users.update({ _id: u.rocketId }, { $addToSet: { importIds: u.user_id } }); Users.setEmail(existantUser._id, u.email); Users.setEmailVerified(existantUser._id, u.email); @@ -150,7 +149,7 @@ export class SlackUsersImporter extends Base { Meteor.runAsUser(userId, () => { Meteor.call('setUsername', u.username, { joinDefaultChannelsSilenced: true }); Users.setName(userId, u.name); - Users.update({ _id: userId }, { $addToSet: { importIds: u.user_id }, $set: { origin: USER_ORIGIN.SLACK_USER_IMPORT } }); + Users.update({ _id: userId }, { $addToSet: { importIds: u.user_id } }); Users.setEmail(userId, u.email); Users.setEmailVerified(userId, u.email); u.rocketId = userId; diff --git a/app/importer-slack/server/importer.js b/app/importer-slack/server/importer.js index 42e087abee7..e2270576fcc 100644 --- a/app/importer-slack/server/importer.js +++ b/app/importer-slack/server/importer.js @@ -5,7 +5,6 @@ import { Messages, ImportData } from '../../models/server'; import { settings } from '../../settings/server'; import { MentionsParser } from '../../mentions/lib/MentionsParser'; import { getUserAvatarURL } from '../../utils/lib/getUserAvatarURL'; -import { USER_ORIGIN } from '../../../definition/IUser'; export class SlackImporter extends Base { parseData(data) { @@ -144,7 +143,6 @@ export class SlackImporter extends Base { statusText: user.profile.status_text || undefined, bio: user.profile.title || undefined, type: 'user', - origin: USER_ORIGIN.SLACK_IMPORT, }; if (user.profile.email) { diff --git a/app/importer/server/classes/ImportDataConverter.ts b/app/importer/server/classes/ImportDataConverter.ts index a08c16dfbc7..5cfee061b8c 100644 --- a/app/importer/server/classes/ImportDataConverter.ts +++ b/app/importer/server/classes/ImportDataConverter.ts @@ -262,10 +262,6 @@ export class ImportDataConverter { saveUserIdentity({ _id, name: userData.name, username: userData.username } as Parameters[0]); } - if (userData.origin) { - Users.update({ _id }, { $set: { origin: userData.origin } }); - } - if (userData.importIds.length) { this.addUserToCache(userData.importIds[0], existingUser._id, existingUser.username || userData.username); } diff --git a/app/lib/server/methods/sendInvitationEmail.js b/app/lib/server/methods/sendInvitationEmail.js index b3622c769d7..f5927e8c5a0 100644 --- a/app/lib/server/methods/sendInvitationEmail.js +++ b/app/lib/server/methods/sendInvitationEmail.js @@ -4,7 +4,6 @@ import { check } from 'meteor/check'; import * as Mailer from '../../../mailer'; import { hasPermission } from '../../../authorization'; import { settings } from '../../../settings'; -import { Settings } from '../../../models/server'; let html = ''; Meteor.startup(() => { @@ -38,7 +37,7 @@ Meteor.methods({ return validEmails.filter((email) => { try { - const result = Mailer.send({ + return Mailer.send({ to: email, from: settings.get('From_Email'), subject, @@ -47,8 +46,6 @@ Meteor.methods({ email, }, }); - Settings.updateValueById('Invitation_Email_Count', settings.get('Invitation_Email_Count') + 1); - return result; } catch ({ message }) { throw new Meteor.Error('error-email-send-failed', `Error trying to send email: ${message}`, { method: 'sendInvitationEmail', diff --git a/app/lib/server/startup/email.ts b/app/lib/server/startup/email.ts index e9e9bb4658a..b5e1d2f938c 100644 --- a/app/lib/server/startup/email.ts +++ b/app/lib/server/startup/email.ts @@ -473,10 +473,6 @@ settingsRegistry.addGroup('Email', function () { }, ); }); - this.add('Invitation_Email_Count', 0, { - type: 'int', - hidden: true, - }); this.section('Forgot_password_section', function () { this.add('Forgot_Password_Email_Subject', '{Forgot_Password_Email_Subject}', { diff --git a/app/models/server/models/Messages.js b/app/models/server/models/Messages.js index d7157c15018..dae73072ba1 100644 --- a/app/models/server/models/Messages.js +++ b/app/models/server/models/Messages.js @@ -461,15 +461,6 @@ export class Messages extends Base { return this.find(query, options); } - findE2EByRoom(roomId, options) { - const query = { - _hidden: { $ne: true }, - rid: roomId, - t: 'e2e', - }; - return this.find(query, options); - } - findStarredByUserAtRoom(userId, roomId, options) { const query = { '_hidden': { $ne: true }, @@ -480,16 +471,6 @@ export class Messages extends Base { return this.find(query, options); } - findStarredByRoom(roomId, options) { - const query = { - _hidden: { $ne: true }, - starred: { $ne: null }, - rid: roomId, - }; - - return this.find(query, options); - } - findPinnedByRoom(roomId, options) { const query = { t: { $ne: 'rm' }, @@ -511,34 +492,6 @@ export class Messages extends Base { return this.find(query, options); } - findStarred(options) { - const query = { - _hidden: { $ne: true }, - starred: { $ne: null }, - }; - - return this.find(query, options); - } - - findPinned(options) { - const query = { - t: { $ne: 'rm' }, - _hidden: { $ne: true }, - pinned: true, - }; - - return this.find(query, options); - } - - findSnippet(options) { - const query = { - _hidden: { $ne: true }, - snippeted: true, - }; - - return this.find(query, options); - } - getLastTimestamp(options = { fields: { _id: 0, ts: 1 } }) { options.sort = { ts: -1 }; options.limit = 1; diff --git a/app/models/server/models/Rooms.js b/app/models/server/models/Rooms.js index 11ae0e66e95..de1145d2fed 100644 --- a/app/models/server/models/Rooms.js +++ b/app/models/server/models/Rooms.js @@ -1344,15 +1344,6 @@ export class Rooms extends Base { return this.update(query, update); } - findByE2E(options) { - return this.find( - { - encrypted: true, - }, - options, - ); - } - updateGroupDMsRemovingUsernamesByUsername(username, userId) { const query = { t: 'd', diff --git a/app/models/server/models/Users.js b/app/models/server/models/Users.js index 418ab12e652..2dc47a80ec3 100644 --- a/app/models/server/models/Users.js +++ b/app/models/server/models/Users.js @@ -1701,16 +1701,6 @@ Find users to send a message by email if: return this.find(query, options).count(); } - countUsersByService(serviceName, options) { - const query = { - type: { $nin: ['app'] }, - roles: { $ne: ['guest'] }, - [`services.${serviceName}`]: { $exists: true }, - }; - - return this.find(query, options).count(); - } - getActiveLocalUserCount() { return this.findActive().count() - this.findActiveRemote().count(); } @@ -1747,22 +1737,6 @@ Find users to send a message by email if: return this.find(query, options); } - findActiveUsersTOTPEnable(options) { - const query = { - 'active': true, - 'services.totp.enabled': true, - }; - return this.find(query, options); - } - - findActiveUsersEmail2faEnable(options) { - const query = { - 'active': true, - 'services.email2fa.enabled': true, - }; - return this.find(query, options); - } - updateCustomFieldsById(userId, customFields) { return this.update(userId, { $set: { diff --git a/app/statistics/server/lib/getServicesStatistics.ts b/app/statistics/server/lib/getServicesStatistics.ts index 841a4629592..b41cbb2d838 100644 --- a/app/statistics/server/lib/getServicesStatistics.ts +++ b/app/statistics/server/lib/getServicesStatistics.ts @@ -7,7 +7,6 @@ function getCustomOAuthServices(): Record< enabled: boolean; mergeRoles: boolean; users: number; - createdUsers: number; } > { const customOauth = settings.getByRegexp(/Accounts_OAuth_Custom-[^-]+$/im); @@ -20,7 +19,6 @@ function getCustomOAuthServices(): Record< enabled: Boolean(value), mergeRoles: settings.get(`Accounts_OAuth_Custom-${name}-merge_roles`), users: Users.countActiveUsersByService(name), - createdUsers: Users.countUsersByService(name), }, ]; }), @@ -31,7 +29,6 @@ export function getServicesStatistics(): Record { return { ldap: { users: Users.countActiveUsersByService('ldap'), - createdUsers: Users.countUsersByService('ldap'), enabled: settings.get('LDAP_Enable'), loginFallback: settings.get('LDAP_Login_Fallback'), encryption: settings.get('LDAP_Encryption'), @@ -57,7 +54,6 @@ export function getServicesStatistics(): Record { saml: { enabled: settings.get('SAML_Custom_Default'), users: Users.countActiveUsersByService('saml'), - createdUsers: Users.countUsersByService('saml'), signatureValidationType: settings.get('SAML_Custom_Default_signature_validation_type'), generateUsername: settings.get('SAML_Custom_Default_generate_username'), updateSubscriptionsOnLogin: settings.get('SAML_Custom_Default_channels_update'), @@ -66,7 +62,6 @@ export function getServicesStatistics(): Record { cas: { enabled: settings.get('CAS_enabled'), users: Users.countActiveUsersByService('cas'), - createdUsers: Users.countUsersByService('cas'), allowUserCreation: settings.get('CAS_Creation_User_Enabled'), alwaysSyncUserData: settings.get('CAS_Sync_User_Data_Enabled'), }, @@ -74,72 +69,58 @@ export function getServicesStatistics(): Record { apple: { enabled: settings.get('Accounts_OAuth_Apple'), users: Users.countActiveUsersByService('apple'), - createdUsers: Users.countUsersByService('apple'), }, dolphin: { enabled: settings.get('Accounts_OAuth_Dolphin'), users: Users.countActiveUsersByService('dolphin'), - createdUsers: Users.countUsersByService('dolphin'), }, drupal: { enabled: settings.get('Accounts_OAuth_Drupal'), users: Users.countActiveUsersByService('drupal'), - createdUsers: Users.countUsersByService('drupal'), }, facebook: { enabled: settings.get('Accounts_OAuth_Facebook'), users: Users.countActiveUsersByService('facebook'), - createdUsers: Users.countUsersByService('facebook'), }, github: { enabled: settings.get('Accounts_OAuth_Github'), users: Users.countActiveUsersByService('github'), - createdUsers: Users.countUsersByService('github'), }, githubEnterprise: { enabled: settings.get('Accounts_OAuth_GitHub_Enterprise'), users: Users.countActiveUsersByService('github_enterprise'), - createdUsers: Users.countUsersByService('github_enterprise'), }, gitlab: { enabled: settings.get('Accounts_OAuth_Gitlab'), users: Users.countActiveUsersByService('gitlab'), - createdUsers: Users.countUsersByService('gitlab'), }, google: { enabled: settings.get('Accounts_OAuth_Google'), users: Users.countActiveUsersByService('google'), - createdUsers: Users.countUsersByService('google'), }, linkedin: { enabled: settings.get('Accounts_OAuth_Linkedin'), users: Users.countActiveUsersByService('linkedin'), - createdUsers: Users.countUsersByService('linkedin'), }, meteor: { enabled: settings.get('Accounts_OAuth_Meteor'), users: Users.countActiveUsersByService('meteor'), - createdUsers: Users.countUsersByService('meteor'), }, nextcloud: { enabled: settings.get('Accounts_OAuth_Nextcloud'), users: Users.countActiveUsersByService('nextcloud'), - createdUsers: Users.countUsersByService('nextcloud'), }, tokenpass: { enabled: settings.get('Accounts_OAuth_Tokenpass'), users: Users.countActiveUsersByService('tokenpass'), - createdUsers: Users.countUsersByService('tokenpass'), }, twitter: { enabled: settings.get('Accounts_OAuth_Twitter'), users: Users.countActiveUsersByService('twitter'), - createdUsers: Users.countUsersByService('twitter'), }, wordpress: { enabled: settings.get('Accounts_OAuth_Wordpress'), users: Users.countActiveUsersByService('wordpress'), - createdUsers: Users.countUsersByService('wordpress'), }, custom: getCustomOAuthServices(), }, diff --git a/app/statistics/server/lib/statistics.ts b/app/statistics/server/lib/statistics.ts index e2b94ae9413..8f3420ead8a 100644 --- a/app/statistics/server/lib/statistics.ts +++ b/app/statistics/server/lib/statistics.ts @@ -23,7 +23,6 @@ import { LivechatBusinessHours, Messages as MessagesRaw, InstanceStatus, - Invites, } from '../../../models/server/raw'; import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred'; import { getAppsStatistics } from './getAppsStatistics'; @@ -33,7 +32,6 @@ import { Analytics } from '../../../../server/sdk'; import { getSettingsStatistics } from '../../../../server/lib/statistics/getSettingsStatistics'; import { IRoom } from '../../../../definition/IRoom'; import { IStats } from '../../../../definition/IStats'; -import { USER_ORIGIN } from '../../../../definition/IUser'; const wizardFields = ['Organization_Type', 'Industry', 'Size', 'Country', 'Language', 'Server_Type', 'Register_Server']; @@ -463,108 +461,6 @@ export const statistics = { await Promise.all(statsPms).catch(log); - statistics.showHomeButton = settings.get('Layout_Show_Home_Button'); - statistics.homeTitle = settings.get('Layout_Home_Title'); - - const layoutHomeBody = settings.get('Layout_Home_Body') as string; - if (layoutHomeBody) { - statistics.homeBody = layoutHomeBody.split('\n')[0]; - } - - const homeBody = settings.get('Layout_Home_Body') as string; - if (homeBody) { - statistics.homeBody = homeBody.split('\n')[0]; - } - - const logoChange = Object.keys(settings.get('Assets_logo')); - if (logoChange) { - statistics.logoChange = logoChange.includes('url'); - } - - statistics.logoChange = Object.keys(settings.get('Assets_logo')).includes('url'); - - const customCSS = settings.get('theme-custom-css') as string; - if (customCSS) { - statistics.customCSS = customCSS.split('\n').length; - } - statistics.customScript = _.reduce( - ['Custom_Script_On_Logout', 'Custom_Script_Logged_Out', 'Custom_Script_Logged_In'], - function _custonScript(num, setting) { - const script = settings.get(setting) as string; - if (script !== '//Add your script') { - return num + script.split('\n').length; - } - return num; - }, - 0, - ); - - statistics.tabInvites = await Invites.find().count(); - statistics.totalEmailInvitation = settings.get('Invitation_Email_Count'); - - statistics.totalRoomsWithSnippet = _.reduce( - Rooms.find({}).fetch(), - function _roomsWithSnippet(num, room: any) { - const { _id } = room; - const snippetMessages = Messages.findSnippetedByRoom(_id).count(); - if (snippetMessages > 0) { - return num + 1; - } - return num; - }, - 0, - ); - - statistics.totalRoomsWithStarred = _.reduce( - Rooms.find({}).fetch(), - function _roomsWithPinned(num, room: any) { - const { _id } = room; - const starredMessages = Messages.findStarredByRoom(_id).count(); - if (starredMessages > 0) { - return num + 1; - } - return num; - }, - 0, - ); - - statistics.totalRoomsWithPinned = _.reduce( - Rooms.find({}).fetch(), - function _roomsWithPinned(num, room: any) { - const { _id } = room; - const pinnedMessages = Messages.findPinnedByRoom(_id).count(); - if (pinnedMessages > 0) { - return num + 1; - } - return num; - }, - 0, - ); - - statistics.totalSnippet = Messages.findSnippet().count(); - statistics.totalStarred = Messages.findStarred().count(); - statistics.totalPinned = Messages.findPinned().count(); - - statistics.totalE2ERooms = Rooms.findByE2E().count(); - statistics.totalE2EMessages = _.reduce( - Rooms.findByE2E().fetch(), - function _e2eMessages(num, room: any) { - const { _id } = room; - const e2eMessages = Messages.findE2EByRoom(_id).count(); - return num + e2eMessages; - }, - 0, - ); - - statistics.totalUserTOTP = Users.findActiveUsersTOTPEnable().count(); - statistics.totalUserEmail2fa = Users.findActiveUsersEmail2faEnable().count(); - - statistics.usersCreatedADM = await Users.find({ origin: USER_ORIGIN.ADMIN_ADD }).count(); - statistics.usersCreatedSlackImport = await Users.find({ origin: USER_ORIGIN.SLACK_IMPORT }).count(); - statistics.usersCreatedSlackUser = await Users.find({ origin: USER_ORIGIN.SLACK_USER_IMPORT }).count(); - statistics.usersCreatedCSVImport = await Users.find({ origin: USER_ORIGIN.CSV_IMPORT }).count(); - statistics.usersCreatedHiptext = await Users.find({ origin: USER_ORIGIN.HIPTEXT_IMPORT }).count(); - return statistics; }, async save(): Promise { diff --git a/definition/IImportUser.ts b/definition/IImportUser.ts index 7b779ea7e21..e1f8543805c 100644 --- a/definition/IImportUser.ts +++ b/definition/IImportUser.ts @@ -13,7 +13,6 @@ export interface IImportUser { roles?: Array; type: 'user' | 'bot'; bio?: string; - origin?: string; services?: Record>; customFields?: Record; diff --git a/definition/IStats.ts b/definition/IStats.ts index 2cf12ba37c9..a9d49a11a44 100644 --- a/definition/IStats.ts +++ b/definition/IStats.ts @@ -138,29 +138,6 @@ export interface IStats { businessUnits: number; }; createdAt: Date | string; - showHomeButton: boolean; - homeTitle: string; - homeBody: string; - logoChange: boolean; - customCSS: number; - customScript: number; - tabInvites: number; - totalEmailInvitation: number; - totalRoomsWithSnippet: number; - totalRoomsWithStarred: number; - totalRoomsWithPinned: number; - totalSnippet: number; - totalStarred: number; - totalPinned: number; - totalE2ERooms: number; - totalE2EMessages: number; - totalUserTOTP: number; - totalUserEmail2fa: number; - usersCreatedADM: number; - usersCreatedSlackImport: number; - usersCreatedSlackUser: number; - usersCreatedCSVImport: number; - usersCreatedHiptext: number; totalOTR: number; totalOTRRooms: number; slashCommandsJitsi: number; diff --git a/definition/IUser.ts b/definition/IUser.ts index 1cdc9be214b..6b65fd4aaa8 100644 --- a/definition/IUser.ts +++ b/definition/IUser.ts @@ -146,7 +146,6 @@ export interface IUser extends IRocketChatRecord { defaultRoom?: string; ldap?: boolean; extension?: string; - origin?: string; inviteToken?: string; } @@ -171,11 +170,3 @@ export type IUserDataEvent = { unset: Record; } ); - -export enum USER_ORIGIN { - ADMIN_ADD = 'admin_add', - SLACK_IMPORT = 'slack_import', - SLACK_USER_IMPORT = 'slack_user_import', - CSV_IMPORT = 'csv_import', - HIPTEXT_IMPORT = 'hiptext_import', -} diff --git a/server/services/team/service.ts b/server/services/team/service.ts index 8736591ba8d..37dc3475d83 100644 --- a/server/services/team/service.ts +++ b/server/services/team/service.ts @@ -974,8 +974,9 @@ export class TeamService extends ServiceClassInternal implements ITeamService { teamMain: { $exists: false }, }).toArray(); const roomIds = teamRooms.map((r) => r._id); - const [totalMessagesInTeam, totalMembers] = await Promise.all([ + const [totalMessagesInTeam, defaultRooms, totalMembers] = await Promise.all([ this.MessagesModel.find({ rid: { $in: roomIds } }).count(), + this.RoomsModel.findDefaultRoomsForTeam(team._id).count(), this.TeamMembersModel.findByTeamId(team._id).count(), ]); @@ -986,7 +987,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService { totalMessages: totalMessagesInTeam, totalPublicRooms: teamRooms.filter((r) => r.t === 'c').length, totalPrivateRooms: teamRooms.filter((r) => r.t !== 'c').length, - totalDefaultRooms: teamRooms.filter((r) => r.default === true).length, + totalDefaultRooms: defaultRooms, totalMembers, };