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

[FIX] Slack import failing and not being able to be restarted #8390

Merged
merged 1 commit into from
Oct 5, 2017
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
4 changes: 3 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@
"IMAP_intercepter_Not_running": "IMAP intercepter Not running",
"Impersonate_user": "Impersonate User",
"Impersonate_user_description": "When enabled, integration posts as the user that triggered integration",
"Import": "Import",
"Importer_Archived": "Archived",
"Importer_CSV_Information": "The CSV importer requires a specific format, please read the documentation for how to structure your zip file:",
"Importer_done": "Importing complete!",
Expand Down Expand Up @@ -1663,6 +1664,7 @@
"SSL": "SSL",
"Star_Message": "Star Message",
"Starred_Messages": "Starred Messages",
"Start": "Start",
"Start_audio_call": "Start audio call",
"Start_Chat": "Start Chat",
"Start_of_conversation": "Start of conversation",
Expand Down Expand Up @@ -2029,4 +2031,4 @@
"your_message_optional": "your message (optional)",
"Your_password_is_wrong": "Your password is wrong!",
"Your_push_was_sent_to_s_devices": "Your push was sent to %s devices"
}
}
530 changes: 286 additions & 244 deletions packages/rocketchat-importer-slack/server.js

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions packages/rocketchat-importer/client/admin/adminImport.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@
<header class="fixed-title border-component-color">
{{> burger}}
<h2>
<span class="room-title">Import</span>
<span class="room-title">{{_ "Import"}}</span>
</h2>
</header>
<div class="content">
{{#unless isAdmin}}
<p>You are not authorized to view this page.</p>
<p>{{_ "You_are_not_authorized_to_view_this_page"}}</p>
{{else}}
{{#if isImporters}}
<div class="rocket-form">
<fieldset>
{{#each importers}}
<div class="section">
<h1>{{name}}</h1>
<h1>{{ name }}</h1>
<div class="section-content">
<div>{{getDescription .}}</div>
<button class="button primary start-import">Start</button>
<button class="button primary start-import">{{_ "Start"}}</button>
</div>
</div>
{{/each}}
</fieldset>
</div>
{{else}}
No Importers Available
{{/if}}
{{/unless}}
</div>
</section>
Expand Down
12 changes: 6 additions & 6 deletions packages/rocketchat-importer/client/admin/adminImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ Template.adminImport.helpers({
isAdmin() {
return RocketChat.authz.hasRole(Meteor.userId(), 'admin');
},
isImporters() {
return Object.keys(Importer.Importers).length > 0;
},
getDescription(importer) {
return TAPi18n.__('Importer_From_Description', { from: importer.name });
},
Expand All @@ -22,12 +19,15 @@ Template.adminImport.helpers({
Template.adminImport.events({
'click .start-import'() {
const importer = this;
return Meteor.call('setupImporter', importer.key, function(error) {

Meteor.call('setupImporter', importer.key, function(error) {
if (error) {
console.log(t('importer_setup_error'), importer.key, error);
return handleError(error);
handleError(error);
return;
}
return FlowRouter.go(`/admin/import/prepare/${ importer.key }`);

FlowRouter.go(`/admin/import/prepare/${ importer.key }`);
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>
</header>
<div class="content">
{{#unless isAdmin}}
<p>You are not authorized to view this page.</p>
<p>{{_ "You_are_not_authorized_to_view_this_page"}}</p>
{{else}}
<div class="rocket-form">
<fieldset>
Expand Down
15 changes: 7 additions & 8 deletions packages/rocketchat-importer/client/admin/adminImportPrepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ Template.adminImportPrepare.helpers({
Template.adminImportPrepare.events({
'change .import-file-input'(event, template) {
const importer = this;
if (!importer.key) { return; }
if (!importer || !importer.key) { return; }

const e = event.originalEvent || event;
let { files } = e.target;
if (!files || (files.length === 0)) {
files = (e.dataTransfer != null ? e.dataTransfer.files : undefined) || [];
}

return Array.from(files).map((blob) => {
return Array.from(files).map((file) => {
template.preparing.set(true);

const reader = new FileReader();
reader.readAsDataURL(blob);
reader.readAsDataURL(file);
reader.onloadend = () => {
Meteor.call('prepareImport', importer.key, reader.result, blob.type, blob.name, function(error, data) {
Meteor.call('prepareImport', importer.key, reader.result, file.type, file.name, function(error, data) {
if (error) {
toastr.error(t('Invalid_Import_File_Type'));
template.preparing.set(false);
Expand Down Expand Up @@ -84,7 +84,6 @@ Template.adminImportPrepare.events({
'click .button.start'(event, template) {
const btn = this;
$(btn).prop('disabled', true);
// const importer = this;
for (const user of Array.from(template.users.get())) {
user.do_import = $(`[name=${ user.user_id }]`).is(':checked');
}
Expand All @@ -93,12 +92,12 @@ Template.adminImportPrepare.events({
channel.do_import = $(`[name=${ channel.channel_id }]`).is(':checked');
}

return Meteor.call('startImport', FlowRouter.getParam('importer'), { users: template.users.get(), channels: template.channels.get() }, function(error) {
Meteor.call('startImport', FlowRouter.getParam('importer'), { users: template.users.get(), channels: template.channels.get() }, function(error) {
if (error) {
console.warn('Error on starting the import:', error);
return handleError(error);
handleError(error);
} else {
return FlowRouter.go(`/admin/import/progress/${ FlowRouter.getParam('importer') }`);
FlowRouter.go(`/admin/import/progress/${ FlowRouter.getParam('importer') }`);
}
});
},
Expand Down
21 changes: 21 additions & 0 deletions packages/rocketchat-importer/server/classes/ImporterBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,22 @@ Importer.Base = class Base {
this.addCountCompleted = this.addCountCompleted.bind(this);
this.updateRecord = this.updateRecord.bind(this);
this.uploadFile = this.uploadFile.bind(this);

this.name = name;
this.description = description;
this.mimeType = mimeType;

this.logger = new Logger(`${ this.name } Importer`, {});
this.progress = new Importer.Progress(this.name);
this.collection = Importer.RawImports;

const importId = Importer.Imports.insert({ 'type': this.name, 'ts': Date.now(), 'status': this.progress.step, 'valid': true, 'user': Meteor.user()._id });
this.importRecord = Importer.Imports.findOne(importId);

this.users = {};
this.channels = {};
this.messages = {};
this.oldSettings = {};
}

// Takes the uploaded file and extracts the users, channels, and messages from it.
Expand All @@ -89,6 +94,7 @@ Importer.Base = class Base {

if (!fileType || (fileType.mime !== this.mimeType)) {
this.logger.warn(`Invalid file uploaded for the ${ this.name } importer.`);
this.updateProgress(Importer.ProgressStep.ERROR);
throw new Meteor.Error('error-invalid-file-uploaded', `Invalid file uploaded to import ${ this.name } data from.`, { step: 'prepare' });
}

Expand Down Expand Up @@ -137,6 +143,21 @@ Importer.Base = class Base {
updateProgress(step) {
this.progress.step = step;

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

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

this.logger.debug(`${ this.name } is now at ${ step }.`);
this.updateRecord({ 'status': this.progress.step });

Expand Down
6 changes: 5 additions & 1 deletion packages/rocketchat-importer/server/methods/startImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ Meteor.methods({
}

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

if (!name) {
throw new Meteor.Error('error-invalid-importer', `No defined importer by: "${ name }"`, { method: 'startImport' });
}

if (Importer.Importers[name] && Importer.Importers[name].importerInstance) {
Expand Down
12 changes: 4 additions & 8 deletions packages/rocketchat-lib/server/methods/filterATAllTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ RocketChat.callbacks.add('beforeSaveMessage', function(message) {
});

// Also throw to stop propagation of 'sendMessage'.
throw new Meteor.Error(
'error-action-not-allowed',
'Notify all in this room not allowed',
{
method: 'filterATAllTag',
action: 'Notify_all_in_this_room'
}
);
throw new Meteor.Error('error-action-not-allowed', 'Notify all in this room not allowed', {
method: 'filterATAllTag',
action: 'Notify_all_in_this_room'
});
}
}

Expand Down
10 changes: 2 additions & 8 deletions packages/rocketchat-lib/server/methods/setUsername.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Meteor.methods({
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'setUsername' });
}

if (user.username === username) {
if (user.username === username || (user.username && user.username.toLowerCase() === username.toLowerCase())) {
return username;
}

Expand All @@ -28,13 +28,7 @@ Meteor.methods({
throw new Meteor.Error('username-invalid', `${ _.escape(username) } is not a valid username, use only letters, numbers, dots, hyphens and underscores`);
}

if (user.username !== undefined) {
if (!username.toLowerCase() === user.username.toLowerCase()) {
if (!RocketChat.checkUsernameAvailability(username)) {
throw new Meteor.Error('error-field-unavailable', `<strong>${ _.escape(username) }</strong> is already in use :(`, { method: 'setUsername', field: username });
}
}
} else if (!RocketChat.checkUsernameAvailability(username)) {
if (!RocketChat.checkUsernameAvailability(username)) {
throw new Meteor.Error('error-field-unavailable', `<strong>${ _.escape(username) }</strong> is already in use :(`, { method: 'setUsername', field: username });
}

Expand Down