set_system_information.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::System::SetSystemInformation < Service::Base
  3. # Setup basic system settigns
  4. #
  5. # @param [Hash] input basic settings
  6. # @option input [String] :url system URL to work out http type and FQDN from
  7. # @option input [String] :organization aka organization name
  8. # @option input [String] :locale_default optional locale name
  9. # @option input [String] :timezone_default optional timezone
  10. # @option input [String] :logo binary string of an image
  11. # @option input [String] :logo_resize binary string of an image
  12. #
  13. attr_reader :new_setting_data
  14. def initialize(data:)
  15. super()
  16. @new_settings = parse_data(data)
  17. end
  18. def execute
  19. update_settings
  20. end
  21. private
  22. def parse_data(kwargs)
  23. params = {}
  24. if !Setting.get('system_online_service')
  25. begin
  26. url_information = UrlInformation.new(kwargs[:url])
  27. params[:http_type] = url_information.scheme
  28. params[:fqdn] = url_information.fqdn
  29. rescue
  30. raise Exceptions::InvalidAttribute.new('url', __('Please include a valid url.'))
  31. end
  32. end
  33. raise Exceptions::MissingAttribute.new('organizaton', __("The required attribute 'organization' is missing.")) if kwargs[:organization].blank?
  34. params[:organization] = kwargs[:organization]
  35. params[:locale_default] = kwargs[:locale_default] if kwargs[:locale_default].present?
  36. params[:timezone_default] = kwargs[:timezone_default] if kwargs[:timezone_default].present?
  37. if (logo_timestamp = Service::SystemAssets::ProductLogo.store(kwargs[:logo], kwargs[:logo_resize]))
  38. params[:product_logo] = logo_timestamp
  39. end
  40. params
  41. end
  42. def update_settings
  43. @new_settings.each do |key, value|
  44. Setting.set(key, value)
  45. end
  46. end
  47. end