Skip to content

Commit

Permalink
settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-lehnen-rc authored and dougfabris committed Apr 3, 2023
1 parent 0774e3f commit acc9bd5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 38 deletions.
19 changes: 13 additions & 6 deletions apps/meteor/client/lib/outlookCalendar/getOutlookEvents.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable new-cap */
import type { Appointment } from 'ews-js-api-browser';
import type { Appointment, IXHROptions } from 'ews-js-api-browser';
import {
ExchangeCredentials,
ExchangeService,
ExchangeVersion,
WebCredentials,
Uri,
FolderId,
CalendarView,
Expand All @@ -13,13 +13,20 @@ import {
BasePropertySet,
} from 'ews-js-api-browser';

// #ToDo: Remove this line
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
class TokenCredentials extends ExchangeCredentials {
constructor(private token: string) {
super('', '');
}

export const getOutlookEvents = async (date: Date, server: string, user: string, password: string): Promise<Appointment[]> => {
PrepareWebRequest(request: IXHROptions): void {
request.headers.Authorization = `Basic ${this.token}`;
}
}

export const getOutlookEvents = async (date: Date, server: string, token: string): Promise<Appointment[]> => {
const exchange = new ExchangeService(ExchangeVersion.Exchange2013);

exchange.Credentials = new WebCredentials(user, password);
exchange.Credentials = new TokenCredentials(token);
exchange.Url = new Uri(server);

const folderId = new FolderId(WellKnownFolderName.Calendar);
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/lib/outlookCalendar/syncOutlookEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import { APIClient } from '../../../app/utils/client/lib/RestApiClient';
import { getOutlookEvents } from './getOutlookEvents';

export const syncOutlookEvents = async (date: Date, server: string, user: string, password: string): Promise<void> => {
export const syncOutlookEvents = async (date: Date, server: string, token: string): Promise<void> => {
// Load all the event that are already on the calendar for today
const serverEvents = await APIClient.get('/v1/calendar-events.list', {
date: date.toISOString().substring(0, 10),
});
const externalEvents = serverEvents.data.filter(({ externalId }) => externalId);

const appointments = await getOutlookEvents(date, server, user, password);
const appointments = await getOutlookEvents(date, server, token);
const appointmentsFound = appointments.map((appointment) => appointment.Id.UniqueId);

for await (const appointment of appointments) {
Expand Down
27 changes: 1 addition & 26 deletions apps/meteor/ee/server/configuration/outlookCalendar.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
import { Meteor } from 'meteor/meteor';
// import { Users } from '@rocket.chat/models';

import { onLicense } from '../../app/license/server';
import { addSettings } from '../settings/outlookCalendar';
// import { settings } from '../../../app/settings/server';
// import { VirtualDataConverter } from '../../../app/importer/server/classes/VirtualDataConverter';

// async function maybeCreateOutlookBot() {
// // Create the outlook bot if it doesn't exist.
// const botUser = await Users.findOneById('outlook-calendar.bot');
// if (!botUser) {
// VirtualDataConverter.convertSingleUser({
// _id: 'outlook-calendar.bot',
// username: 'outlook-calendar.bot',
// emails: [],
// importIds: ['outlook-calendar.bot'],
// name: 'Outlook Calendar',
// type: 'bot',
// roles: ['bot'],
// });
// }
// }

Meteor.startup(() =>
onLicense('outlook-calendar', () => {
// addSettings();

// settings.watch('Outlook_Calendar_Enabled', (value) => {
// if (value) {
// maybeCreateOutlookBot();
// }
// });
addSettings();
}),
);
11 changes: 7 additions & 4 deletions apps/meteor/ee/server/settings/outlookCalendar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { settingsRegistry } from '../../../app/settings/server';

export function addSettings(): void {
settingsRegistry.addGroup('General', function () {
void settingsRegistry.addGroup('Outlook_Calendar', function () {
this.with(
{
enterprise: true,
Expand All @@ -12,17 +12,20 @@ export function addSettings(): void {
type: 'boolean',
public: true,
invalidValue: false,
hidden: true,
});

this.add('Outlook_Calendar_Exchange_Url', '', {
type: 'string',
public: true,
invalidValue: '',
hidden: true,
});

this.add('Outlook_Calendar_Outlook_Url', '', {
type: 'string',
public: true,
invalidValue: '',
});
},
);
});
}

4 changes: 4 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3758,6 +3758,10 @@
"Outgoing": "Outgoing",
"Outgoing_WebHook": "Outgoing WebHook",
"Outgoing_WebHook_Description": "Get data out of Rocket.Chat in real-time.",
"Outlook_Calendar": "Outlook Calendar",
"Outlook_Calendar_Enabled": "Enabled",
"Outlook_Calendar_Exchange_Url": "Exchange URL",
"Outlook_Calendar_Outlook_Url": "Outlook URL",
"Output_format": "Output format",
"Override_URL_to_which_files_are_uploaded_This_url_also_used_for_downloads_unless_a_CDN_is_given": "Override URL to which files are uploaded. This url also used for downloads unless a CDN is given",
"Owner": "Owner",
Expand Down

0 comments on commit acc9bd5

Please sign in to comment.