Skip to content

Commit

Permalink
Merge branch 'chore/refactor-register-username' of github.com:RocketC…
Browse files Browse the repository at this point in the history
…hat/Rocket.Chat into chore/refactor-register-username
  • Loading branch information
ggazzo committed Mar 13, 2023
2 parents 66f4c8d + 911f177 commit 2c7fb58
Show file tree
Hide file tree
Showing 58 changed files with 922 additions and 587 deletions.
15 changes: 9 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!-- This is a pull request template, you do not need to uncomment or remove the comments, they won't show up in the PR text. -->

<!-- Your Pull Request name should start with one of the following tags
[NEW] For new features
[IMPROVE] For an improvement (performance or little improvements) in existing features
[FIX] For bug fixes that affect the end-user
[BREAK] For pull requests including breaking changes
Chore: For small tasks
Doc: For documentation
feat: Adding a new feature
refactor: A code change that doesn't change behavior (it doesn't add anything and doesn't fix anything)
fix: For bug fixes that affect the end-user
chore: For small tasks
docs: For documentation
ci: For updating CI configuration
test: For adding tests
i18n: For updating any translations
regression: Issues created/reported/fixed during the development phase. kind of problem that never existed in production and that we don't need to list in a changelog for the end user
-->

<!-- Checklist!!! If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/.eslintcache

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions apps/meteor/app/api/server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { hasPermission } from '../../authorization/server';
import { getDefaultUserFields } from '../../utils/server/functions/getDefaultUserFields';
import { checkCodeForUser } from '../../2fa/server/code';
import { checkPermissionsForInvocation, checkPermissions } from './api.helpers';
import { isObject } from '../../../lib/utils/isObject';

const logger = new Logger('API');

Expand Down Expand Up @@ -125,7 +126,7 @@ export class APIClass extends Restivus {
}

