aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Legler <a3li@gentoo.org>2012-08-27 22:25:11 +0200
committerAlex Legler <a3li@gentoo.org>2012-08-27 22:25:11 +0200
commit2fd3f5d97a0c8a38d9d09f8bc09517bd93728dd0 (patch)
tree8e35ef2a417a6e87b15bfd6e5492b7c057ca55c7
parentPortage lib: Add helper to find out whether a package has ebuilds in the tree (diff)
downloadglsamaker-2fd3f5d97a0c8a38d9d09f8bc09517bd93728dd0.tar.gz
glsamaker-2fd3f5d97a0c8a38d9d09f8bc09517bd93728dd0.tar.bz2
glsamaker-2fd3f5d97a0c8a38d9d09f8bc09517bd93728dd0.zip
API: Setup and first function: Create requestapi
-rw-r--r--app/controllers/api/glsa_controller.rb22
-rw-r--r--app/helpers/api/glsa_helper.rb2
-rw-r--r--app/views/api/glsa/create_request.html.erb2
-rw-r--r--config/routes.rb2
-rw-r--r--test/functional/api/glsa_controller_test.rb9
-rw-r--r--test/unit/helpers/api/glsa_helper_test.rb4
6 files changed, 41 insertions, 0 deletions
diff --git a/app/controllers/api/glsa_controller.rb b/app/controllers/api/glsa_controller.rb
new file mode 100644
index 0000000..7645dfd
--- /dev/null
+++ b/app/controllers/api/glsa_controller.rb
@@ -0,0 +1,22 @@
+class Api::GlsaController < ApplicationController
+ layout false
+
+ # Limited to creating requests for now
+ def create
+ @glsa = nil
+
+ if params[:type] == 'request'
+ @glsa = Glsa.new_request(params[:title], params[:bugs], params[:comment], params[:access], (params[:import_references].to_i == 1), current_user)
+ Glsamaker::Mail.request_notification(@glsa, current_user)
+ end
+
+ respond_to do |format|
+ if @glsa and @glsa.save
+ format.json { render :json => @glsa, :status => :created }
+ else
+ format.json { render :json => @glsa ? @glsa.errors : ['error: unknown action'], :status => :unprocessable_entity }
+ end
+ end
+ end
+
+end
diff --git a/app/helpers/api/glsa_helper.rb b/app/helpers/api/glsa_helper.rb
new file mode 100644
index 0000000..22f2ceb
--- /dev/null
+++ b/app/helpers/api/glsa_helper.rb
@@ -0,0 +1,2 @@
+module Api::GlsaHelper
+end
diff --git a/app/views/api/glsa/create_request.html.erb b/app/views/api/glsa/create_request.html.erb
new file mode 100644
index 0000000..7ac0448
--- /dev/null
+++ b/app/views/api/glsa/create_request.html.erb
@@ -0,0 +1,2 @@
+<h1>Api::Glsa#create_request</h1>
+<p>Find me in app/views/api/glsa/create_request.html.erb</p>
diff --git a/config/routes.rb b/config/routes.rb
index 1b46f3e..ce16275 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -9,6 +9,8 @@ Glsamaker::Application.routes.draw do
match 'admin' => 'admin/index#index'
+ match 'api/glsa/create_request' => 'api/glsa#create_request'
+
resources :glsas, :controller => 'glsa' do
resources :comments
resources :bugs
diff --git a/test/functional/api/glsa_controller_test.rb b/test/functional/api/glsa_controller_test.rb
new file mode 100644
index 0000000..d214f08
--- /dev/null
+++ b/test/functional/api/glsa_controller_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class Api::GlsaControllerTest < ActionController::TestCase
+ test "should get create_request" do
+ get :create_request
+ assert_response :success
+ end
+
+end
diff --git a/test/unit/helpers/api/glsa_helper_test.rb b/test/unit/helpers/api/glsa_helper_test.rb
new file mode 100644
index 0000000..b651f0f
--- /dev/null
+++ b/test/unit/helpers/api/glsa_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class Api::GlsaHelperTest < ActionView::TestCase
+end