mirror of
https://github.com/discourse/discourse-chat-integration.git
synced 2025-02-16 16:34:50 +00:00
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_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'
|
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 ###########
|
######### TELEGRAM SETTINGS ###########
|
||||||
#######################################
|
#######################################
|
||||||
|
@ -12,8 +12,10 @@ plugins:
|
|||||||
#######################################
|
#######################################
|
||||||
chat_integration_slack_enabled:
|
chat_integration_slack_enabled:
|
||||||
default: false
|
default: false
|
||||||
|
validator: "ChatIntegrationSlackEnabledSettingValidator"
|
||||||
chat_integration_slack_outbound_webhook_url:
|
chat_integration_slack_outbound_webhook_url:
|
||||||
default: ''
|
default: ''
|
||||||
|
regex: '^https:\/\/hooks\.slack\.com\/services\/.+$'
|
||||||
chat_integration_slack_excerpt_length:
|
chat_integration_slack_excerpt_length:
|
||||||
default: 400
|
default: 400
|
||||||
chat_integration_slack_icon_url:
|
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
|
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
enabled_site_setting :chat_integration_enabled
|
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
|
after_initialize do
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user