success(result = {}) {
if (_.isObject(result)) {
if (isObject(result)) {
result.success = true;
}

Expand All @@ -138,7 +139,7 @@ export class APIClass extends Restivus {
}

failure(result, errorType, stack, error) {
if (_.isObject(result)) {
if (isObject(result)) {
result.success = false;
} else {
result = {
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/app/bot-helpers/server/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import './settings';
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';

import { Users, Rooms } from '../../models/server';
import { settings } from '../../settings/server';
import { hasRole } from '../../authorization/server';
import { isObject } from '../../../lib/utils/isObject';
import './settings';

/**
* BotHelpers helps bots
Expand Down Expand Up @@ -54,7 +54,7 @@ class BotHelpers {
addUserToRoom(userName, room) {
const foundRoom = Rooms.findOneByIdOrName(room);

if (!_.isObject(foundRoom)) {
if (!isObject(foundRoom)) {
throw new Meteor.Error('invalid-channel');
}

Expand All @@ -67,7 +67,7 @@ class BotHelpers {
removeUserFromRoom(userName, room) {
const foundRoom = Rooms.findOneByIdOrName(room);

if (!_.isObject(foundRoom)) {
if (!isObject(foundRoom)) {
throw new Meteor.Error('invalid-channel');
}
const data = {};
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/custom-oauth/server/transform_helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'underscore';
import { isObject } from '../../../lib/utils/isObject';

export const normalizers = {
// Set 'id' to '_id' for any sources that provide it
Expand Down Expand Up @@ -106,7 +106,7 @@ export const renameInvalidProperties = (input) => {
if (Array.isArray(input)) {
return input.map(renameInvalidProperties);
}
if (!_.isObject(input)) {
if (!isObject(input)) {
return input;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';
import type { IRoom, IUser, RoomType } from '@rocket.chat/core-typings';

import { Rooms, Users, Subscriptions } from '../../../models/server';
import { isObject } from '../../../../lib/utils/isObject';

export const getRoomByNameOrIdWithOptionToJoin = ({
currentUserId = '',
Expand Down Expand Up @@ -38,14 +38,14 @@ export const getRoomByNameOrIdWithOptionToJoin = ({
});
}

const rid = _.isObject(roomUser) ? [currentUserId, roomUser._id].sort().join('') : nameOrId;
const rid = isObject(roomUser) ? [currentUserId, roomUser._id].sort().join('') : nameOrId;
room = Rooms.findOneById(rid);

// If the room hasn't been found yet, let's try some more
if (!_.isObject(room)) {
if (!isObject(room)) {
// If the roomUser wasn't found, then there's no destination to point towards
// so return out based upon errorOnEmpty
if (!_.isObject(roomUser)) {
if (!isObject(roomUser)) {
if (errorOnEmpty) {
throw new Meteor.Error('invalid-channel');
} else {
Expand Down
12 changes: 7 additions & 5 deletions apps/meteor/app/livechat/imports/server/rest/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { OmnichannelSourceType } from '@rocket.chat/core-typings';
import { LivechatVisitors } from '@rocket.chat/models';
import { OmnichannelIntegration } from '@rocket.chat/core-services';

import { FileUpload } from '../../../../file-upload/server';
import { LivechatRooms, LivechatDepartment } from '../../../../models/server';
import { API } from '../../../../api/server';
import { fetch } from '../../../../../server/lib/http/fetch';
import { SMS } from '../../../../sms/server';
import { Livechat } from '../../../server/lib/Livechat';
import { settings } from '../../../../settings/server';

const getUploadFile = async (details, fileUrl) => {
const response = await fetch(fileUrl);
Expand Down Expand Up @@ -72,16 +73,17 @@ const normalizeLocationSharing = (payload) => {

API.v1.addRoute('livechat/sms-incoming/:service', {
async post() {
if (!SMS.isConfiguredService(this.urlParams.service)) {
if (!(await OmnichannelIntegration.isConfiguredSmsService(this.urlParams.service))) {
return API.v1.failure('Invalid service');
}

const SMSService = SMS.getService(this.urlParams.service);
const smsDepartment = settings.get('SMS_Default_Omnichannel_Department');
const SMSService = await OmnichannelIntegration.getSmsService(this.urlParams.service);
const sms = SMSService.parse(this.bodyParams);
const { department } = this.queryParams;
let targetDepartment = defineDepartment(department || SMS.department);
let targetDepartment = defineDepartment(department || smsDepartment);
if (!targetDepartment) {
targetDepartment = defineDepartment(SMS.department);
targetDepartment = defineDepartment(smsDepartment);
}

const visitor = await defineVisitor(sms.from, targetDepartment);
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/v1/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { addUserToRoom } from '../../../../lib/server/functions';
import { apiDeprecationLogger } from '../../../../lib/server/lib/deprecationWarningLogger';
import { deprecationWarning } from '../../../../api/server/helpers/deprecationWarning';
import { callbacks } from '../../../../../lib/callbacks';
import type { CloseRoomParams } from '../../lib/LivechatTyped.d';
import type { CloseRoomParams } from '../../lib/LivechatTyped';

const isAgentWithInfo = (agentObj: ILivechatAgent | { hiddenInfo: true }): agentObj is ILivechatAgent => !('hiddenInfo' in agentObj);

Expand Down
164 changes: 164 additions & 0 deletions apps/meteor/app/livechat/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,4 +616,168 @@ Meteor.startup(function () {
enableQuery: omnichannelEnabledQuery,
});
});
settingsRegistry.addGroup('SMS', function () {
this.add('SMS_Enabled', false, {
type: 'boolean',
i18nLabel: 'Enabled',
});

this.add('SMS_Service', 'twilio', {
type: 'select',
values: [
{
key: 'twilio',
i18nLabel: 'Twilio',
},
{
key: 'voxtelesys',
i18nLabel: 'Voxtelesys',
},
{
key: 'mobex',
i18nLabel: 'Mobex',
},
],
i18nLabel: 'Service',
});

this.add('SMS_Default_Omnichannel_Department', '', {
type: 'string',
});

this.section('Twilio', function () {
this.add('SMS_Twilio_Account_SID', '', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'twilio',
},
i18nLabel: 'Account_SID',
secret: true,
});
this.add('SMS_Twilio_authToken', '', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'twilio',
},
i18nLabel: 'Auth_Token',
secret: true,
});
this.add('SMS_Twilio_FileUpload_Enabled', true, {
type: 'boolean',
enableQuery: {
_id: 'SMS_Service',
value: 'twilio',
},
i18nLabel: 'FileUpload_Enabled',
secret: true,
});
this.add('SMS_Twilio_FileUpload_MediaTypeWhiteList', 'image/*,audio/*,video/*,text/*,application/pdf', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'twilio',
},
i18nLabel: 'FileUpload_MediaTypeWhiteList',
i18nDescription: 'FileUpload_MediaTypeWhiteListDescription',
secret: true,
});
});

this.section('Voxtelesys', function () {
this.add('SMS_Voxtelesys_authToken', '', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'voxtelesys',
},
i18nLabel: 'Auth_Token',
secret: true,
});
this.add('SMS_Voxtelesys_URL', 'https://smsapi.voxtelesys.net/api/v1/sms', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'voxtelesys',
},
i18nLabel: 'URL',
secret: true,
});
this.add('SMS_Voxtelesys_FileUpload_Enabled', true, {
type: 'boolean',
enableQuery: {
_id: 'SMS_Service',
value: 'voxtelesys',
},
i18nLabel: 'FileUpload_Enabled',
secret: true,
});
this.add('SMS_Voxtelesys_FileUpload_MediaTypeWhiteList', 'image/*,audio/*,video/*,text/*,application/pdf', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'voxtelesys',
},
i18nLabel: 'FileUpload_MediaTypeWhiteList',
i18nDescription: 'FileUpload_MediaTypeWhiteListDescription',
secret: true,
});
});

this.section('Mobex', function () {
this.add('SMS_Mobex_gateway_address', '', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'mobex',
},
i18nLabel: 'Mobex_sms_gateway_address',
i18nDescription: 'Mobex_sms_gateway_address_desc',
});
this.add('SMS_Mobex_restful_address', '', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'mobex',
},
i18nLabel: 'Mobex_sms_gateway_restful_address',
i18nDescription: 'Mobex_sms_gateway_restful_address_desc',
});
this.add('SMS_Mobex_username', '', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'mobex',
},
i18nLabel: 'Mobex_sms_gateway_username',
});
this.add('SMS_Mobex_password', '', {
type: 'password',
enableQuery: {
_id: 'SMS_Service',
value: 'mobex',
},
i18nLabel: 'Mobex_sms_gateway_password',
});
this.add('SMS_Mobex_from_number', '', {
type: 'int',
enableQuery: {
_id: 'SMS_Service',
value: 'mobex',
},
i18nLabel: 'Mobex_sms_gateway_from_number',
i18nDescription: 'Mobex_sms_gateway_from_number_desc',
});
this.add('SMS_Mobex_from_numbers_list', '', {
type: 'string',
enableQuery: {
_id: 'SMS_Service',
value: 'mobex',
},
i18nLabel: 'Mobex_sms_gateway_from_numbers_list',
i18nDescription: 'Mobex_sms_gateway_from_numbers_list_desc',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LivechatRooms } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { Livechat } from '../lib/LivechatTyped';
import type { CloseRoomParams } from '../lib/LivechatTyped.d';
import type { CloseRoomParams } from '../lib/LivechatTyped';

type LivechatCloseCallbackParams = {
room: IOmnichannelRoom;
Expand Down
31 changes: 0 additions & 31 deletions apps/meteor/app/livechat/server/lib/LivechatTyped.d.ts

This file was deleted.

0 comments on commit 2c7fb58

Please sign in to comment.