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
self
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
SecurityEvent
.
create
(
author_id:
@author
.
id
,
...
...
app/services/users/update_service.rb
View file @
82f5cd46
module
Users
class
UpdateService
<
BaseService
include
EE
::
Audit
::
Changes
include
NewUserNotifier
def
initialize
(
current_user
,
user
,
params
=
{})
...
...
@@ -16,6 +17,9 @@ module Users
user_exists
=
@user
.
persisted?
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
success
...
...
lib/ee/audit/changes.rb
View file @
82f5cd46
module
EE
module
Audit
module
Changes
def
audit_changes
(
current_user
,
column
,
options
=
{})
def
audit_changes
(
column
,
options
=
{})
column
=
options
[
:column
]
||
column
return
unless
changed?
(
column
)
audit_event
(
current_user
,
parse_options
(
column
,
options
))
audit_event
(
parse_options
(
column
,
options
))
end
protected
...
...
@@ -35,8 +37,8 @@ module EE
end
end
def
audit_event
(
current_user
,
options
)
AuditEventService
.
new
(
current_user
,
model
,
options
).
def
audit_event
(
options
)
AuditEventService
.
new
(
@
current_user
,
model
,
options
).
for_changes
.
security_event
end
end
...
...
spec/lib/ee/audit/changes_spec.rb
View file @
82f5cd46
...
...
@@ -3,10 +3,11 @@ require 'spec_helper'
describe
EE
::
Audit
::
Changes
do
describe
'.audit_changes'
do
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
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
describe
'non audit changes'
do
...
...
@@ -14,7 +15,7 @@ describe EE::Audit::Changes do
expect_any_instance_of
(
AuditEventService
).
not_to
receive
(
:security_event
)
user
.
update!
(
name:
'new name'
)
foo_
class
.
new
.
audit_changes
(
user
,
:email
)
foo_
instance
.
audit_changes
(
:email
)
end
end
...
...
@@ -23,7 +24,7 @@ describe EE::Audit::Changes do
expect_any_instance_of
(
AuditEventService
).
to
receive
(
:security_event
)
user
.
update!
(
name:
'new name'
)
foo_
class
.
new
.
audit_changes
(
user
,
:name
)
foo_
instance
.
audit_changes
(
:name
)
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