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
72b9c14e
Commit
72b9c14e
authored
Jun 14, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored mail observer
parent
f5ee330a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
37 deletions
+40
-37
app/models/mailer_observer.rb
app/models/mailer_observer.rb
+40
-37
No files found.
app/models/mailer_observer.rb
View file @
72b9c14e
...
@@ -27,25 +27,31 @@ class MailerObserver < ActiveRecord::Observer
...
@@ -27,25 +27,31 @@ class MailerObserver < ActiveRecord::Observer
end
end
def
new_note
(
note
)
def
new_note
(
note
)
# Notify whole team except author of note
if
note
.
notify
if
note
.
notify
note
.
project
.
users
.
reject
{
|
u
|
u
.
id
==
current_user
.
id
}
.
each
do
|
u
|
# Notify whole team except author of note
case
note
.
noteable_type
notify_note
(
note
)
when
"Commit"
then
Notify
.
note_commit_email
(
u
.
id
,
note
.
id
).
deliver
when
"Issue"
then
Notify
.
note_issue_email
(
u
.
id
,
note
.
id
).
deliver
when
"MergeRequest"
then
Notify
.
note_merge_request_email
(
u
.
id
,
note
.
id
).
deliver
when
"Snippet"
true
else
Notify
.
note_wall_email
(
u
.
id
,
note
.
id
).
deliver
end
end
# Notify only author of resource
elsif
note
.
notify_author
elsif
note
.
notify_author
# Notify only author of resource
Notify
.
note_commit_email
(
note
.
commit_author
.
id
,
note
.
id
).
deliver
Notify
.
note_commit_email
(
note
.
commit_author
.
id
,
note
.
id
).
deliver
else
# Otherwise ignore it
nil
end
end
def
notify_note
note
# reject author of note from mail list
users
=
note
.
project
.
users
.
reject
{
|
u
|
u
.
id
==
current_user
.
id
}
users
.
each
do
|
u
|
case
note
.
noteable_type
when
"Commit"
;
Notify
.
note_commit_email
(
u
.
id
,
note
.
id
).
deliver
when
"Issue"
;
Notify
.
note_issue_email
(
u
.
id
,
note
.
id
).
deliver
when
"MergeRequest"
;
Notify
.
note_merge_request_email
(
u
.
id
,
note
.
id
).
deliver
when
"Snippet"
;
true
else
Notify
.
note_wall_email
(
u
.
id
,
note
.
id
).
deliver
end
end
end
end
end
...
@@ -56,37 +62,34 @@ class MailerObserver < ActiveRecord::Observer
...
@@ -56,37 +62,34 @@ class MailerObserver < ActiveRecord::Observer
end
end
def
changed_merge_request
(
merge_request
)
def
changed_merge_request
(
merge_request
)
if
merge_request
.
assignee_id_changed?
status_notify_and_comment
issue
,
:reassigned_merge_request_email
recipients_ids
=
merge_request
.
assignee_id_was
,
merge_request
.
assignee_id
recipients_ids
.
delete
current_user
.
id
User
.
find
(
recipients_ids
).
each
do
|
user
|
Notify
.
reassigned_merge_request_email
(
user
.
id
,
merge_request
.
id
,
merge_request
.
assignee_id_was
).
deliver
end
end
if
merge_request
.
closed_changed?
note
=
Note
.
new
(
:noteable
=>
merge_request
,
:project
=>
merge_request
.
project
)
note
.
author
=
current_user
note
.
note
=
"_Status changed to
#{
merge_request
.
closed
?
'closed'
:
'reopened'
}
_"
note
.
save
()
end
end
end
def
changed_issue
(
issue
)
def
changed_issue
(
issue
)
if
issue
.
assignee_id_changed?
status_notify_and_comment
issue
,
:reassigned_issue_email
recipients_ids
=
issue
.
assignee_id_was
,
issue
.
assignee_id
end
# This method used for Issues & Merge Requests
#
# It create a comment for Issue or MR if someone close/reopen.
# It also notify via email if assignee was changed
#
def
status_notify_and_comment
target
,
mail_method
# If assigne changed - notify to recipients
if
target
.
assignee_id_changed?
recipients_ids
=
target
.
assignee_id_was
,
target
.
assignee_id
recipients_ids
.
delete
current_user
.
id
recipients_ids
.
delete
current_user
.
id
recipients_ids
.
each
do
|
recipient_id
|
recipients_ids
.
each
do
|
recipient_id
|
Notify
.
reassigned_issue_email
(
recipient_id
,
issue
.
id
,
issue
.
assignee_id_was
).
deliver
Notify
.
send
(
mail_method
,
recipient_id
,
target
.
id
,
target
.
assignee_id_was
).
deliver
end
end
end
end
if
issue
.
closed_changed?
# Create comment about status changed
note
=
Note
.
new
(
:noteable
=>
issue
,
:project
=>
issue
.
project
)
if
target
.
closed_changed?
note
=
Note
.
new
(
:noteable
=>
target
,
:project
=>
target
.
project
)
note
.
author
=
current_user
note
.
author
=
current_user
note
.
note
=
"_Status changed to
#{
issue
.
closed
?
'closed'
:
'reopened'
}
_"
note
.
note
=
"_Status changed to
#{
target
.
closed
?
'closed'
:
'reopened'
}
_"
note
.
save
()
note
.
save
()
end
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