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
Léo-Paul Géneau
gitlab-ce
Commits
ce0945ef
Commit
ce0945ef
authored
Mar 26, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor observers. Added BaseObserver with helper methods
parent
6abf5846
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
26 additions
and
45 deletions
+26
-45
app/observers/base_observer.rb
app/observers/base_observer.rb
+11
-0
app/observers/issue_observer.rb
app/observers/issue_observer.rb
+1
-5
app/observers/key_observer.rb
app/observers/key_observer.rb
+2
-5
app/observers/merge_request_observer.rb
app/observers/merge_request_observer.rb
+1
-7
app/observers/note_observer.rb
app/observers/note_observer.rb
+1
-7
app/observers/project_observer.rb
app/observers/project_observer.rb
+1
-7
app/observers/system_hook_observer.rb
app/observers/system_hook_observer.rb
+1
-1
app/observers/user_observer.rb
app/observers/user_observer.rb
+1
-11
app/observers/users_project_observer.rb
app/observers/users_project_observer.rb
+7
-2
No files found.
app/observers/base_observer.rb
0 → 100644
View file @
ce0945ef
class
BaseObserver
<
ActiveRecord
::
Observer
protected
def
notification
NotificationService
.
new
end
def
log_info
message
Gitlab
::
AppLogger
.
info
message
end
end
app/observers/issue_observer.rb
View file @
ce0945ef
class
IssueObserver
<
ActiveRecord
::
Observer
class
IssueObserver
<
Base
Observer
cattr_accessor
:current_user
cattr_accessor
:current_user
def
after_create
(
issue
)
def
after_create
(
issue
)
...
@@ -27,8 +27,4 @@ class IssueObserver < ActiveRecord::Observer
...
@@ -27,8 +27,4 @@ class IssueObserver < ActiveRecord::Observer
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
)
end
end
def
notification
NotificationService
.
new
end
end
end
app/observers/key_observer.rb
View file @
ce0945ef
class
KeyObserver
<
ActiveRecord
::
Observer
class
KeyObserver
<
BaseObserver
include
Gitlab
::
ShellAdapter
def
after_save
(
key
)
def
after_save
(
key
)
GitlabShellWorker
.
perform_async
(
GitlabShellWorker
.
perform_async
(
:add_key
,
:add_key
,
...
@@ -8,8 +6,7 @@ class KeyObserver < ActiveRecord::Observer
...
@@ -8,8 +6,7 @@ class KeyObserver < ActiveRecord::Observer
key
.
key
key
.
key
)
)
# Notify about ssh key being added
notification
.
new_key
(
key
)
NotificationService
.
new
.
new_key
(
key
)
end
end
def
after_destroy
(
key
)
def
after_destroy
(
key
)
...
...
app/observers/merge_request_observer.rb
View file @
ce0945ef
class
MergeRequestObserver
<
ActiveRecord
::
Observer
class
MergeRequestObserver
<
Base
Observer
cattr_accessor
:current_user
cattr_accessor
:current_user
def
after_create
(
merge_request
)
def
after_create
(
merge_request
)
...
@@ -16,10 +16,4 @@ class MergeRequestObserver < ActiveRecord::Observer
...
@@ -16,10 +16,4 @@ class MergeRequestObserver < ActiveRecord::Observer
def
after_update
(
merge_request
)
def
after_update
(
merge_request
)
notification
.
reassigned_merge_request
(
merge_request
)
if
merge_request
.
is_being_reassigned?
notification
.
reassigned_merge_request
(
merge_request
)
if
merge_request
.
is_being_reassigned?
end
end
protected
def
notification
NotificationService
.
new
end
end
end
app/observers/note_observer.rb
View file @
ce0945ef
class
NoteObserver
<
ActiveRecord
::
Observer
class
NoteObserver
<
Base
Observer
def
after_create
(
note
)
def
after_create
(
note
)
notification
.
new_note
(
note
)
notification
.
new_note
(
note
)
end
end
protected
def
notification
NotificationService
.
new
end
end
end
app/observers/project_observer.rb
View file @
ce0945ef
class
ProjectObserver
<
ActiveRecord
::
Observer
class
ProjectObserver
<
Base
Observer
def
after_create
(
project
)
def
after_create
(
project
)
GitlabShellWorker
.
perform_async
(
GitlabShellWorker
.
perform_async
(
:add_repository
,
:add_repository
,
...
@@ -27,10 +27,4 @@ class ProjectObserver < ActiveRecord::Observer
...
@@ -27,10 +27,4 @@ class ProjectObserver < ActiveRecord::Observer
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
log_info
(
"Project
\"
#{
project
.
name
}
\"
was removed"
)
end
end
protected
def
log_info
message
Gitlab
::
AppLogger
.
info
message
end
end
end
app/observers/system_hook_observer.rb
View file @
ce0945ef
class
SystemHookObserver
<
ActiveRecord
::
Observer
class
SystemHookObserver
<
Base
Observer
observe
:user
,
:project
,
:users_project
observe
:user
,
:project
,
:users_project
def
after_create
(
model
)
def
after_create
(
model
)
...
...
app/observers/user_observer.rb
View file @
ce0945ef
class
UserObserver
<
ActiveRecord
::
Observer
class
UserObserver
<
Base
Observer
def
after_create
(
user
)
def
after_create
(
user
)
log_info
(
"User
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
) was created"
)
log_info
(
"User
\"
#{
user
.
name
}
\"
(
#{
user
.
email
}
) was created"
)
...
@@ -18,14 +18,4 @@ class UserObserver < ActiveRecord::Observer
...
@@ -18,14 +18,4 @@ class UserObserver < ActiveRecord::Observer
end
end
end
end
end
end
protected
def
log_info
message
Gitlab
::
AppLogger
.
info
message
end
def
notification
NotificationService
.
new
end
end
end
app/observers/users_project_observer.rb
View file @
ce0945ef
class
UsersProjectObserver
<
ActiveRecord
::
Observer
class
UsersProjectObserver
<
Base
Observer
def
after_commit
(
users_project
)
def
after_commit
(
users_project
)
return
if
users_project
.
destroyed?
return
if
users_project
.
destroyed?
Notify
.
delay
.
project_access_granted_email
(
users_project
.
id
)
end
end
def
after_create
(
users_project
)
def
after_create
(
users_project
)
...
@@ -10,6 +9,12 @@ class UsersProjectObserver < ActiveRecord::Observer
...
@@ -10,6 +9,12 @@ class UsersProjectObserver < ActiveRecord::Observer
action:
Event
::
JOINED
,
action:
Event
::
JOINED
,
author_id:
users_project
.
user
.
id
author_id:
users_project
.
user
.
id
)
)
notification
.
new_team_member
(
users_project
)
end
def
after_update
(
users_project
)
notification
.
update_team_member
(
users_project
)
end
end
def
after_destroy
(
users_project
)
def
after_destroy
(
users_project
)
...
...
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