Skip to content

Commit

Permalink
[api] support and test release split (project copy with makeolder). F…
Browse files Browse the repository at this point in the history
…ix backend to modify right projects
  • Loading branch information
adrianschroeter committed Oct 20, 2011
1 parent 0557ad6 commit f6c5e68
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/api/app/controllers/source_controller.rb
Expand Up @@ -175,11 +175,19 @@ def index_project
end

if 'copy' == command
unless @http_user.can_create_project?(project_name) and pro.nil?
unless @http_user.can_create_project?(project_name)
render_error :status => 403, :errorcode => "cmd_execution_no_permission1",
:message => "no permission to execute command '#{command}'"
return
end
if params.has_key?(:makeolder)
oproject = DbProject.get_by_name(params[:oproject])
unless @http_user.can_modify_project?(oproject)
render_error :status => 403, :errorcode => "cmd_execution_no_permission1",
:message => "no permission to execute command '#{command}', requires modification permission in oproject"
return
end
end
dispatch_command
return
end
Expand Down Expand Up @@ -1428,7 +1436,7 @@ def index_project_copy
# copy entire project in the backend
begin
path = request.path
path << build_query_from_hash(params, [:cmd, :user, :comment, :oproject, :withbinaries, :withhistory])
path << build_query_from_hash(params, [:cmd, :user, :comment, :oproject, :withbinaries, :withhistory, :makeolder])
pass_to_backend path
rescue
# we need to check results of backend in any case (also timeout error eg)
Expand Down
57 changes: 57 additions & 0 deletions src/api/test/functional/release_management_test.rb
@@ -0,0 +1,57 @@
require File.expand_path(File.dirname(__FILE__) + "/..") + "/test_helper"
require 'source_controller'

class ReleaseManagementTests < ActionController::IntegrationTest
fixtures :all

def test_release_project
ActionController::IntegrationTest::reset_auth
prepare_request_with_user "tom", "thunder"

# copy any entire project
post "/source/home:tom:BaseDistro", :cmd => :copy, :oproject => "BaseDistro"
assert_response :success

# try a split
post "/source/home:tom:BaseDistro", :cmd => :copy, :oproject => "BaseDistro", :makeolder => 1
assert_response 403

#cleanup
delete "/source/home:tom:BaseDistro"
assert_response :success

get "/source/BaseDistro"
assert_response :success
packages = ActiveXML::XMLNode.new(@response.body)
vrevs = {}
packages.each_entry do |p|
get "/source/BaseDistro/#{p.name}"
assert_response :success
files = ActiveXML::XMLNode.new(@response.body)
vrevs[p.name] = files.vrev
end
assert_not_equal vrevs.count, 0

# make a full split as admin
prepare_request_with_user "king", "sunflower"
post "/source/TEST:BaseDistro", :cmd => :copy, :oproject => "BaseDistro", :makeolder => 1, :withhistory => 1
assert_response :success

# the origin must got increased by 2
vrevs.each_key do |k|
get "/source/BaseDistro/#{k}"
assert_response :success
files = ActiveXML::XMLNode.new(@response.body)
assert_equal "#{vrevs[k].to_i+2}", files.vrev
end

# the copy must have a vrev by one higher and an extended .1
vrevs.each_key do |k|
get "/source/TEST:BaseDistro/#{k}"
assert_response :success
files = ActiveXML::XMLNode.new(@response.body)
assert_equal "#{vrevs[k].to_i+1}.1", files.vrev
end
end

end
2 changes: 1 addition & 1 deletion src/backend/bs_srcserver
Expand Up @@ -4380,7 +4380,7 @@ sub copyproject {
$lastorev->{'time'} = time();
$lastorev->{'vrev'} =~ s/(\d+)$/$1+2/e;
delete $lastorev->{'rev'};
$lastorev = BSFileDB::fdb_add_i("$projectsdir/$projid.pkg/$packid.rev", $srcrevlay, $lastorev);
$lastorev = BSFileDB::fdb_add_i("$projectsdir/$oprojid.pkg/$packid.rev", $srcrevlay, $lastorev);
}
}
# XXX: does this make any sense?
Expand Down

0 comments on commit f6c5e68

Please sign in to comment.