Commit 57f8ecfc authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ccr/6274/add_weight_to_payload' into 'master'

Add weight to issue hook

Closes #6274

See merge request gitlab-org/gitlab-ee!6859
parents 0f978604 bda9bfb1
---
title: Add weight to issue hook
merge_request:
author:
type: fixed
# frozen_string_literal: true
module EE
module Gitlab
module HookData
module IssueBuilder
extend ActiveSupport::Concern
EE_SAFE_HOOK_ATTRIBUTES = %i[
weight
].freeze
class_methods do
extend ::Gitlab::Utils::Override
override :safe_hook_attributes
def safe_hook_attributes
super + EE_SAFE_HOOK_ATTRIBUTES
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::HookData::IssueBuilder do
set(:issue) { create(:issue) }
let(:builder) { described_class.new(issue) }
describe '#build' do
let(:data) { builder.build }
it 'includes safe attribute' do
%w[
assignee_id
author_id
closed_at
confidential
created_at
description
due_date
id
iid
last_edited_at
last_edited_by_id
milestone_id
moved_to_id
project_id
relative_position
state
time_estimate
title
updated_at
updated_by_id
weight
].each do |key|
expect(data).to include(key)
end
end
it 'includes additional attr' do
expect(data).to include(:weight)
end
context 'when the issue has an image in the description' do
let(:issue_with_description) { create(:issue, description: 'test![Issue_Image](/uploads/abc/Issue_Image.png)') }
let(:builder) { described_class.new(issue_with_description) }
it 'sets the image to use an absolute URL' do
expect(data[:description]).to eq("test![Issue_Image](#{Settings.gitlab.url}/uploads/abc/Issue_Image.png)")
end
end
end
end
......@@ -28,7 +28,7 @@ module Gitlab
end
def safe_keys
issuable_builder::SAFE_HOOK_ATTRIBUTES + issuable_builder::SAFE_HOOK_RELATIONS
issuable_builder.safe_hook_attributes + issuable_builder::SAFE_HOOK_RELATIONS
end
private
......
module Gitlab
module HookData
class IssueBuilder < BaseBuilder
SAFE_HOOK_ATTRIBUTES = %i[
assignee_id
author_id
closed_at
confidential
created_at
description
due_date
id
iid
last_edited_at
last_edited_by_id
milestone_id
moved_to_id
project_id
relative_position
state
time_estimate
title
updated_at
updated_by_id
].freeze
prepend ::EE::Gitlab::HookData::IssueBuilder
SAFE_HOOK_RELATIONS = %i[
assignees
......@@ -30,6 +9,31 @@ module Gitlab
total_time_spent
].freeze
def self.safe_hook_attributes
%i[
assignee_id
author_id
closed_at
confidential
created_at
description
due_date
id
iid
last_edited_at
last_edited_by_id
milestone_id
moved_to_id
project_id
relative_position
state
time_estimate
title
updated_at
updated_by_id
].freeze
end
alias_method :issue, :object
def build
......@@ -43,7 +47,7 @@ module Gitlab
assignee_id: issue.assignee_ids.first # This key is deprecated
}
issue.attributes.with_indifferent_access.slice(*SAFE_HOOK_ATTRIBUTES)
issue.attributes.with_indifferent_access.slice(*self.class.safe_hook_attributes)
.merge!(attrs)
end
end
......
module Gitlab
module HookData
class MergeRequestBuilder < BaseBuilder
SAFE_HOOK_ATTRIBUTES = %i[
assignee_id
author_id
created_at
description
head_pipeline_id
id
iid
last_edited_at
last_edited_by_id
merge_commit_sha
merge_error
merge_params
merge_status
merge_user_id
merge_when_pipeline_succeeds
milestone_id
source_branch
source_project_id
state
target_branch
target_project_id
time_estimate
title
updated_at
updated_by_id
].freeze
def self.safe_hook_attributes
%i[
assignee_id
author_id
created_at
description
head_pipeline_id
id
iid
last_edited_at
last_edited_by_id
merge_commit_sha
merge_error
merge_params
merge_status
merge_user_id
merge_when_pipeline_succeeds
milestone_id
source_branch
source_project_id
state
target_branch
target_project_id
time_estimate
title
updated_at
updated_by_id
].freeze
end
SAFE_HOOK_RELATIONS = %i[
assignee
......@@ -50,7 +52,7 @@ module Gitlab
human_time_estimate: merge_request.human_time_estimate
}
merge_request.attributes.with_indifferent_access.slice(*SAFE_HOOK_ATTRIBUTES)
merge_request.attributes.with_indifferent_access.slice(*self.class.safe_hook_attributes)
.merge!(attrs)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment