Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
220 commits
Select commit Hold shift + click to select a range
670233e
Implement base for Api services
sampaiodiego Sep 3, 2020
9f34c42
Internal authorization service
sampaiodiego Sep 4, 2020
2194a92
Remove cache
sampaiodiego Sep 4, 2020
341e3bb
Bind instance to method on local broker
sampaiodiego Sep 4, 2020
3e8e866
Fix spotlight permission check
sampaiodiego Sep 4, 2020
14345d6
Compile typescript
sampaiodiego Sep 4, 2020
5c4760b
Remove delay from broker calls
rodrigok Sep 4, 2020
af70caa
Remove github actions
sampaiodiego Sep 4, 2020
ad5cfae
Fix compilation errors
rodrigok Sep 4, 2020
61033c9
Move everything to /server and services out from skd
rodrigok Sep 4, 2020
5359a88
Initial version with MS running
rodrigok Sep 4, 2020
742413b
Move microservices intances to ee folder
rodrigok Sep 5, 2020
9d6c121
Add PM2 options
rodrigok Sep 5, 2020
2989b27
Implements async local storage for context
rodrigok Sep 5, 2020
00d97e3
Move ee Accounts service to a folder
rodrigok Sep 5, 2020
dc4a509
Implement broker node list helper
rodrigok Sep 5, 2020
9d9b63c
Add missing interfaces
rodrigok Sep 5, 2020
bb1bcc8
Implement central place for collections and fix error when compiling …
rodrigok Sep 5, 2020
ac330af
Initial implementation of Presence
rodrigok Sep 5, 2020
bd3c7ec
Reorganization of Presence
rodrigok Sep 5, 2020
3feffd9
Fix types and resolve hooks
rodrigok Sep 5, 2020
073dcce
Finish Presence implementation
rodrigok Sep 5, 2020
1cea003
Implement service Accounts
rodrigok Sep 5, 2020
8730ae3
Fix build error
rodrigok Sep 5, 2020
cd003ce
Fix typo
rodrigok Sep 5, 2020
1e2b1d6
Implement StreamHub
rodrigok Sep 5, 2020
301328f
Organize names
rodrigok Sep 5, 2020
0bb15ed
Initial version of DDPSrteamer
rodrigok Sep 6, 2020
f2c58ed
Fix more TS errors
rodrigok Sep 6, 2020
5405154
Import canAccessRooms from other areas
rodrigok Sep 7, 2020
7d5bbb9
DDPStreamer: Use canAccessRoom
rodrigok Sep 7, 2020
ca19598
DDPStreamer: Fix ClientMobile
rodrigok Sep 7, 2020
6f9034c
DDPStreamer: Finish import
rodrigok Sep 7, 2020
88858fa
Fix small errors
rodrigok Sep 7, 2020
e9f098f
Fix issues with Authorization importing meteor code
rodrigok Sep 7, 2020
b184070
Prevent DDPStreamer to lock http calls
rodrigok Sep 7, 2020
c5760ea
Fix canAccessRoom not been registered as micro services
rodrigok Sep 7, 2020
baae8fc
Fix some exceptions
rodrigok Sep 7, 2020
0a47431
DDPStreamer: Add proxy to localhost:3000
rodrigok Sep 7, 2020
ae5eec5
Register events correctly
rodrigok Sep 7, 2020
4f7fa34
Improve PM2 config watch
rodrigok Sep 7, 2020
babfcda
Add typecheck script
rodrigok Sep 7, 2020
7031547
Fix missing module
rodrigok Sep 7, 2020
7977226
First implementation of license check
rodrigok Sep 8, 2020
f733acc
Fix whitelist and ensure license module availability on broker
rodrigok Sep 8, 2020
a07ac65
Disable CI
rodrigok Sep 8, 2020
cb18b2e
Fix issue when calling events
rodrigok Sep 8, 2020
ce65cab
Start network broaker as soon as possible
rodrigok Sep 8, 2020
3773f4b
Merge branch 'upstream/develop' into network-broker
rodrigok Sep 19, 2020
a3113eb
Fix lint
rodrigok Sep 19, 2020
6c5d983
Fix missing type
rodrigok Sep 19, 2020
8616171
Implement initial option to build containers
rodrigok Sep 19, 2020
85feb78
Rremove uncessary ls command
rodrigok Sep 19, 2020
411fc6c
Implement local broker event broadcast
rodrigok Sep 19, 2020
6079eee
Resolve some TODOs
rodrigok Sep 19, 2020
58b534d
Remove msgpack from internal events
rodrigok Sep 19, 2020
b4d45da
Add Grafana/Prometheus, use EJSON as Serializer and fix some things
rodrigok Sep 19, 2020
a25fb84
Implement Traefik
rodrigok Sep 20, 2020
3b6b75a
Enable tracing via jagger
rodrigok Sep 20, 2020
44e24d1
Add more metrics
rodrigok Sep 20, 2020
4fe5d7f
Use Traefik to redirect websocket calls to docker host 3000
rodrigok Sep 20, 2020
7d88d22
Remove unused file
rodrigok Sep 20, 2020
c9b0507
Add TODOs
sampaiodiego Sep 22, 2020
7ed522b
Revert changes
sampaiodiego Sep 22, 2020
4be3af8
Merge branch 'develop' into network-broker
sampaiodiego Sep 22, 2020
b7ecafa
Adjust some TODOs
sampaiodiego Sep 22, 2020
98b0ddc
Rename methods to use the same as used by Meteor
sampaiodiego Sep 23, 2020
82feba1
Fix OplogHandle typings
sampaiodiego Sep 23, 2020
6ea53ec
Merge branch 'develop' into micro-services
sampaiodiego Sep 23, 2020
4d706c0
Streamer service
sampaiodiego Sep 24, 2020
48dfe71
Merge branch 'develop' into micro-services
sampaiodiego Sep 25, 2020
46de01c
Send notifications for permissions, settings and avatar
sampaiodiego Sep 25, 2020
d20289c
Use streamer for roles updates
sampaiodiego Sep 25, 2020
a0db4b8
Use streamer for custom status, custom emojis and some user actions
sampaiodiego Sep 25, 2020
d4742c3
Fix streamer payload
sampaiodiego Sep 25, 2020
af41954
Fix others streams
sampaiodiego Sep 25, 2020
be8fa70
Declare meteor module
sampaiodiego Sep 25, 2020
cd319b8
Undeclare meteor module
sampaiodiego Sep 25, 2020
290d0f0
Improve broaker loading to wait correctly on license check
rodrigok Sep 26, 2020
beb55c3
Implement publication `meteor_autoupdate_clientVersions`
rodrigok Sep 26, 2020
754dd41
Implement publication `meteor.loginServiceConfiguration`
rodrigok Sep 26, 2020
3a93f35
[FIX] Reactivity of the login services configuration not working
rodrigok Sep 26, 2020
bcc2763
Stream: Implement sendEphemeralMessage
rodrigok Sep 27, 2020
8e4805f
Move most of the notifications and streams code to a isolated module …
rodrigok Sep 28, 2020
a61552c
Init streamer de duplication
rodrigok Sep 28, 2020
2de16b4
Resolve IStreamer type error
rodrigok Sep 28, 2020
d9d01d1
Fix import
sampaiodiego Sep 28, 2020
67219c2
Broadcast user presence
sampaiodiego Sep 28, 2020
b53b0a5
Development instructions
sampaiodiego Sep 29, 2020
46b467f
Remove STATUS_MAP
sampaiodiego Sep 29, 2020
ff30c55
Merge branch 'develop' into micro-services
sampaiodiego Sep 29, 2020
85ee26e
Use correct @types/node version
sampaiodiego Sep 29, 2020
fa728b2
Add missing typescript module for async_hooks
sampaiodiego Sep 29, 2020
cc64b66
Import Meteor.Streamer code and unify with DDP Streamer
rodrigok Sep 30, 2020
d50c2da
Merge branch 'micro-services' of https://github.com/RocketChat/Rocket…
rodrigok Sep 30, 2020
2a7f6ef
Fix initial errors after the refactoring
rodrigok Sep 30, 2020
70a8b18
Resolve alerts from lgtm
rodrigok Sep 30, 2020
d0169f9
gracefully closes oplog connection on SIGTERM
sampaiodiego Sep 30, 2020
07ff2ad
Fix unhandled promise exception
rodrigok Sep 30, 2020
270c581
Move all allow calls to the same file
rodrigok Sep 30, 2020
68025fe
emoji.deleteCustom
alansikora Sep 30, 2020
712e1c1
emoji.updateCustom
alansikora Sep 30, 2020
b4e2879
Fix Streamer sendFrame
sampaiodiego Sep 30, 2020
a073e1d
roomMessages streamer
sampaiodiego Sep 30, 2020
3608346
Merge branch 'micro-services' of github.com:RocketChat/Rocket.Chat in…
sampaiodiego Sep 30, 2020
3a9401e
Fix lint
sampaiodiego Oct 1, 2020
afe82a1
user.deleted && user.deleteCustomStatus
alansikora Oct 1, 2020
c9532ae
user.updateCustomStatus
alansikora Oct 1, 2020
c9b9f07
permission.changed
alansikora Oct 1, 2020
d09daa7
setting.privateChanged
alansikora Oct 1, 2020
058f201
notify.ephemeralMessage
alansikora Oct 1, 2020
9d9300d
user.avatarUpdate
alansikora Oct 1, 2020
c71df4e
user.roleUpdate
alansikora Oct 1, 2020
1681484
room.avatarUpdate and removed StreamService and everything related to it
alansikora Oct 1, 2020
fb27e6f
Move streamRoomUsers to inside notifications module
rodrigok Oct 1, 2020
84f18d1
notify-room stream permissions
sampaiodiego Oct 1, 2020
fc276c8
Fix RoomStreamer/rooms-changed
sampaiodiego Oct 1, 2020
e59f547
Move streamCannedResponses to inside Notifications module
rodrigok Oct 1, 2020
cdb77eb
Implement integrationHistory stream
sampaiodiego Oct 1, 2020
29898a5
Remove old streamRoom allowRead/allowWrite
sampaiodiego Oct 1, 2020
051af39
Fix room access validators
sampaiodiego Oct 1, 2020
8722331
Implement stream room-data
sampaiodiego Oct 1, 2020
fde5d37
Implement stream room-data
sampaiodiego Oct 1, 2020
8926ea2
Merge branch 'micro-services' of github.com:RocketChat/Rocket.Chat in…
sampaiodiego Oct 1, 2020
d9da8b9
Parse both websocket formats correctly
rodrigok Oct 1, 2020
7967d7d
PM2: Watch modules folder
rodrigok Oct 1, 2020
80398bf
Add broker method to call methods on monolith
rodrigok Oct 1, 2020
66ec7a9
Remove isEmitAllowed from roomTypes
sampaiodiego Oct 2, 2020
832fedb
Merge branch 'micro-services' of https://github.com/RocketChat/Rocket…
rodrigok Oct 2, 2020
3a1f5b9
Disable react-hooks/exhaustive-deps warning
rodrigok Oct 2, 2020
0bf5217
Implement stream stdout
sampaiodiego Oct 2, 2020
fa1c2ff
Merge branch 'micro-services' of github.com:RocketChat/Rocket.Chat in…
sampaiodiego Oct 2, 2020
87dd68e
Implement livechat:setUpConnection on DDPStreamer
rodrigok Oct 2, 2020
c3c1eec
Suport send message to both wesocket types again
rodrigok Oct 2, 2020
c31d1a1
FIx parse of params for subscriptions on DDPStreamer
rodrigok Oct 2, 2020
dc9a507
Move streamLivechatRoom to inside module
rodrigok Oct 2, 2020
5c63459
Move streamLivechatQueueData to inside module
rodrigok Oct 2, 2020
911f266
Move streamAll `private-settings-changed` to inside module
rodrigok Oct 2, 2020
d11a46d
Merge branch 'micro-services' of github.com:RocketChat/Rocket.Chat in…
sampaiodiego Oct 2, 2020
be832b8
Remove commented code
rodrigok Oct 2, 2020
ddbfc85
Make RoomStreamer from Notifications more close to the DDPStreamer one
rodrigok Oct 2, 2020
11a98d0
Make MessageStream from Notifications more close to DDPStreamer one
rodrigok Oct 2, 2020
710f3c1
Use publication._session to get userId and unify Publication type def
rodrigok Oct 2, 2020
ca60ba6
Prevent infinite loop
sampaiodiego Oct 2, 2020
d9d6262
Add Meteor.bindEnvironment to stream broadcast
sampaiodiego Oct 2, 2020
ffe2919
Unify RoomStreamer and MessageStreamer
rodrigok Oct 3, 2020
9b3809c
Fix userpresence
rodrigok Oct 3, 2020
a99e811
Resolve network broaker chain
rodrigok Oct 3, 2020
6752e5b
Init wathers.module
rodrigok Oct 4, 2020
34f7630
Type improvements
rodrigok Oct 5, 2020
a84ed8f
Implement Roles watcher
sampaiodiego Oct 5, 2020
48aedfa
Move Permissions change watcher to module
rodrigok Oct 5, 2020
bdd30a9
Move settings to module
rodrigok Oct 6, 2020
789bfb9
Move LivechatInquiry to module
rodrigok Oct 6, 2020
81d088b
Move UserPrensenceMonitor to module
rodrigok Oct 6, 2020
7592159
Add room watcher
sampaiodiego Oct 7, 2020
40b8325
Clear cache on roles change
sampaiodiego Oct 7, 2020
2ff9e8b
Merge remote-tracking branch 'origin/develop' into micro-services
rodrigok Oct 12, 2020
943e68e
Move User watch to module
rodrigok Oct 12, 2020
78bd9d2
Move search watchers to a module
rodrigok Oct 12, 2020
90ed53f
Convert login service configuration to module
rodrigok Oct 12, 2020
eae1922
Move Instance Status to module
rodrigok Oct 12, 2020
5821f32
Move Integration History to module
rodrigok Oct 12, 2020
f7d1fce
Move LivechatDepartmentAgents to module
rodrigok Oct 12, 2020
8e98241
Move Integrations watch to module
rodrigok Oct 12, 2020
611c958
Remove unecessary events
rodrigok Oct 12, 2020
8adb53d
Fix errors
rodrigok Oct 12, 2020
7ba70c5
Prevent process to be stucked on exit
rodrigok Oct 12, 2020
8953a8e
Fix error Settings.findOneById is not a function
rodrigok Oct 13, 2020
8bb777c
removing meteor dependencies from StreamHub, using SubscriptionsRaw t…
alansikora Oct 14, 2020
14f6954
Merge remote-tracking branch 'origin/develop' into micro-services
rodrigok Oct 14, 2020
342a4ad
Fix test error
rodrigok Oct 14, 2020
2956986
fixed Livechat files: Custom.ts and Multiple.ts, the latter still com…
alansikora Oct 14, 2020
36db460
Type cast LivechatDepartmentAgentsRaw
sampaiodiego Oct 14, 2020
e4dfd0e
Remove SettingType
sampaiodiego Oct 14, 2020
87fbee2
Remove mongodb connection close on SIGTERM
rodrigok Oct 14, 2020
19de68a
Merge branches 'micro-services' and 'micro-services' of https://githu…
rodrigok Oct 14, 2020
ce4c0e9
Remove some TODOs
rodrigok Oct 15, 2020
2921c2d
Remove external dependencies from license module
sampaiodiego Oct 15, 2020
532c5d5
Hook up license events to micro services
sampaiodiego Oct 15, 2020
fcc7440
Remove AuthorizationUtils TODO
sampaiodiego Oct 15, 2020
ab379ad
Convert listeners/notifications to module
rodrigok Oct 15, 2020
5f2d3ba
Merge branch 'micro-services' of https://github.com/RocketChat/Rocket…
rodrigok Oct 15, 2020
780d48d
Remove uncessary todo
rodrigok Oct 15, 2020
b54c04f
Remove unecessary type cast
rodrigok Oct 15, 2020
cb00886
Build services Docker images
sampaiodiego Oct 15, 2020
8b10f16
Merge branch 'micro-services' of github.com:RocketChat/Rocket.Chat in…
sampaiodiego Oct 15, 2020
719ccf1
Add npm install to root repo
sampaiodiego Oct 15, 2020
bc1014c
Fix error on localbroker emit
rodrigok Oct 15, 2020
e32ba79
Merge branch 'micro-services' of https://github.com/RocketChat/Rocket…
rodrigok Oct 15, 2020
fc5f9bb
Use ts-node --files to run on PM2
sampaiodiego Oct 16, 2020
ddd277c
Upgrade mongodb type definition
rodrigok Oct 16, 2020
3a5a87c
Revert "Upgrade mongodb type definition"
rodrigok Oct 16, 2020
fe58828
Add DISABLE_DB_WATCH env var to disable monolith oplog
rodrigok Oct 16, 2020
04591e9
Increase mongodb connection poll to 15 since we have 14 change streams
rodrigok Oct 16, 2020
2c37fdd
Increase number of connections for stream hub
rodrigok Oct 16, 2020
e3ce73e
fxing user presence duplications
alansikora Oct 19, 2020
65a2801
Change monolith change stream to use 15 connections as well
rodrigok Oct 19, 2020
5316be1
Emit stdout to local clients only
sampaiodiego Oct 19, 2020
c2e5dde
Broadcast status changes from monolith only
sampaiodiego Oct 19, 2020
770fcbe
BaseRaw: Allow findOne to receive string to find by id
rodrigok Oct 19, 2020
dcc5133
Merge branch 'develop' into micro-services
sampaiodiego Oct 20, 2020
582b741
Fix trash find collection name
sampaiodiego Oct 21, 2020
9e9039f
Broadcast to watch.subscription even if not found on trash
sampaiodiego Oct 21, 2020
4a0f569
Add typing to BaseRaw.name
sampaiodiego Oct 21, 2020
63bf9de
Add context to broker lifecycle events
sampaiodiego Oct 21, 2020
a485913
Add broadcast on presence if status has changed
sampaiodiego Oct 21, 2020
2eed85f
Broadcast user presense on setStatus
sampaiodiego Oct 21, 2020
b36bb69
Merge branch 'develop' into micro-services
sampaiodiego Oct 21, 2020
a46cf3c
Fix trash collection name
sampaiodiego Oct 23, 2020
05b20c2
Merge branch 'develop' into micro-services
sampaiodiego Oct 23, 2020
c345e65
Fix IUser
sampaiodiego Oct 23, 2020
120b6ce
Merge remote-tracking branch 'origin/develop' into micro-services
rodrigok Oct 27, 2020
7d37c5a
Fix lint and typecheck
rodrigok Oct 27, 2020
339f396
Merge branch 'develop' into micro-services
sampaiodiego Oct 28, 2020
b453930
Fix OmnichannelQueueRaw
sampaiodiego Oct 28, 2020
33c695c
Finish services Docker image build
sampaiodiego Oct 28, 2020
fffe526
Fix Change Stream $unset
sampaiodiego Oct 28, 2020
a7dc4c4
Suggestions from review
sampaiodiego Oct 28, 2020
bd60936
Remove msgpack5
sampaiodiego Oct 28, 2020
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ public/pdf.worker.min.js
public/workers/**/*
imports/client/
!/.storybook/
ee/server/services/dist/**
37 changes: 37 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,40 @@ jobs:

docker build -t ${IMAGE}:develop .
docker push ${IMAGE}:develop

services-image-build:
runs-on: ubuntu-latest
needs: deploy
if: github.event.pull_request.head.repo.full_name == github.repository

strategy:
matrix:
service: ["account", "authorization", "ddp-streamer", "presence", "stream-hub"]

steps:
- uses: actions/checkout@v2

- name: Use Node.js 12.18.4
uses: actions/setup-node@v1
with:
node-version: "12.18.4"

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}

- name: Build Docker images
run: |
npm i

cd ./ee/server/services
npm i
npm run build

echo "Building Docker image for service: ${{ matrix.service }}"

docker build --build-arg SERVICE=${{ matrix.service }} -t rocketchat/${{ matrix.service }}-service .

docker push rocketchat/${{ matrix.service }}-service
1 change: 1 addition & 0 deletions .meteorignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ee/server/services
13 changes: 10 additions & 3 deletions .scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ const isPortTaken = (port) => new Promise((resolve, reject) => {
.listen(port);
});

const waitPortRelease = (port) => new Promise((resolve, reject) => {
const waitPortRelease = (port, count = 0) => new Promise((resolve, reject) => {
isPortTaken(port).then((taken) => {
if (!taken) {
return resolve();
}
if (count > 60) {
return reject();
}
console.log('Port', port, 'not release, waiting 1s...');
setTimeout(() => {
waitPortRelease(port).then(resolve).catch(reject);
waitPortRelease(port, ++count).then(resolve).catch(reject);
}, 1000);
});
});
Expand Down Expand Up @@ -77,7 +81,10 @@ function startProcess(opts, callback) {

processes.splice(processes.indexOf(proc), 1);

processes.forEach((p) => p.kill());
processes.forEach((p) => {
console.log('Killing process', p.pid);
p.kill();
});

if (processes.length === 0) {
waitPortRelease(appOptions.env.PORT).then(() => {
Expand Down
2 changes: 2 additions & 0 deletions app/api/server/v1/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Settings } from '../../../models/server';
import { hasPermission } from '../../../authorization';
import { API } from '../api';
import { SettingsEvents, settings } from '../../../settings/server';
import { setValue } from '../../../settings/server/raw';

const fetchSettings = (query, sort, offset, count, fields) => {
const settings = Settings.find(query, {
Expand Down Expand Up @@ -150,6 +151,7 @@ API.v1.addRoute('settings/:_id', { authRequired: true }, {
_id: this.urlParams._id,
value: this.bodyParams.value,
});
setValue(this.urlParams._id, this.bodyParams.value);
return API.v1.success();
}

Expand Down
20 changes: 7 additions & 13 deletions app/apps/server/bridges/messages.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Random } from 'meteor/random';

import { Messages, Users, Subscriptions } from '../../../models/server';
import { Notifications } from '../../../notifications';
import { updateMessage } from '../../../lib/server/functions/updateMessage';
import { executeSendMessage } from '../../../lib/server/methods/sendMessage';
import { api } from '../../../../server/sdk/api';
import notifications from '../../../notifications/server/lib/Notifications';

export class AppMessageBridge {
constructor(orch) {
Expand Down Expand Up @@ -52,10 +51,8 @@ export class AppMessageBridge {
return;
}

Notifications.notifyUser(user.id, 'message', {
api.broadcast('stream.ephemeralMessage', user.id, msg.rid, {
...msg,
_id: Random.id(),
ts: new Date(),
});
}

Expand All @@ -67,11 +64,6 @@ export class AppMessageBridge {
}

const msg = this.orch.getConverters().get('messages').convertAppMessage(message);
const rmsg = Object.assign(msg, {
_id: Random.id(),
rid: room.id,
ts: new Date(),
});

const users = Subscriptions.findByRoomIdWhenUserIdExists(room.id, { fields: { 'u._id': 1 } })
.fetch()
Expand All @@ -80,14 +72,16 @@ export class AppMessageBridge {
Users.findByIds(users, { fields: { _id: 1 } })
.fetch()
.forEach(({ _id }) =>
Notifications.notifyUser(_id, 'message', rmsg),
api.broadcast('stream.ephemeralMessage', _id, room.id, {
...msg,
}),
);
}

async typing({ scope, id, username, isTyping }) {
switch (scope) {
case 'room':
Notifications.notifyRoom(id, 'typing', username, isTyping);
notifications.notifyRoom(id, 'typing', username, isTyping);
return;
default:
throw new Error('Unrecognized typing scope provided');
Expand Down
15 changes: 4 additions & 11 deletions app/apps/server/communication/websockets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { AppStatusUtils } from '@rocket.chat/apps-engine/definition/AppStatus';

import notifications from '../../../notifications/server/lib/Notifications';

export const AppEvents = Object.freeze({
APP_ADDED: 'app/added',
APP_REMOVED: 'app/removed',
Expand Down Expand Up @@ -101,18 +102,10 @@ export class AppServerListener {

export class AppServerNotifier {
constructor(orch) {
this.engineStreamer = new Meteor.Streamer('apps-engine', { retransmit: false });
this.engineStreamer.serverOnly = true;
this.engineStreamer.allowRead('none');
this.engineStreamer.allowEmit('all');
this.engineStreamer.allowWrite('none');
this.engineStreamer = notifications.streamAppsEngine;

// This is used to broadcast to the web clients
this.clientStreamer = new Meteor.Streamer('apps', { retransmit: false });
this.clientStreamer.serverOnly = true;
this.clientStreamer.allowRead('all');
this.clientStreamer.allowEmit('all');
this.clientStreamer.allowWrite('none');
this.clientStreamer = notifications.streamApps;

this.received = new Map();
this.listener = new AppServerListener(orch, this.engineStreamer, this.clientStreamer, this.received);
Expand Down
4 changes: 2 additions & 2 deletions app/authentication/server/lib/restrictLoginAttempts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export const isValidLoginAttemptByIp = async (ip: string): Promise<boolean> => {
return true;
}

const lastLogin = await Sessions.findLastLoginByIp(ip);
const lastLogin = await Sessions.findLastLoginByIp(ip) as {loginAt?: Date} | undefined;
let failedAttemptsSinceLastLogin;

if (!lastLogin) {
if (!lastLogin || !lastLogin.loginAt) {
failedAttemptsSinceLastLogin = await ServerEvents.countFailedAttemptsByIp(ip);
} else {
failedAttemptsSinceLastLogin = await ServerEvents.countFailedAttemptsByIpSince(ip, new Date(lastLogin.loginAt));
Expand Down
14 changes: 6 additions & 8 deletions app/authorization/lib/AuthorizationUtils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Meteor } from 'meteor/meteor';

const restrictedRolePermissions = new Map();

export const AuthorizationUtils = class {
static addRolePermissionWhiteList(roleId: string, list: [string]): void {
static addRolePermissionWhiteList(roleId: string, list: string[]): void {
if (!roleId) {
throw new Meteor.Error('invalid-param');
throw new Error('invalid-param');
}

if (!list) {
throw new Meteor.Error('invalid-param');
throw new Error('invalid-param');
}

if (!restrictedRolePermissions.has(roleId)) {
Expand All @@ -25,7 +23,7 @@ export const AuthorizationUtils = class {

static isPermissionRestrictedForRole(permissionId: string, roleId: string): boolean {
if (!roleId || !permissionId) {
throw new Meteor.Error('invalid-param');
throw new Error('invalid-param');
}

if (!restrictedRolePermissions.has(roleId)) {
Expand All @@ -40,9 +38,9 @@ export const AuthorizationUtils = class {
return !rules.has(permissionId);
}

static isPermissionRestrictedForRoleList(permissionId: string, roleList: [string]): boolean {
static isPermissionRestrictedForRoleList(permissionId: string, roleList: string[]): boolean {
if (!roleList || !permissionId) {
throw new Meteor.Error('invalid-param');
throw new Error('invalid-param');
}

for (const roleId of roleList) {
Expand Down
40 changes: 0 additions & 40 deletions app/authorization/server/functions/canAccessRoom.js

This file was deleted.

8 changes: 8 additions & 0 deletions app/authorization/server/functions/canAccessRoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Promise } from 'meteor/promise';

import { Authorization } from '../../../../server/sdk';
import { IAuthorization } from '../../../../server/sdk/types/IAuthorization';

export const canAccessRoomAsync = Authorization.canAccessRoom;

export const canAccessRoom = (...args: Parameters<IAuthorization['canAccessRoom']>): boolean => Promise.await(canAccessRoomAsync(...args));
63 changes: 4 additions & 59 deletions app/authorization/server/functions/hasPermission.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,8 @@
import mem from 'mem';
import { Authorization } from '../../../../server/sdk';

import { Permissions, Users, Subscriptions } from '../../../models/server/raw';
import { AuthorizationUtils } from '../../lib/AuthorizationUtils';

const rolesHasPermission = mem(async (permission, roles) => {
if (AuthorizationUtils.isPermissionRestrictedForRoleList(permission, roles)) {
return false;
}

const result = await Permissions.findOne({ _id: permission, roles: { $in: roles } }, { projection: { _id: 1 } });
return !!result;
}, {
cacheKey: JSON.stringify,
...process.env.TEST_MODE === 'true' && { maxAge: 1 },
});

const getRoles = mem(async (uid, scope) => {
const { roles: userRoles = [] } = await Users.findOne({ _id: uid }, { projection: { roles: 1 } });
const { roles: subscriptionsRoles = [] } = (scope && await Subscriptions.findOne({ rid: scope, 'u._id': uid }, { projection: { roles: 1 } })) || {};
return [...userRoles, ...subscriptionsRoles].sort((a, b) => a.localeCompare(b));
}, { maxAge: 1000, cacheKey: JSON.stringify });

export const clearCache = () => {
mem.clear(getRoles);
mem.clear(rolesHasPermission);
};

async function atLeastOne(uid, permissions = [], scope) {
const sortedRoles = await getRoles(uid, scope);
for (const permission of permissions) {
if (await rolesHasPermission(permission, sortedRoles)) { // eslint-disable-line
return true;
}
}

return false;
}

async function all(uid, permissions = [], scope) {
const sortedRoles = await getRoles(uid, scope);
for (const permission of permissions) {
if (!await rolesHasPermission(permission, sortedRoles)) { // eslint-disable-line
return false;
}
}

return true;
}

function _hasPermission(userId, permissions, scope, strategy) {
if (!userId) {
return false;
}
return strategy(userId, [].concat(permissions), scope);
}

export const hasAllPermissionAsync = async (userId, permissions, scope) => _hasPermission(userId, permissions, scope, all);
export const hasPermissionAsync = async (userId, permissionId, scope) => _hasPermission(userId, permissionId, scope, all);
export const hasAtLeastOnePermissionAsync = async (userId, permissions, scope) => _hasPermission(userId, permissions, scope, atLeastOne);
export const hasAllPermissionAsync = async (userId, permissions, scope) => Authorization.hasAllPermission(userId, permissions, scope);
export const hasPermissionAsync = async (userId, permissionId, scope) => Authorization.hasPermission(userId, permissionId, scope);
export const hasAtLeastOnePermissionAsync = async (userId, permissions, scope) => Authorization.hasAtLeastOnePermission(userId, permissions, scope);

export const hasAllPermission = (userId, permissions, scope) => Promise.await(hasAllPermissionAsync(userId, permissions, scope));
export const hasPermission = (userId, permissionId, scope) => Promise.await(hasPermissionAsync(userId, permissionId, scope));
Expand Down
2 changes: 0 additions & 2 deletions app/authorization/server/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { addUserRoles } from './functions/addUserRoles';
import {
addRoomAccessValidator,
canAccessRoom,
roomAccessValidators,
} from './functions/canAccessRoom';
Expand Down Expand Up @@ -32,7 +31,6 @@ export {
removeUserFromRoles,
canSendMessage,
validateRoomMessagePermissions,
addRoomAccessValidator,
roomAccessValidators,
addUserRoles,
canAccessRoom,
Expand Down
5 changes: 0 additions & 5 deletions app/authorization/server/lib/streamer.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/authorization/server/methods/addUserToRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import _ from 'underscore';

import { Users, Roles } from '../../../models/server';
import { settings } from '../../../settings/server';
import { Notifications } from '../../../notifications/server';
import { hasPermission } from '../functions/hasPermission';
import { api } from '../../../../server/sdk/api';

Meteor.methods({
'authorization:addUserToRole'(roleName, username, scope) {
Expand Down Expand Up @@ -50,7 +50,7 @@ Meteor.methods({
const add = Roles.addUserRoles(user._id, roleName, scope);

if (settings.get('UI_DisplayRoles')) {
Notifications.notifyLogged('roles-change', {
api.broadcast('user.roleUpdate', {
type: 'added',
_id: roleName,
u: {
Expand Down
Loading