Add validation to slack settings (adapted from old slack plugin)

This commit is contained in:
David Taylor 2017-07-03 16:28:26 +01:00
parent 1c416d5a81
commit f40f602a4f
4 changed files with 23 additions and 0 deletions

View File

@ -14,6 +14,9 @@ en:
chat_integration_slack_icon_url: 'Icon to post to slack with (defaults to forum logo)'
chat_integration_slack_access_token: 'Token if you are using the Web API instead of webhooks'
errors:
chat_integration_slack_api_configs_are_empty: "You must enter either an outbound webhook URL, or an access token"
#######################################
######### TELEGRAM SETTINGS ###########
#######################################

View File

@ -12,8 +12,10 @@ plugins:
#######################################
chat_integration_slack_enabled:
default: false
validator: "ChatIntegrationSlackEnabledSettingValidator"
chat_integration_slack_outbound_webhook_url:
default: ''
regex: '^https:\/\/hooks\.slack\.com\/services\/.+$'
chat_integration_slack_excerpt_length:
default: 400
chat_integration_slack_icon_url:

View File

@ -0,0 +1,16 @@
class ChatIntegrationSlackEnabledSettingValidator
def initialize(opts={})
@opts = opts
end
def valid_value?(val)
return true if val == 'f'
return false if SiteSetting.chat_integration_slack_outbound_webhook_url.blank? && SiteSetting.chat_integration_slack_access_token.blank?
true
end
def error_message
I18n.t('site_settings.errors.chat_integration_slack_api_configs_are_empty')
end
end

View File

@ -5,6 +5,8 @@
enabled_site_setting :chat_integration_enabled
# Site setting validators must be loaded before initialize
require_relative "lib/validators/chat_integration_slack_enabled_setting_validator"
after_initialize do