Skip to content

Commit

Permalink
[api] fix configuration update in webui
Browse files Browse the repository at this point in the history
Conflicts:
	src/api/app/controllers/configurations_controller.rb
	src/api/test/functional/configurations_controller_test.rb
  • Loading branch information
adrianschroeter committed Jun 28, 2012
1 parent 3410f68 commit 2a3fbc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api/api/configuration.rng
Expand Up @@ -16,6 +16,7 @@
<element name="description">
<text/>
</element>
<empty/>
</interleave>
</element>
</define>
Expand Down
5 changes: 4 additions & 1 deletion src/api/app/controllers/configurations_controller.rb
Expand Up @@ -4,7 +4,8 @@ class ConfigurationsController < ApplicationController
before_filter :require_admin, :only => [:update]

validate_action :show => {:method => :get, :response => :configuration}
validate_action :update => {:method => :put, :request => :configuration}
# webui is using this route with parameters instead of content
# validate_action :update => {:method => :put, :request => :configuration}

# GET /configuration
# GET /configuration.json
Expand All @@ -31,6 +32,8 @@ def update
# User didn't really upload www-form-urlencoded data but raw XML, try to parse that
xml = REXML::Document.new(request.raw_post)
attribs = {}
attribs[:title] = params["title"]
attribs[:description] = params["description"]
attribs[:title] = xml.elements['/configuration/title'].text if xml.elements['/configuration/title']
attribs[:description] = xml.elements['/configuration/description'].text if xml.elements['/configuration/description']
ret = @configuration.update_attributes(attribs)
Expand Down
13 changes: 12 additions & 1 deletion src/api/test/functional/configurations_controller_test.rb
Expand Up @@ -6,13 +6,24 @@ def setup
end

def test_show_and_update_configuration
prepare_request_with_user "tom", "thunder"
get '/configuration'
assert_response :success
config = @response.body
put '/configuration?title="openSUSE Build Service"&description="Long description"', config
assert_response 403 # Normal users can't change site-wide configuration
prepare_request_with_user 'king', 'sunflower' # User with admin rights
put '/configuration?title="openSUSE Build Service"&description="Long description"', config
get '/configuration'
assert_response :success
put '/configuration', config
assert_response :success
# webui is using this way to store data
put '/configuration?title=openSUSE&description=blah_fasel'
assert_response :success
prepare_request_with_user "tom", "thunder"
get '/configuration.xml'
assert_response :success
assert_xml_tag :tag => "title", :content => "openSUSE"
assert_xml_tag :tag => "description", :content => "blah_fasel"
end
end

0 comments on commit 2a3fbc0

Please sign in to comment.