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
448152ab
Commit
448152ab
authored
Mar 26, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use NotificationService for observers pt1
parent
f7e630c4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
17 deletions
+13
-17
app/observers/issue_observer.rb
app/observers/issue_observer.rb
+8
-16
app/observers/key_observer.rb
app/observers/key_observer.rb
+1
-1
app/observers/note_observer.rb
app/observers/note_observer.rb
+4
-0
No files found.
app/observers/issue_observer.rb
View file @
448152ab
...
@@ -2,41 +2,33 @@ class IssueObserver < ActiveRecord::Observer
...
@@ -2,41 +2,33 @@ class IssueObserver < ActiveRecord::Observer
cattr_accessor
:current_user
cattr_accessor
:current_user
def
after_create
(
issue
)
def
after_create
(
issue
)
if
issue
.
assignee
&&
issue
.
assignee
!=
current_user
notification
.
new_issue
(
issue
,
current_user
)
Notify
.
delay
.
new_issue_email
(
issue
.
id
)
end
end
end
def
after_close
(
issue
,
transition
)
def
after_close
(
issue
,
transition
)
send_reassigned_email
(
issue
)
if
issue
.
is_being_reassigned?
notification
.
close_issue
(
issue
,
current_user
)
create_note
(
issue
)
create_note
(
issue
)
end
end
def
after_reopen
(
issue
,
transition
)
def
after_reopen
(
issue
,
transition
)
send_reassigned_email
(
issue
)
if
issue
.
is_being_reassigned?
create_note
(
issue
)
create_note
(
issue
)
end
end
def
after_update
(
issue
)
def
after_update
(
issue
)
send_reassigned_email
(
issue
)
if
issue
.
is_being_reassigned?
if
issue
.
is_being_reassigned?
notification
.
reassigned_issue
(
issue
,
current_user
)
end
end
end
protected
protected
# Create issue note with service comment like 'Status changed to closed'
def
create_note
(
issue
)
def
create_note
(
issue
)
Note
.
create_status_change_note
(
issue
,
current_user
,
issue
.
state
)
Note
.
create_status_change_note
(
issue
,
current_user
,
issue
.
state
)
[
issue
.
author
,
issue
.
assignee
].
compact
.
uniq
.
each
do
|
recipient
|
Notify
.
delay
.
issue_status_changed_email
(
recipient
.
id
,
issue
.
id
,
issue
.
state
,
current_user
.
id
)
end
end
end
def
send_reassigned_email
(
issue
)
recipient_ids
=
[
issue
.
assignee_id
,
issue
.
assignee_id_was
].
keep_if
{
|
id
|
id
&&
id
!=
current_user
.
id
}
recipient_ids
.
each
do
|
recipient_id
|
def
notification
Notify
.
delay
.
reassigned_issue_email
(
recipient_id
,
issue
.
id
,
issue
.
assignee_id_was
)
NotificationService
.
new
end
end
end
end
end
app/observers/key_observer.rb
View file @
448152ab
...
@@ -9,7 +9,7 @@ class KeyObserver < ActiveRecord::Observer
...
@@ -9,7 +9,7 @@ class KeyObserver < ActiveRecord::Observer
)
)
# Notify about ssh key being added
# Notify about ssh key being added
Notif
y
.
delay
.
new_ssh_key_email
(
key
.
id
)
if
key
.
user
Notif
icationService
.
new
.
new_key
(
key
)
end
end
def
after_destroy
(
key
)
def
after_destroy
(
key
)
...
...
app/observers/note_observer.rb
View file @
448152ab
...
@@ -35,4 +35,8 @@ class NoteObserver < ActiveRecord::Observer
...
@@ -35,4 +35,8 @@ class NoteObserver < ActiveRecord::Observer
def
team_without_note_author
(
note
)
def
team_without_note_author
(
note
)
note
.
project
.
users
.
reject
{
|
u
|
u
.
id
==
note
.
author
.
id
}
note
.
project
.
users
.
reject
{
|
u
|
u
.
id
==
note
.
author
.
id
}
end
end
def
notification
NotificationService
.
new
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