Revert "[NEW] Engagement Statistics (#24777)" (#24989)

This reverts commit f79e7eb5bb.
pull/24991/head
Diego Sampaio 4 years ago committed by GitHub
parent 083775f74e
commit 32bcd1d1de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/api/server/v1/users.js
  2. 2
      app/importer-csv/server/importer.js
  3. 2
      app/importer-hipchat-enterprise/server/importer.js
  4. 5
      app/importer-slack-users/server/importer.js
  5. 2
      app/importer-slack/server/importer.js
  6. 4
      app/importer/server/classes/ImportDataConverter.ts
  7. 5
      app/lib/server/methods/sendInvitationEmail.js
  8. 4
      app/lib/server/startup/email.ts
  9. 47
      app/models/server/models/Messages.js
  10. 9
      app/models/server/models/Rooms.js
  11. 26
      app/models/server/models/Users.js
  12. 19
      app/statistics/server/lib/getServicesStatistics.ts
  13. 104
      app/statistics/server/lib/statistics.ts
  14. 1
      definition/IImportUser.ts
  15. 23
      definition/IStats.ts
  16. 9
      definition/IUser.ts
  17. 5
      server/services/team/service.ts

@ -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 }) });

@ -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,
});
}

@ -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++;

@ -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;

@ -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) {

@ -262,10 +262,6 @@ export class ImportDataConverter {
saveUserIdentity({ _id, name: userData.name, username: userData.username } as Parameters<typeof saveUserIdentity>[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);
}

@ -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',

@ -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}', {

@ -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;

@ -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',

@ -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: {

@ -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<boolean>(`Accounts_OAuth_Custom-${name}-merge_roles`),
users: Users.countActiveUsersByService(name),
createdUsers: Users.countUsersByService(name),
},
];
}),
@ -31,7 +29,6 @@ export function getServicesStatistics(): Record<string, unknown> {
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<string, unknown> {
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<string, unknown> {
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<string, unknown> {
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(),
},

@ -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<IStats> {

@ -13,7 +13,6 @@ export interface IImportUser {
roles?: Array<string>;
type: 'user' | 'bot';
bio?: string;
origin?: string;
services?: Record<string, Record<string, any>>;
customFields?: Record<string, any>;

@ -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;

@ -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<keyof IUser, boolean | 0 | 1>;
}
);
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',
}

@ -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,
};

Loading…
Cancel
Save