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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
d9cd6269
Commit
d9cd6269
authored
Jul 20, 2012
by
Valeriy Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
System Hooks: move callback to observer
parent
86bd11cb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
74 deletions
+69
-74
app/models/project.rb
app/models/project.rb
+0
-26
app/models/user.rb
app/models/user.rb
+1
-19
app/models/users_project.rb
app/models/users_project.rb
+0
-28
app/observers/system_hook_observer.rb
app/observers/system_hook_observer.rb
+67
-0
config/application.rb
config/application.rb
+1
-1
No files found.
app/models/project.rb
View file @
d9cd6269
...
...
@@ -107,32 +107,6 @@ class Project < ActiveRecord::Base
validate
:check_limit
validate
:repo_name
after_create
:create_hooks
after_destroy
:destroy_hooks
def
create_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"project_create"
,
name:
self
.
name
,
path:
self
.
path
,
project_id:
self
.
id
,
owner_name:
self
.
owner
.
name
,
owner_email:
self
.
owner
.
email
,
created_at:
self
.
created_at
})
end
def
destroy_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"project_destroy"
,
name:
self
.
name
,
path:
self
.
path
,
project_id:
self
.
id
,
owner_name:
self
.
owner
.
name
,
owner_email:
self
.
owner
.
email
,
})
end
def
check_limit
unless
owner
.
can_create_project?
errors
[
:base
]
<<
(
"Your own projects limit is
#{
owner
.
projects_limit
}
! Please contact administrator to increase it"
)
...
...
app/models/user.rb
View file @
d9cd6269
class
User
<
ActiveRecord
::
Base
include
Account
devise
:database_authenticatable
,
:token_authenticatable
,
:lockable
,
...
...
@@ -57,25 +58,6 @@ class User < ActiveRecord::Base
scope
:active
,
where
(
:blocked
=>
false
)
before_validation
:generate_password
,
:on
=>
:create
after_create
:create_hooks
after_destroy
:destroy_hooks
def
create_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_create"
,
name:
self
.
name
,
email:
self
.
email
,
created_at:
self
.
created_at
})
end
def
destroy_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_destroy"
,
name:
self
.
name
,
email:
self
.
email
})
end
def
generate_password
if
self
.
force_random_password
...
...
app/models/users_project.rb
View file @
d9cd6269
...
...
@@ -11,9 +11,6 @@ class UsersProject < ActiveRecord::Base
after_save
:update_repository
after_destroy
:update_repository
after_create
:add_to_team_hooks
after_destroy
:remove_from_team_hooks
validates_uniqueness_of
:user_id
,
:scope
=>
[
:project_id
]
validates_presence_of
:user_id
...
...
@@ -21,31 +18,6 @@ class UsersProject < ActiveRecord::Base
delegate
:name
,
:email
,
:to
=>
:user
,
:prefix
=>
true
def
add_to_team_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_add_to_team"
,
project_name:
self
.
project
.
name
,
project_path:
self
.
project
.
path
,
project_id:
self
.
project_id
,
user_name:
self
.
user
.
name
,
user_email:
self
.
user
.
email
,
project_access:
self
.
repo_access_human
,
created_at:
self
.
created_at
})
end
def
remove_from_team_hooks
SystemHook
.
all_hooks_fire
({
event_name:
"user_remove_from_team"
,
project_name:
self
.
project
.
name
,
project_path:
self
.
project
.
path
,
project_id:
self
.
project_id
,
user_name:
self
.
user
.
name
,
user_email:
self
.
user
.
email
,
project_access:
self
.
repo_access_human
})
end
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
)
UsersProject
.
transaction
do
user_ids
.
each
do
|
user_id
|
...
...
app/observers/system_hook_observer.rb
0 → 100644
View file @
d9cd6269
class
SystemHookObserver
<
ActiveRecord
::
Observer
observe
:user
,
:project
,
:users_project
def
after_create
(
model
)
if
model
.
kind_of?
Project
SystemHook
.
all_hooks_fire
({
event_name:
"project_create"
,
name:
model
.
name
,
path:
model
.
path
,
project_id:
model
.
id
,
owner_name:
model
.
owner
.
name
,
owner_email:
model
.
owner
.
email
,
created_at:
model
.
created_at
})
elsif
model
.
kind_of?
User
SystemHook
.
all_hooks_fire
({
event_name:
"user_create"
,
name:
model
.
name
,
email:
model
.
email
,
created_at:
model
.
created_at
})
elsif
model
.
kind_of?
UsersProject
SystemHook
.
all_hooks_fire
({
event_name:
"user_add_to_team"
,
project_name:
model
.
project
.
name
,
project_path:
model
.
project
.
path
,
project_id:
model
.
project_id
,
user_name:
model
.
user
.
name
,
user_email:
model
.
user
.
email
,
project_access:
model
.
repo_access_human
,
created_at:
model
.
created_at
})
end
end
def
after_destroy
(
model
)
if
model
.
kind_of?
Project
SystemHook
.
all_hooks_fire
({
event_name:
"project_destroy"
,
name:
model
.
name
,
path:
model
.
path
,
project_id:
model
.
id
,
owner_name:
model
.
owner
.
name
,
owner_email:
model
.
owner
.
email
,
})
elsif
model
.
kind_of?
User
SystemHook
.
all_hooks_fire
({
event_name:
"user_destroy"
,
name:
model
.
name
,
email:
model
.
email
})
elsif
model
.
kind_of?
UsersProject
SystemHook
.
all_hooks_fire
({
event_name:
"user_remove_from_team"
,
project_name:
model
.
project
.
name
,
project_path:
model
.
project
.
path
,
project_id:
model
.
project_id
,
user_name:
model
.
user
.
name
,
user_email:
model
.
user
.
email
,
project_access:
model
.
repo_access_human
})
end
end
end
config/application.rb
View file @
d9cd6269
...
...
@@ -23,7 +23,7 @@ module Gitlab
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
,
:project_observer
,
:key_observer
,
:issue_observer
,
:user_observer
config
.
active_record
.
observers
=
:mailer_observer
,
:activity_observer
,
:project_observer
,
:key_observer
,
:issue_observer
,
:user_observer
,
:system_hook_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