Skip to content

Commit 606d9d3

Browse files
Avielle WolfelauraGitlab
Avielle Wolfe
andcommitted
Merge branch 'mark-catalog-resource-as-draft' into 'master'
Return catalog resource to `draft` See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/130555 Merged-by: Avielle Wolfe <[email protected]> Approved-by: Avielle Wolfe <[email protected]> Approved-by: Kasia Misirli <[email protected]> Co-authored-by: Laura Montemayor <[email protected]>
2 parents 34895a4 + 8808138 commit 606d9d3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

app/services/releases/destroy_service.rb

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def execute
77
return error(_('Access Denied'), 403) unless allowed?
88

99
if release.destroy
10+
update_catalog_resource!
11+
1012
success(tag: existing_tag, release: release)
1113
else
1214
error(release.errors.messages || '400 Bad request', 400)
@@ -15,6 +17,14 @@ def execute
1517

1618
private
1719

20+
def update_catalog_resource!
21+
return unless project.catalog_resource
22+
23+
return unless project.catalog_resource.versions.none?
24+
25+
project.catalog_resource.update!(state: 'draft')
26+
end
27+
1828
def allowed?
1929
Ability.allowed?(current_user, :destroy_release, release)
2030
end

spec/services/releases/destroy_service_spec.rb

+20
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@
2828
it 'returns the destroyed object' do
2929
is_expected.to include(status: :success, release: release)
3030
end
31+
32+
context 'when the release is for a catalog resource' do
33+
let!(:catalog_resource) { create(:catalog_resource, project: project, state: 'published') }
34+
let!(:version) { create(:catalog_resource_version, catalog_resource: catalog_resource, release: release) }
35+
36+
it 'does not update the catalog resources if there are still releases' do
37+
second_release = create(:release, project: project, tag: 'v1.2.0')
38+
create(:catalog_resource_version, catalog_resource: catalog_resource, release: second_release)
39+
40+
subject
41+
42+
expect(catalog_resource.reload.state).to eq('published')
43+
end
44+
45+
it 'updates the catalog resource if there are no more releases' do
46+
subject
47+
48+
expect(catalog_resource.reload.state).to eq('draft')
49+
end
50+
end
3151
end
3252

3353
context 'when tag does not exist in the repository' do

0 commit comments

Comments
 (0)