Skip to content

Commit

Permalink
Add permission check to the import methods and not just the UI (#6400)
Browse files Browse the repository at this point in the history
  • Loading branch information
graywolf336 authored and rodrigok committed Mar 23, 2017
1 parent 20695fa commit 7d2e696
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'getImportProgress' }

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

if Importer.Importers[name]?
return Importer.Importers[name].importerInstance?.getProgress()
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'getSelectionData' }

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

if Importer.Importers[name]?.importerInstance?
progress = Importer.Importers[name].importerInstance.getProgress()
switch progress.step
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-importer/server/methods/prepareImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'prepareImport' });
}

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

check(name, String);
check(dataURI, String);
check(fileName, String);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'restartImport' }

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

if Importer.Importers[name]?
importer = Importer.Importers[name]
importer.importerInstance.updateProgress Importer.ProgressStep.CANCELLED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'setupImporter' }

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

if Importer.Importers[name]?.importer?
importer = Importer.Importers[name]
# If they currently have progress, get it and return the progress.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'startImport' }

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

if Importer.Importers[name]?.importerInstance?
usersSelection = input.users.map (user) ->
return new Importer.SelectionUser user.user_id, user.username, user.email, user.is_deleted, user.is_bot, user.do_import
Expand Down

0 comments on commit 7d2e696

Please sign in to comment.