Skip to content

Commit

Permalink
Service Accounts Notifications and broadcast added (#64)
Browse files Browse the repository at this point in the history
* [NEW] Service Account Admin Settings and Configuration files added

* [NEW] Service Account Admin Settings and Configuration files added

* [NEW] Service Account Admin Settings and Configuration files added

* [NEW] Service Account Admin Settings and Configuration files added

* Service Account Creation dialog added

* [NEW] Service Account Creation method

* Service Account owner username update method added

* Fixed CLI errors

* Fixed CLI errors

* Service Account creation heading fixed

* Service Account broadcast room callback added

* Service Account creation method refactored

* Service Account Callback completed

* Typos fixed

* CLI errors fixed

* [NEW] Service Account one-tap login complete

* Callbacks modified

* Service Accounts directory tab added

* Refactored creation method and added tests

* CLI errors fixed

* CLI errors fixed

* Bugs fixed

* [NEW] Service Accounts Login method

* Typo fixed

* CLI errors fixed

* CLI errors fixed

* [New] Service Account directory feature

* CLI errors fixed

* UsernameExists meteor method fixed

* Sync commit

* [NEW] Service Account subscription method added

* [NEW] Service Account Broadcast Feature Added

* [NEW] Service Account Broadcast Feature Added

* [NEW] Service account subscription sidenav type

* Broadcast Room name change handled

* Lint errors fixed

* getLoginToken method refactored

* Console statements removed

* Sidebar header permission modified

* Merge branch service-accounts

* Added service account directory search translation key

* Subscribers count added

* [NEW] Service Account sidenav type

* Unread counter added in popver

* Get linked service account method added

* Partial rate limiter added

* Added unread counter

* Fixed CLI errors

* Broadcast feature added

* [FIX] Custom status displayed on room leader panel (RocketChat#14958)

* [FIX] LDAP login with customField sync (RocketChat#14808)

Closes RocketChat#14661

* [FIX] Prevent error on trying insert message with duplicated id (RocketChat#14945)

* [FIX] OTR key icon missing on messages (RocketChat#14953)

* [FIX] Method `getUsersOfRoom` not returning offline users if limit is not defined (RocketChat#14753)

* [IMPROVE] Remove too specific helpers isFirefox() and isChrome() (RocketChat#14963)

* [FIX] Jump to message missing in Starred Messages (RocketChat#14949)

* [IMPROVE] Update tabs markup (RocketChat#14964)

* [FIX] Loading indicator positioning (RocketChat#14968)

* Remove broken markup

* Recover lost class

* [FIX] load more messages (RocketChat#14967)

* [FIX] eternal loading file list (RocketChat#14952)

* [FIX] 50 custom emoji limit (RocketChat#14951)

* Bump jquery from 3.3.1 to 3.4.0 in /packages/rocketchat-livech… (RocketChat#14922)

Bumps [jquery](https://github.com/jquery/jquery) from 3.3.1 to 3.4.0.
- [Release notes](https://github.com/jquery/jquery/releases)
- [Commits](jquery/jquery@3.3.1...3.4.0)

Signed-off-by: dependabot[bot] <support@github.com>

* [FIX] Allow storing the navigation history of unregistered Livechat visitors (RocketChat#14970)

* Remove validations before storing visitor navigation history.

* Removed unused imports.

* Update GPG key

* [FIX] Wrong label order on room settings (RocketChat#14960)

* [FIX] Chrome doesn't load additional search results when botto… (RocketChat#14965)

* fix scroll

* fix review

* ops

* [IMPROVEMENT] patch to improve emoji render (RocketChat#14722)

* path to improve emoji render

* Apply suggestions from code review

Co-Authored-By: Tasso Evangelista <tasso.evangelista@rocket.chat>

* Regression: patch to improve emoji render (RocketChat#14980)

This reverts commit b395b50.

* [FIX] Users staying online after logout (RocketChat#14966)

* Remove unused dependency (lokijs) (RocketChat#14973)

* Bump juice version to 5.2.0 (RocketChat#14974)

* Bump node-rsa version to 1.0.5 (RocketChat#14976)

* Bump photoswipe version to 4.1.3 (RocketChat#14977)

* Remove unused Meteor dependency (yasinuslu:blaze-meta) (RocketChat#14971)

* Bump marked from 0.5.2 to 0.6.1 (RocketChat#14969)

* Bump marked from 0.5.2 to 0.6.1

Bumps [marked](https://github.com/markedjs/marked) from 0.5.2 to 0.6.1.
- [Release notes](https://github.com/markedjs/marked/releases)
- [Commits](markedjs/marked@v0.5.2...v0.6.1)

Signed-off-by: dependabot[bot] <support@github.com>

* Update package-lock

* [IMPROVE] Federation routes RocketChat#14972

* [IMPROVE] Extract federation config to its own file (RocketChat#14992)

* Revert "[IMPROVE] Federation routes RocketChat#14972"

* Extract federation config logic to its own file

* Service account configurable approval process

* Improve Docker compose readability (RocketChat#14457)

* [FIX] Not being able to mention users with "all" and "here" usernames - do not allow users register that usernames (RocketChat#14468)

* [FIX] Custom User Status throttled by rate limiter (RocketChat#15001)

* [FIX] CustomOauth Identity Step errors displayed in HTML format (RocketChat#15000)

* Service account message alert added

* Lint errors fixed

* fixed browseChannels method

* fixed browseChannels method
  • Loading branch information
bhardwajaditya authored and Kailash0311 committed Jul 17, 2019
1 parent 62fca65 commit e4ef980
Show file tree
Hide file tree
Showing 61 changed files with 564 additions and 256 deletions.
Binary file modified .circleci/sign.key.gpg
Binary file not shown.
1 change: 0 additions & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ raix:handlebar-helpers
rocketchat:push
raix:ui-dropped-event
todda00:friendly-slugs
yasinuslu:blaze-meta

tap:i18n
underscore@1.0.10
Expand Down
3 changes: 1 addition & 2 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ konecty:change-case@2.3.0
konecty:delayed-task@1.0.0
konecty:mongo-counter@0.0.5_3
konecty:multiple-instances-status@1.1.0
konecty:user-presence@2.4.0
konecty:user-presence@2.5.0
launch-screen@1.1.1
less@2.8.0
littledata:synced-cron@1.5.1
Expand Down Expand Up @@ -159,4 +159,3 @@ underscore@1.0.10
url@1.2.0
webapp@1.7.2
webapp-hashing@1.0.9
yasinuslu:blaze-meta@0.3.3
8 changes: 4 additions & 4 deletions app/channel-settings/client/views/channelSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
<div class="rc-user-info__row rc-user-info__row--separator">
<div class="rc-switch-double">
<div class="rc-switch-double__label {{equal false value 'disabled'}}">
{{_ "React_when_read_only"}}
{{_ "Disallow_reacting"}}
<div class="rc-switch-double__description">
{{_ "React_when_read_only"}}
{{_ "Disallow_reacting_Description"}}
</div>
</div>
<div class="rc-switch rc-switch--blue">
Expand All @@ -136,9 +136,9 @@
</label>
</div>
<div class="rc-switch-double__label {{equal true value 'disabled'}}">
{{_ "Disallow_reacting"}}
{{_ "React_when_read_only"}}
<div class="rc-switch-double__description">
{{_ "Disallow_reacting_Description"}}
{{_ "React_when_read_only"}}
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/custom-oauth/server/custom_oauth_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class CustomOAuth {
const params = {};
const headers = {
'User-Agent': this.userAgent, // http://doc.gitlab.com/ce/api/users.html#Current-user
Accept: 'application/json',
};

if (this.identityTokenSentVia === 'header') {
Expand Down
12 changes: 12 additions & 0 deletions app/emoji-custom/client/admin/adminEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ Template.adminEmoji.helpers({
data: Template.instance().tabBarData.get(),
};
},
onTableScroll() {
const instance = Template.instance();
return function(currentTarget) {
if ((currentTarget.offsetHeight + currentTarget.scrollTop) < (currentTarget.scrollHeight - 100)) {
return;
}
if (Template.instance().limit.get() > Template.instance().customemoji().length) {
return false;
}
instance.limit.set(instance.limit.get() + 50);
};
},
onTableItemClick() {
const instance = Template.instance();
return function({ _id }) {
Expand Down
74 changes: 74 additions & 0 deletions app/federation/server/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import mem from 'mem';

import { getWorkspaceAccessToken } from '../../cloud/server';
import { FederationKeys } from '../../models/server';
import { settings } from '../../settings/server';
import * as SettingsUpdater from './settingsUpdater';
import { logger } from './logger';

const defaultConfig = {
hub: {
active: null,
url: null,
},
peer: {
uniqueId: null,
domain: null,
url: null,
public_key: null,
},
cloud: {
token: null,
},
};

const getConfigLocal = () => {
const _enabled = settings.get('FEDERATION_Enabled');

if (!_enabled) { return defaultConfig; }

// If it is enabled, check if the settings are there
const _uniqueId = settings.get('FEDERATION_Unique_Id');
const _domain = settings.get('FEDERATION_Domain');
const _discoveryMethod = settings.get('FEDERATION_Discovery_Method');
const _hubUrl = settings.get('FEDERATION_Hub_URL');
const _peerUrl = settings.get('Site_Url');

if (!_domain || !_discoveryMethod || !_hubUrl || !_peerUrl) {
SettingsUpdater.updateStatus('Could not enable, settings are not fully set');

logger.setup.error('Could not enable Federation, settings are not fully set');

return defaultConfig;
}

logger.setup.info('Updating settings...');

// Normalize the config values
return {
hub: {
active: _discoveryMethod === 'hub',
url: _hubUrl.replace(/\/+$/, ''),
},
peer: {
uniqueId: _uniqueId,
domain: _domain.replace('@', '').trim(),
url: _peerUrl.replace(/\/+$/, ''),
public_key: FederationKeys.getPublicKeyString(),
},
cloud: {
token: getWorkspaceAccessToken(),
},
};
};

export const getConfig = mem(getConfigLocal);

const updateValue = () => mem.clear(getConfig);

settings.get('FEDERATION_Enabled', updateValue);
settings.get('FEDERATION_Unique_Id', updateValue);
settings.get('FEDERATION_Domain', updateValue);
settings.get('FEDERATION_Status', updateValue);
settings.get('FEDERATION_Discovery_Method', updateValue);
settings.get('FEDERATION_Hub_URL', updateValue);
36 changes: 2 additions & 34 deletions app/federation/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import './methods/dashboard';
import { addUser } from './methods/addUser';
import { searchUsers } from './methods/searchUsers';
import { ping } from './methods/ping';
import { getWorkspaceAccessToken } from '../../cloud/server';
import { FederationKeys } from '../../models';
import { settings } from '../../settings';
import { getConfig } from './config';

const peerClient = new PeerClient();
const peerDNS = new PeerDNS();
Expand Down Expand Up @@ -73,39 +73,7 @@ const updateSettings = _.debounce(Meteor.bindEnvironment(function() {

if (!_enabled) { return; }

// If it is enabled, check if the settings are there
const _uniqueId = settings.get('FEDERATION_Unique_Id');
const _domain = settings.get('FEDERATION_Domain');
const _discoveryMethod = settings.get('FEDERATION_Discovery_Method');
const _hubUrl = settings.get('FEDERATION_Hub_URL');
const _peerUrl = settings.get('Site_Url');

if (!_domain || !_discoveryMethod || !_hubUrl || !_peerUrl) {
SettingsUpdater.updateStatus('Could not enable, settings are not fully set');

logger.setup.error('Could not enable Federation, settings are not fully set');

return;
}

logger.setup.info('Updating settings...');

// Normalize the config values
const config = {
hub: {
active: _discoveryMethod === 'hub',
url: _hubUrl.replace(/\/+$/, ''),
},
peer: {
uniqueId: _uniqueId,
domain: _domain.replace('@', '').trim(),
url: _peerUrl.replace(/\/+$/, ''),
public_key: FederationKeys.getPublicKeyString(),
},
cloud: {
token: getWorkspaceAccessToken(),
},
};
const config = getConfig();

// If the settings are correctly set, let's update the configuration

Expand Down
2 changes: 1 addition & 1 deletion app/ldap/server/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function getDataToSyncUserData(ldapUser, user) {
if (currKey === lastKey) {
obj[currKey] = tmpLdapField;
} else {
obj[currKey] = obj[currKey];
obj[currKey] = obj[currKey] || {};
}
return obj[currKey];
}, userData);
Expand Down
6 changes: 6 additions & 0 deletions app/lib/client/methods/sendMessage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Meteor } from 'meteor/meteor';
import { TimeSync } from 'meteor/mizzao:timesync';
import s from 'underscore.string';
import toastr from 'toastr';

import { ChatMessage } from '../../../models';
import { settings } from '../../../settings';
import { callbacks } from '../../../callbacks';
import { promises } from '../../../promises/client';
import { t } from '../../../utils/client';

Meteor.methods({
sendMessage(message) {
if (!Meteor.userId() || s.trim(message.msg) === '') {
return false;
}
const messageAlreadyExists = message._id && ChatMessage.findOne({ _id: message._id });
if (messageAlreadyExists) {
return toastr.error(t('Message_Already_Sent'));
}
const user = Meteor.user();
message.ts = isNaN(TimeSync.serverOffset()) ? new Date() : new Date(Date.now() + TimeSync.serverOffset());
message.u = {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/server/functions/checkUsernameAvailability.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let usernameBlackList = [];
const toRegExp = (username) => new RegExp(`^${ s.escapeRegExp(username).trim() }$`, 'i');

settings.get('Accounts_BlockedUsernameList', (key, value) => {
usernameBlackList = value.split(',').map(toRegExp);
usernameBlackList = ['all', 'here'].concat(value.split(',')).map(toRegExp);
});

const usernameIsBlocked = (username, usernameBlackList) => usernameBlackList.length
Expand Down
31 changes: 31 additions & 0 deletions app/lib/server/functions/notifications/serviceAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { metrics } from '../../../../metrics';
import { Notifications } from '../../../../notifications';

export function shouldNotifyServiceAccountOwner({
statusConnection,
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
}) {
if (statusConnection === 'online') {
return false;
}
return roomType === 'd' || hasMentionToAll || hasMentionToHere || isHighlighted || hasMentionToUser || hasReplyToThread;
}

export function notifyServiceAccountOwner(receiver, ownerId, message, room) {
metrics.notificationsSent.inc({ notification_type: 'sa' });
Notifications.notifyUser(ownerId, 'sa-notification', {
payload: {
_id: message._id,
rid: message.rid,
sender: message.u,
receiver: receiver.username,
type: room.t,
name: room.name,
},
});
}
4 changes: 4 additions & 0 deletions app/lib/server/functions/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ export const sendMessage = function(user, message, room, upsert = false) {
}, message);
message._id = _id;
} else {
const messageAlreadyExists = message._id && Messages.findOneById(message._id, { fields: { _id: 1 } });
if (messageAlreadyExists) {
return;
}
message._id = Messages.insert(message);
}

Expand Down
2 changes: 1 addition & 1 deletion app/lib/server/functions/setStatusText.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const _setStatusText = function(userId, statusText) {
return true;
};

export const setStatusText = RateLimiter.limitFunction(_setStatusText, 1, 60000, {
export const setStatusText = RateLimiter.limitFunction(_setStatusText, 5, 60000, {
0() {
// Administrators have permission to change others status, so don't limit those
return !Meteor.userId() || !hasPermission(Meteor.userId(), 'edit-other-user-info');
Expand Down
15 changes: 15 additions & 0 deletions app/lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { sendEmail, shouldNotifyEmail } from '../functions/notifications/email';
import { sendSinglePush, shouldNotifyMobile } from '../functions/notifications/mobile';
import { notifyDesktopUser, shouldNotifyDesktop } from '../functions/notifications/desktop';
import { notifyAudioUser, shouldNotifyAudio } from '../functions/notifications/audio';
import { notifyServiceAccountOwner, shouldNotifyServiceAccountOwner } from '../functions/notifications/serviceAccount';

export const sendNotification = async ({
subscription,
Expand Down Expand Up @@ -46,6 +47,7 @@ export const sendNotification = async ({
status: 1,
statusConnection: 1,
username: 1,
u: 1,
},
}),
];
Expand Down Expand Up @@ -149,6 +151,18 @@ export const sendNotification = async ({
return false;
});
}

if (receiver.u && shouldNotifyServiceAccountOwner({
statusConnection: receiver.statusConnection,
hasMentionToAll,
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
})) {
notifyServiceAccountOwner(receiver, receiver.u._id, message, room);
}
};

const project = {
Expand All @@ -168,6 +182,7 @@ const project = {
'receiver.status': 1,
'receiver.statusConnection': 1,
'receiver.username': 1,
'receiver.u': 1,
},
};

Expand Down
15 changes: 1 addition & 14 deletions app/livechat/server/api/v1/pageVisited.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import _ from 'underscore';

import { API } from '../../../../api';
import { findGuest, findRoom } from '../lib/livechat';
import { Livechat } from '../../lib/Livechat';

API.v1.addRoute('livechat/page.visited', {
post() {
try {
check(this.bodyParams, {
token: String,
rid: String,
rid: Match.Maybe(String),
pageInfo: Match.ObjectIncluding({
change: String,
title: String,
Expand All @@ -22,17 +20,6 @@ API.v1.addRoute('livechat/page.visited', {
});

const { token, rid, pageInfo } = this.bodyParams;

const guest = findGuest(token);
if (!guest) {
throw new Meteor.Error('invalid-token');
}

const room = findRoom(token, rid);
if (!room) {
throw new Meteor.Error('invalid-room');
}

const obj = Livechat.savePageHistory(token, rid, pageInfo);
if (obj) {
const page = _.pick(obj, 'msg', 'navigation');
Expand Down
2 changes: 1 addition & 1 deletion app/message-pin/client/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Meteor.startup(function() {
id: 'jump-to-pin-message',
icon: 'jump',
label: 'Jump_to_message',
context: ['pinned'],
context: ['pinned', 'message', 'message-mobile'],
action() {
const { msg: message } = messageArgs(this);
if (window.matchMedia('(max-width: 500px)').matches) {
Expand Down
2 changes: 1 addition & 1 deletion app/message-star/client/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Meteor.startup(function() {
id: 'jump-to-star-message',
icon: 'jump',
label: 'Jump_to_message',
context: ['starred', 'threads'],
context: ['starred', 'threads', 'message', 'message-mobile'],
action() {
const { msg: message } = messageArgs(this);
if (window.matchMedia('(max-width: 500px)').matches) {
Expand Down
Loading

0 comments on commit e4ef980

Please sign in to comment.