2020-06-12 17:42:47 +00:00
|
|
|
class Integrations::App
|
|
|
|
attr_accessor :params
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def id
|
|
|
|
params[:id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
2020-11-30 10:54:54 +00:00
|
|
|
I18n.t("integration_apps.#{params[:i18n_key]}.name")
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2020-11-30 10:54:54 +00:00
|
|
|
I18n.t("integration_apps.#{params[:i18n_key]}.description")
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def logo
|
|
|
|
params[:logo]
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
params[:fields]
|
|
|
|
end
|
|
|
|
|
2020-06-22 07:49:26 +00:00
|
|
|
def action
|
|
|
|
case params[:id]
|
|
|
|
when 'slack'
|
2022-07-15 02:51:59 +00:00
|
|
|
"#{params[:action]}&client_id=#{ENV.fetch('SLACK_CLIENT_ID', nil)}&redirect_uri=#{self.class.slack_integration_url}"
|
2020-06-22 07:49:26 +00:00
|
|
|
else
|
|
|
|
params[:action]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def active?
|
|
|
|
case params[:id]
|
|
|
|
when 'slack'
|
|
|
|
ENV['SLACK_CLIENT_SECRET'].present?
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def enabled?(account)
|
2020-06-22 07:49:26 +00:00
|
|
|
case params[:id]
|
|
|
|
when 'slack'
|
2020-09-08 05:54:08 +00:00
|
|
|
account.hooks.exists?(app_id: id)
|
2020-06-22 07:49:26 +00:00
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def hooks
|
|
|
|
Current.account.hooks.where(app_id: id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.slack_integration_url
|
2022-07-15 02:51:59 +00:00
|
|
|
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/integrations/slack"
|
2020-06-12 17:42:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def apps
|
|
|
|
Hashie::Mash.new(APPS_CONFIG)
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
|
|
|
apps.values.each_with_object([]) do |app, result|
|
|
|
|
result << new(app)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find(params)
|
|
|
|
all.detect { |app| app.id == params[:id] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|