#698: updated Advisories API
This commit is contained in:
parent
84e5f3ead3
commit
8bbb82faa8
|
@ -17,8 +17,7 @@ class Api::V1::AdvisoriesController < Api::V1::BaseController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@advisory = @build_list.build_and_associate_advisory(params[:advisory])
|
@advisory = @build_list.build_and_associate_advisory(params[:advisory])
|
||||||
if @build_list.status == BuildList::BUILD_PUBLISHED &&
|
if may_be_published? && @advisory.save && @build_list.save
|
||||||
@advisory.save && @build_list.save
|
|
||||||
render_json_response @advisory, 'Advisory has been created successfully'
|
render_json_response @advisory, 'Advisory has been created successfully'
|
||||||
else
|
else
|
||||||
render_validation_error @advisory, error_message(@build_list, 'Advisory has not been created')
|
render_validation_error @advisory, error_message(@build_list, 'Advisory has not been created')
|
||||||
|
@ -26,7 +25,7 @@ class Api::V1::AdvisoriesController < Api::V1::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @advisory && @build_list.status == BuildList::BUILD_PUBLISHED &&
|
if @advisory && may_be_published?
|
||||||
@advisory.attach_build_list(@build_list) &&
|
@advisory.attach_build_list(@build_list) &&
|
||||||
@advisory.save && @build_list.save
|
@advisory.save && @build_list.save
|
||||||
render_json_response @advisory, "Build list '#{@build_list.id}' has been attached to advisory successfully"
|
render_json_response @advisory, "Build list '#{@build_list.id}' has been attached to advisory successfully"
|
||||||
|
@ -39,7 +38,13 @@ class Api::V1::AdvisoriesController < Api::V1::BaseController
|
||||||
|
|
||||||
def find_build_list
|
def find_build_list
|
||||||
@build_list = BuildList.find params[:build_list_id]
|
@build_list = BuildList.find params[:build_list_id]
|
||||||
authorize! :publish, @build_list
|
end
|
||||||
|
|
||||||
|
def may_be_published?
|
||||||
|
!@build_list.save_to_repository.publish_without_qa &&
|
||||||
|
can?(:update, @build_list.save_to_platform) &&
|
||||||
|
@build_list.save_to_platform.released &&
|
||||||
|
@build_list.status == BuildList::BUILD_PUBLISHED
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -88,6 +88,8 @@ describe Api::V1::AdvisoriesController do
|
||||||
|
|
||||||
@advisory = FactoryGirl.create(:advisory)
|
@advisory = FactoryGirl.create(:advisory)
|
||||||
@build_list = FactoryGirl.create(:build_list_core)
|
@build_list = FactoryGirl.create(:build_list_core)
|
||||||
|
@build_list.save_to_platform.update_column(:released, true)
|
||||||
|
@build_list.save_to_repository.update_column(:publish_without_qa, false)
|
||||||
@build_list.update_column(:status, BuildList::BUILD_PUBLISHED)
|
@build_list.update_column(:status, BuildList::BUILD_PUBLISHED)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,7 +133,6 @@ describe Api::V1::AdvisoriesController do
|
||||||
context 'for user who has access to update build_list' do
|
context 'for user who has access to update build_list' do
|
||||||
before do
|
before do
|
||||||
@user = FactoryGirl.create(:user)
|
@user = FactoryGirl.create(:user)
|
||||||
@build_list.project.relations.create(:role => 'admin', :actor => @user)
|
|
||||||
@build_list.save_to_platform.relations.create(:role => 'admin', :actor => @user)
|
@build_list.save_to_platform.relations.create(:role => 'admin', :actor => @user)
|
||||||
http_login(@user)
|
http_login(@user)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue