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
iv
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
end
def
new_note
(
note
)
# Notify whole team except author of note
if
note
.
notify
note
.
project
.
users
.
reject
{
|
u
|
u
.
id
==
current_user
.
id
}
.
each
do
|
u
|
case
note
.
noteable_type
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
# Notify whole team except author of note
notify_note
(
note
)
elsif
note
.
notify_author
# Notify only author of resource
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
...
...
@@ -56,37 +62,34 @@ class MailerObserver < ActiveRecord::Observer
end
def
changed_merge_request
(
merge_request
)
if
merge_request
.
assignee_id_changed?
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
status_notify_and_comment
issue
,
:reassigned_merge_request_email
end
def
changed_issue
(
issue
)
if
issue
.
assignee_id_changed?
recipients_ids
=
issue
.
assignee_id_was
,
issue
.
assignee_id
status_notify_and_comment
issue
,
:reassigned_issue_email
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
.
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
if
issue
.
closed_changed?
note
=
Note
.
new
(
:noteable
=>
issue
,
:project
=>
issue
.
project
)
# Create comment about status changed
if
target
.
closed_changed?
note
=
Note
.
new
(
:noteable
=>
target
,
:project
=>
target
.
project
)
note
.
author
=
current_user
note
.
note
=
"_Status changed to
#{
issue
.
closed
?
'closed'
:
'reopened'
}
_"
note
.
note
=
"_Status changed to
#{
target
.
closed
?
'closed'
:
'reopened'
}
_"
note
.
save
()
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