diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-02 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-02 18:09:37 +0300 |
commit | 1bdf79827c623cc92504223a1085f366115bbb3d (patch) | |
tree | 80ed68ac6c4fcb59bdd4735120da8e241f7f99a2 /app/services/system_hooks_service.rb | |
parent | 21e08b6197f192c983f8527f4bba1f2aaec8abf2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/system_hooks_service.rb')
-rw-r--r-- | app/services/system_hooks_service.rb | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb index 0d369c23b57..881a139437a 100644 --- a/app/services/system_hooks_service.rb +++ b/app/services/system_hooks_service.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class SystemHooksService + BUILDER_DRIVEN_EVENT_DATA_AVAILABLE_FOR_CLASSES = [GroupMember].freeze + def execute_hooks_for(model, event) data = build_event_data(model, event) @@ -20,6 +22,9 @@ class SystemHooksService private def build_event_data(model, event) + # return entire event data from its builder class, if available. + return builder_driven_event_data(model, event) if builder_driven_event_data_available?(model) + data = { event_name: build_event_name(model, event), created_at: model.created_at&.xmlschema, @@ -62,8 +67,6 @@ class SystemHooksService old_full_path: model.full_path_before_last_save ) end - when GroupMember - data.merge!(group_member_data(model)) end data @@ -75,10 +78,6 @@ class SystemHooksService return "user_add_to_team" if event == :create return "user_remove_from_team" if event == :destroy return "user_update_for_team" if event == :update - when GroupMember - return 'user_add_to_group' if event == :create - return 'user_remove_from_group' if event == :destroy - return 'user_update_for_group' if event == :update else "#{model.class.name.downcase}_#{event}" end @@ -128,19 +127,6 @@ class SystemHooksService } end - def group_member_data(model) - { - group_name: model.group.name, - group_path: model.group.path, - group_id: model.group.id, - user_username: model.user.username, - user_name: model.user.name, - user_email: model.user.email, - user_id: model.user.id, - group_access: model.human_access - } - end - def user_data(model) { name: model.name, @@ -149,6 +135,17 @@ class SystemHooksService username: model.username } end + + def builder_driven_event_data_available?(model) + model.class.in?(BUILDER_DRIVEN_EVENT_DATA_AVAILABLE_FOR_CLASSES) + end + + def builder_driven_event_data(model, event) + case model + when GroupMember + Gitlab::HookData::GroupMemberBuilder.new(model).build(event) + end + end end SystemHooksService.prepend_if_ee('EE::SystemHooksService') |