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
Tatuya Kamada
gitlab-ce
Commits
6abf5846
Commit
6abf5846
authored
Mar 26, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move new_note email logic to NotificationService
parent
f93c4dc0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
34 deletions
+34
-34
app/observers/note_observer.rb
app/observers/note_observer.rb
+1
-32
app/observers/user_observer.rb
app/observers/user_observer.rb
+5
-2
app/services/notification_service.rb
app/services/notification_service.rb
+28
-0
No files found.
app/observers/note_observer.rb
View file @
6abf5846
class
NoteObserver
<
ActiveRecord
::
Observer
def
after_create
(
note
)
send_notify_mails
(
note
)
notification
.
new_note
(
note
)
end
protected
def
send_notify_mails
(
note
)
if
note
.
notify
notify_team
(
note
)
elsif
note
.
notify_author
# Notify only author of resource
if
note
.
commit_author
Notify
.
delay
.
note_commit_email
(
note
.
commit_author
.
id
,
note
.
id
)
end
else
# Otherwise ignore it
nil
end
end
# Notifies the whole team except the author of note
def
notify_team
(
note
)
# Note: wall posts are not "attached" to anything, so fall back to "Wall"
noteable_type
=
note
.
noteable_type
.
presence
||
"Wall"
notify_method
=
"note_
#{
noteable_type
.
underscore
}
_email"
.
to_sym
if
Notify
.
respond_to?
notify_method
team_without_note_author
(
note
).
map
do
|
u
|
Notify
.
delay
.
send
(
notify_method
,
u
.
id
,
note
.
id
)
end
end
end
def
team_without_note_author
(
note
)
note
.
project
.
users
.
reject
{
|
u
|
u
.
id
==
note
.
author
.
id
}
end
def
notification
NotificationService
.
new
end
...
...
app/observers/user_observer.rb
View file @
6abf5846
...
...
@@ -2,8 +2,7 @@ class UserObserver < ActiveRecord::Observer
def
after_create
(
user
)
log_info
(
"User
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
) was created"
)
# Dont email omniauth created users
Notify
.
delay
.
new_user_email
(
user
.
id
,
user
.
password
)
unless
user
.
extern_uid?
notification
.
new_user
(
user
)
end
def
after_destroy
user
...
...
@@ -25,4 +24,8 @@ class UserObserver < ActiveRecord::Observer
def
log_info
message
Gitlab
::
AppLogger
.
info
message
end
def
notification
NotificationService
.
new
end
end
app/services/notification_service.rb
View file @
6abf5846
...
...
@@ -80,4 +80,32 @@ class NotificationService
Notify
.
delay
.
reassigned_merge_request_email
(
recipient_id
,
merge_request
.
id
,
merge_request
.
assignee_id_was
)
end
end
# Notify new user with email after creation
def
new_user
(
user
)
# Dont email omniauth created users
Notify
.
delay
.
new_user_email
(
user
.
id
,
user
.
password
)
unless
user
.
extern_uid?
end
# Notify users on new note in system
#
# TODO: split on methods and refactor
#
def
new_note
(
note
)
if
note
.
notify
users
=
note
.
project
.
users
.
reject
{
|
u
|
u
.
id
==
note
.
author
.
id
}
# Note: wall posts are not "attached" to anything, so fall back to "Wall"
noteable_type
=
note
.
noteable_type
.
presence
||
"Wall"
notify_method
=
"note_
#{
noteable_type
.
underscore
}
_email"
.
to_sym
if
Notify
.
respond_to?
notify_method
team_without_note_author
(
note
).
map
do
|
u
|
Notify
.
delay
.
send
(
notify_method
,
u
.
id
,
note
.
id
)
end
end
elsif
note
.
notify_author
&&
note
.
commit_author
Notify
.
delay
.
note_commit_email
(
note
.
commit_author
.
id
,
note
.
id
)
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