2021-11-09 18:13:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Integrations
|
|
|
|
class Shimo < Integration
|
|
|
|
prop_accessor :external_wiki_url
|
|
|
|
validates :external_wiki_url, presence: true, public_url: true, if: :activated?
|
|
|
|
|
2021-11-18 18:14:27 +00:00
|
|
|
after_commit :cache_project_has_shimo
|
|
|
|
|
2021-11-09 18:13:13 +00:00
|
|
|
def render?
|
2021-11-18 18:14:27 +00:00
|
|
|
return false unless Feature.enabled?(:shimo_integration, project)
|
|
|
|
|
2021-11-09 18:13:13 +00:00
|
|
|
valid? && activated?
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
s_('Shimo|Shimo')
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
s_('Shimo|Link to a Shimo Workspace from the sidebar.')
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.to_param
|
|
|
|
'shimo'
|
|
|
|
end
|
|
|
|
|
|
|
|
# support for `test` method
|
|
|
|
def execute(_data)
|
|
|
|
response = Gitlab::HTTP.get(properties['external_wiki_url'], verify: true, use_read_total_timeout: true)
|
|
|
|
response.body if response.code == 200
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.supported_events
|
|
|
|
%w()
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
name: 'external_wiki_url',
|
|
|
|
title: s_('Shimo|Shimo Workspace URL'),
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2021-11-18 18:14:27 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def cache_project_has_shimo
|
|
|
|
return unless project && !project.destroyed?
|
|
|
|
|
|
|
|
project.project_setting.save! unless project.project_setting.persisted?
|
|
|
|
project.project_setting.update_column(:has_shimo, activated?)
|
|
|
|
end
|
2021-11-09 18:13:13 +00:00
|
|
|
end
|
|
|
|
end
|