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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
7713f7fe
Commit
7713f7fe
authored
Dec 17, 2011
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notification refactoring
parent
f7859ec1
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
28 deletions
+55
-28
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+0
-1
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+5
-0
app/controllers/issues_controller.rb
app/controllers/issues_controller.rb
+1
-4
app/controllers/notes_controller.rb
app/controllers/notes_controller.rb
+2
-22
app/models/mailer_observer.rb
app/models/mailer_observer.rb
+41
-0
app/models/note.rb
app/models/note.rb
+5
-0
config/application.rb
config/application.rb
+1
-1
No files found.
app/controllers/admin/users_controller.rb
View file @
7713f7fe
...
...
@@ -27,7 +27,6 @@ class Admin::UsersController < ApplicationController
respond_to
do
|
format
|
if
@admin_user
.
save
Notify
.
new_user_email
(
@admin_user
,
params
[
:user
][
:password
]).
deliver
format
.
html
{
redirect_to
[
:admin
,
@admin_user
],
notice:
'User was successfully created.'
}
format
.
json
{
render
json:
@admin_user
,
status: :created
,
location:
@admin_user
}
else
...
...
app/controllers/application_controller.rb
View file @
7713f7fe
class
ApplicationController
<
ActionController
::
Base
before_filter
:authenticate_user!
before_filter
:set_current_user_for_mailer
protect_from_forgery
helper_method
:abilities
,
:can?
...
...
@@ -19,6 +20,10 @@ class ApplicationController < ActionController::Base
end
end
def
set_current_user_for_mailer
MailerObserver
.
current_user
=
current_user
end
def
abilities
@abilities
||=
Six
.
new
end
...
...
app/controllers/issues_controller.rb
View file @
7713f7fe
...
...
@@ -67,10 +67,7 @@ class IssuesController < ApplicationController
def
create
@issue
=
@project
.
issues
.
new
(
params
[
:issue
])
@issue
.
author
=
current_user
if
@issue
.
save
&&
@issue
.
assignee
!=
current_user
Notify
.
new_issue_email
(
@issue
).
deliver
end
@issue
.
save
respond_with
(
@issue
)
end
...
...
app/controllers/notes_controller.rb
View file @
7713f7fe
...
...
@@ -12,10 +12,8 @@ class NotesController < ApplicationController
def
create
@note
=
@project
.
notes
.
new
(
params
[
:note
])
@note
.
author
=
current_user
if
@note
.
save
notify
if
params
[
:notify
]
==
'1'
end
@note
.
notify
=
true
if
params
[
:notify
]
==
'1'
@note
.
save
respond_to
do
|
format
|
format
.
html
{
redirect_to
:back
}
...
...
@@ -35,22 +33,4 @@ class NotesController < ApplicationController
end
end
protected
def
notify
@project
.
users
.
reject
{
|
u
|
u
.
id
==
current_user
.
id
}
.
each
do
|
u
|
case
@note
.
noteable_type
when
"Commit"
then
Notify
.
note_commit_email
(
u
,
@note
).
deliver
when
"Issue"
then
Notify
.
note_issue_email
(
u
,
@note
).
deliver
when
"MergeRequest"
true
# someone should write email notification
when
"Snippet"
true
else
Notify
.
note_wall_email
(
u
,
@note
).
deliver
end
end
end
end
app/models/mailer_observer.rb
0 → 100644
View file @
7713f7fe
class
MailerObserver
<
ActiveRecord
::
Observer
observe
:issue
,
:user
,
:note
,
:snippet
cattr_accessor
:current_user
def
after_create
(
model
)
new_issue
(
model
)
if
model
.
kind_of?
(
Issue
)
new_user
(
model
)
if
model
.
kind_of?
(
User
)
new_note
(
model
)
if
model
.
kind_of?
(
Note
)
end
protected
def
new_issue
(
issue
)
if
issue
.
assignee
!=
current_user
Notify
.
new_issue_email
(
issue
).
deliver
end
end
def
new_user
(
user
)
Notify
.
new_user_email
(
user
,
user
.
password
).
deliver
end
def
new_note
(
note
)
return
unless
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
,
note
).
deliver
when
"Issue"
then
Notify
.
note_issue_email
(
u
,
note
).
deliver
when
"MergeRequest"
true
# someone should write email notification
when
"Snippet"
true
else
Notify
.
note_wall_email
(
u
,
note
).
deliver
end
end
end
end
app/models/note.rb
View file @
7713f7fe
...
...
@@ -13,6 +13,7 @@ class Note < ActiveRecord::Base
:prefix
=>
true
attr_protected
:author
,
:author_id
attr_accessor
:notify
validates_presence_of
:project
...
...
@@ -35,6 +36,10 @@ class Note < ActiveRecord::Base
scope
:inc_author
,
includes
(
:author
)
mount_uploader
:attachment
,
AttachmentUploader
def
notify
@notify
||=
false
end
end
# == Schema Information
#
...
...
config/application.rb
View file @
7713f7fe
...
...
@@ -23,7 +23,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum
_observer
config
.
active_record
.
observers
=
:mailer
_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.
...
...
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