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

Remove dependency of RC namespace in rc-importer #13280

Merged
merged 20 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
801ed01
Move RestAPI client to rc-api package
MarcosSpessatto Jan 28, 2019
1238c2c
Remove dependency of RC namespace in rc-api/helpers and api.js
MarcosSpessatto Jan 28, 2019
dc8f615
Remove dependency of RC namespace on half of api files
MarcosSpessatto Jan 28, 2019
c6db2d5
Partial Remove dependency of RC namespace in rc-api
MarcosSpessatto Jan 28, 2019
06f62e6
import API where it was being used by the RC namespace
MarcosSpessatto Jan 28, 2019
cd1930c
Move processWebhookMessage function to rc-lib package
MarcosSpessatto Jan 28, 2019
d7eab39
Remove API from RC namespace and import missing function that was bei…
MarcosSpessatto Jan 28, 2019
59bbccc
Remove dependency of RC namespace in rc-graphql
MarcosSpessatto Jan 28, 2019
e90ab24
Fix import from wrong package
MarcosSpessatto Jan 28, 2019
fd4f74c
Remove dependency of RC namespace in rc-importer
MarcosSpessatto Jan 28, 2019
b42676d
Merge branch 'depackaging' into globals/api-wave-1
MarcosSpessatto Feb 4, 2019
9db42c7
Merge branch 'globals/api-wave-1' into globals/api-wave-2
MarcosSpessatto Feb 4, 2019
d9635ae
Merge branch 'globals/api-wave-2' into globals/api-wave-3
MarcosSpessatto Feb 4, 2019
5560fb1
Merge branch 'globals/api-wave-3' into globals/api-wave-4
MarcosSpessatto Feb 4, 2019
765a43a
Merge branch 'globals/api-wave-4' into globals/graphql
MarcosSpessatto Feb 4, 2019
b567143
Merge branch 'globals/graphql' into globals/importer
MarcosSpessatto Feb 4, 2019
d39b6cd
Remove namespace in the new livechat endpoint
MarcosSpessatto Feb 4, 2019
e08efcd
Merge branch 'globals/api-wave-4' into globals/graphql
MarcosSpessatto Feb 4, 2019
20a71ff
Merge branch 'globals/graphql' into globals/importer
MarcosSpessatto Feb 4, 2019
07d7b1b
Merge remote-tracking branch 'origin/depackaging' into globals/importer
rodrigok Feb 6, 2019
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import { CachedCollectionManager } from 'meteor/rocketchat:ui-cached-collection';

