Skip to content

Commit

Permalink
Merge pull request #5 from RocketChat/develop
Browse files Browse the repository at this point in the history
update branch
  • Loading branch information
gsunit authored Apr 13, 2019
2 parents 9217ebf + d5c14f7 commit 12812ab
Show file tree
Hide file tree
Showing 287 changed files with 6,886 additions and 3,621 deletions.
63 changes: 54 additions & 9 deletions .scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,45 @@
const path = require('path');
const fs = require('fs');
const extend = require('util')._extend;
const { exec } = require('child_process');
const { spawn } = require('child_process');
const net = require('net');
const processes = [];
let exitCode;

const baseDir = path.resolve(__dirname, '..');
const srcDir = path.resolve(baseDir);

const isPortTaken = (port) => new Promise((resolve, reject) => {
const tester = net.createServer()
.once('error', (err) => (err.code === 'EADDRINUSE' ? resolve(true) : reject(err)))
.once('listening', () => tester.once('close', () => resolve(false)).close())
.listen(port);
});

const waitPortRelease = (port) => new Promise((resolve, reject) => {
isPortTaken(port).then((taken) => {
if (!taken) {
return resolve();
}
setTimeout(() => {
waitPortRelease(port).then(resolve).catch(reject);
}, 1000);
});
});

const appOptions = {
env: {
PORT: 3000,
ROOT_URL: 'http://localhost:3000',
// MONGO_URL: 'mongodb://localhost:27017/test',
// MONGO_OPLOG_URL: 'mongodb://localhost:27017/local',
},
};

function startProcess(opts, callback) {
const proc = exec(
const proc = spawn(
opts.command,
opts.params,
opts.options
);

Expand All @@ -43,20 +66,39 @@ function startProcess(opts, callback) {
proc.stderr.pipe(logStream);
}

proc.on('close', function(code) {
console.log(opts.name, `exited with code ${ code }`);
for (let i = 0; i < processes.length; i += 1) {
processes[i].kill();
proc.on('exit', function(code, signal) {
if (code != null) {
exitCode = code;
console.log(opts.name, `exited with code ${ code }`);
} else {
console.log(opts.name, `exited with signal ${ signal }`);
}

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

processes.forEach((p) => p.kill());

if (processes.length === 0) {
waitPortRelease(appOptions.env.PORT).then(() => {
console.log(`Port ${ appOptions.env.PORT } was released, exiting with code ${ exitCode }`);
process.exit(exitCode);
}).catch((error) => {
console.error(`Error waiting port ${ appOptions.env.PORT } to be released, exiting with code ${ exitCode }`);
console.error(error);
process.exit(exitCode);
});
}
process.exit(code);
});
processes.push(proc);
}

function startApp(callback) {
startProcess({
name: 'Meteor App',
command: 'node /tmp/build-test/bundle/main.js',
command: 'node',
params: ['/tmp/build-test/bundle/main.js'],
// command: 'node',
// params: ['.meteor/local/build/main.js'],
waitForMessage: appOptions.waitForMessage,
options: {
cwd: srcDir,
Expand All @@ -68,7 +110,10 @@ function startApp(callback) {
function startChimp() {
startProcess({
name: 'Chimp',
command: 'npm run chimp-test',
command: 'npm',
params: ['run', 'chimp-test'],
// command: 'exit',
// params: ['2'],
options: {
env: Object.assign({}, process.env, {
NODE_PATH: `${ process.env.NODE_PATH +
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Testing with [BrowserStack](https://www.browserstack.com)

Rocket.Chat will be free forever, but you can help us speed up the development!

[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZL94ZE6LGVUSN)
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9MT88JJ9X4A6U&source=url)


[BountySource](https://www.bountysource.com/teams/rocketchat)
13 changes: 8 additions & 5 deletions app/action-links/client/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';
import { handleError } from '../../utils';
import { fireGlobalEvent, Layout } from '../../ui-utils';
import { messageArgs } from '../../ui-utils/client/lib/messageArgs';
import { actionLinks } from '../both/lib/actionLinks';



Template.room.events({
'click .action-link'(event, instance) {
event.preventDefault();
event.stopPropagation();

const data = Blaze.getData(event.currentTarget);

const { msg } = messageArgs(data);
if (Layout.isEmbedded()) {
return fireGlobalEvent('click-action-link', {
actionlink: $(event.currentTarget).data('actionlink'),
value: data._arguments[1]._id,
message: data._arguments[1],
value: msg._id,
message: msg,
});
}

if (data && data._arguments && data._arguments[1] && data._arguments[1]._id) {
actionLinks.run($(event.currentTarget).data('actionlink'), data._arguments[1]._id, instance, (err) => {
if (msg._id) {
actionLinks.run($(event.currentTarget).data('actionlink'), msg._id, instance, (err) => {
if (err) {
handleError(err);
}
Expand Down
4 changes: 2 additions & 2 deletions app/api/server/helpers/deprecationWarning.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { API } from '../api';

API.helperMethods.set('deprecationWarning', function _deprecationWarning({ endpoint, versionWillBeRemove, response }) {
const warningMessage = `The endpoint "${ endpoint }" is deprecated and will be removed after version ${ versionWillBeRemove }`;
API.helperMethods.set('deprecationWarning', function _deprecationWarning({ endpoint, versionWillBeRemoved, response }) {
const warningMessage = `The endpoint "${ endpoint }" is deprecated and will be removed after version ${ versionWillBeRemoved }`;
console.warn(warningMessage);
if (process.env.NODE_ENV === 'development') {
return {
Expand Down
40 changes: 39 additions & 1 deletion app/api/server/v1/emoji-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,50 @@ import { EmojiCustom } from '../../../models';
import { API } from '../api';
import Busboy from 'busboy';

// DEPRECATED
// Will be removed after v1.12.0
API.v1.addRoute('emoji-custom', { authRequired: true }, {
get() {
const warningMessage = 'The endpoint "emoji-custom" is deprecated and will be removed after version v1.12.0';
console.warn(warningMessage);
const { query } = this.parseJsonQuery();
const emojis = Meteor.call('listEmojiCustom', query);

return API.v1.success({ emojis });
return API.v1.success(this.deprecationWarning({
endpoint: 'emoji-custom',
versionWillBeRemoved: '1.12.0',
response: {
emojis,
},
}));
},
});

API.v1.addRoute('emoji-custom.list', { authRequired: true }, {
get() {
const { query } = this.parseJsonQuery();
const { updatedSince } = this.queryParams;
let updatedSinceDate;
if (updatedSince) {
if (isNaN(Date.parse(updatedSince))) {
throw new Meteor.Error('error-roomId-param-invalid', 'The "updatedSince" query parameter must be a valid date.');
} else {
updatedSinceDate = new Date(updatedSince);
}
return API.v1.success({
emojis: {
update: EmojiCustom.find({ ...query, _updatedAt: { $gt: updatedSinceDate } }).fetch(),
remove: EmojiCustom.trashFindDeletedAfter(updatedSinceDate).fetch(),
},
});
}

return API.v1.success({
emojis: {
update: EmojiCustom.find(query).fetch(),
remove: [],
},
});
},
});

Expand Down
53 changes: 40 additions & 13 deletions app/api/server/v1/groups.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
import _ from 'underscore';

import { Meteor } from 'meteor/meteor';
import { Subscriptions, Rooms, Messages, Uploads, Integrations, Users } from '../../../models';
import { hasPermission } from '../../../authorization';
import { composeMessageObjectWithUser } from '../../../utils';

import { Subscriptions, Rooms, Messages, Uploads, Integrations, Users } from '../../../models/server';
import { hasPermission, canAccessRoom } from '../../../authorization/server';
import { composeMessageObjectWithUser } from '../../../utils/server';

import { API } from '../api';
import _ from 'underscore';

// Returns the private group subscription IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
function findPrivateGroupByIdOrName({ params, userId, checkedArchived = true }) {
if ((!params.roomId || !params.roomId.trim()) && (!params.roomName || !params.roomName.trim())) {
throw new Meteor.Error('error-room-param-not-provided', 'The parameter "roomId" or "roomName" is required');
}

let roomSub;
if (params.roomId) {
roomSub = Subscriptions.findOneByRoomIdAndUserId(params.roomId, userId);
} else if (params.roomName) {
roomSub = Subscriptions.findOneByRoomNameAndUserId(params.roomName, userId);
const roomOptions = {
fields: {
t: 1,
ro: 1,
name: 1,
fname: 1,
prid: 1,
archived: 1,
},
};
const room = params.roomId ?
Rooms.findOneById(params.roomId, roomOptions) :
Rooms.findOneByName(params.roomName, roomOptions);

if (!room || room.t !== 'p') {
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
}

if (!roomSub || roomSub.t !== 'p') {
const user = Users.findOneById(userId, { fields: { username: 1 } });

if (!canAccessRoom(room, user)) {
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
}

if (checkedArchived && roomSub.archived) {
throw new Meteor.Error('error-room-archived', `The private group, ${ roomSub.name }, is archived`);
// discussions have their names saved on `fname` property
const roomName = room.prid ? room.fname : room.name;

if (checkedArchived && room.archived) {
throw new Meteor.Error('error-room-archived', `The private group, ${ roomName }, is archived`);
}

return roomSub;
const sub = Subscriptions.findOneByRoomIdAndUserId(room._id, userId, { fields: { open: 1 } });

return {
rid: room._id,
open: sub && sub.open,
ro: room.ro,
t: room.t,
name: roomName,
};
}

API.v1.addRoute('groups.addAll', { authRequired: true }, {
Expand Down
72 changes: 46 additions & 26 deletions app/api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,35 @@ import { Users } from '../../../models';
import { settings } from '../../../settings';
import { API } from '../api';

import s from 'underscore.string';

// DEPRECATED
// Will be removed after v1.12.0
API.v1.addRoute('info', { authRequired: false }, {
get() {
const warningMessage = 'The endpoint "/v1/info" is deprecated and will be removed after version v1.12.0';
console.warn(warningMessage);
const user = this.getLoggedInUser();

if (user && hasRole(user._id, 'admin')) {
return API.v1.success({
info: Info,
});
return API.v1.success(this.deprecationWarning({
endpoint: 'info',
versionWillBeRemoved: '1.12.0',
response: {
info: Info,
},
}));
}

return API.v1.success({
info: {
version: Info.version,
return API.v1.success(this.deprecationWarning({
endpoint: 'info',
versionWillBeRemoved: '1.12.0',
response: {
info: {
version: Info.version,
},
},
});
}));
},
});

Expand All @@ -36,7 +50,8 @@ let onlineCacheDate = 0;
const cacheInvalid = 60000; // 1 minute
API.v1.addRoute('shield.svg', { authRequired: false }, {
get() {
const { type, channel, name, icon } = this.queryParams;
const { type, icon } = this.queryParams;
let { channel, name } = this.queryParams;
if (!settings.get('API_Enable_Shields')) {
throw new Meteor.Error('error-endpoint-disabled', 'This endpoint is disabled', { route: '/api/v1/shield.svg' });
}
Expand Down Expand Up @@ -102,29 +117,34 @@ API.v1.addRoute('shield.svg', { authRequired: false }, {
const rightSize = text.length * 6 + 20;
const width = leftSize + rightSize;
const height = 20;

channel = s.escapeHTML(channel);
text = s.escapeHTML(text);
name = s.escapeHTML(name);

return {
headers: { 'Content-Type': 'image/svg+xml;charset=utf-8' },
body: `
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${ width }" height="${ height }">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="a">
<rect width="${ width }" height="${ height }" rx="3" fill="#fff"/>
</mask>
<g mask="url(#a)">
<path fill="#555" d="M0 0h${ leftSize }v${ height }H0z"/>
<path fill="${ backgroundColor }" d="M${ leftSize } 0h${ rightSize }v${ height }H${ leftSize }z"/>
<path fill="url(#b)" d="M0 0h${ width }v${ height }H0z"/>
</g>
${ hideIcon ? '' : '<image x="5" y="3" width="14" height="14" xlink:href="/assets/favicon.svg"/>' }
<g fill="#fff" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="a">
<rect width="${ width }" height="${ height }" rx="3" fill="#fff"/>
</mask>
<g mask="url(#a)">
<path fill="#555" d="M0 0h${ leftSize }v${ height }H0z"/>
<path fill="${ backgroundColor }" d="M${ leftSize } 0h${ rightSize }v${ height }H${ leftSize }z"/>
<path fill="url(#b)" d="M0 0h${ width }v${ height }H0z"/>
</g>
${ hideIcon ? '' : '<image x="5" y="3" width="14" height="14" xlink:href="/assets/favicon.svg"/>' }
<g fill="#fff" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
${ name ? `<text x="${ iconSize }" y="15" fill="#010101" fill-opacity=".3">${ name }</text>
<text x="${ iconSize }" y="14">${ name }</text>` : '' }
<text x="${ leftSize + 7 }" y="15" fill="#010101" fill-opacity=".3">${ text }</text>
<text x="${ leftSize + 7 }" y="14">${ text }</text>
</g>
<text x="${ iconSize }" y="14">${ name }</text>` : '' }
<text x="${ leftSize + 7 }" y="15" fill="#010101" fill-opacity=".3">${ text }</text>
<text x="${ leftSize + 7 }" y="14">${ text }</text>
</g>
</svg>
`.trim().replace(/\>[\s]+\</gm, '><'),
};
Expand Down
2 changes: 1 addition & 1 deletion app/api/server/v1/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ API.v1.addRoute('permissions.list', { authRequired: true }, {

return API.v1.success(this.deprecationWarning({
endpoint: 'permissions.list',
versionWillBeRemove: '0.85',
versionWillBeRemoved: '0.85',
response: {
permissions: result,
},
Expand Down
Loading

0 comments on commit 12812ab

Please sign in to comment.