Commit a54408b9ed65a02bce73bd3ce3eb689a05cd0a93

Authored by Dmitriy Zaporozhets
2 parents c355b9ab 31b0e149

Merge branch 'expose_visibility_in_project_create_service_hook' into 'master'

Expose project visibility in system service hooks

Our gitlab installation is currently setup with a system hook to ping our hubot. Currently whenever a project is created, hubot announces this, regardless of project visibility. It didn't really make sense for everyone to see this, and as the project visibility wasn't exposed in the JSON hook output, I thought I'd add it in!

As far as I'm aware, tests still run and pass OK. I'm not exactly rails savvy though, so any pointers/fixes/etc, please let me know!
app/services/system_hooks_service.rb
@@ -31,7 +31,8 @@ class SystemHooksService @@ -31,7 +31,8 @@ class SystemHooksService
31 path_with_namespace: model.path_with_namespace, 31 path_with_namespace: model.path_with_namespace,
32 project_id: model.id, 32 project_id: model.id,
33 owner_name: owner.name, 33 owner_name: owner.name,
34 - owner_email: owner.respond_to?(:email) ? owner.email : nil 34 + owner_email: owner.respond_to?(:email) ? owner.email : nil,
  35 + project_visibility: Project.visibility_levels.key(model.visibility_level_field).downcase
35 }) 36 })
36 when User 37 when User
37 data.merge!({ 38 data.merge!({
@@ -46,7 +47,8 @@ class SystemHooksService @@ -46,7 +47,8 @@ class SystemHooksService
46 project_id: model.project_id, 47 project_id: model.project_id,
47 user_name: model.user.name, 48 user_name: model.user.name,
48 user_email: model.user.email, 49 user_email: model.user.email,
49 - project_access: model.human_access 50 + project_access: model.human_access,
  51 + project_visibility: Project.visibility_levels.key(model.project.visibility_level_field).downcase
50 }) 52 })
51 end 53 end
52 end 54 end
doc/system_hooks/system_hooks.md
@@ -16,6 +16,7 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser @@ -16,6 +16,7 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser
16 "path": "stormcloud", 16 "path": "stormcloud",
17 "path_with_namespace": "jsmith/stormcloud", 17 "path_with_namespace": "jsmith/stormcloud",
18 "project_id": 74, 18 "project_id": 74,
  19 + "project_visibility": "private",
19 } 20 }
20 ``` 21 ```
21 22
@@ -31,6 +32,7 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser @@ -31,6 +32,7 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser
31 "path": "underscore", 32 "path": "underscore",
32 "path_with_namespace": "jsmith/underscore", 33 "path_with_namespace": "jsmith/underscore",
33 "project_id": 73, 34 "project_id": 73,
  35 + "project_visibility": "internal",
34 } 36 }
35 ``` 37 ```
36 38
@@ -38,14 +40,15 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser @@ -38,14 +40,15 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser
38 40
39 ```json 41 ```json
40 { 42 {
41 - "created_at": "2012-07-21T07:30:56Z",  
42 - "event_name": "user_add_to_team",  
43 - "project_access": "Master",  
44 - "project_id": 74,  
45 - "project_name": "StoreCloud",  
46 - "project_path": "storecloud",  
47 - "user_email": "johnsmith@gmail.com",  
48 - "user_name": "John Smith", 43 + "created_at": "2012-07-21T07:30:56Z",
  44 + "event_name": "user_add_to_team",
  45 + "project_access": "Master",
  46 + "project_id": 74,
  47 + "project_name": "StoreCloud",
  48 + "project_path": "storecloud",
  49 + "user_email": "johnsmith@gmail.com",
  50 + "user_name": "John Smith",
  51 + "project_visibility": "private",
49 } 52 }
50 ``` 53 ```
51 54
@@ -53,14 +56,15 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser @@ -53,14 +56,15 @@ System hooks can be used, e.g. for logging or changing information in a LDAP ser
53 56
54 ```json 57 ```json
55 { 58 {
56 - "created_at": "2012-07-21T07:30:56Z",  
57 - "event_name": "user_remove_from_team",  
58 - "project_access": "Master",  
59 - "project_id": 74,  
60 - "project_name": "StoreCloud",  
61 - "project_path": "storecloud",  
62 - "user_email": "johnsmith@gmail.com",  
63 - "user_name": "John Smith", 59 + "created_at": "2012-07-21T07:30:56Z",
  60 + "event_name": "user_remove_from_team",
  61 + "project_access": "Master",
  62 + "project_id": 74,
  63 + "project_name": "StoreCloud",
  64 + "project_path": "storecloud",
  65 + "user_email": "johnsmith@gmail.com",
  66 + "user_name": "John Smith",
  67 + "project_visibility": "private",
64 } 68 }
65 ``` 69 ```
66 70
spec/services/system_hooks_service_spec.rb
@@ -8,10 +8,10 @@ describe SystemHooksService do @@ -8,10 +8,10 @@ describe SystemHooksService do
8 context 'event data' do 8 context 'event data' do
9 it { event_data(user, :create).should include(:event_name, :name, :created_at, :email, :user_id) } 9 it { event_data(user, :create).should include(:event_name, :name, :created_at, :email, :user_id) }
10 it { event_data(user, :destroy).should include(:event_name, :name, :created_at, :email, :user_id) } 10 it { event_data(user, :destroy).should include(:event_name, :name, :created_at, :email, :user_id) }
11 - it { event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email) }  
12 - it { event_data(project, :destroy).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email) }  
13 - it { event_data(users_project, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access) }  
14 - it { event_data(users_project, :destroy).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access) } 11 + it { event_data(project, :create).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
  12 + it { event_data(project, :destroy).should include(:event_name, :name, :created_at, :path, :project_id, :owner_name, :owner_email, :project_visibility) }
  13 + it { event_data(users_project, :create).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access, :project_visibility) }
  14 + it { event_data(users_project, :destroy).should include(:event_name, :created_at, :project_name, :project_path, :project_id, :user_name, :user_email, :project_access, :project_visibility) }
15 end 15 end
16 16
17 context 'event names' do 17 context 'event names' do