class ImporterWebsocketReceiverDef {
constructor() {
this.streamer = new Meteor.Streamer('importers');

this.callbacks = [];
RocketChat.CachedCollectionManager.onLogin(() => {
CachedCollectionManager.onLogin(() => {
this.streamer.on('progress', this.progressUpdated.bind(this));
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/rocketchat-importer/client/admin/adminImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Importers } from 'meteor/rocketchat:importer';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/tap:i18n';
import { RocketChat, handleError } from 'meteor/rocketchat:lib';
import { t } from 'meteor/rocketchat:utils';
import { hasRole } from 'meteor/rocketchat:authorization';
import { t, handleError } from 'meteor/rocketchat:utils';

Template.adminImport.helpers({
isAdmin() {
return RocketChat.authz.hasRole(Meteor.userId(), 'admin');
return hasRole(Meteor.userId(), 'admin');
},
getDescription(importer) {
return TAPi18n.__('Importer_From_Description', { from: importer.name });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Importers } from 'meteor/rocketchat:importer';
import { Template } from 'meteor/templating';
import { RocketChat } from 'meteor/rocketchat:lib';
import { hasRole } from 'meteor/rocketchat:authorization';
import { t } from 'meteor/rocketchat:utils';
import toastr from 'toastr';
import { ReactiveVar } from 'meteor/reactive-var';
Expand All @@ -11,7 +11,7 @@ import { API } from 'meteor/rocketchat:api';

Template.adminImportHistory.helpers({
isAdmin() {
return RocketChat.authz.hasRole(Meteor.userId(), 'admin');
return hasRole(Meteor.userId(), 'admin');
},
importers() {
return Importers.getAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { Importers } from 'meteor/rocketchat:importer';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/tap:i18n';
import { RocketChat, handleError } from 'meteor/rocketchat:lib';
import { t } from 'meteor/rocketchat:utils';
import { hasRole } from 'meteor/rocketchat:authorization';
import { settings } from 'meteor/rocketchat:settings';
import { t, handleError } from 'meteor/rocketchat:utils';
import { API } from 'meteor/rocketchat:api';
import toastr from 'toastr';

Template.adminImportPrepare.helpers({
isAdmin() {
return RocketChat.authz.hasRole(Meteor.userId(), 'admin');
return hasRole(Meteor.userId(), 'admin');
},
importer() {
const importerKey = FlowRouter.getParam('importer');
Expand All @@ -34,7 +35,7 @@ Template.adminImportPrepare.helpers({
return Template.instance().message_count.get();
},
fileSizeLimitMessage() {
const maxFileSize = RocketChat.settings.get('FileUpload_MaxFileSize');
const maxFileSize = settings.get('FileUpload_MaxFileSize');
let message;

if (maxFileSize > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { ReactiveVar } from 'meteor/reactive-var';
import { Importers, ImporterWebsocketReceiver, ProgressStep } from 'meteor/rocketchat:importer';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';
import { t } from 'meteor/rocketchat:utils';
import { handleError } from 'meteor/rocketchat:lib';
import { t, handleError } from 'meteor/rocketchat:utils';
import toastr from 'toastr';

Template.adminImportProgress.helpers({
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-importer/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Package.onUse(function(api) {
'check',
'rocketchat:utils',
'rocketchat:lib',
'rocketchat:models',
'rocketchat:authorization',
'rocketchat:ui-cached-collection',
'rocketchat:settings',
'rocketchat:api',
'rocketchat:logger',
'rocketchat:file-upload',
Expand Down
29 changes: 15 additions & 14 deletions packages/rocketchat-importer/server/classes/ImporterBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Imports } from '../models/Imports';
import { ImporterInfo } from '../../lib/ImporterInfo';
import { RawImports } from '../models/RawImports';
import { ImporterWebsocket } from './ImporterWebsocket';
import { RocketChat } from 'meteor/rocketchat:lib';
import { Settings } from 'meteor/rocketchat:models';
import { Logger } from 'meteor/rocketchat:logger';
import { FileUpload } from 'meteor/rocketchat:file-upload';
import { sendMessage } from 'meteor/rocketchat:lib';
import http from 'http';
import fs from 'fs';
import https from 'https';
Expand Down Expand Up @@ -230,24 +231,24 @@ export class Base {

switch (step) {
case ProgressStep.IMPORTING_STARTED:
this.oldSettings.Accounts_AllowedDomainsList = RocketChat.models.Settings.findOneById('Accounts_AllowedDomainsList').value;
RocketChat.models.Settings.updateValueById('Accounts_AllowedDomainsList', '');
this.oldSettings.Accounts_AllowedDomainsList = Settings.findOneById('Accounts_AllowedDomainsList').value;
Settings.updateValueById('Accounts_AllowedDomainsList', '');

this.oldSettings.Accounts_AllowUsernameChange = RocketChat.models.Settings.findOneById('Accounts_AllowUsernameChange').value;
RocketChat.models.Settings.updateValueById('Accounts_AllowUsernameChange', true);
this.oldSettings.Accounts_AllowUsernameChange = Settings.findOneById('Accounts_AllowUsernameChange').value;
Settings.updateValueById('Accounts_AllowUsernameChange', true);

this.oldSettings.FileUpload_MaxFileSize = RocketChat.models.Settings.findOneById('FileUpload_MaxFileSize').value;
RocketChat.models.Settings.updateValueById('FileUpload_MaxFileSize', -1);
this.oldSettings.FileUpload_MaxFileSize = Settings.findOneById('FileUpload_MaxFileSize').value;
Settings.updateValueById('FileUpload_MaxFileSize', -1);

this.oldSettings.FileUpload_MediaTypeWhiteList = RocketChat.models.Settings.findOneById('FileUpload_MediaTypeWhiteList').value;
RocketChat.models.Settings.updateValueById('FileUpload_MediaTypeWhiteList', '*');
this.oldSettings.FileUpload_MediaTypeWhiteList = Settings.findOneById('FileUpload_MediaTypeWhiteList').value;
Settings.updateValueById('FileUpload_MediaTypeWhiteList', '*');
break;
case ProgressStep.DONE:
case ProgressStep.ERROR:
RocketChat.models.Settings.updateValueById('Accounts_AllowedDomainsList', this.oldSettings.Accounts_AllowedDomainsList);
RocketChat.models.Settings.updateValueById('Accounts_AllowUsernameChange', this.oldSettings.Accounts_AllowUsernameChange);
RocketChat.models.Settings.updateValueById('FileUpload_MaxFileSize', this.oldSettings.FileUpload_MaxFileSize);
RocketChat.models.Settings.updateValueById('FileUpload_MediaTypeWhiteList', this.oldSettings.FileUpload_MediaTypeWhiteList);
Settings.updateValueById('Accounts_AllowedDomainsList', this.oldSettings.Accounts_AllowedDomainsList);
Settings.updateValueById('Accounts_AllowUsernameChange', this.oldSettings.Accounts_AllowUsernameChange);
Settings.updateValueById('FileUpload_MaxFileSize', this.oldSettings.FileUpload_MaxFileSize);
Settings.updateValueById('FileUpload_MediaTypeWhiteList', this.oldSettings.FileUpload_MediaTypeWhiteList);
break;
}

Expand Down Expand Up @@ -421,7 +422,7 @@ export class Base {
msg._id = details.message_id;
}

return RocketChat.sendMessage(user, msg, room, true);
return sendMessage(user, msg, room, true);
}
});
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Importers } from 'meteor/rocketchat:importer';
import { RocketChatImportFileInstance } from '../startup/store';
import { ProgressStep } from '../../lib/ImporterProgressStep';
import { hasRole } from 'meteor/rocketchat:authorization';
import http from 'http';
import fs from 'fs';

Expand All @@ -24,7 +25,7 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'downloadPublicImportFile' });
}

if (!RocketChat.authz.hasRole(userId, 'admin')) {
if (!hasRole(userId, 'admin')) {
throw new Meteor.Error('not_authorized', 'User not authorized', { method: 'downloadPublicImportFile' });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RocketChatImportFileInstance } from '../startup/store';
import { Meteor } from 'meteor/meteor';
import { Importers } from 'meteor/rocketchat:importer';
import { hasRole } from 'meteor/rocketchat:authorization';
import { ProgressStep } from '../../lib/ImporterProgressStep';
import path from 'path';

Expand All @@ -12,7 +13,7 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getImportFileData' });
}

if (!RocketChat.authz.hasRole(userId, 'admin')) {
if (!hasRole(userId, 'admin')) {
throw new Meteor.Error('not_authorized', 'User not authorized', { method: 'getImportFileData' });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { Importers } from 'meteor/rocketchat:importer';
import { RocketChat } from 'meteor/rocketchat:lib';
import { hasPermission } from 'meteor/rocketchat:authorization';

Meteor.methods({
getImportProgress(key) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getImportProgress' });
}

if (!RocketChat.authz.hasPermission(Meteor.userId(), 'run-import')) {
if (!hasPermission(Meteor.userId(), 'run-import')) {
throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', { method: 'setupImporter' });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { Imports } from '../models/Imports';
import { hasRole } from 'meteor/rocketchat:authorization';

Meteor.methods({
getLatestImportOperations() {
Expand All @@ -9,7 +10,7 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getLatestImportOperations' });
}

if (!RocketChat.authz.hasRole(userId, 'admin')) {
if (!hasRole(userId, 'admin')) {
throw new Meteor.Error('not_authorized', 'User not authorized', { method: 'getLatestImportOperations' });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
Importers,
ProgressStep,
} from 'meteor/rocketchat:importer';
import { RocketChat } from 'meteor/rocketchat:lib';
import { hasPermission } from 'meteor/rocketchat:authorization';

Meteor.methods({
getSelectionData(key) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getSelectionData' });
}

if (!RocketChat.authz.hasPermission(Meteor.userId(), 'run-import')) {
if (!hasPermission(Meteor.userId(), 'run-import')) {
throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', { method: 'setupImporter' });
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-importer/server/methods/prepareImport.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { Importers } from 'meteor/rocketchat:importer';
import { RocketChat } from 'meteor/rocketchat:lib';
import { hasPermission } from 'meteor/rocketchat:authorization';

Meteor.methods({
prepareImport(key, dataURI, contentType, fileName) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'prepareImport' });
}

if (!RocketChat.authz.hasPermission(Meteor.userId(), 'run-import')) {
if (!hasPermission(Meteor.userId(), 'run-import')) {
throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', { method: 'setupImporter' });
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-importer/server/methods/restartImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
Importers,
ProgressStep,
} from 'meteor/rocketchat:importer';
import { RocketChat } from 'meteor/rocketchat:lib';
import { hasPermission } from 'meteor/rocketchat:authorization';

Meteor.methods({
restartImport(key) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'restartImport' });
}

if (!RocketChat.authz.hasPermission(Meteor.userId(), 'run-import')) {
if (!hasPermission(Meteor.userId(), 'run-import')) {
throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', { method: 'setupImporter' });
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-importer/server/methods/setupImporter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { Importers } from 'meteor/rocketchat:importer';
import { RocketChat } from 'meteor/rocketchat:lib';
import { hasPermission } from 'meteor/rocketchat:authorization';

Meteor.methods({
setupImporter(key) {
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setupImporter' });
}

if (!RocketChat.authz.hasPermission(Meteor.userId(), 'run-import')) {
if (!hasPermission(Meteor.userId(), 'run-import')) {
throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', { method: 'setupImporter' });
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-importer/server/methods/startImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
SelectionChannel,
SelectionUser,
} from 'meteor/rocketchat:importer';
import { RocketChat } from 'meteor/rocketchat:lib';
import { hasPermission } from 'meteor/rocketchat:authorization';

Meteor.methods({
startImport(key, input) {
Expand All @@ -14,7 +14,7 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'startImport' });
}

if (!RocketChat.authz.hasPermission(Meteor.userId(), 'run-import')) {
if (!hasPermission(Meteor.userId(), 'run-import')) {
throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', { method: 'startImport' });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Importers } from 'meteor/rocketchat:importer';
import { RocketChatFile } from 'meteor/rocketchat:file';
import { RocketChatImportFileInstance } from '../startup/store';
import { hasRole } from 'meteor/rocketchat:authorization';

Meteor.methods({
uploadImportFile(binaryContent, contentType, fileName, importerKey) {
Expand All @@ -11,7 +12,7 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'uploadImportFile' });
}

if (!RocketChat.authz.hasRole(userId, 'admin')) {
if (!hasRole(userId, 'admin')) {
throw new Meteor.Error('not_authorized', 'User not authorized', { method: 'uploadImportFile' });
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-importer/server/models/Imports.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProgressStep } from '../../lib/ImporterProgressStep';
import { RocketChat } from 'meteor/rocketchat:lib';
import { Base } from 'meteor/rocketchat:models';

class ImportsModel extends RocketChat.models._Base {
class ImportsModel extends Base {
constructor() {
super('import');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-importer/server/models/RawImports.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Base as _Base } from 'meteor/rocketchat:models';
import { Base } from 'meteor/rocketchat:models';

class RawImportsModel extends _Base {
class RawImportsModel extends Base {
constructor() {
super('raw_imports');
}
Expand Down
7 changes: 4 additions & 3 deletions packages/rocketchat-importer/server/startup/store.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Meteor } from 'meteor/meteor';
import { RocketChatFile } from 'meteor/rocketchat:file';
import { settings } from 'meteor/rocketchat:settings';

export let RocketChatImportFileInstance;

Meteor.startup(function() {
const RocketChatStore = RocketChatFile.FileSystem;

let path = '/tmp/rocketchat-importer';
if (RocketChat.settings.get('ImportFile_FileSystemPath') != null) {
if (RocketChat.settings.get('ImportFile_FileSystemPath').trim() !== '') {
path = RocketChat.settings.get('ImportFile_FileSystemPath');
if (settings.get('ImportFile_FileSystemPath') != null) {
if (settings.get('ImportFile_FileSystemPath').trim() !== '') {
path = settings.get('ImportFile_FileSystemPath');
}
}

Expand Down