Add validation to slack settings (adapted from old slack plugin)
This commit is contained in:
parent
1c416d5a81
commit
f40f602a4f
|
@ -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 ###########
|
||||
#######################################
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue