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
f3fc5ac9
Commit
f3fc5ac9
authored
Feb 03, 2020
by
Tan Le
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record audit event when hard-deleting user
Add tests to cover all available user actions
parent
a2e4362e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
0 deletions
+102
-0
ee/app/services/ee/audit_event_service.rb
ee/app/services/ee/audit_event_service.rb
+4
-0
ee/app/services/ee/users/destroy_service.rb
ee/app/services/ee/users/destroy_service.rb
+10
-0
ee/spec/services/audit_event_service_spec.rb
ee/spec/services/audit_event_service_spec.rb
+55
-0
ee/spec/services/users/destroy_service_spec.rb
ee/spec/services/users/destroy_service_spec.rb
+33
-0
No files found.
ee/app/services/ee/audit_event_service.rb
View file @
f3fc5ac9
...
@@ -120,6 +120,10 @@ module EE
...
@@ -120,6 +120,10 @@ module EE
)
)
end
end
def
for_user
for_custom_model
(
'user'
,
@entity
.
full_path
)
end
def
for_project
def
for_project
for_custom_model
(
'project'
,
@entity
.
full_path
)
for_custom_model
(
'project'
,
@entity
.
full_path
)
end
end
...
...
ee/app/services/ee/users/destroy_service.rb
View file @
f3fc5ac9
...
@@ -10,6 +10,8 @@ module EE
...
@@ -10,6 +10,8 @@ module EE
super
(
user
,
options
)
do
|
delete_user
|
super
(
user
,
options
)
do
|
delete_user
|
mirror_cleanup
(
delete_user
)
mirror_cleanup
(
delete_user
)
end
end
log_audit_event
(
user
)
if
options
[
:hard_delete
]
end
end
def
mirror_cleanup
(
user
)
def
mirror_cleanup
(
user
)
...
@@ -31,6 +33,14 @@ module EE
...
@@ -31,6 +33,14 @@ module EE
mirror_owners
.
first
mirror_owners
.
first
end
end
def
log_audit_event
(
user
)
::
AuditEventService
.
new
(
current_user
,
user
,
action: :destroy
).
for_user
.
security_event
end
end
end
end
end
end
end
ee/spec/services/audit_event_service_spec.rb
View file @
f3fc5ac9
...
@@ -214,6 +214,61 @@ describe AuditEventService do
...
@@ -214,6 +214,61 @@ describe AuditEventService do
end
end
end
end
describe
'#for_user'
do
let
(
:author_name
)
{
'Administrator'
}
let
(
:current_user
)
{
instance_spy
(
User
,
name:
author_name
)
}
let
(
:target_user_full_path
)
{
'ejohn'
}
let
(
:user
)
{
instance_spy
(
User
,
full_path:
target_user_full_path
)
}
let
(
:custom_message
)
{
'Some strange event has occurred'
}
let
(
:ip_address
)
{
'127.0.0.1'
}
let
(
:options
)
{
{
action:
action
,
custom_message:
custom_message
,
ip_address:
ip_address
}
}
subject
(
:service
)
{
described_class
.
new
(
current_user
,
user
,
options
).
for_user
}
context
'with destroy action'
do
let
(
:action
)
{
:destroy
}
it
'sets the details attribute'
do
expect
(
service
.
instance_variable_get
(
:@details
)).
to
eq
(
remove:
'user'
,
author_name:
author_name
,
target_id:
target_user_full_path
,
target_type:
'User'
,
target_details:
target_user_full_path
)
end
end
context
'with create action'
do
let
(
:action
)
{
:create
}
it
'sets the details attribute'
do
expect
(
service
.
instance_variable_get
(
:@details
)).
to
eq
(
add:
'user'
,
author_name:
author_name
,
target_id:
target_user_full_path
,
target_type:
'User'
,
target_details:
target_user_full_path
)
end
end
context
'with custom action'
do
let
(
:action
)
{
:custom
}
it
'sets the details attribute'
do
expect
(
service
.
instance_variable_get
(
:@details
)).
to
eq
(
custom_message:
custom_message
,
author_name:
author_name
,
target_id:
target_user_full_path
,
target_type:
'User'
,
target_details:
target_user_full_path
,
ip_address:
ip_address
)
end
end
end
describe
'license'
do
describe
'license'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
ee/spec/services/users/destroy_service_spec.rb
0 → 100644
View file @
f3fc5ac9
# frozen_string_literal: true
require
'spec_helper'
describe
Users
::
DestroyService
do
let
(
:current_user
)
{
create
(
:admin
)
}
subject
(
:service
)
{
described_class
.
new
(
current_user
)
}
describe
'#execute'
do
let
(
:user
)
{
create
(
:user
)
}
describe
'audit events'
do
before
do
stub_licensed_features
(
admin_audit_log:
true
)
end
context
'when hard_delete'
do
let
(
:hard_delete
)
{
true
}
it
'logs audit event'
do
expected_message
=
"Removed user"
expect
do
service
.
execute
(
user
,
hard_delete:
hard_delete
)
end
.
to
change
{
AuditEvent
.
count
}.
by
(
1
)
expect
(
AuditEvent
.
last
.
present
.
action
).
to
eq
(
expected_message
)
end
end
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