2022-08-13 15:12:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module WorkItems
|
|
|
|
module Widgets
|
|
|
|
class BaseService < ::BaseService
|
|
|
|
WidgetError = Class.new(StandardError)
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
attr_reader :widget, :work_item, :current_user, :service_params
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
def initialize(widget:, current_user:, service_params: {})
|
2022-08-13 15:12:31 +05:30
|
|
|
@widget = widget
|
2022-08-27 11:52:29 +05:30
|
|
|
@work_item = widget.work_item
|
2022-08-13 15:12:31 +05:30
|
|
|
@current_user = current_user
|
2022-11-25 23:54:43 +05:30
|
|
|
@service_params = service_params
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def new_type_excludes_widget?
|
|
|
|
return false unless service_params[:work_item_type]
|
|
|
|
|
|
|
|
service_params[:work_item_type].widgets.exclude?(@widget.class)
|
|
|
|
end
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
def has_permission?(permission)
|
|
|
|
can?(current_user, permission, widget.work_item)
|
|
|
|
end
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
def service_response!(result)
|
|
|
|
return result unless result[:status] == :error
|
|
|
|
|
|
|
|
raise WidgetError, result[:message]
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|