Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing (almost) every dynamic imports #13767

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/apps/server/bridges/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { Messages, Users, Subscriptions } from '../../../models';
import { Notifications } from '../../../notifications';
import { updateMessage } from '../../../lib/server/functions/updateMessage';

export class AppMessageBridge {
constructor(orch) {
Expand All @@ -28,10 +29,6 @@ export class AppMessageBridge {

async update(message, appId) {
console.log(`The App ${ appId } is updating a message.`);
if (!this.updateMessage) {
const { updateMessage } = await import('../../../lib');
this.updateMessage = updateMessage;
}

if (!message.editor) {
throw new Error('Invalid editor assigned to the message for the update.');
Expand All @@ -44,7 +41,7 @@ export class AppMessageBridge {
const msg = this.orch.getConverters().get('messages').convertAppMessage(message);
const editor = Users.findOneById(message.editor.id);

this.updateMessage(msg, editor);
updateMessage(msg, editor);
}

async notifyUser(user, message, appId) {
Expand Down
8 changes: 2 additions & 6 deletions app/apps/server/bridges/rooms.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Rooms, Subscriptions, Users } from '../../../models';
import { RoomType } from '@rocket.chat/apps-engine/definition/rooms';
import { addUserToRoom } from '../../../lib/server/functions/addUserToRoom';

export class AppRoomBridge {
constructor(orch) {
Expand Down Expand Up @@ -101,11 +102,6 @@ export class AppRoomBridge {
async update(room, members = [], appId) {
console.log(`The App ${ appId } is updating a room.`);

if (!this.addUserToRoom) {
const { addUserToRoom } = await import('../../../lib');
this.addUserToRoom = addUserToRoom;
}

if (!room.id || !Rooms.findOneById(room.id)) {
throw new Error('A room must exist to update.');
}
Expand All @@ -121,7 +117,7 @@ export class AppRoomBridge {
continue;
}

this.addUserToRoom(rm._id, member);
addUserToRoom(rm._id, member);
}
}
}
83 changes: 40 additions & 43 deletions app/apps/server/communication/rest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { HTTP } from 'meteor/http';
import { API } from '../../../api/server/api';
import Busboy from 'busboy';

let _API;

export class AppsRestApi {
constructor(orch, manager) {
this._orch = orch;
Expand Down Expand Up @@ -33,8 +32,6 @@ export class AppsRestApi {
}

async loadAPI() {
const { API } = await import('../../../api');
_API = API;
this.api = new API.ApiClass({
version: 'apps',
useDefaultAuth: true,
Expand All @@ -60,7 +57,7 @@ export class AppsRestApi {
return info;
});

return _API.v1.success({ apps });
return API.v1.success({ apps });
},
post() {
let buff;
Expand All @@ -69,7 +66,7 @@ export class AppsRestApi {
const result = HTTP.call('GET', this.bodyParams.url, { npmRequestOptions: { encoding: 'base64' } });

if (result.statusCode !== 200 || !result.headers['content-type'] || result.headers['content-type'] !== 'application/zip') {
return _API.v1.failure({ error: 'Invalid url. It doesn\'t exist or is not "application/zip".' });
return API.v1.failure({ error: 'Invalid url. It doesn\'t exist or is not "application/zip".' });
}

buff = Buffer.from(result.content, 'base64');
Expand All @@ -78,7 +75,7 @@ export class AppsRestApi {
}

if (!buff) {
return _API.v1.failure({ error: 'Failed to get a file to install for the App. ' });
return API.v1.failure({ error: 'Failed to get a file to install for the App. ' });
}

const aff = Promise.await(manager.add(buff.toString('base64'), false));
Expand All @@ -91,7 +88,7 @@ export class AppsRestApi {
info.status = 'compiler_error';
}

return _API.v1.success({
return API.v1.success({
app: info,
implemented: aff.getImplementedInferfaces(),
compilerErrors: aff.getCompilerErrors(),
Expand All @@ -106,7 +103,7 @@ export class AppsRestApi {
languages: prl.getStorageItem().languageContent,
}));

return _API.v1.success({ apps });
return API.v1.success({ apps });
},
});

Expand All @@ -119,9 +116,9 @@ export class AppsRestApi {
const info = prl.getInfo();
info.status = prl.getStatus();

return _API.v1.success({ app: info });
return API.v1.success({ app: info });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
post() {
Expand All @@ -134,7 +131,7 @@ export class AppsRestApi {
const result = HTTP.call('GET', this.bodyParams.url, { npmRequestOptions: { encoding: 'base64' } });

if (result.statusCode !== 200 || !result.headers['content-type'] || result.headers['content-type'] !== 'application/zip') {
return _API.v1.failure({ error: 'Invalid url. It doesn\'t exist or is not "application/zip".' });
return API.v1.failure({ error: 'Invalid url. It doesn\'t exist or is not "application/zip".' });
}

buff = Buffer.from(result.content, 'base64');
Expand All @@ -143,7 +140,7 @@ export class AppsRestApi {
}

if (!buff) {
return _API.v1.failure({ error: 'Failed to get a file to install for the App. ' });
return API.v1.failure({ error: 'Failed to get a file to install for the App. ' });
}

const aff = Promise.await(manager.update(buff.toString('base64')));
Expand All @@ -156,7 +153,7 @@ export class AppsRestApi {
info.status = 'compiler_error';
}

return _API.v1.success({
return API.v1.success({
app: info,
implemented: aff.getImplementedInferfaces(),
compilerErrors: aff.getCompilerErrors(),
Expand All @@ -172,9 +169,9 @@ export class AppsRestApi {
const info = prl.getInfo();
info.status = prl.getStatus();

return _API.v1.success({ app: info });
return API.v1.success({ app: info });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
});
Expand All @@ -187,9 +184,9 @@ export class AppsRestApi {
if (prl) {
const info = prl.getInfo();

return _API.v1.success({ iconFileContent: info.iconFileContent });
return API.v1.success({ iconFileContent: info.iconFileContent });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
});
Expand All @@ -202,9 +199,9 @@ export class AppsRestApi {
if (prl) {
const languages = prl.getStorageItem().languageContent || {};

return _API.v1.success({ languages });
return API.v1.success({ languages });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
});
Expand All @@ -228,9 +225,9 @@ export class AppsRestApi {

const logs = Promise.await(orchestrator.getLogStorage().find(ourQuery, options));

return _API.v1.success({ logs });
return API.v1.success({ logs });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
});
Expand All @@ -249,21 +246,21 @@ export class AppsRestApi {
}
});

return _API.v1.success({ settings });
return API.v1.success({ settings });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
post() {
console.log(`Updating ${ this.urlParams.id }'s settings..`);
if (!this.bodyParams || !this.bodyParams.settings) {
return _API.v1.failure('The settings to update must be present.');
return API.v1.failure('The settings to update must be present.');
}

const prl = manager.getOneById(this.urlParams.id);

if (!prl) {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}

const { settings } = prl.getStorageItem();
Expand All @@ -277,7 +274,7 @@ export class AppsRestApi {
}
});

return _API.v1.success({ updated });
return API.v1.success({ updated });
},
});

Expand All @@ -288,35 +285,35 @@ export class AppsRestApi {
try {
const setting = manager.getSettingsManager().getAppSetting(this.urlParams.id, this.urlParams.settingId);

_API.v1.success({ setting });
API.v1.success({ setting });
} catch (e) {
if (e.message.includes('No setting found')) {
return _API.v1.notFound(`No Setting found on the App by the id of: "${ this.urlParams.settingId }"`);
return API.v1.notFound(`No Setting found on the App by the id of: "${ this.urlParams.settingId }"`);
} else if (e.message.includes('No App found')) {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
} else {
return _API.v1.failure(e.message);
return API.v1.failure(e.message);
}
}
},
post() {
console.log(`Updating the App ${ this.urlParams.id }'s setting ${ this.urlParams.settingId }`);

if (!this.bodyParams.setting) {
return _API.v1.failure('Setting to update to must be present on the posted body.');
return API.v1.failure('Setting to update to must be present on the posted body.');
}

try {
Promise.await(manager.getSettingsManager().updateAppSetting(this.urlParams.id, this.bodyParams.setting));

return _API.v1.success();
return API.v1.success();
} catch (e) {
if (e.message.includes('No setting found')) {
return _API.v1.notFound(`No Setting found on the App by the id of: "${ this.urlParams.settingId }"`);
return API.v1.notFound(`No Setting found on the App by the id of: "${ this.urlParams.settingId }"`);
} else if (e.message.includes('No App found')) {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
} else {
return _API.v1.failure(e.message);
return API.v1.failure(e.message);
}
}
},
Expand All @@ -328,11 +325,11 @@ export class AppsRestApi {
const prl = manager.getOneById(this.urlParams.id);

if (prl) {
return _API.v1.success({
return API.v1.success({
apis: manager.apiManager.listApis(this.urlParams.id),
});
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
});
Expand All @@ -343,14 +340,14 @@ export class AppsRestApi {
const prl = manager.getOneById(this.urlParams.id);

if (prl) {
return _API.v1.success({ status: prl.getStatus() });
return API.v1.success({ status: prl.getStatus() });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
post() {
if (!this.bodyParams.status || typeof this.bodyParams.status !== 'string') {
return _API.v1.failure('Invalid status provided, it must be "status" field and a string.');
return API.v1.failure('Invalid status provided, it must be "status" field and a string.');
}

console.log(`Updating ${ this.urlParams.id }'s status...`, this.bodyParams.status);
Expand All @@ -359,9 +356,9 @@ export class AppsRestApi {
if (prl) {
const result = Promise.await(manager.changeStatus(prl.getID(), this.bodyParams.status));

return _API.v1.success({ status: result.getStatus() });
return API.v1.success({ status: result.getStatus() });
} else {
return _API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
return API.v1.notFound(`No App found by the id of: ${ this.urlParams.id }`);
}
},
});
Expand Down
4 changes: 2 additions & 2 deletions app/authorization/client/startup.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Meteor } from 'meteor/meteor';
import { CachedCollectionManager } from '../../ui-cached-collection';
import { hasAllPermission } from './hasPermission';
import { AdminBox } from '../../ui-utils/client/lib/AdminBox';

Meteor.startup(async() => {
const { AdminBox } = await import('../../ui-utils');
Meteor.startup(() => {

CachedCollectionManager.onLogin(() => Meteor.subscribe('roles'));

Expand Down
11 changes: 3 additions & 8 deletions app/authorization/client/views/permissionsRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Template } from 'meteor/templating';
import { t, handleError } from '../../../utils';
import { Roles } from '../../../models';
import { hasAllPermission } from '../hasPermission';
import { modal } from '../../../ui-utils/client/lib/modal';
import toastr from 'toastr';

let _modal;

Template.permissionsRole.helpers({
role() {
return Roles.findOne({
Expand Down Expand Up @@ -113,12 +112,8 @@ Template.permissionsRole.helpers({

Template.permissionsRole.events({
async 'click .remove-user'(e, instance) {
if (!_modal) {
const { modal } = await import('../../../ui-utils');
_modal = modal;
}
e.preventDefault();
_modal.open({
modal.open({
title: t('Are_you_sure'),
type: 'warning',
showCancelButton: true,
Expand All @@ -133,7 +128,7 @@ Template.permissionsRole.events({
return handleError(error);
}

_modal.open({
modal.open({
title: t('Removed'),
text: t('User_removed'),
type: 'success',
Expand Down
2 changes: 1 addition & 1 deletion app/authorization/server/publications/permissions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { Permissions } from '../../../models';
import Permissions from '../../../models/server/models/Permissions';
import { Notifications } from '../../../notifications';

Meteor.methods({
Expand Down
Loading