Skip to content

Commit

Permalink
Merge pull request #4238 from ChrisBr/bugfix/attributes
Browse files Browse the repository at this point in the history
[api] Fix attribute creation
  • Loading branch information
adrianschroeter committed Dec 15, 2017
2 parents 9999132 + 211246c commit bb607ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/api/app/controllers/attribute_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def cmd_attribute
# init
req = ActiveXML::Node.new(request.raw_post)

# checks
# This is necessary for checking the authorization and do not create the attribute
# The attribute creation will happen in @attribute_container.store_attribute_axml
req.each('attribute') do |attr|
attrib_type = AttribType.find_by_namespace_and_name!(attr.value("namespace"), attr.value("name"))
attrib = Attrib.new(attrib_type: attrib_type)
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/mixins/has_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def store_attribute(namespace, name, values, issues, binary = nil)
a.package = self if is_a? Package
if a.attrib_type.value_count
a.attrib_type.value_count.times do |i|
a.values.build(position: i, value: "")
a.values.build(position: i, value: values[i])
end
end
raise AttributeSaveError, a.errors.full_messages.join(", ") unless a.save
Expand Down
26 changes: 26 additions & 0 deletions src/api/test/functional/attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ def test_create_type
assert_response :success
get "/attribute/TEST/Dummy/_meta"
assert_response :success
# use it
attrib_data = "<attributes>
<attribute namespace='TEST' name='Dummy' >
<value>M</value>
<value>A</value>
</attribute>
</attributes>"
post "/source/home:adrian/_attribute", params: attrib_data
assert_response 400
assert_match(/Values Value ('|")M('|") is not allowed./, @response.body)
get "/source/home:adrian/_attribute"
assert_response :success
attrib_data = "<attributes>
<attribute namespace='TEST' name='Dummy' >
<value>A</value>
<value>B</value>
</attribute>
</attributes>"
post "/source/home:adrian/_attribute", params: attrib_data

assert_response :success
get "/source/home:adrian/_attribute"
assert_response :success
assert_xml_tag tag: 'value', content: "A"
assert_xml_tag tag: 'value', content: "B"
# cleanup
login_Iggy
delete "/attribute/TEST/Dummy/_meta"
assert_response 403
Expand Down

0 comments on commit bb607ec

Please sign in to comment.