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
Kazuhiko Shiozaki
gitlab-ce
Commits
a90a201d
Commit
a90a201d
authored
10 years ago
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove user observer
parent
a7d5052c
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
50 deletions
+37
-50
app/models/user.rb
app/models/user.rb
+36
-0
app/observers/user_observer.rb
app/observers/user_observer.rb
+0
-21
config/application.rb
config/application.rb
+1
-2
spec/observers/user_observer_spec.rb
spec/observers/user_observer_spec.rb
+0
-27
No files found.
app/models/user.rb
View file @
a90a201d
...
...
@@ -132,6 +132,10 @@ class User < ActiveRecord::Base
before_validation
:sanitize_attrs
before_save
:ensure_authentication_token
after_save
:ensure_namespace_correct
after_create
:post_create_hook
after_destroy
:post_destroy_hook
alias_attribute
:private_token
,
:authentication_token
...
...
@@ -490,4 +494,36 @@ class User < ActiveRecord::Base
GravatarService
.
new
.
execute
(
email
,
size
)
end
end
def
ensure_namespace_correct
# Ensure user has namespace
self
.
create_namespace!
(
path:
self
.
username
,
name:
self
.
username
)
unless
self
.
namespace
if
self
.
username_changed?
self
.
namespace
.
update_attributes
(
path:
self
.
username
,
name:
self
.
username
)
end
end
def
post_create_hook
log_info
(
"User
\"
#{
self
.
name
}
\"
(
#{
self
.
email
}
) was created"
)
notification
.
new_user
(
self
)
system_hook_service
.
execute_hooks_for
(
self
,
:create
)
end
def
post_destroy_hook
log_info
(
"User
\"
#{
self
.
name
}
\"
(
#{
self
.
email
}
) was removed"
)
system_hook_service
.
execute_hooks_for
(
self
,
:destroy
)
end
def
notification
NotificationService
.
new
end
def
log_info
message
Gitlab
::
AppLogger
.
info
message
end
def
system_hook_service
SystemHooksService
.
new
end
end
This diff is collapsed.
Click to expand it.
app/observers/user_observer.rb
deleted
100644 → 0
View file @
a7d5052c
class
UserObserver
<
BaseObserver
def
after_create
(
user
)
log_info
(
"User
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
) was created"
)
notification
.
new_user
(
user
)
system_hook_service
.
execute_hooks_for
(
user
,
:create
)
end
def
after_destroy
user
log_info
(
"User
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
) was removed"
)
system_hook_service
.
execute_hooks_for
(
user
,
:destroy
)
end
def
after_save
user
# Ensure user has namespace
user
.
create_namespace!
(
path:
user
.
username
,
name:
user
.
username
)
unless
user
.
namespace
if
user
.
username_changed?
user
.
namespace
.
update_attributes
(
path:
user
.
username
,
name:
user
.
username
)
end
end
end
This diff is collapsed.
Click to expand it.
config/application.rb
View file @
a90a201d
...
...
@@ -19,8 +19,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:user_observer
,
:users_project_observer
config
.
active_record
.
observers
=
:users_project_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
...
...
This diff is collapsed.
Click to expand it.
spec/observers/user_observer_spec.rb
deleted
100644 → 0
View file @
a7d5052c
require
'spec_helper'
describe
UserObserver
do
before
(
:each
)
{
enable_observers
}
after
(
:each
)
{
disable_observers
}
subject
{
UserObserver
.
instance
}
before
{
subject
.
stub
(
notification:
double
(
'NotificationService'
).
as_null_object
)
}
it
'calls #after_create when new users are created'
do
new_user
=
build
(
:user
)
subject
.
should_receive
(
:after_create
).
with
(
new_user
)
new_user
.
save
end
context
'when a new user is created'
do
it
'sends an email'
do
subject
.
should_receive
(
:notification
)
create
(
:user
)
end
it
'trigger logger'
do
user
=
double
(
:user
,
id:
42
,
password:
'P@ssword!'
,
name:
'John'
,
email:
'u@mail.local'
,
extern_uid?:
false
)
Gitlab
::
AppLogger
.
should_receive
(
:info
)
create
(
:user
)
end
end
end
This diff is collapsed.
Click to expand it.
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