Skip to content

Commit

Permalink
Merge branch 'develop' into improve/videoconf-configModal
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Nov 16, 2022
2 parents 8449f81 + ed63a76 commit e629047
Show file tree
Hide file tree
Showing 144 changed files with 2,972 additions and 1,585 deletions.
6 changes: 5 additions & 1 deletion apps/meteor/app/api/server/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,12 @@ API.v1.addRoute(
return API.v1.failure('Username is already in use');
}

const { secret: secretURL, ...params } = this.bodyParams;
// Register the user
const userId = Meteor.call('registerUser', this.bodyParams);
const userId = Meteor.call('registerUser', {
...params,
...(secretURL && { secretURL }),
});

// Now set their username
Meteor.runAsUser(userId, () => Meteor.call('setUsername', this.bodyParams.username));
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/server/bridges/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class AppSchedulerBridge extends SchedulerBridge {
}

private async scheduleOnceAfterRegister(job: IOnetimeSchedule, appId: string): Promise<void | string> {
const scheduledJobs = await this.scheduler.jobs({ name: job.id, type: 'normal' });
const scheduledJobs = await this.scheduler.jobs({ name: job.id, type: 'normal' }, {}, 1);
if (!scheduledJobs.length) {
return this.scheduleOnce(job, appId);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class AppsRestApi {
return API.v1.failure({ error: 'Invalid purchase type' });
}

const token = getUserCloudAccessToken(this.getLoggedInUser()._id, true, 'marketplace:purchase', false);
const token = await getUserCloudAccessToken(this.getLoggedInUser()._id, true, 'marketplace:purchase', false);
if (!token) {
return API.v1.failure({ error: 'Unauthorized' });
}
Expand Down
6 changes: 5 additions & 1 deletion apps/meteor/app/authentication/server/startup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ Accounts.onCreateUser(function (options, user = {}) {
to: destinations,
from: settings.get('From_Email'),
subject: Accounts.emailTemplates.userToActivate.subject(),
html: Accounts.emailTemplates.userToActivate.html(options),
html: Accounts.emailTemplates.userToActivate.html({
...options,
name: options.name || options.profile?.name,
email: options.email || user.emails[0].address,
}),
};

Mailer.send(email);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { HTTP } from 'meteor/http';
import { Users } from '@rocket.chat/models';
import type { IUser } from '@rocket.chat/core-typings';

import { getRedirectUri } from './getRedirectUri';
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';
import { unregisterWorkspace } from './unregisterWorkspace';
import { userLoggedOut } from './userLoggedOut';
import { Users } from '../../../models/server';
import { settings } from '../../../settings/server';
import { userScopes } from '../oauthScopes';
import { SystemLogger } from '../../../../server/lib/logger/system';

export function getUserCloudAccessToken(userId, forceNew = false, scope = '', save = true) {
export async function getUserCloudAccessToken(userId: string, forceNew = false, scope = '', save = true) {
const { connectToCloud, workspaceRegistered } = retrieveRegistrationStatus();

if (!connectToCloud || !workspaceRegistered) {
Expand All @@ -20,28 +21,30 @@ export function getUserCloudAccessToken(userId, forceNew = false, scope = '', sa
return '';
}

const user = Users.findOneById(userId);

if (!user || !user.services || !user.services.cloud || !user.services.cloud.accessToken || !user.services.cloud.refreshToken) {
const user = await Users.findOneById<Pick<IUser, '_id' | 'services'>>(userId, { projection: { 'services.cloud': 1 } });
if (!user?.services?.cloud?.accessToken || !user?.services?.cloud?.refreshToken) {
return '';
}

const { accessToken, refreshToken } = user.services.cloud;
const { accessToken, refreshToken, expiresAt } = user.services.cloud;

const clientId = settings.get<string>('Cloud_Workspace_Client_Id');
if (!clientId) {
return '';
}

const client_id = settings.get('Cloud_Workspace_Client_Id');
if (!client_id) {
const clientSecret = settings.get<string>('Cloud_Workspace_Client_Secret');
if (!clientSecret) {
return '';
}

const expires = user.services.cloud.expiresAt;
const now = new Date();

if (now < expires.value && !forceNew) {
if (now < expiresAt && !forceNew) {
return accessToken;
}

const cloudUrl = settings.get('Cloud_Url');
const client_secret = settings.get('Cloud_Workspace_Client_Secret');
const redirectUri = getRedirectUri();

if (scope === '') {
Expand All @@ -53,15 +56,15 @@ export function getUserCloudAccessToken(userId, forceNew = false, scope = '', sa
authTokenResult = HTTP.post(`${cloudUrl}/api/oauth/token`, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
params: {
client_id,
client_secret,
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
scope,
grant_type: 'refresh_token',
redirect_uri: redirectUri,
},
});
} catch (err) {
} catch (err: any) {
SystemLogger.error({
msg: 'Failed to get User AccessToken from Rocket.Chat Cloud',
url: '/api/oauth/token',
Expand All @@ -84,19 +87,20 @@ export function getUserCloudAccessToken(userId, forceNew = false, scope = '', sa
}

if (save) {
const expiresAt = new Date();
expiresAt.setSeconds(expiresAt.getSeconds() + authTokenResult.data.expires_in);

Users.update(user._id, {
$set: {
services: {
cloud: {
const willExpireAt = new Date();
willExpireAt.setSeconds(willExpireAt.getSeconds() + authTokenResult.data.expires_in);

await Users.updateOne(
{ _id: user._id },
{
$set: {
'services.cloud': {
accessToken: authTokenResult.data.access_token,
expiresAt,
expiresAt: willExpireAt,
},
},
},
});
);
}

return authTokenResult.data.access_token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function retrieveRegistrationStatus(): {
} {
const info = {
connectToCloud: settings.get<boolean>('Register_Server'),
workspaceRegistered: !!settings.get('Cloud_Workspace_Client_Id'),
workspaceRegistered: !!settings.get('Cloud_Workspace_Client_Id') && !!settings.get('Cloud_Workspace_Client_Secret'),
workspaceId: settings.get<string>('Cloud_Workspace_Id'),
uniqueId: settings.get<string>('uniqueID'),
token: '',
Expand Down
8 changes: 8 additions & 0 deletions apps/meteor/app/livechat/server/hooks/saveAnalyticsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { callbacks } from '../../../../lib/callbacks';
import { LivechatRooms } from '../../../models/server';
import { normalizeMessageFileUpload } from '../../../utils/server/functions/normalizeMessageFileUpload';
import { callbackLogger } from '../lib/callbackLogger';

callbacks.add(
'afterSaveMessage',
function (message, room) {
callbackLogger.debug(`Calculating Omnichannel metrics for room ${room._id}`);
// check if room is livechat
if (!isOmnichannelRoom(room)) {
return message;
Expand All @@ -19,6 +21,10 @@ callbacks.add(

// if the message has a token, it was sent by the visitor
if (message.token) {
// When visitor sends a mesage, most metrics wont be calculated/served.
// But, v.lq (last query) will be updated to the message time. This has to be done
// As not doing it will cause the metrics to be crazy and not have real values.
LivechatRooms.saveAnalyticsDataByRoomId(room, message);
return message;
}

Expand All @@ -37,6 +43,7 @@ callbacks.add(
const isResponseTotal = room.metrics && room.metrics.response && room.metrics.response.total;

if (agentLastReply === room.ts) {
callbackLogger.debug('Calculating: first message from agent');
// first response
const firstResponseDate = now;
const firstResponseTime = (now.getTime() - visitorLastQuery) / 1000;
Expand All @@ -58,6 +65,7 @@ callbacks.add(
reactionTime,
};
} else if (visitorLastQuery > agentLastReply) {
callbackLogger.debug('Calculating: visitor sent a message after agent');
// response, not first
const responseTime = (now.getTime() - visitorLastQuery) / 1000;
const avgResponseTime =
Expand Down
14 changes: 13 additions & 1 deletion apps/meteor/app/mail-messages/server/functions/sendMail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import { placeholders } from '../../../utils/server';
import { SystemLogger } from '../../../../server/lib/logger/system';
import * as Mailer from '../../../mailer';

export const sendMail = function (from: string, subject: string, body: string, dryrun: boolean, query: string): void {
export const sendMail = function ({
from,
subject,
body,
dryrun,
query,
}: {
from: string;
subject: string;
body: string;
dryrun?: boolean;
query?: string;
}): void {
Mailer.checkAddressFormatAndThrow(from, 'Mailer.sendMail');

if (body.indexOf('[unsubscribe]') === -1) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/mail-messages/server/methods/sendMail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Meteor.methods({
});
}

return Mailer.sendMail(from, subject, body, dryrun, query);
return Mailer.sendMail({ from, subject, body, dryrun, query });
},
});

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/slashcommand-asciiarts/lib/shrug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ slashCommands.add({
command: 'shrug',
callback: (_command: 'shrug', params, item): void => {
const msg = item;
msg.msg = `${params} ¯\\_(ツ)_/¯`;
msg.msg = `${params} ¯\\\\_(ツ)_/¯`;
Meteor.call('sendMessage', msg);
},
options: {
Expand Down
10 changes: 2 additions & 8 deletions apps/meteor/app/theme/client/imports/general/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ body {
-moz-osx-font-smoothing: grayscale;
}

@media (width <= 500px) {
body {
position: fixed;
}
}

:focus {
outline: 0 !important;
outline-style: none;
Expand All @@ -54,7 +48,7 @@ body {
display: table;
clear: both;

content: "";
content: '';
}
}

Expand Down Expand Up @@ -136,7 +130,7 @@ button {
width: 100%;
height: 1px;

content: "";
content: '';

animation-name: unread;
animation-duration: 0.2s;
Expand Down
Empty file removed apps/meteor/app/ui-login/README.md
Empty file.
9 changes: 0 additions & 9 deletions apps/meteor/app/ui-login/client/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions apps/meteor/app/ui-login/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './username/username.html';
import './username/username';
Loading

0 comments on commit e629047

Please sign in to comment.