Skip to content

Commit

Permalink
[api] make it possible to configure OBS:RejectRequests for action typ…
Browse files Browse the repository at this point in the history
…es (bnc#804699)
  • Loading branch information
adrianschroeter committed Feb 20, 2013
1 parent 540e2f3 commit e45f7bb
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/api/app/controllers/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,23 @@ def check_action_permission(action)
return false
end
if tprj.class == Project and (a = tprj.find_attribute("OBS", "RejectRequests") and a.values.first)
render_error :status => 403, :errorcode => 'request_rejected',
:message => "The target project #{action.target_project} is not accepting requests because: #{a.values.first.value.to_s}"
return false
if a.values.length < 2 or a.values.find_by_value(action.action_type)
render_error :status => 403, :errorcode => 'request_rejected',
:message => "The target project #{action.target_project} is not accepting requests because: #{a.values.first.value.to_s}"
return false
end
end
if action.target_package
if Package.exists_by_project_and_name(action.target_project, action.target_package) or [:delete, :change_devel, :add_role, :set_bugowner].include? action.action_type
tpkg = Package.get_by_project_and_name action.target_project, action.target_package
end

if tpkg && (a = tpkg.find_attribute("OBS", "RejectRequests") and a.values.first)
render_error :status => 403, :errorcode => 'request_rejected',
:message => "The target package #{action.target_project} / #{action.target_package} is not accepting requests because: #{a.values.first.value.to_s}"
return false
if a.values.length < 2 or a.values.find_by_value(action.action_type)
render_error :status => 403, :errorcode => 'request_rejected',
:message => "The target package #{action.target_project} / #{action.target_package} is not accepting requests because: #{a.values.first.value.to_s}"
return false
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class MakeObsRejectrequestsConfigurable < ActiveRecord::Migration

def self.up
a = AttribType.find_by_id(AttribType.find_by_name("OBS:RejectRequests"))
a.value_count = nil
a.save!
end


def self.down
a = AttribType.find_by_id(AttribType.find_by_name("OBS:RejectRequests"))
a.value_count = 1
a.save!
end

end
2 changes: 1 addition & 1 deletion src/api/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
at.attrib_type_modifiable_bies.find_or_create_by_bs_user_id(admin.id)
at = AttribType.find_or_create_by_attrib_namespace_id_and_name(ans.id, "UpdateProject", :value_count => 1)
at.attrib_type_modifiable_bies.find_or_create_by_bs_user_id(admin.id)
at = AttribType.find_or_create_by_attrib_namespace_id_and_name(ans.id, "RejectRequests", :value_count => 1)
at = AttribType.find_or_create_by_attrib_namespace_id_and_name(ans.id, "RejectRequests")
at.attrib_type_modifiable_bies.find_or_create_by_bs_user_id(admin.id)
at = AttribType.find_or_create_by_attrib_namespace_id_and_name(ans.id, "ApprovedRequestSource", :value_count => 0)
at.attrib_type_modifiable_bies.find_or_create_by_bs_user_id(admin.id)
Expand Down
2 changes: 2 additions & 0 deletions src/api/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ INSERT INTO schema_migrations (version) VALUES ('20121220151549');

INSERT INTO schema_migrations (version) VALUES ('20130111085930');

INSERT INTO schema_migrations (version) VALUES ('20130220160000');

INSERT INTO schema_migrations (version) VALUES ('21');

INSERT INTO schema_migrations (version) VALUES ('22');
Expand Down
1 change: 0 additions & 1 deletion src/api/test/fixtures/attrib_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ OBS_QualityCategory:
OBS_RejectRequests:
id: 64
name: RejectRequests
value_count: 1
attrib_namespace_id: 9
OBS_RequestCloned:
id: 60
Expand Down
36 changes: 31 additions & 5 deletions src/api/test/functional/request_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -870,26 +870,52 @@ def test_reject_request_creation
assert_match(/Go Away/, @response.body)
assert_xml_tag :tag => "status", :attributes => { :code => "request_rejected" }

# just for submit actions
post "/source/home:Iggy/_attribute", "<attributes><attribute namespace='OBS' name='RejectRequests'> <value>No Submits</value> <value>submit</value> </attribute> </attributes>"
assert_response :success
post "/request?cmd=create", rq
assert_response 403
assert_match(/No Submits/, @response.body)
assert_xml_tag :tag => "status", :attributes => { :code => "request_rejected" }
# but it works when blocking only for others
post "/source/home:Iggy/_attribute", "<attributes><attribute namespace='OBS' name='RejectRequests'> <value>Submits welcome</value> <value>delete</value> <value>set_bugowner</value> </attribute> </attributes>"
assert_response :success
post "/request?cmd=create", rq
assert_response :success


# block request creation in package
post "/source/home:Iggy/TestPack/_attribute", "<attributes><attribute namespace='OBS' name='RejectRequests'> <value>Package blocked</value> </attribute> </attributes>"
assert_response :success

post "/request?cmd=create", rq
assert_response 403
assert_match(/Go Away/, @response.body)
assert_match(/Package blocked/, @response.body)
assert_xml_tag :tag => "status", :attributes => { :code => "request_rejected" }

#FIXME: test with request without target

# remove project attribute lock
delete "/source/home:Iggy/_attribute/OBS:RejectRequests"
assert_response :success

# still not working
post "/request?cmd=create", rq
assert_response 403
assert_match(/Package blocked/, @response.body)
assert_xml_tag :tag => "status", :attributes => { :code => "request_rejected" }

# just for submit actions
post "/source/home:Iggy/TestPack/_attribute", "<attributes><attribute namespace='OBS' name='RejectRequests'> <value>No Submits</value> <value>submit</value> </attribute> </attributes>"
assert_response :success
post "/request?cmd=create", rq
assert_response 403
assert_match(/No Submits/, @response.body)
assert_xml_tag :tag => "status", :attributes => { :code => "request_rejected" }
# but it works when blocking only for others
post "/source/home:Iggy/TestPack/_attribute", "<attributes><attribute namespace='OBS' name='RejectRequests'> <value>Submits welcome</value> <value>delete</value> <value>set_bugowner</value> </attribute> </attributes>"
assert_response :success
post "/request?cmd=create", rq
assert_response :success

#FIXME: test with request without target

#cleanup
delete "/source/home:Iggy/TestPack/_attribute/OBS:RejectRequests"
assert_response :success
Expand Down

0 comments on commit e45f7bb

Please sign in to comment.