Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
25e0765b
Commit
25e0765b
authored
May 26, 2021
by
Vladimir Shushlin
Committed by
Douglas Barbosa Alexandre
May 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix pages domains not being deleted when pages destroyed
parent
15448f95
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
27 deletions
+30
-27
app/models/pages_domain.rb
app/models/pages_domain.rb
+2
-0
app/services/pages/delete_service.rb
app/services/pages/delete_service.rb
+7
-2
spec/models/pages_domain_spec.rb
spec/models/pages_domain_spec.rb
+9
-0
spec/services/pages/delete_service_spec.rb
spec/services/pages/delete_service_spec.rb
+12
-25
No files found.
app/models/pages_domain.rb
View file @
25e0765b
...
...
@@ -50,6 +50,8 @@ class PagesDomain < ApplicationRecord
after_update
:update_daemon
,
if: :saved_change_to_pages_config?
after_destroy
:update_daemon
scope
:for_project
,
->
(
project
)
{
where
(
project:
project
)
}
scope
:enabled
,
->
{
where
(
'enabled_until >= ?'
,
Time
.
current
)
}
scope
:needs_verification
,
->
do
verified_at
=
arel_table
[
:verified_at
]
...
...
app/services/pages/delete_service.rb
View file @
25e0765b
...
...
@@ -3,8 +3,13 @@
module
Pages
class
DeleteService
<
BaseService
def
execute
project
.
mark_pages_as_not_deployed
# prevents domain from updating config when deleted
project
.
pages_domains
.
delete_all
project
.
mark_pages_as_not_deployed
# project.pages_domains.delete_all will just nullify project_id:
# > If no :dependent option is given, then it will follow the default
# > strategy for `has_many :through` associations.
# > The default strategy is :nullify which sets the foreign keys to NULL.
PagesDomain
.
for_project
(
project
).
delete_all
DestroyPagesDeploymentsWorker
.
perform_async
(
project
.
id
)
...
...
spec/models/pages_domain_spec.rb
View file @
25e0765b
...
...
@@ -12,6 +12,15 @@ RSpec.describe PagesDomain do
it
{
is_expected
.
to
have_many
(
:serverless_domain_clusters
)
}
end
describe
'.for_project'
do
it
'returns domains assigned to project'
do
domain
=
create
(
:pages_domain
,
:with_project
)
create
(
:pages_domain
)
# unrelated domain
expect
(
described_class
.
for_project
(
domain
.
project
)).
to
eq
([
domain
])
end
end
describe
'validate domain'
do
subject
(
:pages_domain
)
{
build
(
:pages_domain
,
domain:
domain
)
}
...
...
spec/services/pages/delete_service_spec.rb
View file @
25e0765b
...
...
@@ -6,7 +6,6 @@ RSpec.describe Pages::DeleteService do
let_it_be
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
path:
"my.project"
)}
let!
(
:domain
)
{
create
(
:pages_domain
,
project:
project
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
admin
)}
before
do
...
...
@@ -14,8 +13,6 @@ RSpec.describe Pages::DeleteService do
end
it
'deletes published pages'
,
:sidekiq_inline
do
expect
(
project
.
pages_deployed?
).
to
be
(
true
)
expect_next_instance_of
(
Gitlab
::
PagesTransfer
)
do
|
pages_transfer
|
expect
(
pages_transfer
).
to
receive
(
:rename_project
).
and_return
true
end
...
...
@@ -23,11 +20,9 @@ RSpec.describe Pages::DeleteService do
expect
(
PagesWorker
).
to
receive
(
:perform_in
).
with
(
5
.
minutes
,
:remove
,
project
.
namespace
.
full_path
,
anything
)
service
.
execute
expect
(
project
.
pages_deployed?
).
to
be
(
false
)
end
it
"doesn't remove anything from the legacy storage"
,
:sidekiq_inline
do
it
"doesn't remove anything from the legacy storage
if local_store is disabled
"
,
:sidekiq_inline
do
allow
(
Settings
.
pages
.
local_store
).
to
receive
(
:enabled
).
and_return
(
false
)
expect
(
project
.
pages_deployed?
).
to
be
(
true
)
...
...
@@ -38,12 +33,20 @@ RSpec.describe Pages::DeleteService do
expect
(
project
.
pages_deployed?
).
to
be
(
false
)
end
it
'deletes all domains'
,
:sidekiq_inline
do
expect
(
project
.
pages_domains
.
count
).
to
eq
(
1
)
it
'marks pages as not deployed'
do
expect
do
service
.
execute
end
.
to
change
{
project
.
reload
.
pages_deployed?
}.
from
(
true
).
to
(
false
)
end
it
'deletes all domains'
do
domain
=
create
(
:pages_domain
,
project:
project
)
unrelated_domain
=
create
(
:pages_domain
)
service
.
execute
expect
(
project
.
reload
.
pages_domains
.
count
).
to
eq
(
0
)
expect
(
PagesDomain
.
find_by_id
(
domain
.
id
)).
to
eq
(
nil
)
expect
(
PagesDomain
.
find_by_id
(
unrelated_domain
.
id
)).
to
be
end
it
'schedules a destruction of pages deployments'
do
...
...
@@ -61,20 +64,4 @@ RSpec.describe Pages::DeleteService do
service
.
execute
end
.
to
change
{
PagesDeployment
.
count
}.
by
(
-
1
)
end
it
'marks pages as not deployed, deletes domains and schedules worker to remove pages from disk'
do
expect
(
project
.
pages_deployed?
).
to
eq
(
true
)
expect
(
project
.
pages_domains
.
count
).
to
eq
(
1
)
service
.
execute
expect
(
project
.
pages_deployed?
).
to
eq
(
false
)
expect
(
project
.
pages_domains
.
count
).
to
eq
(
0
)
expect_next_instance_of
(
Gitlab
::
PagesTransfer
)
do
|
pages_transfer
|
expect
(
pages_transfer
).
to
receive
(
:rename_project
).
and_return
true
end
Sidekiq
::
Worker
.
drain_all
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment