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
82f5cd46
Commit
82f5cd46
authored
Jul 04, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add event changes to users update service
parent
dff7db5a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
8 deletions
+30
-8
app/services/audit_event_service.rb
app/services/audit_event_service.rb
+15
-0
app/services/users/update_service.rb
app/services/users/update_service.rb
+4
-0
lib/ee/audit/changes.rb
lib/ee/audit/changes.rb
+6
-4
spec/lib/ee/audit/changes_spec.rb
spec/lib/ee/audit/changes_spec.rb
+5
-4
No files found.
app/services/audit_event_service.rb
View file @
82f5cd46
...
@@ -16,6 +16,21 @@ class AuditEventService
...
@@ -16,6 +16,21 @@ class AuditEventService
self
self
end
end
def
for_changes
@details
=
{
change:
@details
[
:as
]
||
@details
[
:column
],
from:
@details
[
:from
],
to:
@details
[
:to
],
author_name:
@author
.
name
,
target_id:
@entity
.
id
,
target_type:
@entity
.
class
,
target_details:
@entity
.
name
}
self
end
def
security_event
def
security_event
SecurityEvent
.
create
(
SecurityEvent
.
create
(
author_id:
@author
.
id
,
author_id:
@author
.
id
,
...
...
app/services/users/update_service.rb
View file @
82f5cd46
module
Users
module
Users
class
UpdateService
<
BaseService
class
UpdateService
<
BaseService
include
EE
::
Audit
::
Changes
include
NewUserNotifier
include
NewUserNotifier
def
initialize
(
current_user
,
user
,
params
=
{})
def
initialize
(
current_user
,
user
,
params
=
{})
...
@@ -16,6 +17,9 @@ module Users
...
@@ -16,6 +17,9 @@ module Users
user_exists
=
@user
.
persisted?
user_exists
=
@user
.
persisted?
if
@user
.
save
(
validate:
validate
)
if
@user
.
save
(
validate:
validate
)
audit_changes
:email
,
as:
'email address'
,
column: :notification_email
audit_changes
:encrypted_password
,
as:
'password'
,
skip_changes:
true
notify_new_user
(
@user
,
nil
)
unless
user_exists
notify_new_user
(
@user
,
nil
)
unless
user_exists
success
success
...
...
lib/ee/audit/changes.rb
View file @
82f5cd46
module
EE
module
EE
module
Audit
module
Audit
module
Changes
module
Changes
def
audit_changes
(
current_user
,
column
,
options
=
{})
def
audit_changes
(
column
,
options
=
{})
column
=
options
[
:column
]
||
column
return
unless
changed?
(
column
)
return
unless
changed?
(
column
)
audit_event
(
current_user
,
parse_options
(
column
,
options
))
audit_event
(
parse_options
(
column
,
options
))
end
end
protected
protected
...
@@ -35,8 +37,8 @@ module EE
...
@@ -35,8 +37,8 @@ module EE
end
end
end
end
def
audit_event
(
current_user
,
options
)
def
audit_event
(
options
)
AuditEventService
.
new
(
current_user
,
model
,
options
).
AuditEventService
.
new
(
@
current_user
,
model
,
options
).
for_changes
.
security_event
for_changes
.
security_event
end
end
end
end
...
...
spec/lib/ee/audit/changes_spec.rb
View file @
82f5cd46
...
@@ -3,10 +3,11 @@ require 'spec_helper'
...
@@ -3,10 +3,11 @@ require 'spec_helper'
describe
EE
::
Audit
::
Changes
do
describe
EE
::
Audit
::
Changes
do
describe
'.audit_changes'
do
describe
'.audit_changes'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:foo_
class
)
{
Class
.
new
{
include
EE
::
Audit
::
Changes
}
}
let
(
:foo_
instance
)
{
Class
.
new
{
include
EE
::
Audit
::
Changes
}.
new
}
before
do
before
do
allow_any_instance_of
(
foo_class
).
to
receive
(
:model
).
and_return
(
user
)
foo_instance
.
instance_variable_set
(
:@current_user
,
user
)
allow
(
foo_instance
).
to
receive
(
:model
).
and_return
(
user
)
end
end
describe
'non audit changes'
do
describe
'non audit changes'
do
...
@@ -14,7 +15,7 @@ describe EE::Audit::Changes do
...
@@ -14,7 +15,7 @@ describe EE::Audit::Changes do
expect_any_instance_of
(
AuditEventService
).
not_to
receive
(
:security_event
)
expect_any_instance_of
(
AuditEventService
).
not_to
receive
(
:security_event
)
user
.
update!
(
name:
'new name'
)
user
.
update!
(
name:
'new name'
)
foo_
class
.
new
.
audit_changes
(
user
,
:email
)
foo_
instance
.
audit_changes
(
:email
)
end
end
end
end
...
@@ -23,7 +24,7 @@ describe EE::Audit::Changes do
...
@@ -23,7 +24,7 @@ describe EE::Audit::Changes do
expect_any_instance_of
(
AuditEventService
).
to
receive
(
:security_event
)
expect_any_instance_of
(
AuditEventService
).
to
receive
(
:security_event
)
user
.
update!
(
name:
'new name'
)
user
.
update!
(
name:
'new name'
)
foo_
class
.
new
.
audit_changes
(
user
,
:name
)
foo_
instance
.
audit_changes
(
:name
)
end
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