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
dff7db5a
Commit
dff7db5a
authored
Jul 04, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor changes framework and fix spec
parent
defa48ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
16 deletions
+21
-16
lib/ee/audit/changes.rb
lib/ee/audit/changes.rb
+17
-12
spec/lib/ee/audit/changes_spec.rb
spec/lib/ee/audit/changes_spec.rb
+4
-4
No files found.
lib/ee/audit/changes.rb
View file @
dff7db5a
module
EE
module
Audit
module
Changes
def
audit_changes
(
column
,
options
=
{})
return
unless
model
.
send
(
"
#{
column
}
_changed?"
)
def
audit_changes
(
c
urrent_user
,
c
olumn
,
options
=
{})
return
unless
changed?
(
column
)
@column
=
column
@options
=
generate_options
(
options
)
audit_event
audit_event
(
current_user
,
parse_options
(
column
,
options
))
end
protected
...
...
@@ -18,20 +15,28 @@ module EE
private
def
generate_options
(
options
)
def
changed?
(
column
)
model
.
previous_changes
.
has_key?
(
column
)
end
def
changes
(
column
)
model
.
previous_changes
[
column
]
end
def
parse_options
(
column
,
options
)
options
.
tap
do
|
options_hash
|
options_hash
[
:column
]
=
@
column
options_hash
[
:column
]
=
column
options_hash
[
:action
]
=
:update
unless
options
[
:skip_changes
]
options_hash
[
:from
]
=
model
.
public_send
(
"
#{
@column
}
_was"
)
options_hash
[
:to
]
=
model
.
public_send
(
"
#{
@column
}
"
)
options_hash
[
:from
]
=
changes
(
column
).
first
options_hash
[
:to
]
=
changes
(
column
).
last
end
end
end
def
audit_event
AuditEventService
.
new
(
@current_user
,
model
,
@
options
).
def
audit_event
(
current_user
,
options
)
AuditEventService
.
new
(
current_user
,
model
,
options
).
for_changes
.
security_event
end
end
...
...
spec/lib/ee/audit/changes_spec.rb
View file @
dff7db5a
...
...
@@ -13,8 +13,8 @@ describe EE::Audit::Changes do
it
'does not call the audit event service'
do
expect_any_instance_of
(
AuditEventService
).
not_to
receive
(
:security_event
)
user
.
name
=
'new name'
foo_class
.
new
.
audit_changes
(
:email
)
user
.
update!
(
name:
'new name'
)
foo_class
.
new
.
audit_changes
(
user
,
:email
)
end
end
...
...
@@ -22,8 +22,8 @@ describe EE::Audit::Changes do
it
'calls the audit event service'
do
expect_any_instance_of
(
AuditEventService
).
to
receive
(
:security_event
)
user
.
name
=
'new name'
foo_class
.
new
.
audit_changes
(
:name
)
user
.
update!
(
name:
'new name'
)
foo_class
.
new
.
audit_changes
(
user
,
: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