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
0
Merge Requests
0
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
Kazuhiko Shiozaki
gitlab-ce
Commits
f862b4ae
Commit
f862b4ae
authored
Jan 30, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/background-delete-process'
parents
3d61cf9f
f255313e
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
44 additions
and
9 deletions
+44
-9
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+6
-2
app/models/project.rb
app/models/project.rb
+1
-0
app/services/delete_user_service.rb
app/services/delete_user_service.rb
+1
-1
app/services/destroy_group_service.rb
app/services/destroy_group_service.rb
+1
-1
app/services/projects/destroy_service.rb
app/services/projects/destroy_service.rb
+6
-0
app/workers/project_destroy_worker.rb
app/workers/project_destroy_worker.rb
+17
-0
db/migrate/20160122185421_add_pending_delete_to_project.rb
db/migrate/20160122185421_add_pending_delete_to_project.rb
+5
-0
db/schema.rb
db/schema.rb
+1
-0
lib/api/projects.rb
lib/api/projects.rb
+2
-2
spec/models/hooks/system_hook_spec.rb
spec/models/hooks/system_hook_spec.rb
+3
-3
No files found.
CHANGELOG
View file @
f862b4ae
...
@@ -42,6 +42,7 @@ v 8.4.1
...
@@ -42,6 +42,7 @@ v 8.4.1
- Fix redirect loop during import
- Fix redirect loop during import
- Fix diff highlighting for all syntax themes
- Fix diff highlighting for all syntax themes
- Warn admin during OAuth of granting admin rights (Zeger-Jan van de Weg)
- Warn admin during OAuth of granting admin rights (Zeger-Jan van de Weg)
- Delete project and associations in a background worker
v 8.4.0
v 8.4.0
- Allow LDAP users to change their email if it was not set by the LDAP server
- Allow LDAP users to change their email if it was not set by the LDAP server
...
...
app/controllers/projects_controller.rb
View file @
f862b4ae
...
@@ -93,6 +93,10 @@ class ProjectsController < ApplicationController
...
@@ -93,6 +93,10 @@ class ProjectsController < ApplicationController
return
return
end
end
if
@project
.
pending_delete?
flash
[
:alert
]
=
"Project queued for delete."
end
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
if
@project
.
repository_exists?
if
@project
.
repository_exists?
...
@@ -120,8 +124,8 @@ class ProjectsController < ApplicationController
...
@@ -120,8 +124,8 @@ class ProjectsController < ApplicationController
def
destroy
def
destroy
return
access_denied!
unless
can?
(
current_user
,
:remove_project
,
@project
)
return
access_denied!
unless
can?
(
current_user
,
:remove_project
,
@project
)
::
Projects
::
DestroyService
.
new
(
@project
,
current_user
,
{}).
execute
::
Projects
::
DestroyService
.
new
(
@project
,
current_user
,
{}).
pending_delete!
flash
[
:alert
]
=
"Project '
#{
@project
.
name
}
' w
as
deleted."
flash
[
:alert
]
=
"Project '
#{
@project
.
name
}
' w
ill be
deleted."
redirect_to
dashboard_projects_path
redirect_to
dashboard_projects_path
rescue
Projects
::
DestroyService
::
DestroyError
=>
ex
rescue
Projects
::
DestroyService
::
DestroyError
=>
ex
...
...
app/models/project.rb
View file @
f862b4ae
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
# build_coverage_regex :string
# build_coverage_regex :string
# build_allow_git_fetch :boolean default(TRUE), not null
# build_allow_git_fetch :boolean default(TRUE), not null
# build_timeout :integer default(3600), not null
# build_timeout :integer default(3600), not null
# pending_delete :boolean
#
#
require
'carrierwave/orm/activerecord'
require
'carrierwave/orm/activerecord'
...
...
app/services/delete_user_service.rb
View file @
f862b4ae
...
@@ -13,7 +13,7 @@ class DeleteUserService
...
@@ -13,7 +13,7 @@ class DeleteUserService
user
.
personal_projects
.
each
do
|
project
|
user
.
personal_projects
.
each
do
|
project
|
# Skip repository removal because we remove directory with namespace
# Skip repository removal because we remove directory with namespace
# that contain all this repositories
# that contain all this repositories
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
execute
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
pending_delete!
end
end
user
.
destroy
user
.
destroy
...
...
app/services/destroy_group_service.rb
View file @
f862b4ae
...
@@ -9,7 +9,7 @@ class DestroyGroupService
...
@@ -9,7 +9,7 @@ class DestroyGroupService
@group
.
projects
.
each
do
|
project
|
@group
.
projects
.
each
do
|
project
|
# Skip repository removal because we remove directory with namespace
# Skip repository removal because we remove directory with namespace
# that contain all this repositories
# that contain all this repositories
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
execute
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
pending_delete!
end
end
@group
.
destroy
@group
.
destroy
...
...
app/services/projects/destroy_service.rb
View file @
f862b4ae
...
@@ -6,6 +6,12 @@ module Projects
...
@@ -6,6 +6,12 @@ module Projects
DELETED_FLAG
=
'+deleted'
DELETED_FLAG
=
'+deleted'
def
pending_delete!
project
.
update_attribute
(
:pending_delete
,
true
)
ProjectDestroyWorker
.
perform_in
(
1
.
minute
,
project
.
id
,
current_user
.
id
,
params
)
end
def
execute
def
execute
return
false
unless
can?
(
current_user
,
:remove_project
,
project
)
return
false
unless
can?
(
current_user
,
:remove_project
,
project
)
...
...
app/workers/project_destroy_worker.rb
0 → 100644
View file @
f862b4ae
class
ProjectDestroyWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :default
def
perform
(
project_id
,
user_id
,
params
)
begin
project
=
Project
.
find
(
project_id
)
rescue
ActiveRecord
::
RecordNotFound
return
end
user
=
User
.
find
(
user_id
)
::
Projects
::
DestroyService
.
new
(
project
,
user
,
params
).
execute
end
end
db/migrate/20160122185421_add_pending_delete_to_project.rb
0 → 100644
View file @
f862b4ae
class
AddPendingDeleteToProject
<
ActiveRecord
::
Migration
def
change
add_column
:projects
,
:pending_delete
,
:boolean
,
default:
false
end
end
db/schema.rb
View file @
f862b4ae
...
@@ -677,6 +677,7 @@ ActiveRecord::Schema.define(version: 20160128233227) do
...
@@ -677,6 +677,7 @@ ActiveRecord::Schema.define(version: 20160128233227) do
t
.
string
"build_coverage_regex"
t
.
string
"build_coverage_regex"
t
.
boolean
"build_allow_git_fetch"
,
default:
true
,
null:
false
t
.
boolean
"build_allow_git_fetch"
,
default:
true
,
null:
false
t
.
integer
"build_timeout"
,
default:
3600
,
null:
false
t
.
integer
"build_timeout"
,
default:
3600
,
null:
false
t
.
boolean
"pending_delete"
,
default:
false
end
end
add_index
"projects"
,
[
"builds_enabled"
,
"shared_runners_enabled"
],
name:
"index_projects_on_builds_enabled_and_shared_runners_enabled"
,
using: :btree
add_index
"projects"
,
[
"builds_enabled"
,
"shared_runners_enabled"
],
name:
"index_projects_on_builds_enabled_and_shared_runners_enabled"
,
using: :btree
...
...
lib/api/projects.rb
View file @
f862b4ae
...
@@ -187,7 +187,7 @@ module API
...
@@ -187,7 +187,7 @@ module API
else
else
present
@forked_project
,
with:
Entities
::
Project
,
present
@forked_project
,
with:
Entities
::
Project
,
user_can_admin_project:
can?
(
current_user
,
:admin_project
,
@forked_project
)
user_can_admin_project:
can?
(
current_user
,
:admin_project
,
@forked_project
)
end
end
end
end
# Update an existing project
# Update an existing project
...
@@ -246,7 +246,7 @@ module API
...
@@ -246,7 +246,7 @@ module API
# DELETE /projects/:id
# DELETE /projects/:id
delete
":id"
do
delete
":id"
do
authorize!
:remove_project
,
user_project
authorize!
:remove_project
,
user_project
::
Projects
::
DestroyService
.
new
(
user_project
,
current_user
,
{}).
execute
::
Projects
::
DestroyService
.
new
(
user_project
,
current_user
,
{}).
pending_delete!
end
end
# Mark this project as forked from another
# Mark this project as forked from another
...
...
spec/models/hooks/system_hook_spec.rb
View file @
f862b4ae
...
@@ -36,7 +36,7 @@ describe SystemHook, models: true do
...
@@ -36,7 +36,7 @@ describe SystemHook, models: true do
it
"project_destroy hook"
do
it
"project_destroy hook"
do
user
=
create
(
:user
)
user
=
create
(
:user
)
project
=
create
(
:empty_project
,
namespace:
user
.
namespace
)
project
=
create
(
:empty_project
,
namespace:
user
.
namespace
)
Projects
::
DestroyService
.
new
(
project
,
user
,
{}).
execute
Projects
::
DestroyService
.
new
(
project
,
user
,
{}).
pending_delete!
expect
(
WebMock
).
to
have_requested
(
:post
,
@system_hook
.
url
).
with
(
expect
(
WebMock
).
to
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/project_destroy/
,
body:
/project_destroy/
,
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'System Hook'
}
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'System Hook'
}
...
@@ -65,7 +65,7 @@ describe SystemHook, models: true do
...
@@ -65,7 +65,7 @@ describe SystemHook, models: true do
project
=
create
(
:project
)
project
=
create
(
:project
)
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
expect
(
WebMock
).
to
have_requested
(
:post
,
@system_hook
.
url
).
with
(
expect
(
WebMock
).
to
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/user_add_to_team/
,
body:
/user_add_to_team/
,
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'System Hook'
}
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'System Hook'
}
).
once
).
once
end
end
...
@@ -76,7 +76,7 @@ describe SystemHook, models: true do
...
@@ -76,7 +76,7 @@ describe SystemHook, models: true do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
project
.
project_members
.
destroy_all
project
.
project_members
.
destroy_all
expect
(
WebMock
).
to
have_requested
(
:post
,
@system_hook
.
url
).
with
(
expect
(
WebMock
).
to
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/user_remove_from_team/
,
body:
/user_remove_from_team/
,
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'System Hook'
}
headers:
{
'Content-Type'
=>
'application/json'
,
'X-Gitlab-Event'
=>
'System Hook'
}
).
once
).
once
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