Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into thre…
Browse files Browse the repository at this point in the history
…adMessagePreview

* 'develop' of github.com:RocketChat/Rocket.Chat: (29 commits)
  [FIX] Pinned Message display cutting off information (#25535)
  Chore: Dependencies upgrade (#25290)
  Chore: bump fuselage (#25605)
  [NEW] Federation (Alpha Stabilization) (#25457)
  Chore: Convert to typescript some functions from app/lib/server/functions (#24519)
  [NEW] Add option to show mentions badge when show counter is disabled (#25329)
  [FIX] Fixing Network connectivity issues with SIP client. (#25391)
  [FIX] Ordered and unordered list styles, Line breaks. (#25494)
  Chore: Convert slashCommands to typescript (#25592)
  [NEW] Get user's preferred language via apps (#25514)
  [NEW] Star message, report and delete message events (#25383)
  [NEW] Add new events after user login, logout and change his status (#25234)
  [NEW] Add new app events for pin, react and follow message (#25337)
  Chore: Convert AutoTranslate (#25591)
  Chore: Migrate retention-policy to ts (#25582)
  Chore: Convert to typescript the slash commands help files (#24307)
  Chore: Convert Create Channel (#25589)
  Chore: Convert additionalForms (#25586)
  Chore: Rewrite autotranslate to ts (#25425)
  [NEW] Add user events for apps (#25165)
  ...
  • Loading branch information
gabriellsh committed May 23, 2022
2 parents fb31655 + 8c75345 commit a0278a2
Show file tree
Hide file tree
Showing 284 changed files with 6,624 additions and 4,021 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"changeProcessCWD": true
}
],
"typescript.tsdk": "./node_modules/typescript/lib"
"typescript.tsdk": "./node_modules/typescript/lib",
"cSpell.words": ["photoswipe"]
}
2 changes: 1 addition & 1 deletion _templates/package/new/package.json.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ to: packages/<%= name %>/package.json
"eslint": "^8.12.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typescript": "~4.3.5"
"typescript": "~4.3.4"
},
"scripts": {
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ spacebars
standard-minifier-js@2.8.0
tracker@1.2.0

#rocketchat:google-natural-language
rocketchat:livechat
rocketchat:streamer
rocketchat:version
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/lib/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const findOneIntegration = async ({
}: {
userId: string;
integrationId: string;
createdBy: IUser;
createdBy?: IUser['_id'];
}): Promise<IIntegration> => {
const integration = await Integrations.findOneByIdAndCreatedByIfExists({
_id: integrationId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { IIntegration } from '@rocket.chat/core-typings';
import {
isIntegrationsCreateProps,
isIntegrationsHistoryProps,
isIntegrationsRemoveProps,
isIntegrationsGetProps,
isIntegrationsUpdateProps,
} from '@rocket.chat/rest-typings';

import { hasAtLeastOnePermission } from '../../../authorization/server';
import { Integrations, IntegrationHistory } from '../../../models/server/raw';
Expand All @@ -12,45 +20,32 @@ import { findOneIntegration } from '../lib/integrations';

API.v1.addRoute(
'integrations.create',
{ authRequired: true },
{ authRequired: true, validateParams: isIntegrationsCreateProps },
{
post() {
check(
this.bodyParams,
Match.ObjectIncluding({
type: String,
name: String,
enabled: Boolean,
username: String,
urls: Match.Maybe([String]),
channel: String,
event: Match.Maybe(String),
triggerWords: Match.Maybe([String]),
alias: Match.Maybe(String),
avatar: Match.Maybe(String),
emoji: Match.Maybe(String),
token: Match.Maybe(String),
scriptEnabled: Boolean,
script: Match.Maybe(String),
targetChannel: Match.Maybe(String),
}),
);

let integration;

switch (this.bodyParams.type) {
case 'webhook-outgoing':
Meteor.runAsUser(this.userId, () => {
integration = Meteor.call('addOutgoingIntegration', this.bodyParams);
});
break;
case 'webhook-incoming':
Meteor.runAsUser(this.userId, () => {
integration = Meteor.call('addIncomingIntegration', this.bodyParams);
});
break;
default:
return API.v1.failure('Invalid integration type.');
const { userId, bodyParams } = this;

const integration = ((): IIntegration | undefined => {
let integration: IIntegration | undefined;

switch (bodyParams.type) {
case 'webhook-outgoing':
Meteor.runAsUser(userId, () => {
integration = Meteor.call('addOutgoingIntegration', bodyParams);
});
break;
case 'webhook-incoming':
Meteor.runAsUser(userId, () => {
integration = Meteor.call('addIncomingIntegration', bodyParams);
});
break;
}

return integration;
})();

if (!integration) {
return API.v1.failure('Invalid integration type.');
}

return API.v1.success({ integration });
Expand All @@ -60,21 +55,23 @@ API.v1.addRoute(

API.v1.addRoute(
'integrations.history',
{ authRequired: true },
{ authRequired: true, validateParams: isIntegrationsHistoryProps },
{
get() {
if (!hasAtLeastOnePermission(this.userId, ['manage-outgoing-integrations', 'manage-own-outgoing-integrations'])) {
const { userId, queryParams } = this;

if (!hasAtLeastOnePermission(userId, ['manage-outgoing-integrations', 'manage-own-outgoing-integrations'])) {
return API.v1.unauthorized();
}

if (!this.queryParams.id || this.queryParams.id.trim() === '') {
if (!queryParams.id || queryParams.id.trim() === '') {
return API.v1.failure('Invalid integration id.');
}

const { id } = this.queryParams;
const { id } = queryParams;
const { offset, count } = this.getPaginationItems();
const { sort, fields: projection, query } = this.parseJsonQuery();
const ourQuery = Object.assign(mountIntegrationHistoryQueryBasedOnPermissions(this.userId, id), query);
const ourQuery = Object.assign(mountIntegrationHistoryQueryBasedOnPermissions(userId, id), query);

const cursor = IntegrationHistory.find(ourQuery, {
sort: sort || { _updatedAt: -1 },
Expand All @@ -90,6 +87,7 @@ API.v1.addRoute(
history,
offset,
items: history.length,
count: history.length,
total,
});
},
Expand Down Expand Up @@ -131,6 +129,7 @@ API.v1.addRoute(
integrations,
offset,
items: integrations.length,
count: integrations.length,
total,
});
},
Expand All @@ -139,7 +138,7 @@ API.v1.addRoute(

API.v1.addRoute(
'integrations.remove',
{ authRequired: true },
{ authRequired: true, validateParams: isIntegrationsRemoveProps },
{
post() {
if (
Expand All @@ -153,48 +152,51 @@ API.v1.addRoute(
return API.v1.unauthorized();
}

check(
this.bodyParams,
Match.ObjectIncluding({
type: String,
target_url: Match.Maybe(String),
integrationId: Match.Maybe(String),
}),
);

if (!this.bodyParams.target_url && !this.bodyParams.integrationId) {
return API.v1.failure('An integrationId or target_url needs to be provided.');
}
const { bodyParams } = this;

let integration;
switch (this.bodyParams.type) {
let integration: IIntegration | null = null;
switch (bodyParams.type) {
case 'webhook-outgoing':
if (this.bodyParams.target_url) {
integration = Promise.await(Integrations.findOne({ urls: this.bodyParams.target_url }));
} else if (this.bodyParams.integrationId) {
integration = Promise.await(Integrations.findOne({ _id: this.bodyParams.integrationId }));
if (!bodyParams.target_url && !bodyParams.integrationId) {
return API.v1.failure('An integrationId or target_url needs to be provided.');
}

if (bodyParams.target_url) {
integration = Promise.await(Integrations.findOne({ urls: bodyParams.target_url }));
} else if (bodyParams.integrationId) {
integration = Promise.await(Integrations.findOne({ _id: bodyParams.integrationId }));
}

if (!integration) {
return API.v1.failure('No integration found.');
}

const outgoingId = integration._id;

Meteor.runAsUser(this.userId, () => {
Meteor.call('deleteOutgoingIntegration', integration._id);
Meteor.call('deleteOutgoingIntegration', outgoingId);
});

return API.v1.success({
integration,
});
case 'webhook-incoming':
integration = Promise.await(Integrations.findOne({ _id: this.bodyParams.integrationId }));
check(
bodyParams,
Match.ObjectIncluding({
integrationId: String,
}),
);

integration = Promise.await(Integrations.findOne({ _id: bodyParams.integrationId }));

if (!integration) {
return API.v1.failure('No integration found.');
}

const incomingId = integration._id;
Meteor.runAsUser(this.userId, () => {
Meteor.call('deleteIncomingIntegration', integration._id);
Meteor.call('deleteIncomingIntegration', incomingId);
});

return API.v1.success({
Expand All @@ -209,7 +211,7 @@ API.v1.addRoute(

API.v1.addRoute(
'integrations.get',
{ authRequired: true },
{ authRequired: true, validateParams: isIntegrationsGetProps },
{
get() {
const { integrationId, createdBy } = this.queryParams;
Expand All @@ -232,58 +234,37 @@ API.v1.addRoute(

API.v1.addRoute(
'integrations.update',
{ authRequired: true },
{ authRequired: true, validateParams: isIntegrationsUpdateProps },
{
put() {
check(
this.bodyParams,
Match.ObjectIncluding({
type: String,
name: String,
enabled: Boolean,
username: String,
urls: Match.Maybe([String]),
channel: String,
event: Match.Maybe(String),
triggerWords: Match.Maybe([String]),
alias: Match.Maybe(String),
avatar: Match.Maybe(String),
emoji: Match.Maybe(String),
token: Match.Maybe(String),
scriptEnabled: Boolean,
script: Match.Maybe(String),
targetChannel: Match.Maybe(String),
integrationId: Match.Maybe(String),
target_url: Match.Maybe(String),
}),
);
const { bodyParams } = this;

let integration;
switch (this.bodyParams.type) {
switch (bodyParams.type) {
case 'webhook-outgoing':
if (this.bodyParams.target_url) {
integration = Promise.await(Integrations.findOne({ urls: this.bodyParams.target_url }));
} else if (this.bodyParams.integrationId) {
integration = Promise.await(Integrations.findOne({ _id: this.bodyParams.integrationId }));
if (bodyParams.target_url) {
integration = Promise.await(Integrations.findOne({ urls: bodyParams.target_url }));
} else if (bodyParams.integrationId) {
integration = Promise.await(Integrations.findOne({ _id: bodyParams.integrationId }));
}

if (!integration) {
return API.v1.failure('No integration found.');
}

Meteor.call('updateOutgoingIntegration', integration._id, this.bodyParams);
Meteor.call('updateOutgoingIntegration', integration._id, bodyParams);

return API.v1.success({
integration: Promise.await(Integrations.findOne({ _id: integration._id })),
});
case 'webhook-incoming':
integration = Promise.await(Integrations.findOne({ _id: this.bodyParams.integrationId }));
integration = Promise.await(Integrations.findOne({ _id: bodyParams.integrationId }));

if (!integration) {
return API.v1.failure('No integration found.');
}

Meteor.call('updateIncomingIntegration', integration._id, this.bodyParams);
Meteor.call('updateIncomingIntegration', integration._id, bodyParams);

return API.v1.success({
integration: Promise.await(Integrations.findOne({ _id: integration._id })),
Expand Down
Loading

0 comments on commit a0278a2

Please sign in to comment.