Skip to content
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

[IMPROVE] Add flag to identify remote federation users #15004

Merged
merged 4 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/federation/server/federatedResources/FederatedUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class FederatedUser extends FederatedResource {
if (federation.peer === localPeerIdentifier || user.username === 'rocket.cat') {
localUser.username = user.username.split('@')[0];
localUser.name = user.name.split('@')[0];
} else if (federation.peer !== localPeerIdentifier) {
geekgonecrazy marked this conversation as resolved.
Show resolved Hide resolved
localUser.isRemote = true;
}

return localUser;
Expand Down
4 changes: 3 additions & 1 deletion app/federation/server/federation-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Meteor.startup(function() {
// const federationUniqueId = FederationKeys.getUniqueId();
const federationPublicKey = FederationKeys.getPublicKeyString();

const defaultHubURL = process.env.NODE_ENV === 'development' ? 'http://localhost:8080' : 'https://hub.rocket.chat';

settings.addGroup('Federation', function() {
this.add('FEDERATION_Enabled', false, {
type: 'boolean',
Expand Down Expand Up @@ -45,7 +47,7 @@ Meteor.startup(function() {
i18nDescription: 'FEDERATION_Public_Key_Description',
});

this.add('FEDERATION_Hub_URL', 'https://hub.rocket.chat', {
this.add('FEDERATION_Hub_URL', defaultHubURL, {
group: 'Federation Hub',
type: 'string',
i18nLabel: 'FEDERATION_Hub_URL',
Expand Down
23 changes: 17 additions & 6 deletions app/federation/server/methods/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { Meteor } from 'meteor/meteor';
import moment from 'moment';

// We do not import the whole Federation object here because statistics cron
// job use this file, and some of the features are not available on the cron
import { FederationEvents, FederationPeers, Users } from '../../../models';
import { getConfig } from '../config';

import { Federation } from '..';
export function getStatistics() {
const localIdentifier = getConfig().peer.domain;

const numberOfEvents = FederationEvents.find({ t: { $ne: 'png' } }).count();
const numberOfFederatedUsers = Users.find({ isRemote: true }).count();
const numberOfActivePeers = FederationPeers.find({ active: true, peer: { $ne: localIdentifier } }).count();
geekgonecrazy marked this conversation as resolved.
Show resolved Hide resolved
const numberOfInactivePeers = FederationPeers.find({ active: false, peer: { $ne: localIdentifier } }).count();

return { numberOfEvents, numberOfFederatedUsers, numberOfActivePeers, numberOfInactivePeers };
}

export function federationGetOverviewData() {
if (!Meteor.userId()) {
throw new Meteor.Error('not-authorized');
}

const numberOfEvents = FederationEvents.find({ t: { $ne: 'png' } }).count();
const numberOfFederatedUsers = Users.find({ federation: { $exists: true }, 'federation.peer': { $ne: Federation.localIdentifier } }).count();
const numberOfActivePeers = FederationPeers.find({ active: true, peer: { $ne: Federation.localIdentifier } }).count();
const numberOfInactivePeers = FederationPeers.find({ active: false, peer: { $ne: Federation.localIdentifier } }).count();
const { numberOfEvents, numberOfFederatedUsers, numberOfActivePeers, numberOfInactivePeers } = getStatistics();

return {
data: [{
Expand All @@ -33,11 +42,13 @@ export function federationGetOverviewData() {
}

export function federationGetPeerStatuses() {
const localIdentifier = getConfig().peer.domain;

if (!Meteor.userId()) {
throw new Meteor.Error('not-authorized');
}

const peers = FederationPeers.find({ peer: { $ne: Federation.localIdentifier } }).fetch();
const peers = FederationPeers.find({ peer: { $ne: localIdentifier } }).fetch();

const peerStatuses = [];

Expand Down
1 change: 1 addition & 0 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class Users extends Base {
this.tryEnsureIndex({ type: 1 });
this.tryEnsureIndex({ 'visitorEmails.address': 1 });
this.tryEnsureIndex({ federation: 1 }, { sparse: true });
this.tryEnsureIndex({ isRemote: 1 }, { sparse: true });
}

getLoginTokensByUserId(userId) {
Expand Down
8 changes: 8 additions & 0 deletions app/statistics/server/functions/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { settings } from '../../../settings/server';
import { Info, getMongoInfo } from '../../../utils/server';
import { Migrations } from '../../../migrations/server';
import { statistics } from '../statisticsNamespace';
import { getStatistics as federationGetStatistics } from '../../../federation/server/methods/dashboard';

const wizardFields = [
'Organization_Type',
Expand Down Expand Up @@ -100,6 +101,13 @@ statistics.get = function _getStatistics() {
statistics.totalDirectMessages = _.reduce(Rooms.findByType('d', { fields: { msgs: 1 } }).fetch(), function _countDirectMessages(num, room) { return num + room.msgs; }, 0);
statistics.totalLivechatMessages = _.reduce(Rooms.findByType('l', { fields: { msgs: 1 } }).fetch(), function _countLivechatMessages(num, room) { return num + room.msgs; }, 0);

// Federation statistics
const federationOverviewData = federationGetStatistics();

statistics.federatedServers = federationOverviewData.numberOfActivePeers + federationOverviewData.numberOfInactivePeers;
statistics.federatedServersActive = federationOverviewData.numberOfActivePeers;
statistics.federatedUsers = federationOverviewData.numberOfFederatedUsers;

statistics.lastLogin = Users.getLastLogin();
statistics.lastMessageSentAt = Messages.getLastTimestamp();
statistics.lastSeenSubscription = Subscriptions.getLastSeen();
Expand Down
Loading