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
4d4ef89c
Commit
4d4ef89c
authored
Aug 13, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master' into pipeline-hooks-without-slack
parents
cd4d8b91
11eefba8
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
237 additions
and
50 deletions
+237
-50
.gitlab-ci.yml
.gitlab-ci.yml
+2
-2
CHANGELOG
CHANGELOG
+2
-0
app/assets/stylesheets/pages/environments.scss
app/assets/stylesheets/pages/environments.scss
+30
-0
app/controllers/admin/groups_controller.rb
app/controllers/admin/groups_controller.rb
+2
-2
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+2
-2
app/helpers/avatars_helper.rb
app/helpers/avatars_helper.rb
+0
-2
app/models/namespace.rb
app/models/namespace.rb
+2
-0
app/services/delete_user_service.rb
app/services/delete_user_service.rb
+6
-1
app/services/destroy_group_service.rb
app/services/destroy_group_service.rb
+13
-3
app/views/projects/deployments/_actions.haml
app/views/projects/deployments/_actions.haml
+3
-3
app/views/projects/deployments/_commit.html.haml
app/views/projects/deployments/_commit.html.haml
+6
-2
app/views/projects/deployments/_deployment.html.haml
app/views/projects/deployments/_deployment.html.haml
+1
-0
app/views/projects/environments/_environment.html.haml
app/views/projects/environments/_environment.html.haml
+6
-2
app/views/projects/environments/index.html.haml
app/views/projects/environments/index.html.haml
+4
-3
app/views/projects/environments/show.html.haml
app/views/projects/environments/show.html.haml
+2
-2
app/workers/group_destroy_worker.rb
app/workers/group_destroy_worker.rb
+17
-0
config/initializers/metrics.rb
config/initializers/metrics.rb
+3
-0
db/migrate/20140407135544_fix_namespaces.rb
db/migrate/20140407135544_fix_namespaces.rb
+8
-2
db/migrate/20160805041956_add_deleted_at_to_namespaces.rb
db/migrate/20160805041956_add_deleted_at_to_namespaces.rb
+12
-0
db/schema.rb
db/schema.rb
+2
-0
spec/controllers/admin/groups_controller_spec.rb
spec/controllers/admin/groups_controller_spec.rb
+24
-0
spec/controllers/groups_controller_spec.rb
spec/controllers/groups_controller_spec.rb
+29
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+2
-0
spec/services/delete_user_service_spec.rb
spec/services/delete_user_service_spec.rb
+4
-2
spec/services/destroy_group_service_spec.rb
spec/services/destroy_group_service_spec.rb
+36
-22
spec/workers/group_destroy_worker_spec.rb
spec/workers/group_destroy_worker_spec.rb
+19
-0
No files found.
.gitlab-ci.yml
View file @
4d4ef89c
image
:
"
ruby:2.3"
image
:
"
ruby:2.3
.1
"
cache
:
key
:
"
ruby-23"
key
:
"
ruby-23
1
"
paths
:
-
vendor/apt
-
vendor/ruby
...
...
CHANGELOG
View file @
4d4ef89c
...
...
@@ -25,6 +25,7 @@ v 8.11.0 (unreleased)
- Pre-create all builds for a Pipeline when the new Pipeline is created !5295
- Fix of 'Commits being passed to custom hooks are already reachable when using the UI'
- Show member roles to all users on members page
- Project.visible_to_user is instrumented again
- Fix awardable button mutuality loading spinners (ClemMakesApps)
- Add support for using RequestStore within Sidekiq tasks via SIDEKIQ_REQUEST_STORE env variable
- Optimize maximum user access level lookup in loading of notes
...
...
@@ -93,6 +94,7 @@ v 8.11.0 (unreleased)
- Bump gitlab_git to lazy load compare commits
- Reduce number of queries made for merge_requests/:id/diffs
- Sensible state specific default sort order for issues and merge requests !5453 (tomb0y)
- Fix bug where destroying a namespace would not always destroy projects
- Fix RequestProfiler::Middleware error when code is reloaded in development
- Catch what warden might throw when profiling requests to re-throw it
- Avoid commit lookup on diff_helper passing existing local variable to the helper method
...
...
app/assets/stylesheets/pages/environments.scss
View file @
4d4ef89c
.environments
{
.commit-title
{
margin
:
0
;
}
.fa-play
{
font-size
:
14px
;
}
.dropdown-new
{
color
:
$table-text-gray
;
}
.dropdown-menu
{
.fa
{
margin-right
:
6px
;
color
:
$table-text-gray
;
}
}
.branch-name
{
color
:
$gl-dark-link-color
;
}
}
.table.builds.environments
{
min-width
:
500px
;
.icon-container
{
width
:
20px
;
text-align
:
center
;
}
}
app/controllers/admin/groups_controller.rb
View file @
4d4ef89c
...
...
@@ -48,9 +48,9 @@ class Admin::GroupsController < Admin::ApplicationController
end
def
destroy
DestroyGroupService
.
new
(
@group
,
current_user
).
execute
DestroyGroupService
.
new
(
@group
,
current_user
).
async_
execute
redirect_to
admin_groups_path
,
notice:
'Group was successfully deleted.'
redirect_to
admin_groups_path
,
alert:
"Group '
#{
@group
.
name
}
' was scheduled for deletion."
end
private
...
...
app/controllers/groups_controller.rb
View file @
4d4ef89c
...
...
@@ -87,9 +87,9 @@ class GroupsController < Groups::ApplicationController
end
def
destroy
DestroyGroupService
.
new
(
@group
,
current_user
).
execute
DestroyGroupService
.
new
(
@group
,
current_user
).
async_
execute
redirect_to
root_path
,
alert:
"Group '
#{
@group
.
name
}
' was s
uccessfully deleted
."
redirect_to
root_path
,
alert:
"Group '
#{
@group
.
name
}
' was s
cheduled for deletion
."
end
protected
...
...
app/helpers/avatars_helper.rb
View file @
4d4ef89c
...
...
@@ -7,8 +7,6 @@ module AvatarsHelper
}))
end
private
def
user_avatar
(
options
=
{})
avatar_size
=
options
[
:size
]
||
16
user_name
=
options
[
:user
].
try
(
:name
)
||
options
[
:user_name
]
...
...
app/models/namespace.rb
View file @
4d4ef89c
class
Namespace
<
ActiveRecord
::
Base
acts_as_paranoid
include
Sortable
include
Gitlab
::
ShellAdapter
...
...
app/services/delete_user_service.rb
View file @
4d4ef89c
...
...
@@ -21,6 +21,11 @@ class DeleteUserService
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
async_execute
end
user
.
destroy
# Destroy the namespace after destroying the user since certain methods may depend on the namespace existing
namespace
=
user
.
namespace
user_data
=
user
.
destroy
namespace
.
really_destroy!
user_data
end
end
app/services/destroy_group_service.rb
View file @
4d4ef89c
...
...
@@ -5,13 +5,23 @@ class DestroyGroupService
@group
,
@current_user
=
group
,
user
end
def
async_execute
group
.
transaction
do
# Soft delete via paranoia gem
group
.
destroy
job_id
=
GroupDestroyWorker
.
perform_async
(
group
.
id
,
current_user
.
id
)
Rails
.
logger
.
info
(
"User
#{
current_user
.
id
}
scheduled a deletion of group ID
#{
group
.
id
}
with job ID
#{
job_id
}
"
)
end
end
def
execute
group
.
projects
.
each
do
|
project
|
# Execute the destruction of the models immediately to ensure atomic cleanup.
# Skip repository removal because we remove directory with namespace
# that contain all th
is
repositories
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
async_
execute
# that contain all th
ese
repositories
::
Projects
::
DestroyService
.
new
(
project
,
current_user
,
skip_repo:
true
).
execute
end
group
.
destroy
group
.
really_destroy!
end
end
app/views/projects/deployments/_actions.haml
View file @
4d4ef89c
...
...
@@ -2,9 +2,9 @@
.pull-right
-
actions
=
deployment
.
manual_actions
-
if
actions
.
present?
.
btn-group.
inline
.
btn-group
%a
.dropdown-
toggle
.btn.btn-default
{
type:
'button'
,
'data-toggle'
=>
'dropdown'
}
.inline
.
dropdown
%a
.dropdown-
new
.btn.btn-default
{
type:
'button'
,
'data-toggle'
=>
'dropdown'
}
=
icon
(
"play"
)
%b
.caret
%ul
.dropdown-menu.dropdown-menu-align-right
...
...
app/views/projects/deployments/_commit.html.haml
View file @
4d4ef89c
%div
.branch-commit
-
if
deployment
.
ref
=
link_to
deployment
.
ref
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
deployment
.
ref
),
class:
"monospace"
·
.icon-container
=
deployment
.
tag?
?
icon
(
'tag'
)
:
icon
(
'code-fork'
)
=
link_to
deployment
.
ref
,
namespace_project_commits_path
(
@project
.
namespace
,
@project
,
deployment
.
ref
),
class:
"monospace branch-name"
.icon-container
=
custom_icon
(
"icon_commit"
)
=
link_to
deployment
.
short_sha
,
namespace_project_commit_path
(
@project
.
namespace
,
@project
,
deployment
.
sha
),
class:
"commit-id monospace"
%p
.commit-title
%span
-
if
commit_title
=
deployment
.
commit_title
=
author_avatar
(
deployment
.
commit
,
size:
20
)
=
link_to_gfm
commit_title
,
namespace_project_commit_path
(
@project
.
namespace
,
@project
,
deployment
.
sha
),
class:
"commit-row-message"
-
else
Cant find HEAD commit for this branch
app/views/projects/deployments/_deployment.html.haml
View file @
4d4ef89c
...
...
@@ -8,6 +8,7 @@
%td
-
if
deployment
.
deployable
=
link_to
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
deployment
.
deployable
]
do
=
user_avatar
(
user:
deployment
.
user
,
size:
20
)
=
"
#{
deployment
.
deployable
.
name
}
(#
#{
deployment
.
deployable
.
id
}
)"
%td
...
...
app/views/projects/environments/_environment.html.haml
View file @
4d4ef89c
...
...
@@ -2,8 +2,12 @@
%tr
.environment
%td
%strong
=
link_to
environment
.
name
,
namespace_project_environment_path
(
@project
.
namespace
,
@project
,
environment
)
=
link_to
environment
.
name
,
namespace_project_environment_path
(
@project
.
namespace
,
@project
,
environment
)
%td
-
if
last_deployment
=
user_avatar
(
user:
last_deployment
.
user
,
size:
20
)
%strong
##{last_deployment.id}
%td
-
if
last_deployment
...
...
app/views/projects/environments/index.html.haml
View file @
4d4ef89c
...
...
@@ -23,10 +23,11 @@
New environment
-
else
.table-holder
%table
.table.environments
%table
.table.
builds.
environments
%tbody
%th
Environment
%th
Last deployment
%th
Date
%th
Last Deployment
%th
Commit
%th
%th
=
render
@environments
app/views/projects/environments/show.html.haml
View file @
4d4ef89c
...
...
@@ -23,13 +23,13 @@
=
link_to
"Read more"
,
help_page_path
(
"ci/environments"
),
class:
"btn btn-success"
-
else
.table-holder
%table
.table.environments
%table
.table.
builds.
environments
%thead
%tr
%th
ID
%th
Commit
%th
Build
%th
Date
%th
%th
=
render
@deployments
...
...
app/workers/group_destroy_worker.rb
0 → 100644
View file @
4d4ef89c
class
GroupDestroyWorker
include
Sidekiq
::
Worker
sidekiq_options
queue: :default
def
perform
(
group_id
,
user_id
)
begin
group
=
Group
.
with_deleted
.
find
(
group_id
)
rescue
ActiveRecord
::
RecordNotFound
return
end
user
=
User
.
find
(
user_id
)
DestroyGroupService
.
new
(
group
,
user
).
execute
end
end
config/initializers/metrics.rb
View file @
4d4ef89c
...
...
@@ -148,6 +148,9 @@ if Gitlab::Metrics.enabled?
config
.
instrument_methods
(
Gitlab
::
Highlight
)
config
.
instrument_instance_methods
(
Gitlab
::
Highlight
)
# This is a Rails scope so we have to instrument it manually.
config
.
instrument_method
(
Project
,
:visible_to_user
)
end
GC
::
Profiler
.
enable
...
...
db/migrate/20140407135544_fix_namespaces.rb
View file @
4d4ef89c
# rubocop:disable all
class
FixNamespaces
<
ActiveRecord
::
Migration
DOWNTIME
=
false
def
up
Namespace
.
where
(
'name <> path and type is null'
).
each
do
|
namespace
|
namespace
.
update_attribute
(
:name
,
namespace
.
path
)
namespaces
=
exec_query
(
'SELECT id, path FROM namespaces WHERE name <> path and type is null'
)
namespaces
.
each
do
|
row
|
id
=
row
[
'id'
]
path
=
row
[
'path'
]
exec_query
(
"UPDATE namespaces SET name = '
#{
path
}
' WHERE id =
#{
id
}
"
)
end
end
...
...
db/migrate/20160805041956_add_deleted_at_to_namespaces.rb
0 → 100644
View file @
4d4ef89c
class
AddDeletedAtToNamespaces
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
change
add_column
:namespaces
,
:deleted_at
,
:datetime
add_concurrent_index
:namespaces
,
:deleted_at
end
end
db/schema.rb
View file @
4d4ef89c
...
...
@@ -640,9 +640,11 @@ ActiveRecord::Schema.define(version: 20160810142633) do
t
.
boolean
"share_with_group_lock"
,
default:
false
t
.
integer
"visibility_level"
,
default:
20
,
null:
false
t
.
boolean
"request_access_enabled"
,
default:
true
,
null:
false
t
.
datetime
"deleted_at"
end
add_index
"namespaces"
,
[
"created_at"
],
name:
"index_namespaces_on_created_at"
,
using: :btree
add_index
"namespaces"
,
[
"deleted_at"
],
name:
"index_namespaces_on_deleted_at"
,
using: :btree
add_index
"namespaces"
,
[
"name"
],
name:
"index_namespaces_on_name"
,
unique:
true
,
using: :btree
add_index
"namespaces"
,
[
"name"
],
name:
"index_namespaces_on_name_trigram"
,
using: :gin
,
opclasses:
{
"name"
=>
"gin_trgm_ops"
}
add_index
"namespaces"
,
[
"owner_id"
],
name:
"index_namespaces_on_owner_id"
,
using: :btree
...
...
spec/controllers/admin/groups_controller_spec.rb
0 → 100644
View file @
4d4ef89c
require
'spec_helper'
describe
Admin
::
GroupsController
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:admin
)
{
create
(
:admin
)
}
before
do
sign_in
(
admin
)
Sidekiq
::
Testing
.
fake!
end
describe
'DELETE #destroy'
do
it
'schedules a group destroy'
do
expect
{
delete
:destroy
,
id:
project
.
group
.
path
}.
to
change
(
GroupDestroyWorker
.
jobs
,
:size
).
by
(
1
)
end
it
'redirects to the admin group path'
do
delete
:destroy
,
id:
project
.
group
.
path
expect
(
response
).
to
redirect_to
(
admin_groups_path
)
end
end
end
spec/controllers/groups_controller_spec.rb
View file @
4d4ef89c
...
...
@@ -75,4 +75,33 @@ describe GroupsController do
end
end
end
describe
'DELETE #destroy'
do
context
'as another user'
do
it
'returns 404'
do
sign_in
(
create
(
:user
))
delete
:destroy
,
id:
group
.
path
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'as the group owner'
do
before
do
Sidekiq
::
Testing
.
fake!
sign_in
(
user
)
end
it
'schedules a group destroy'
do
expect
{
delete
:destroy
,
id:
group
.
path
}.
to
change
(
GroupDestroyWorker
.
jobs
,
:size
).
by
(
1
)
end
it
'redirects to the root path'
do
delete
:destroy
,
id:
group
.
path
expect
(
response
).
to
redirect_to
(
root_path
)
end
end
end
end
spec/requests/api/users_spec.rb
View file @
4d4ef89c
...
...
@@ -564,12 +564,14 @@ describe API::API, api: true do
end
describe
"DELETE /users/:id"
do
let!
(
:namespace
)
{
user
.
namespace
}
before
{
admin
}
it
"deletes user"
do
delete
api
(
"/users/
#{
user
.
id
}
"
,
admin
)
expect
(
response
).
to
have_http_status
(
200
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordNotFound
expect
{
Namespace
.
find
(
namespace
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordNotFound
expect
(
json_response
[
'email'
]).
to
eq
(
user
.
email
)
end
...
...
spec/services/delete_user_service_spec.rb
View file @
4d4ef89c
...
...
@@ -9,9 +9,11 @@ describe DeleteUserService, services: true do
context
'no options are given'
do
it
'deletes the user'
do
DeleteUserService
.
new
(
current_user
).
execute
(
user
)
user_data
=
DeleteUserService
.
new
(
current_user
).
execute
(
user
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
user_data
[
'email'
].
to
eq
(
user
.
email
)
}
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
{
Namespace
.
with_deleted
.
find
(
user
.
namespace
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
it
'will delete the project in the near future'
do
...
...
spec/services/destroy_group_service_spec.rb
View file @
4d4ef89c
...
...
@@ -7,38 +7,52 @@ describe DestroyGroupService, services: true do
let!
(
:gitlab_shell
)
{
Gitlab
::
Shell
.
new
}
let!
(
:remove_path
)
{
group
.
path
+
"+
#{
group
.
id
}
+deleted"
}
context
'database records'
do
before
do
destroy_group
(
group
,
user
)
shared_examples
'group destruction'
do
|
async
|
context
'database records'
do
before
do
destroy_group
(
group
,
user
,
async
)
end
it
{
expect
(
Group
.
all
).
not_to
include
(
group
)
}
it
{
expect
(
Project
.
all
).
not_to
include
(
project
)
}
end
it
{
expect
(
Group
.
all
).
not_to
include
(
group
)
}
it
{
expect
(
Project
.
all
).
not_to
include
(
project
)
}
end
context
'file system'
do
context
'Sidekiq inline'
do
before
do
# Run sidekiq immediatly to check that renamed dir will be removed
Sidekiq
::
Testing
.
inline!
{
destroy_group
(
group
,
user
,
async
)
}
end
context
'file system'
do
context
'Sidekiq inline'
do
before
do
# Run sidekiq immediatly to check that renamed dir will be removed
Sidekiq
::
Testing
.
inline!
{
destroy_group
(
group
,
user
)
}
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
group
.
path
)).
to
be_falsey
}
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
remove_path
)).
to
be_falsey
}
end
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
group
.
path
)).
to
be_falsey
}
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
remove_path
)).
to
be_falsey
}
end
context
'Sidekiq fake'
do
before
do
# Dont run sidekiq to check if renamed repository exists
Sidekiq
::
Testing
.
fake!
{
destroy_group
(
group
,
user
,
async
)
}
end
context
'Sidekiq fake'
do
before
do
# Dont run sidekiq to check if renamed repository exists
Sidekiq
::
Testing
.
fake!
{
destroy_group
(
group
,
user
)
}
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
group
.
path
)).
to
be_falsey
}
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
remove_path
)).
to
be_truthy
}
end
end
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
group
.
path
)).
to
be_falsey
}
it
{
expect
(
gitlab_shell
.
exists?
(
project
.
repository_storage_path
,
remove_path
)).
to
be_truthy
}
def
destroy_group
(
group
,
user
,
async
)
if
async
DestroyGroupService
.
new
(
group
,
user
).
async_execute
else
DestroyGroupService
.
new
(
group
,
user
).
execute
end
end
end
def
destroy_group
(
group
,
user
)
DestroyGroupService
.
new
(
group
,
user
).
execute
describe
'asynchronous delete'
do
it_behaves_like
'group destruction'
,
true
end
describe
'synchronous delete'
do
it_behaves_like
'group destruction'
,
false
end
end
spec/workers/group_destroy_worker_spec.rb
0 → 100644
View file @
4d4ef89c
require
'spec_helper'
describe
GroupDestroyWorker
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:user
)
{
create
(
:admin
)
}
let!
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
subject
{
GroupDestroyWorker
.
new
}
describe
"#perform"
do
it
"deletes the project"
do
subject
.
perform
(
group
.
id
,
user
.
id
)
expect
(
Group
.
all
).
not_to
include
(
group
)
expect
(
Project
.
all
).
not_to
include
(
project
)
expect
(
Dir
.
exist?
(
project
.
path
)).
to
be_falsey
end
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