aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/api
diff options
context:
space:
mode:
authorXinhui2017-08-23 14:28:22 +0200
committerXinhui2017-08-23 14:28:22 +0200
commit1d496326ca9177bd1b9b5202eaa5f6137bfd7fa6 (patch)
treef40452096e9aa7a96e99bc71534a4a1419cfccf8 /app/controllers/api
parent6ef942b93eaa0a1d0d6203a3e984f95c751e9ea9 (diff)
downloadchouette-core-1d496326ca9177bd1b9b5202eaa5f6137bfd7fa6.tar.bz2
API - WorkbenchImport #create action
Refs #4280
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/v1/iboo_controller.rb11
-rw-r--r--app/controllers/api/v1/imports_controller.rb13
2 files changed, 16 insertions, 8 deletions
diff --git a/app/controllers/api/v1/iboo_controller.rb b/app/controllers/api/v1/iboo_controller.rb
index 7ea4cc22e..4db9e9007 100644
--- a/app/controllers/api/v1/iboo_controller.rb
+++ b/app/controllers/api/v1/iboo_controller.rb
@@ -7,13 +7,10 @@ class Api::V1::IbooController < Api::V1::ChouetteController
private
def authenticate
authenticate_with_http_basic do |code, token|
- api_key = Api::V1::ApiKey.find_by(token: token)
- organisation = Organisation.find_by(code: code)
-
- return unless api_key && organisation
-
- if api_key.organisation == organisation
- @current_organisation = organisation
+ if organisation = Organisation.find_by(code: code)
+ if organisation.api_keys.exists?(token: token)
+ @current_organisation = organisation
+ end
end
end
diff --git a/app/controllers/api/v1/imports_controller.rb b/app/controllers/api/v1/imports_controller.rb
index ac2ec4516..6050418d8 100644
--- a/app/controllers/api/v1/imports_controller.rb
+++ b/app/controllers/api/v1/imports_controller.rb
@@ -1,4 +1,15 @@
class Api::V1::ImportsController < Api::V1::IbooController
- defaults :resource_class => Api::V1::ApiKey
+ defaults :resource_class => WorkbenchImport
belongs_to :workbench
+
+ def create
+ args = workbench_import_params.merge(creator: 'Webservice')
+ @import = parent.workbench_imports.create(args)
+ create!
+ end
+
+ private
+ def workbench_import_params
+ params.require(:workbench_import).permit(:file, :name)
+ end
end