Skip to content
Snippets Groups Projects
Verified Commit d7380d0c authored by Heinrich Lee Yu's avatar Heinrich Lee Yu
Browse files

Remove unused widget service code

parent 2a7ad697
No related branches found
No related tags found
2 merge requests!170053Security patch upgrade alert: Only expose to admins 17-4,!163419Remove unused widget service code
......@@ -39,31 +39,6 @@ def handle_quick_actions(work_item)
handle_widget_quick_actions!(work_item)
end
def execute_widgets(work_item:, callback:, widget_params: {}, service_params: {})
work_item.widgets.each do |widget|
widget_service(widget, service_params).try(callback, params: widget_params[widget.class.api_symbol] || {})
end
end
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def widget_service(widget, service_params)
@widget_services ||= {}
return @widget_services[widget] if @widget_services.has_key?(widget)
@widget_services[widget] = widget_service_class(widget)&.new(
widget: widget,
current_user: current_user,
service_params: service_params
)
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
def widget_service_class(widget)
"WorkItems::Widgets::#{widget.type.to_s.camelize}Service::#{self.class.name.demodulize}".constantize
rescue NameError
nil
end
private
def new_type_excludes_widget?(widget, resource_parent)
......
......@@ -190,7 +190,6 @@ def create(issuable, skip_system_notes: false)
set_issuable_author(issuable)
handle_quick_actions(issuable)
prepare_create_params(issuable)
filter_params(issuable)
params.delete(:state_event)
......@@ -209,6 +208,7 @@ def create(issuable, skip_system_notes: false)
issuable_saved = issuable.with_transaction_returning_status do
@callbacks.each(&:before_create)
transaction_create(issuable)
end
......@@ -261,14 +261,6 @@ def before_update(issuable, skip_spam_check: false)
# To be overridden by subclasses
end
def prepare_update_params(issuable)
# To be overridden by subclasses
end
def prepare_create_params(issuable)
# To be overridden by subclasses
end
def after_update(issuable, old_associations)
handle_description_updated(issuable)
handle_label_changes(issuable, old_associations[:labels])
......@@ -287,7 +279,6 @@ def update(issuable)
old_associations = associations_before_update(issuable)
handle_quick_actions(issuable)
prepare_update_params(issuable)
filter_params(issuable)
change_additional_attributes(issuable)
......
......@@ -31,39 +31,6 @@ def execute(skip_system_notes: false)
error(e.message, :unprocessable_entity)
end
def before_create(work_item)
execute_widgets(
work_item: work_item,
callback: :before_create_callback,
widget_params: @widget_params
)
super
end
def transaction_create(work_item)
super.tap do |save_result|
if save_result
execute_widgets(
work_item: work_item,
callback: :after_create_in_transaction,
widget_params: @widget_params
)
end
end
end
def prepare_create_params(work_item)
execute_widgets(
work_item: work_item,
callback: :prepare_create_params,
widget_params: @widget_params,
service_params: params
)
super
end
def parent
container
end
......
......@@ -38,23 +38,6 @@ def handle_date_changes(work_item)
GraphqlTriggers.issuable_dates_updated(work_item)
end
def prepare_update_params(work_item)
execute_widgets(
work_item: work_item,
callback: :prepare_update_params,
widget_params: @widget_params,
service_params: params
)
super
end
def before_update(work_item, skip_spam_check: false)
execute_widgets(work_item: work_item, callback: :before_update_callback, widget_params: @widget_params)
super
end
override :associations_before_update
def associations_before_update(work_item)
super.merge(
......@@ -62,12 +45,6 @@ def associations_before_update(work_item)
)
end
def transaction_update(work_item, opts = {})
execute_widgets(work_item: work_item, callback: :before_update_in_transaction, widget_params: @widget_params)
super
end
override :after_update
def after_update(work_item, old_associations)
super
......
......@@ -89,14 +89,6 @@
it 'returns validation errors' do
expect(service_result.errors).to contain_exactly("Title can't be blank")
end
it 'does not execute after-create transaction widgets' do
expect(service).to receive(:create).and_call_original
expect(service).not_to receive(:execute_widgets)
.with(callback: :after_create_in_transaction, widget_params: widget_params)
service_result
end
end
context 'checking spam' do
......
......@@ -418,16 +418,6 @@
it 'returns validation errors' do
expect(update_work_item[:message]).to contain_exactly("Title can't be blank")
end
it 'does not execute after-update widgets', :aggregate_failures do
expect(service).to receive(:update).and_call_original
expect(service).not_to receive(:execute_widgets).with(callback: :update, widget_params: widget_params)
expect do
update_work_item
work_item.reload
end.not_to change(work_item, :description)
end
end
end
......@@ -560,14 +550,6 @@
it 'returns validation errors' do
expect(update_work_item[:message]).to contain_exactly("Title can't be blank")
end
it 'does not execute after-update widgets', :aggregate_failures do
expect(service).to receive(:update).and_call_original
expect(service).not_to receive(:execute_widgets).with(callback: :before_update_in_transaction, widget_params: widget_params)
expect(work_item.work_item_children).not_to include(child_work_item)
update_work_item
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment