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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
e94a2fde
Commit
e94a2fde
authored
Aug 25, 2017
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fire system hooks when a user is created via LDAP or OAuth
Closes #37073
parent
2be34630
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
6 deletions
+39
-6
app/services/concerns/users/new_user_notifier.rb
app/services/concerns/users/new_user_notifier.rb
+9
-0
app/services/users/create_service.rb
app/services/users/create_service.rb
+3
-5
app/services/users/update_service.rb
app/services/users/update_service.rb
+6
-0
changelogs/unreleased/sh-system-hooks-ldap-users.yml
changelogs/unreleased/sh-system-hooks-ldap-users.yml
+5
-0
spec/services/users/update_service_spec.rb
spec/services/users/update_service_spec.rb
+16
-1
No files found.
app/services/concerns/users/new_user_notifier.rb
0 → 100644
View file @
e94a2fde
module
Users
module
NewUserNotifier
def
notify_new_user
(
user
,
reset_token
)
log_info
(
"User
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
) was created"
)
notification_service
.
new_user
(
user
,
reset_token
)
if
reset_token
system_hook_service
.
execute_hooks_for
(
user
,
:create
)
end
end
end
app/services/users/create_service.rb
View file @
e94a2fde
module
Users
class
CreateService
<
BaseService
include
NewUserNotifier
def
initialize
(
current_user
,
params
=
{})
@current_user
=
current_user
@params
=
params
.
dup
...
...
@@ -10,11 +12,7 @@ module Users
@reset_token
=
user
.
generate_reset_token
if
user
.
recently_sent_password_reset?
if
user
.
save
log_info
(
"User
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
) was created"
)
notification_service
.
new_user
(
user
,
@reset_token
)
if
@reset_token
system_hook_service
.
execute_hooks_for
(
user
,
:create
)
end
notify_new_user
(
user
,
@reset_token
)
if
user
.
save
user
end
...
...
app/services/users/update_service.rb
View file @
e94a2fde
module
Users
class
UpdateService
<
BaseService
include
NewUserNotifier
def
initialize
(
user
,
params
=
{})
@user
=
user
@params
=
params
.
dup
...
...
@@ -10,7 +12,11 @@ module Users
assign_attributes
(
&
block
)
user_exists
=
@user
.
persisted?
if
@user
.
save
(
validate:
validate
)
notify_new_user
(
@user
,
nil
)
unless
user_exists
success
else
error
(
@user
.
errors
.
full_messages
.
uniq
.
join
(
'. '
))
...
...
changelogs/unreleased/sh-system-hooks-ldap-users.yml
0 → 100644
View file @
e94a2fde
---
title
:
Fire system hooks when a user is created via LDAP
merge_request
:
author
:
type
:
fixed
spec/services/users/update_service_spec.rb
View file @
e94a2fde
...
...
@@ -37,7 +37,10 @@ describe Users::UpdateService do
describe
'#execute!'
do
it
'updates the name'
do
result
=
update_user
(
user
,
name:
'New Name'
)
service
=
described_class
.
new
(
user
,
name:
'New Name'
)
expect
(
service
).
not_to
receive
(
:notify_new_user
)
result
=
service
.
execute!
expect
(
result
).
to
be
true
expect
(
user
.
name
).
to
eq
(
'New Name'
)
...
...
@@ -49,6 +52,18 @@ describe Users::UpdateService do
end
.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
end
it
'fires system hooks when a new user is saved'
do
system_hook_service
=
spy
(
:system_hook_service
)
user
=
build
(
:user
)
service
=
described_class
.
new
(
user
,
name:
'John Doe'
)
expect
(
service
).
to
receive
(
:notify_new_user
).
and_call_original
expect
(
service
).
to
receive
(
:system_hook_service
).
and_return
(
system_hook_service
)
service
.
execute
expect
(
system_hook_service
).
to
have_received
(
:execute_hooks_for
).
with
(
user
,
:create
)
end
def
update_user
(
user
,
opts
)
described_class
.
new
(
user
,
opts
).
execute!
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