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
cbe5c813
Commit
cbe5c813
authored
Apr 29, 2020
by
Rajendra Kadam
Committed by
Peter Leitzen
Apr 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor EE app services
parent
c3e08d1c
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
86 additions
and
83 deletions
+86
-83
app/services/emails/base_service.rb
app/services/emails/base_service.rb
+2
-0
changelogs/unreleased/refactor-ee-app-services.yml
changelogs/unreleased/refactor-ee-app-services.yml
+5
-0
ee/app/controllers/ee/confirmations_controller.rb
ee/app/controllers/ee/confirmations_controller.rb
+1
-1
ee/app/services/concerns/approval_rules/updater.rb
ee/app/services/concerns/approval_rules/updater.rb
+1
-1
ee/app/services/ee/emails/create_service.rb
ee/app/services/ee/emails/create_service.rb
+0
-1
ee/app/services/ee/emails/destroy_service.rb
ee/app/services/ee/emails/destroy_service.rb
+0
-1
ee/app/services/ee/users/update_service.rb
ee/app/services/ee/users/update_service.rb
+1
-1
ee/lib/audit/changes.rb
ee/lib/audit/changes.rb
+73
-0
ee/lib/ee/audit/base_changes_auditor.rb
ee/lib/ee/audit/base_changes_auditor.rb
+1
-1
ee/lib/ee/audit/changes.rb
ee/lib/ee/audit/changes.rb
+0
-75
ee/spec/lib/audit/changes_spec.rb
ee/spec/lib/audit/changes_spec.rb
+2
-2
No files found.
app/services/emails/base_service.rb
View file @
cbe5c813
...
...
@@ -11,3 +11,5 @@ module Emails
end
end
end
Emails
::
BaseService
.
prepend_if_ee
(
'::EE::Emails::BaseService'
)
changelogs/unreleased/refactor-ee-app-services.yml
0 → 100644
View file @
cbe5c813
---
title
:
Move prepend to last line in ee/services
merge_request
:
30425
author
:
Rajendra Kadam
type
:
fixed
ee/app/controllers/ee/confirmations_controller.rb
View file @
cbe5c813
...
...
@@ -2,7 +2,7 @@
module
EE
module
ConfirmationsController
include
EE
::
Audit
::
Changes
# rubocop: disable Cop/InjectEnterpriseEditionModule
include
::
Audit
::
Changes
extend
::
Gitlab
::
Utils
::
Override
protected
...
...
ee/app/services/concerns/approval_rules/updater.rb
View file @
cbe5c813
...
...
@@ -2,7 +2,7 @@
module
ApprovalRules
module
Updater
include
EE
::
Audit
::
Changes
# rubocop: disable Cop/InjectEnterpriseEditionModule
include
Audit
::
Changes
def
action
filter_eligible_users!
...
...
ee/app/services/ee/emails/create_service.rb
View file @
cbe5c813
...
...
@@ -4,7 +4,6 @@ module EE
module
Emails
module
CreateService
extend
::
Gitlab
::
Utils
::
Override
include
::
EE
::
Emails
::
BaseService
# rubocop: disable Cop/InjectEnterpriseEditionModule
override
:execute
def
execute
(
extra_params
=
{})
...
...
ee/app/services/ee/emails/destroy_service.rb
View file @
cbe5c813
...
...
@@ -4,7 +4,6 @@ module EE
module
Emails
module
DestroyService
extend
::
Gitlab
::
Utils
::
Override
include
::
EE
::
Emails
::
BaseService
# rubocop: disable Cop/InjectEnterpriseEditionModule
override
:execute
def
execute
(
email
)
...
...
ee/app/services/ee/users/update_service.rb
View file @
cbe5c813
...
...
@@ -4,8 +4,8 @@ module EE
module
Users
module
UpdateService
extend
::
Gitlab
::
Utils
::
Override
include
EE
::
Audit
::
Changes
# rubocop: disable Cop/InjectEnterpriseEditionModule
include
::
Gitlab
::
Utils
::
StrongMemoize
include
Audit
::
Changes
attr_reader
:group_id_for_saml
...
...
ee/lib/audit/changes.rb
0 → 100644
View file @
cbe5c813
# frozen_string_literal: true
module
Audit
module
Changes
# Records an audit event in DB for model changes
#
# @param [Symbol] column column name to be audited
# @param [Hash] options the options to create an event with
# @option options [Symbol] :column column name to be audited
# @option options [User, Project, Group] :target_model scope the event belongs to
# @option options [Object] :model object being audited
# @option options [Boolean] :skip_changes whether to record from/to values
#
# @return [SecurityEvent, nil] the resulting object or nil if there is no
# change detected
def
audit_changes
(
column
,
options
=
{})
column
=
options
[
:column
]
||
column
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@entity
=
options
[
:entity
]
@model
=
options
[
:model
]
# rubocop:enable Gitlab/ModuleWithInstanceVariables
return
unless
audit_required?
(
column
)
audit_event
(
parse_options
(
column
,
options
))
end
protected
def
entity
@entity
||
model
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def
model
@model
end
private
def
audit_required?
(
column
)
not_recently_created?
&&
changed?
(
column
)
end
def
not_recently_created?
!
model
.
previous_changes
.
has_key?
(
:id
)
end
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
[
:action
]
=
:update
unless
options
[
:skip_changes
]
options_hash
[
:from
]
=
changes
(
column
).
first
options_hash
[
:to
]
=
changes
(
column
).
last
end
end
end
def
audit_event
(
options
)
::
AuditEventService
.
new
(
@current_user
,
entity
,
options
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
.
for_changes
(
model
).
security_event
end
end
end
ee/lib/ee/audit/base_changes_auditor.rb
View file @
cbe5c813
...
...
@@ -3,7 +3,7 @@
module
EE
module
Audit
class
BaseChangesAuditor
include
Changes
include
::
Audit
::
Changes
def
initialize
(
current_user
,
model
)
@model
=
model
...
...
ee/lib/ee/audit/changes.rb
deleted
100644 → 0
View file @
c3e08d1c
# frozen_string_literal: true
module
EE
module
Audit
module
Changes
# Records an audit event in DB for model changes
#
# @param [Symbol] column column name to be audited
# @param [Hash] options the options to create an event with
# @option options [Symbol] :column column name to be audited
# @option options [User, Project, Group] :target_model scope the event belongs to
# @option options [Object] :model object being audited
# @option options [Boolean] :skip_changes whether to record from/to values
#
# @return [SecurityEvent, nil] the resulting object or nil if there is no
# change detected
def
audit_changes
(
column
,
options
=
{})
column
=
options
[
:column
]
||
column
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@entity
=
options
[
:entity
]
@model
=
options
[
:model
]
# rubocop:enable Gitlab/ModuleWithInstanceVariables
return
unless
audit_required?
(
column
)
audit_event
(
parse_options
(
column
,
options
))
end
protected
def
entity
@entity
||
model
# rubocop:disable Gitlab/ModuleWithInstanceVariables
end
def
model
@model
end
private
def
audit_required?
(
column
)
not_recently_created?
&&
changed?
(
column
)
end
def
not_recently_created?
!
model
.
previous_changes
.
has_key?
(
:id
)
end
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
[
:action
]
=
:update
unless
options
[
:skip_changes
]
options_hash
[
:from
]
=
changes
(
column
).
first
options_hash
[
:to
]
=
changes
(
column
).
last
end
end
end
def
audit_event
(
options
)
::
AuditEventService
.
new
(
@current_user
,
entity
,
options
)
# rubocop:disable Gitlab/ModuleWithInstanceVariables
.
for_changes
(
model
).
security_event
end
end
end
end
ee/spec/lib/
ee/
audit/changes_spec.rb
→
ee/spec/lib/audit/changes_spec.rb
View file @
cbe5c813
...
...
@@ -2,8 +2,8 @@
require
'spec_helper'
describe
EE
::
Audit
::
Changes
do
subject
(
:foo_instance
)
{
Class
.
new
{
include
EE
::
Audit
::
Changes
}.
new
}
describe
Audit
::
Changes
do
subject
(
:foo_instance
)
{
Class
.
new
{
include
Audit
::
Changes
}.
new
}
describe
'.audit_changes'
do
let
(
:current_user
)
{
create
(
:user
,
name:
'Mickey Mouse'
)
}
...
...
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